Commit c5fa0c21 authored by huanglu's avatar huanglu

feat: 优化

parent f84c6a1b
...@@ -14,4 +14,8 @@ export default class HomeController extends Controller { ...@@ -14,4 +14,8 @@ export default class HomeController extends Controller {
const { ctx } = this; const { ctx } = this;
await ctx.service.account.login(); await ctx.service.account.login();
} }
public async homePage() {
// const { ctx } = this;
// await ctx.render('')
}
} }
import { Controller } from 'egg';
export default class Person extends Controller {
public async index() {
const { ctx } = this;
await ctx.render('person');
}
}
export default {
get mongo() {
return (this as any).ctx.model;
},
};
export default {
get mongo() {
return (this as any).app.mongo;
},
};
import { Application } from 'egg'; import { Application } from 'egg';
export default (app: Application, path = '/home') => { export default (app: Application) => {
const { router, controller } = app; const { router, controller } = app;
const homeRouter = router.namespace(path); const homeRouter = router.namespace('/home');
homeRouter.get('', controller.home.index); homeRouter.get('/', controller.home.index);
router.redirect('/', '/home/index');
}; };
import { Application } from 'egg';
export default (app: Application) => {
const { router, controller } = app;
const homeRouter = router.namespace('/person');
homeRouter.get('/', controller.home.index);
router.redirect('/', '/home/index');
};
...@@ -9,7 +9,6 @@ export default class Account extends Service { ...@@ -9,7 +9,6 @@ export default class Account extends Service {
const { pwd, name, age } = ctx.request.body; const { pwd, name, age } = ctx.request.body;
const token = ctx.token; const token = ctx.token;
const hashName = await ctx.genHash(pwd); const hashName = await ctx.genHash(pwd);
// const origin = await ctx.compare(pwd, hashName);
logger.info('login: ', { pwd, name, age }); logger.info('login: ', { pwd, name, age });
const user = await ctx.model.User.create({ const user = await ctx.model.User.create({
name, name,
......
...@@ -5,20 +5,24 @@ ...@@ -5,20 +5,24 @@
<link rel="icon" href="https://geek.jkwljy.com/signin/favicon.ico"> <link rel="icon" href="https://geek.jkwljy.com/signin/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title> <title>Document</title>
<meta name="" {% block styles %}
{% endblock %}
</head> </head>
<body> <body>
{% block header %} <div class="wrap">
This is the default content {% block header %}
{% endblock %} This is the default content
{% endblock %}
<section class="left"> <section class="left">
{% block left %}{% endblock %} {% block left %}{% endblock %}
</section> </section>
<section class="right"> <section class="right">
{% block right %} {% block right %}
{% endblock %} {% endblock %}
</section> </section>
</div>
</body> </body>
</html> </html>
\ No newline at end of file
{% extends "./base.html" %}
{% block header %}
<div class="">
</div>
{% endblock %}
\ No newline at end of file
<template>
<div> this is home page </div>
</template>
<script>
export default {
components: {},
data() {
return {};
},
methods: {
},
mounted() {
}
}
</script>
<style>
</style>
\ No newline at end of file
<!DOCTYPE html>
<html lang='en'>
<head>
<title>easyjs</title>
<meta name='keywords'>
<meta name='description'>
<meta http-equiv='content-type' content='text/html;charset=utf-8'>
<meta name='viewport' content='initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui'>
<link rel='shortcut icon' href='/favicon.ico' type='image/x-icon' />
</head>
<body>
<div id='app'><!--vue-ssr-outlet--></div>
</body>
</html>
\ No newline at end of file
import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg'; import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
import path = require('path');
export default (appInfo: EggAppInfo) => { export default (appInfo: EggAppInfo) => {
const config = {} as PowerPartial<EggAppConfig>; const config = {} as PowerPartial<EggAppConfig>;
...@@ -8,6 +9,8 @@ export default (appInfo: EggAppInfo) => { ...@@ -8,6 +9,8 @@ export default (appInfo: EggAppInfo) => {
defaultViewEngine: 'nunjucks', defaultViewEngine: 'nunjucks',
mapping: { mapping: {
'.html': 'nunjucks', '.html': 'nunjucks',
'.js': 'assets',
'.css': 'assets',
}, },
cache: false, cache: false,
trimBlocks: true, trimBlocks: true,
...@@ -23,6 +26,13 @@ export default (appInfo: EggAppInfo) => { ...@@ -23,6 +26,13 @@ export default (appInfo: EggAppInfo) => {
bcrypt: { bcrypt: {
saltRounds: 10, saltRounds: 10,
}, },
vuessr: {
layout: path.join(appInfo.baseDir, 'app/web/view/layout.html'),
// manifest: path.join(appInfo.baseDir, 'config/manifest.json'),
renderOptions: {
basedir: path.join(appInfo.baseDir, 'app/view/pages'),
},
},
}; };
config.jwt = { // jwt配置项 config.jwt = { // jwt配置项
secret: 'geek_jwt', secret: 'geek_jwt',
......
...@@ -25,6 +25,18 @@ const plugin: EggPlugin = { ...@@ -25,6 +25,18 @@ const plugin: EggPlugin = {
enable: true, enable: true,
package: 'egg-mongoose', package: 'egg-mongoose',
}, },
// assets: {
// enable: true,
// package: 'egg-view-assets',
// },
vuessr: {
enable: true,
package: 'egg-view-vue-ssr',
},
// mysql: {
// enable: true,
// package: 'egg-mysql',
// },
}; };
export default plugin; export default plugin;
...@@ -26,12 +26,19 @@ ...@@ -26,12 +26,19 @@
"egg-bcrypt": "^1.1.0", "egg-bcrypt": "^1.1.0",
"egg-jwt": "^3.1.7", "egg-jwt": "^3.1.7",
"egg-mongoose": "^3.2.0", "egg-mongoose": "^3.2.0",
"egg-mysql": "^3.0.0",
"egg-router-plus": "^1.3.1", "egg-router-plus": "^1.3.1",
"egg-scripts": "^2.6.0", "egg-scripts": "^2.6.0",
"egg-validate": "^2.0.2", "egg-validate": "^2.0.2",
"egg-view-assets": "^1.6.1",
"egg-view-nunjucks": "^2.2.0", "egg-view-nunjucks": "^2.2.0",
"egg-view-vue-ssr": "^3.3.2",
"moment": "^2.27.0", "moment": "^2.27.0",
"path-to-regexp": "^6.1.0" "path-to-regexp": "^6.1.0",
"shortid": "^2.2.15",
"vue": "^2.6.11",
"vue-router": "^3.3.4",
"vuex-router-sync": "^5.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/mocha": "^2.2.40", "@types/mocha": "^2.2.40",
......
...@@ -3,11 +3,13 @@ ...@@ -3,11 +3,13 @@
import 'egg'; import 'egg';
import ExportHome from '../../../app/controller/home'; import ExportHome from '../../../app/controller/home';
import ExportPerson from '../../../app/controller/person';
import ExportPublic from '../../../app/controller/public'; import ExportPublic from '../../../app/controller/public';
declare module 'egg' { declare module 'egg' {
interface IController { interface IController {
home: ExportHome; home: ExportHome;
person: ExportPerson;
public: ExportPublic; public: ExportPublic;
} }
} }
// This file is created by egg-ts-helper@1.25.8
// Do not modify this file!!!!!!!!!
import 'egg';
import ExtendApplication from '../../../app/extend/application';
type ExtendApplicationType = typeof ExtendApplication;
declare module 'egg' {
interface Application extends ExtendApplicationType { }
}
\ No newline at end of file
// This file is created by egg-ts-helper@1.25.8
// Do not modify this file!!!!!!!!!
import 'egg';
import ExtendContext from '../../../app/extend/context';
type ExtendContextType = typeof ExtendContext;
declare module 'egg' {
interface Context extends ExtendContextType { }
}
\ No newline at end of file
...@@ -20,6 +20,7 @@ import 'egg-jwt'; ...@@ -20,6 +20,7 @@ import 'egg-jwt';
import 'egg-validate'; import 'egg-validate';
import 'egg-bcrypt'; import 'egg-bcrypt';
import 'egg-mongoose'; import 'egg-mongoose';
import 'egg-view-vue-ssr';
import { EggPluginItem } from 'egg'; import { EggPluginItem } from 'egg';
declare module 'egg' { declare module 'egg' {
interface EggPlugin { interface EggPlugin {
...@@ -41,5 +42,6 @@ declare module 'egg' { ...@@ -41,5 +42,6 @@ declare module 'egg' {
validate?: EggPluginItem; validate?: EggPluginItem;
bcrypt?: EggPluginItem; bcrypt?: EggPluginItem;
mongoose?: EggPluginItem; mongoose?: EggPluginItem;
vuessr?: EggPluginItem;
} }
} }
\ No newline at end of file
import 'egg'; import 'egg';
import { Application, Application } from 'egg'; import { Application, Application } from 'egg';
declare module 'egg' { declare module 'egg' {
interface Application { interface Application {
jwt: any jwt: any
genHash: function(string): Promise<string> genHash: function(string): Promise<string>
compare: function(string, string): Promise<string> compare: function(string, string): Promise<string>
helper: {
formatTime: Function
success: function ({ res: any, msg: string }): any
http: function ({ config: {} }): {
get: (url: string, params: any, options?: any) => Promise<any>
post: (url: string, params: any, options?: any) => Promise<any>
}
}
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment