Commit c5fa0c21 authored by huanglu's avatar huanglu

feat: 优化

parent f84c6a1b
......@@ -14,4 +14,8 @@ export default class HomeController extends Controller {
const { ctx } = this;
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';
export default (app: Application, path = '/home') => {
export default (app: Application) => {
const { router, controller } = app;
const homeRouter = router.namespace(path);
homeRouter.get('', controller.home.index);
const homeRouter = router.namespace('/home');
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 {
const { pwd, name, age } = ctx.request.body;
const token = ctx.token;
const hashName = await ctx.genHash(pwd);
// const origin = await ctx.compare(pwd, hashName);
logger.info('login: ', { pwd, name, age });
const user = await ctx.model.User.create({
name,
......
......@@ -5,20 +5,24 @@
<link rel="icon" href="https://geek.jkwljy.com/signin/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<meta name=""
{% block styles %}
{% endblock %}
</head>
<body>
{% block header %}
This is the default content
{% endblock %}
<div class="wrap">
{% block header %}
This is the default content
{% endblock %}
<section class="left">
{% block left %}{% endblock %}
</section>
<section class="left">
{% block left %}{% endblock %}
</section>
<section class="right">
{% block right %}
{% endblock %}
</section>
<section class="right">
{% block right %}
{% endblock %}
</section>
</div>
</body>
</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 path = require('path');
export default (appInfo: EggAppInfo) => {
const config = {} as PowerPartial<EggAppConfig>;
......@@ -8,6 +9,8 @@ export default (appInfo: EggAppInfo) => {
defaultViewEngine: 'nunjucks',
mapping: {
'.html': 'nunjucks',
'.js': 'assets',
'.css': 'assets',
},
cache: false,
trimBlocks: true,
......@@ -23,6 +26,13 @@ export default (appInfo: EggAppInfo) => {
bcrypt: {
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配置项
secret: 'geek_jwt',
......
......@@ -25,6 +25,18 @@ const plugin: EggPlugin = {
enable: true,
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;
......@@ -26,12 +26,19 @@
"egg-bcrypt": "^1.1.0",
"egg-jwt": "^3.1.7",
"egg-mongoose": "^3.2.0",
"egg-mysql": "^3.0.0",
"egg-router-plus": "^1.3.1",
"egg-scripts": "^2.6.0",
"egg-validate": "^2.0.2",
"egg-view-assets": "^1.6.1",
"egg-view-nunjucks": "^2.2.0",
"egg-view-vue-ssr": "^3.3.2",
"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": {
"@types/mocha": "^2.2.40",
......
......@@ -3,11 +3,13 @@
import 'egg';
import ExportHome from '../../../app/controller/home';
import ExportPerson from '../../../app/controller/person';
import ExportPublic from '../../../app/controller/public';
declare module 'egg' {
interface IController {
home: ExportHome;
person: ExportPerson;
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';
import 'egg-validate';
import 'egg-bcrypt';
import 'egg-mongoose';
import 'egg-view-vue-ssr';
import { EggPluginItem } from 'egg';
declare module 'egg' {
interface EggPlugin {
......@@ -41,5 +42,6 @@ declare module 'egg' {
validate?: EggPluginItem;
bcrypt?: EggPluginItem;
mongoose?: EggPluginItem;
vuessr?: EggPluginItem;
}
}
\ No newline at end of file
import 'egg';
import { Application, Application } from 'egg';
declare module 'egg' {
interface Application {
jwt: any
genHash: function(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