@zhangnpm302/elpis 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +3 -0
- package/.eslintrc +67 -0
- package/.gitattributes +1 -0
- package/README.md +2 -3
- package/app/controller/base.js +39 -0
- package/app/controller/project.js +100 -0
- package/app/controller/view.js +21 -0
- package/app/extend/logger.js +36 -0
- package/app/middleware/api-params-verify.js +85 -0
- package/app/middleware/api-sign-verify.js +32 -0
- package/app/middleware/error-handler.js +35 -0
- package/app/middleware/project-handler.js +31 -0
- package/app/middleware.js +40 -0
- package/app/pages/assets/custom.css +11 -0
- package/app/pages/boot.js +50 -0
- package/app/pages/common/curl.js +88 -0
- package/app/pages/common/utils.js +5 -0
- package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +28 -0
- package/app/pages/dashboard/complex-view/header-view/header-view.vue +125 -0
- package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +48 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +42 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/table-panel.vue +157 -0
- package/app/pages/dashboard/complex-view/schema-view/components/component.config.js +24 -0
- package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +122 -0
- package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +118 -0
- package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +150 -0
- package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +184 -0
- package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +120 -0
- package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +30 -0
- package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +132 -0
- package/app/pages/dashboard/dashboard.vue +100 -0
- package/app/pages/dashboard/entry.dashboard.js +52 -0
- package/app/pages/dashboard/readme.md +4 -0
- package/app/pages/store/index.js +5 -0
- package/app/pages/store/menu.js +61 -0
- package/app/pages/store/project.js +18 -0
- package/app/pages/widgets/header-container/asserts/avatar.png +0 -0
- package/app/pages/widgets/header-container/asserts/logo.png +0 -0
- package/app/pages/widgets/header-container/header-container.vue +105 -0
- package/app/pages/widgets/schema-form/complex-view/input/input.vue +143 -0
- package/app/pages/widgets/schema-form/complex-view/input-number/input-number.vue +143 -0
- package/app/pages/widgets/schema-form/complex-view/select/select.vue +133 -0
- package/app/pages/widgets/schema-form/form-item-config.js +25 -0
- package/app/pages/widgets/schema-form/schema-form.vue +152 -0
- package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +63 -0
- package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +85 -0
- package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +59 -0
- package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +66 -0
- package/app/pages/widgets/schema-search-bar/schema-config.js +30 -0
- package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +145 -0
- package/app/pages/widgets/schema-table/schema-table.vue +275 -0
- package/app/pages/widgets/sider-container/sider-container.vue +29 -0
- package/app/router/project.js +11 -0
- package/app/router/view.js +9 -0
- package/app/router-schema/project.js +55 -0
- package/app/service/base.js +12 -0
- package/app/service/project.js +78 -0
- package/app/view/entry.tpl +29 -0
- package/app/webpack/config/webpack.base.js +223 -0
- package/app/webpack/config/webpack.dev.js +59 -0
- package/app/webpack/config/webpack.prod.js +128 -0
- package/app/webpack/dev.js +60 -0
- package/app/webpack/libs/blank.js +1 -0
- package/app/webpack/prod.js +22 -0
- package/config/config.default.js +4 -0
- package/docs/dashboard-model.js +193 -0
- package/elpis-core/env.js +24 -0
- package/elpis-core/index.js +95 -0
- package/elpis-core/loader/config.js +66 -0
- package/elpis-core/loader/controller.js +74 -0
- package/elpis-core/loader/extend.js +62 -0
- package/elpis-core/loader/middleware.js +74 -0
- package/elpis-core/loader/router-schema.js +50 -0
- package/elpis-core/loader/router.js +50 -0
- package/elpis-core/loader/service.js +69 -0
- package/index.js +48 -0
- package/model/business/model.js +210 -0
- package/model/business/project/jd.js +62 -0
- package/model/business/project/pdd.js +86 -0
- package/model/business/project/taobao.js +45 -0
- package/model/course/model.js +21 -0
- package/model/course/project/bilibili.js +49 -0
- package/model/course/project/douyin.js +29 -0
- package/model/demo.json +246 -0
- package/model/index.js +153 -0
- package/package.json +103 -4
- package/test/controller/project.test.js +220 -0
- package/testmain/project.test.js +228 -0
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"plugin:vue/base",
|
|
4
|
+
"plugin:vue/recommended"
|
|
5
|
+
],
|
|
6
|
+
"plugins": ["vue"],
|
|
7
|
+
"env": {
|
|
8
|
+
"browser": true,
|
|
9
|
+
"node": true
|
|
10
|
+
},
|
|
11
|
+
"parser": "vue-eslint-parser",
|
|
12
|
+
"parserOptions": {
|
|
13
|
+
"parser": "babel-eslint",
|
|
14
|
+
"ecmaVersion": 2017,
|
|
15
|
+
"sourceType": "module"
|
|
16
|
+
},
|
|
17
|
+
"rules": {
|
|
18
|
+
"no-unused-vars": [2, {"args": "none"}],
|
|
19
|
+
"strict": "off",
|
|
20
|
+
"valid-jsdoc": "off",
|
|
21
|
+
"jsdoc/require-param-description": "off",
|
|
22
|
+
"jsdoc/require-param-type": "off",
|
|
23
|
+
"jsdoc/check-param-names": "off",
|
|
24
|
+
"jsdoc/require-param": "off",
|
|
25
|
+
"jsdoc/check-tag-names": "off",
|
|
26
|
+
"linebreak-style": "off",
|
|
27
|
+
"array-bracket-spacing": "off",
|
|
28
|
+
"prefer-promise-reject-errors": "off",
|
|
29
|
+
"comma-dangle": "off",
|
|
30
|
+
"newline-per-chained-call": "off",
|
|
31
|
+
"no-loop-func": "off",
|
|
32
|
+
"no-empty": "off",
|
|
33
|
+
"no-else-return": "off",
|
|
34
|
+
"no-unneeded-ternary": "off",
|
|
35
|
+
"no-eval": "off",
|
|
36
|
+
"prefer-destructuring": "off",
|
|
37
|
+
"no-param-reassign": "off",
|
|
38
|
+
"max-len": "off",
|
|
39
|
+
"no-restricted-syntax": "off",
|
|
40
|
+
"no-plusplus": "off",
|
|
41
|
+
"no-useless-escape": "off",
|
|
42
|
+
"no-nested-ternary": "off",
|
|
43
|
+
"radix": "off",
|
|
44
|
+
"arrow-body-style": "off",
|
|
45
|
+
"arrow-parens": "off",
|
|
46
|
+
"vue/multi-word-component-names": "off",
|
|
47
|
+
"vue/valid-v-for": "off",
|
|
48
|
+
"vue/no-multiple-template-root": "off",
|
|
49
|
+
// 可以闭合
|
|
50
|
+
"vue/html-self-closing": "off",
|
|
51
|
+
"vue/attributes-order": "off",
|
|
52
|
+
"vue/max-attributes-per-line": "off",
|
|
53
|
+
// 关闭属性换行规则
|
|
54
|
+
"vue/singleline-html-element-content-newline": "off",
|
|
55
|
+
// 关闭属性连字符校验(允许驼峰 :menuItem)
|
|
56
|
+
"vue/attribute-hyphenation": "off",
|
|
57
|
+
// 关闭多行标签内容换行校验(允许任意空行)
|
|
58
|
+
"vue/multiline-html-element-content-newline": "off",
|
|
59
|
+
"vue/require-default-prop": "off",
|
|
60
|
+
"vue/require-prop-types": "off"
|
|
61
|
+
},
|
|
62
|
+
"globals": {
|
|
63
|
+
"$": true,
|
|
64
|
+
"axios": true,
|
|
65
|
+
"Vue": true
|
|
66
|
+
}
|
|
67
|
+
}
|
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
package/README.md
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
|
1
|
+
#elpis
|
|
2
|
+
##一个企业级应用,通过全栈实现
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module.exports = (app) => class BaseController {
|
|
2
|
+
// 统一收拢controller相关公共方法
|
|
3
|
+
constructor() {
|
|
4
|
+
this.app = app
|
|
5
|
+
this.config = app.config
|
|
6
|
+
// this.service = app.service
|
|
7
|
+
}
|
|
8
|
+
/*
|
|
9
|
+
* API处理成功统一返回结构
|
|
10
|
+
* @params {object} ctx 上下文
|
|
11
|
+
* @params {object} data 核心数据
|
|
12
|
+
* @params {object} metadata 附加数据
|
|
13
|
+
*/
|
|
14
|
+
success(ctx, data = {}, metadata = {} ) {
|
|
15
|
+
ctx.status = 200
|
|
16
|
+
ctx.body = {
|
|
17
|
+
success: true,
|
|
18
|
+
data,
|
|
19
|
+
metadata
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
* API处理成功统一返回结构
|
|
25
|
+
* @params {object} ctx 上下文
|
|
26
|
+
* @params {object} message 错误信息
|
|
27
|
+
* @params {object} code 错误码
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
fail(ctx, message, code ) {
|
|
31
|
+
ctx.status = 200
|
|
32
|
+
ctx.body = {
|
|
33
|
+
success: false,
|
|
34
|
+
message,
|
|
35
|
+
code
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// 控制层
|
|
2
|
+
module.exports = (app) => {
|
|
3
|
+
const BaseController = require('./base')(app)
|
|
4
|
+
// const modelList = require('../../model/index')(app)
|
|
5
|
+
// console.log(JSON.stringify(modelList), 'modellist')
|
|
6
|
+
return class ProjectController extends BaseController {
|
|
7
|
+
/**
|
|
8
|
+
* 获取项目列表
|
|
9
|
+
* @param {object} ctx 上下文
|
|
10
|
+
*/
|
|
11
|
+
// async getList(ctx) {
|
|
12
|
+
// // console.log(ctx.request.body, 'ctx.request.body')
|
|
13
|
+
// // 测试schema
|
|
14
|
+
// const { proj_key: projKey } = ctx.request.query
|
|
15
|
+
// console.log(projKey, 'projkey')
|
|
16
|
+
// // 实现获取项目列表的逻辑
|
|
17
|
+
// const { project: projectService } = app.service;
|
|
18
|
+
// // this.service对应BaseController的contructor的app.service
|
|
19
|
+
// // const { project: projectService } = this.service
|
|
20
|
+
// // service处理文件读写
|
|
21
|
+
// // controller处理数据业务逻辑拼凑
|
|
22
|
+
// // MVC
|
|
23
|
+
// const projectList = await projectService.getList()
|
|
24
|
+
// // const a = projectList.a.b.c
|
|
25
|
+
// // app.logger.info('123')
|
|
26
|
+
// this.success(ctx, projectList)
|
|
27
|
+
// }
|
|
28
|
+
|
|
29
|
+
// 根据proj_key获取项目配置
|
|
30
|
+
get(ctx) {
|
|
31
|
+
const { proj_key: projKey } = ctx.request.query
|
|
32
|
+
const { project: projectService } = app.service
|
|
33
|
+
const projConfg = projectService.get(projKey)
|
|
34
|
+
|
|
35
|
+
if(!projConfg) {
|
|
36
|
+
this.fail(ctx, '获取项目异常', 50000)
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
this.success(ctx, projConfg)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 获取当前projectKey对应模型下的项目列表(如果无projectKey,全量获取)
|
|
43
|
+
async getList(ctx) {
|
|
44
|
+
const {
|
|
45
|
+
proj_key: projKey
|
|
46
|
+
} = ctx.request.query
|
|
47
|
+
|
|
48
|
+
const { project: projectService } = app.service
|
|
49
|
+
|
|
50
|
+
const projectList = await projectService.getList({ projKey })
|
|
51
|
+
const dtoProjectList = []
|
|
52
|
+
|
|
53
|
+
// 构造关键数据list
|
|
54
|
+
for (let i = 0; i < projectList.length; i++) {
|
|
55
|
+
const { modelKey, key, name, desc, homePage } = projectList[i]
|
|
56
|
+
dtoProjectList.push({ modelKey, key, name, desc, homePage })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.success(ctx, dtoProjectList)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 获取项目所有模型与项目结构化数据
|
|
65
|
+
* @param {} ctx
|
|
66
|
+
*/
|
|
67
|
+
async getModelList(ctx) {
|
|
68
|
+
const { project: projectService } = app.service
|
|
69
|
+
const modelList = await projectService.getModelList()
|
|
70
|
+
|
|
71
|
+
// 业务层处理
|
|
72
|
+
// 构造返回结果
|
|
73
|
+
// 只返回关键数据
|
|
74
|
+
const dtoModelList = modelList.reduce((preList, item) => {
|
|
75
|
+
const { model, project } = item
|
|
76
|
+
// 构造model关键数据
|
|
77
|
+
const { key, name, desc } = model
|
|
78
|
+
const dtoModel = {key, name, desc }
|
|
79
|
+
|
|
80
|
+
// 构造project关键数据
|
|
81
|
+
const dtoProject = Object.keys(project).reduce((preObj, projKey) => {
|
|
82
|
+
const { key, name, desc, homePage } = project[projKey]
|
|
83
|
+
preObj[projKey] = { key, name, desc, homePage }
|
|
84
|
+
return preObj
|
|
85
|
+
}, {})
|
|
86
|
+
|
|
87
|
+
// 整合返回结构
|
|
88
|
+
preList.push({
|
|
89
|
+
model: dtoModel,
|
|
90
|
+
project: dtoProject
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
return preList
|
|
94
|
+
}, [])
|
|
95
|
+
// console.log(dtoModelList, 'dtoModelList')
|
|
96
|
+
this.success(ctx, dtoModelList)
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// 控制层
|
|
2
|
+
module.exports = (app) => {
|
|
3
|
+
return class ViewController {
|
|
4
|
+
/**
|
|
5
|
+
* 渲染页面
|
|
6
|
+
* @param {object} ctx 上下文
|
|
7
|
+
*/
|
|
8
|
+
async renderPage(ctx) {
|
|
9
|
+
// await ctx.render(`output/entry.${ctx.params.page}`, {
|
|
10
|
+
const { query, params } = ctx.request
|
|
11
|
+
app.logger.info(`[ViewController] query: ${JSON.stringify(query)}`)
|
|
12
|
+
app.logger.info(`[ViewController] params: ${JSON.stringify(params)}`)
|
|
13
|
+
await ctx.render(`dist/entry.${ctx.params.page}`, {
|
|
14
|
+
projKey: ctx.query?.proj_key,
|
|
15
|
+
name: app.options?.name,
|
|
16
|
+
env: app.env.get(),
|
|
17
|
+
options: JSON.stringify(app.options)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const log4js = require('log4js')
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* 日志工具
|
|
5
|
+
* 外部调用 app.logger.info app.logger.error
|
|
6
|
+
*/
|
|
7
|
+
module.exports = (app) => {
|
|
8
|
+
let logger
|
|
9
|
+
if (app.env.isLocal()) {
|
|
10
|
+
// 打印在线控制台
|
|
11
|
+
logger = console
|
|
12
|
+
} else {
|
|
13
|
+
// 日志落盘,日志输入磁盘
|
|
14
|
+
log4js.configure({
|
|
15
|
+
appenders: {
|
|
16
|
+
console: {
|
|
17
|
+
type: 'console',
|
|
18
|
+
},
|
|
19
|
+
// 文件切割,按日期
|
|
20
|
+
dateFile: {
|
|
21
|
+
type: 'dateFile',
|
|
22
|
+
filename: './logs/application.log',
|
|
23
|
+
pattern: '.yyyy-MM-dd'
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
categories: {
|
|
27
|
+
default: {
|
|
28
|
+
appenders: ['console', 'dateFile'],
|
|
29
|
+
level: 'trace'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
logger = log4js.getLogger()
|
|
34
|
+
}
|
|
35
|
+
return logger
|
|
36
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const Ajv = require('ajv')
|
|
2
|
+
const ajv = new Ajv()
|
|
3
|
+
module.exports = (app) => {
|
|
4
|
+
// 做个校验
|
|
5
|
+
// 先定一下,这个schema的标准是这样的
|
|
6
|
+
const $schema = 'http://json-schema.org/draft-07/schema#'
|
|
7
|
+
|
|
8
|
+
return async (ctx, next) => {
|
|
9
|
+
// 只对API做参数校验
|
|
10
|
+
if (ctx.path.indexOf('/api/') < 0) {
|
|
11
|
+
return await next()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// 获取请求参数
|
|
15
|
+
const { body, query, headers } = ctx.request
|
|
16
|
+
const { params, path, method } = ctx
|
|
17
|
+
|
|
18
|
+
app.logger.info(`[${method} ${path}] body: ${JSON.stringify(body)}`)
|
|
19
|
+
app.logger.info(`[${method} ${path}] params: ${JSON.stringify(params)}`)
|
|
20
|
+
app.logger.info(`[${method} ${path}] query: ${JSON.stringify(query)}`)
|
|
21
|
+
app.logger.info(`[${method} ${path}] headers: ${JSON.stringify(headers)}`)
|
|
22
|
+
|
|
23
|
+
// 服务端自己的schema
|
|
24
|
+
const schema = app.routerSchema[path]?.[method.toLowerCase()]
|
|
25
|
+
if (!schema) {
|
|
26
|
+
return await next()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let valid = true
|
|
30
|
+
// ajv校验器
|
|
31
|
+
let validate
|
|
32
|
+
|
|
33
|
+
// 校验headers
|
|
34
|
+
if (valid && headers && schema.headers) {
|
|
35
|
+
// 将外部版本赋值给服务端的schema
|
|
36
|
+
schema.headers.$schema = $schema
|
|
37
|
+
// 先获取编译的validate
|
|
38
|
+
validate = ajv.compile(schema.headers)
|
|
39
|
+
// 编译出来的validate就能校验用户传过来的值了
|
|
40
|
+
valid = validate(headers)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 校验body
|
|
44
|
+
if (valid && body && schema.body) {
|
|
45
|
+
// 将外部版本赋值给服务端的schema
|
|
46
|
+
schema.body.$schema = $schema
|
|
47
|
+
// 先获取编译的validate
|
|
48
|
+
validate = ajv.compile(schema.body)
|
|
49
|
+
// 编译出来的validate就能校验用户传过来的值了
|
|
50
|
+
valid = validate(body)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 校验query
|
|
54
|
+
if (valid && query && schema.query) {
|
|
55
|
+
// 将外部版本赋值给服务端的schema
|
|
56
|
+
schema.query.$schema = $schema
|
|
57
|
+
// 先获取编译的validate
|
|
58
|
+
validate = ajv.compile(schema.query)
|
|
59
|
+
// 编译出来的validate就能校验用户传过来的值了
|
|
60
|
+
valid = validate(query)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 校验path
|
|
64
|
+
if (valid && path && schema.path) {
|
|
65
|
+
// 将外部版本赋值给服务端的schema
|
|
66
|
+
schema.path.$schema = $schema
|
|
67
|
+
// 先获取编译的validate
|
|
68
|
+
validate = ajv.compile(schema.path)
|
|
69
|
+
// 编译出来的validate就能校验用户传过来的值了
|
|
70
|
+
valid = validate(path)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!valid) {
|
|
74
|
+
ctx.status = 200
|
|
75
|
+
ctx.body = {
|
|
76
|
+
success: false,
|
|
77
|
+
message: `request validate fail: ${ajv.errorsText(validate.errors)}`,
|
|
78
|
+
code: 442
|
|
79
|
+
}
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
await next()
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const md5 = require("md5")
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* API签名合法性校验
|
|
5
|
+
*/
|
|
6
|
+
module.exports = (app) => {
|
|
7
|
+
return async (ctx, next) => {
|
|
8
|
+
// 只对API请求做校验
|
|
9
|
+
if (ctx.path.indexOf('/api') < 0) {
|
|
10
|
+
return await next()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { path, method } = ctx
|
|
14
|
+
const { headers } = ctx.request
|
|
15
|
+
const { s_sign: sSign, s_t: st } = headers
|
|
16
|
+
|
|
17
|
+
// 前后端共有
|
|
18
|
+
const signKey = 'randomSignKey123'
|
|
19
|
+
const signature = md5(`${signKey}_${st}`)
|
|
20
|
+
app.logger.info(`[${method} ${path}] signature: ${signature}`)
|
|
21
|
+
if (!sSign || !st || signature !== sSign.toLowerCase() || Date.now() - st > 600 * 1000) {
|
|
22
|
+
ctx.status = 200
|
|
23
|
+
ctx.body = {
|
|
24
|
+
success: false,
|
|
25
|
+
message: 'signature not correct',
|
|
26
|
+
code: 445
|
|
27
|
+
}
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
await next()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 运行时异常错误处理,兜底所有异常
|
|
3
|
+
* @param {[object]} app koa 实例
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = (app) => {
|
|
7
|
+
return async (ctx, next) => {
|
|
8
|
+
// 所以怎么接住所有的错误呢?
|
|
9
|
+
try {
|
|
10
|
+
await next()
|
|
11
|
+
} catch (e) {
|
|
12
|
+
const { status, message, detail } = e
|
|
13
|
+
app.logger.info(JSON.stringify(e))
|
|
14
|
+
app.logger.error('[-- expection --]:', e)
|
|
15
|
+
app.logger.error('[-- expection --]:', status, message, detail)
|
|
16
|
+
|
|
17
|
+
// app.logger.info(message.indexOf('template not found') > -1, 'console.log("message.indexOf(template not found) > -1")')
|
|
18
|
+
// 页面不存在
|
|
19
|
+
if (message && message.indexOf('template not found') > -1) {
|
|
20
|
+
// console.log("message.indexOf('template not found') > -1")
|
|
21
|
+
// 临时重定向
|
|
22
|
+
ctx.status = 302
|
|
23
|
+
ctx.redirect(`${app.options?.homePage}`)
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
const resBody = {
|
|
27
|
+
success: false,
|
|
28
|
+
code: 50000,
|
|
29
|
+
message: '网络异常,请稍后重试'
|
|
30
|
+
}
|
|
31
|
+
ctx.status = 200
|
|
32
|
+
ctx.body = resBody
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* projectHandler项目相关处理
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
module.exports = (app) => {
|
|
7
|
+
// 只对业务 API 进行 proj_key 处理
|
|
8
|
+
return async (ctx, next) => {
|
|
9
|
+
if (ctx.path.indexOf('/api/proj/') < 0) {
|
|
10
|
+
return await next()
|
|
11
|
+
}
|
|
12
|
+
const { proj_key: projKey } = ctx.request.headers
|
|
13
|
+
|
|
14
|
+
if (!projKey) {
|
|
15
|
+
ctx.status = 200
|
|
16
|
+
ctx.body = {
|
|
17
|
+
success: false,
|
|
18
|
+
message: 'proj_key not found',
|
|
19
|
+
code: 446
|
|
20
|
+
}
|
|
21
|
+
// 中间件,不放行要return,放行就next()
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
ctx.projKey = projKey
|
|
26
|
+
|
|
27
|
+
await next()
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
// 洋葱圈模型,先进去,再进去
|
|
4
|
+
module.exports = (app) => {
|
|
5
|
+
const koaStatic = require('koa-static');
|
|
6
|
+
// 静态资源目录
|
|
7
|
+
app.use(koaStatic(path.resolve(process.cwd(), './app/public')));
|
|
8
|
+
|
|
9
|
+
// 模板渲染引擎
|
|
10
|
+
// 我们用它来服务器渲染一个页面出来
|
|
11
|
+
const koaNunjucks = require('koa-nunjucks-2');
|
|
12
|
+
app.use(koaNunjucks({
|
|
13
|
+
ext: 'tpl',
|
|
14
|
+
path: path.join(process.cwd(), './app/public'),
|
|
15
|
+
nunjucksConfig: {
|
|
16
|
+
// 去掉多余的行
|
|
17
|
+
trimBlocks: true,
|
|
18
|
+
noCache: true,
|
|
19
|
+
},
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
// 引入ctx.body,处理post请求
|
|
23
|
+
const bodyParser = require('koa-bodyparser')
|
|
24
|
+
app.use(bodyParser({
|
|
25
|
+
formList: '1000mb',
|
|
26
|
+
enableTypes: ['form', 'json', 'text']
|
|
27
|
+
}))
|
|
28
|
+
|
|
29
|
+
// 引入异常捕获中间件
|
|
30
|
+
app.use(app.middlewares.errorHandler)
|
|
31
|
+
|
|
32
|
+
// 签名合法性校验,暂时不想验证可以注释掉
|
|
33
|
+
app.use(app.middlewares.apiSignVerify)
|
|
34
|
+
|
|
35
|
+
// 引入api参数校验
|
|
36
|
+
app.use(app.middlewares.apiParamsVerify)
|
|
37
|
+
|
|
38
|
+
// 引入项目处理中间件
|
|
39
|
+
app.use(app.middlewares.projectHandler)
|
|
40
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
|
|
3
|
+
// 引入elementplus
|
|
4
|
+
import ElementUI from 'element-plus'
|
|
5
|
+
import 'element-plus/theme-chalk/index.css'
|
|
6
|
+
import 'element-plus/theme-chalk/dark/css-vars.css'
|
|
7
|
+
|
|
8
|
+
import './assets/custom.css'
|
|
9
|
+
|
|
10
|
+
import pinia from '$elpisStore'
|
|
11
|
+
|
|
12
|
+
// 由hash路由改成history路由
|
|
13
|
+
import { createRouter, createWebHistory } from 'vue-router'
|
|
14
|
+
/**
|
|
15
|
+
* vue页面启动入口
|
|
16
|
+
* @params pageComponent vue 入口组件
|
|
17
|
+
* @params routes 页面路由配置
|
|
18
|
+
* @params libs 页面依赖的第三方库
|
|
19
|
+
*/
|
|
20
|
+
export default (pageComponent, { routes, libs } = {}) => {
|
|
21
|
+
const app = createApp(pageComponent)
|
|
22
|
+
// 应用
|
|
23
|
+
app.use(ElementUI)
|
|
24
|
+
|
|
25
|
+
// 引入pinia状态管理
|
|
26
|
+
app.use(pinia)
|
|
27
|
+
|
|
28
|
+
// 引入第三方包
|
|
29
|
+
if (libs && libs.length > 0) {
|
|
30
|
+
for (let i = 0; i < libs.length; i++) {
|
|
31
|
+
app.use(libs[i])
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 页面路由
|
|
36
|
+
if (routes && routes.length > 0) {
|
|
37
|
+
const router = createRouter({
|
|
38
|
+
history: createWebHistory(),
|
|
39
|
+
routes
|
|
40
|
+
})
|
|
41
|
+
app.use(router)
|
|
42
|
+
|
|
43
|
+
router.isReady().then(() => {
|
|
44
|
+
app.mount('#root')
|
|
45
|
+
})
|
|
46
|
+
} else {
|
|
47
|
+
app.mount('#root')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
const md5 = require('md5')
|
|
3
|
+
const axios = require('axios')
|
|
4
|
+
const {ElMessage} = require('element-plus')
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 前端封装的 curl 方法
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const curl = ({
|
|
11
|
+
url,
|
|
12
|
+
method = 'post',
|
|
13
|
+
headers,
|
|
14
|
+
query = {}, // 请求参数,url query参数
|
|
15
|
+
data = {}, // 请求体参数,post请求体参数
|
|
16
|
+
responseType = 'json', // 响应类型,默认json
|
|
17
|
+
timeout = 60000, // 超时时间,默认5秒
|
|
18
|
+
errorMessage = '网络异常'
|
|
19
|
+
}) => {
|
|
20
|
+
// 为接口签名处理(接口变动态)
|
|
21
|
+
const signKey = 'randomSignKey123'
|
|
22
|
+
const st = Date.now()
|
|
23
|
+
const signature = md5(`${signKey}_${st}`)
|
|
24
|
+
|
|
25
|
+
// 构造dtoheaders
|
|
26
|
+
const dtoHeaders = {
|
|
27
|
+
...headers,
|
|
28
|
+
's_t': st,
|
|
29
|
+
's_sign': signature
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (url.indexOf('/api/proj/') > -1 && window.projKey) {
|
|
33
|
+
dtoHeaders.proj_key = window.projKey
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const ajaxSettings = {
|
|
37
|
+
url,
|
|
38
|
+
method,
|
|
39
|
+
params: query,
|
|
40
|
+
data, // 请求体参数,post请求体参数
|
|
41
|
+
responseType, // 响应类型,默认json
|
|
42
|
+
timeout, // 超时时间,默认5秒
|
|
43
|
+
errorMessage, // 错误信息,默认'网络异常'
|
|
44
|
+
headers: dtoHeaders
|
|
45
|
+
}
|
|
46
|
+
return axios.request(ajaxSettings).then(response => {
|
|
47
|
+
const resData = response.data || {}
|
|
48
|
+
|
|
49
|
+
// 后端API返回格式
|
|
50
|
+
const { success } = resData
|
|
51
|
+
if (!success) {
|
|
52
|
+
// 除了success还有message和code
|
|
53
|
+
const { message, code } = resData
|
|
54
|
+
// 参数签名错误
|
|
55
|
+
if (code === 442) {
|
|
56
|
+
ElMessage.error('请求参数异常')
|
|
57
|
+
}
|
|
58
|
+
else if (code === 445) {
|
|
59
|
+
ElMessage.error('请求不合法')
|
|
60
|
+
}
|
|
61
|
+
else if (code === 446) {
|
|
62
|
+
ElMessage.error('缺少项目必要参数')
|
|
63
|
+
}
|
|
64
|
+
else if (code === 50000) {
|
|
65
|
+
ElMessage.error(message)
|
|
66
|
+
} else {
|
|
67
|
+
ElMessage.error(errorMessage)
|
|
68
|
+
}
|
|
69
|
+
return Promise.resolve({ success, code, message })
|
|
70
|
+
}
|
|
71
|
+
// 成功的话
|
|
72
|
+
const { data, metadata } = resData
|
|
73
|
+
return Promise.resolve({ success, data, metadata })
|
|
74
|
+
|
|
75
|
+
}).catch(error => {
|
|
76
|
+
const { message } = error
|
|
77
|
+
if (message.match(/timeout/i)) {
|
|
78
|
+
// 处理超时错误
|
|
79
|
+
return Promise.resolve({
|
|
80
|
+
message: 'Request timed out',
|
|
81
|
+
code: 504
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
return Promise.resolve(error)
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default curl
|