@lixianwei/elpis 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 +2 -0
- package/.eslintrc +55 -0
- package/.idea/dictionaries/project.xml +8 -0
- package/.idea/elpis.iml +8 -0
- package/.idea/git_toolbox_prj.xml +15 -0
- package/.idea/inspectionProfiles/Project_Default.xml +329 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +201 -0
- package/app/controller/base.js +77 -0
- package/app/controller/project.js +69 -0
- package/app/controller/view.js +20 -0
- package/app/extend/logger.js +35 -0
- package/app/middleware/api-params-verify.js +74 -0
- package/app/middleware/api-sign-verify.js +33 -0
- package/app/middleware/error-hander.js +32 -0
- package/app/middleware/project-handler.js +25 -0
- package/app/middleware.js +37 -0
- package/app/pages/asserts/custom.css +11 -0
- package/app/pages/boot.js +43 -0
- package/app/pages/common/curl.js +83 -0
- package/app/pages/common/index.js +2 -0
- package/app/pages/common/utils.js +0 -0
- package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +23 -0
- package/app/pages/dashboard/complex-view/header-view/header-view.vue +117 -0
- package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +40 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +45 -0
- package/app/pages/dashboard/complex-view/schema-view/complex-view/tabel-panel/tabel-panel.vue +134 -0
- package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +20 -0
- package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +89 -0
- package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +101 -0
- package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +128 -0
- package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +119 -0
- package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +96 -0
- package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +21 -0
- package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +117 -0
- package/app/pages/dashboard/dashboard.vue +88 -0
- package/app/pages/dashboard/entry.dashboard.js +41 -0
- package/app/pages/router/index.js +11 -0
- package/app/pages/store/index.js +4 -0
- package/app/pages/store/menu.js +65 -0
- package/app/pages/store/project.js +16 -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 +103 -0
- package/app/pages/widgets/schema-form/complex-view/input/input.vue +142 -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 +130 -0
- package/app/pages/widgets/schema-form/form-item-config.js +20 -0
- package/app/pages/widgets/schema-form/schema-form.vue +132 -0
- package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +48 -0
- package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +67 -0
- package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +40 -0
- package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +50 -0
- package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +142 -0
- package/app/pages/widgets/schema-search-bar/search-item-config.js +24 -0
- package/app/pages/widgets/schema-table/schema-table.vue +238 -0
- package/app/pages/widgets/sider-container/sider-container.vue +31 -0
- package/app/public/static/logo.png +0 -0
- package/app/public/static/normalize.css +239 -0
- package/app/router/project.js +9 -0
- package/app/router/view.js +7 -0
- package/app/router-schema/project.js +32 -0
- package/app/service/base.js +12 -0
- package/app/service/project.js +42 -0
- package/app/view/entry.tpl +26 -0
- package/app/webpack/config/webpack.base.js +219 -0
- package/app/webpack/config/webpack.dev.js +55 -0
- package/app/webpack/config/webpack.prod.js +118 -0
- package/app/webpack/dev.js +52 -0
- package/app/webpack/libs/blank.js +2 -0
- package/app/webpack/prod.js +18 -0
- package/config/config.default.js +3 -0
- package/elpis-core/env.js +20 -0
- package/elpis-core/index.js +92 -0
- package/elpis-core/loader/config.js +54 -0
- package/elpis-core/loader/controller.js +61 -0
- package/elpis-core/loader/extend.js +55 -0
- package/elpis-core/loader/middleware.js +61 -0
- package/elpis-core/loader/router-schema.js +39 -0
- package/elpis-core/loader/router.js +42 -0
- package/elpis-core/loader/service.js +64 -0
- package/index.js +41 -0
- package/model/index.js +105 -0
- package/package.json +94 -0
- package/test/controller/project.test.js +194 -0
package/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# elpis
|
|
2
|
+
## 一个企业级应用框架,通过全栈实现
|
|
3
|
+
|
|
4
|
+
### model 配置
|
|
5
|
+
```javascript
|
|
6
|
+
{
|
|
7
|
+
model:'dashboard',//模板类型 不同模板类型对应不一样的模板数据结构
|
|
8
|
+
name:'',//名称
|
|
9
|
+
desc:'',//描述
|
|
10
|
+
icon:'',//iocn
|
|
11
|
+
homePage:'',//首页(项目配置)
|
|
12
|
+
// 头部菜单
|
|
13
|
+
menu:[{
|
|
14
|
+
key:'',//菜单唯一标识
|
|
15
|
+
name:'',//菜单名称
|
|
16
|
+
menuType:'',//枚举值:group/module
|
|
17
|
+
// 当menuType === group时,可填
|
|
18
|
+
subMenu:[{
|
|
19
|
+
|
|
20
|
+
},...],
|
|
21
|
+
// 当前menuType === module 时 可填
|
|
22
|
+
moduleType:'',//枚举值:sider/iframe/custom/schema
|
|
23
|
+
// 当moduleType===sider
|
|
24
|
+
siderConfig:{
|
|
25
|
+
menu:[{
|
|
26
|
+
// 可递归menuItem(除moduleType === sider)
|
|
27
|
+
},...]
|
|
28
|
+
},
|
|
29
|
+
// 当moduleType===iframe
|
|
30
|
+
iframeConfig:{
|
|
31
|
+
path:'' //iframe路径
|
|
32
|
+
},
|
|
33
|
+
// 当moduleType===custom
|
|
34
|
+
customConfig:{
|
|
35
|
+
path:''//自定义路由路径
|
|
36
|
+
},
|
|
37
|
+
// 当moduleType===schema
|
|
38
|
+
schemaConfig:{
|
|
39
|
+
api:'',//数据源API (遵循RESTFUL规范)
|
|
40
|
+
schema:{ //板块数据结构
|
|
41
|
+
type:'object',
|
|
42
|
+
properties: {
|
|
43
|
+
key:{
|
|
44
|
+
...schema,//标准schema 配置
|
|
45
|
+
type:'',//字段类型
|
|
46
|
+
label:'',//字段的中文名
|
|
47
|
+
// 字段在table中的配置
|
|
48
|
+
tableOption:{
|
|
49
|
+
...elTableColumnConfig,//标准的el-table-column 配置
|
|
50
|
+
toFixed:2,
|
|
51
|
+
visible:true //默认为true (false 表示不在表单中显示)
|
|
52
|
+
},
|
|
53
|
+
// 字段在search-bar 中的相关配置
|
|
54
|
+
searchOption:{
|
|
55
|
+
...eleComponentConfig, //标准 el-component-column 配置
|
|
56
|
+
comType:"",//配置组件类型 input /select/...
|
|
57
|
+
default:'',//默认值
|
|
58
|
+
// comType===select
|
|
59
|
+
enumList:[],
|
|
60
|
+
// comType == dynamicSelect
|
|
61
|
+
api:''
|
|
62
|
+
},
|
|
63
|
+
// 字段在不同动态 component 中的相关配置 前缀对应componentConfig 中的键值
|
|
64
|
+
// 如 componentConfig.createForm 这里对应createFormOption
|
|
65
|
+
// 字段在createForm 中相关配置
|
|
66
|
+
createFormOption:{
|
|
67
|
+
...eleComponentConfig,//标准 el-component 配置
|
|
68
|
+
comType:'',//控件类型 input/select/input-number
|
|
69
|
+
visible:true,//是否展示 (true/false)默认为true
|
|
70
|
+
disabled:false,//是否禁用 (true/false)默认false
|
|
71
|
+
default:'',//默认值
|
|
72
|
+
// comType === select
|
|
73
|
+
enumList:[]
|
|
74
|
+
},
|
|
75
|
+
// 字段在editForm中的表单配置
|
|
76
|
+
editFormOption:{
|
|
77
|
+
...eleComponentConfig,//标准 el-component 配置
|
|
78
|
+
comType:'',//控件类型 input/select/input-number
|
|
79
|
+
visible:true,//是否展示 (true/false)默认为true
|
|
80
|
+
disabled:false,//是否禁用 (true/false)默认false
|
|
81
|
+
default:'',//默认值
|
|
82
|
+
// comType === select
|
|
83
|
+
enumList:[]
|
|
84
|
+
},
|
|
85
|
+
// 字段在detailPanel 中的表单配置
|
|
86
|
+
detailPanelOption:{
|
|
87
|
+
...eleComponentConfig,//标准 el-component 配置
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
...
|
|
91
|
+
},
|
|
92
|
+
require:[],//标记哪些字段必填项
|
|
93
|
+
},
|
|
94
|
+
tableConfig:{
|
|
95
|
+
headerButtons:[
|
|
96
|
+
{
|
|
97
|
+
label:'',//按钮中文名
|
|
98
|
+
eventKey:'',//按钮事件名
|
|
99
|
+
//按钮事件具体配置
|
|
100
|
+
eventOption:{
|
|
101
|
+
// 当 eventKey === showComponent
|
|
102
|
+
comName:'',//组件名称
|
|
103
|
+
},
|
|
104
|
+
...elButtonConfig //标准el-button配置
|
|
105
|
+
},
|
|
106
|
+
...
|
|
107
|
+
],
|
|
108
|
+
rowButtons:[
|
|
109
|
+
{
|
|
110
|
+
label:'',//按钮中文名
|
|
111
|
+
eventKey:'',//按钮事件名
|
|
112
|
+
eventOption:{
|
|
113
|
+
// 当 eventKey === showComponent
|
|
114
|
+
comName:'',//组件名称
|
|
115
|
+
// 当eventKey === ‘remove’
|
|
116
|
+
params:{
|
|
117
|
+
// paramKey == 参数的键值
|
|
118
|
+
// rowValueKey == 参数值(当格式为 schema:: tableKey 的时候 到table中找到响应的字段)
|
|
119
|
+
paramKey:rowValueKey
|
|
120
|
+
}
|
|
121
|
+
},//按钮事件具体配置
|
|
122
|
+
...elButtonConfig //标准el-button配置
|
|
123
|
+
},
|
|
124
|
+
...
|
|
125
|
+
]
|
|
126
|
+
},//table 相关配置
|
|
127
|
+
searchConfig:{},//search-bar 相关配置
|
|
128
|
+
componentConfig:{
|
|
129
|
+
//create-form 表单相关配置
|
|
130
|
+
createForm:{
|
|
131
|
+
title:'',//表单标题
|
|
132
|
+
saveBtnText:'' //保存按钮文案
|
|
133
|
+
},
|
|
134
|
+
// edit-form配置
|
|
135
|
+
editForm:{
|
|
136
|
+
mainKey:'',//表单主键,用于唯一标识要修改的数据对象
|
|
137
|
+
title:'', //表单标题
|
|
138
|
+
saveBtnText:'' // 保存按钮文案
|
|
139
|
+
},
|
|
140
|
+
// detail-form 配置
|
|
141
|
+
detailPanel:{
|
|
142
|
+
mainKey:'',//表单主键,用于唯一标识要修改的数据对象
|
|
143
|
+
title:'', //表单标题
|
|
144
|
+
saveBtnText:'' // 保存按钮文案
|
|
145
|
+
}
|
|
146
|
+
// 支持用户动态扩展
|
|
147
|
+
|
|
148
|
+
} //模块组件
|
|
149
|
+
},
|
|
150
|
+
},...]
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 服务端启动
|
|
155
|
+
``` javascript
|
|
156
|
+
const {serverStart} = require('@lixianwei/elpis')
|
|
157
|
+
|
|
158
|
+
// 启动elpis服务
|
|
159
|
+
const app = serverStart({})
|
|
160
|
+
```
|
|
161
|
+
### 自定义服务端
|
|
162
|
+
- router-schema
|
|
163
|
+
- router
|
|
164
|
+
- controller
|
|
165
|
+
- service
|
|
166
|
+
- extend
|
|
167
|
+
- config
|
|
168
|
+
|
|
169
|
+
### 前端构建
|
|
170
|
+
``` javascript
|
|
171
|
+
const {fontendBuild} = require('@lixianwei/elpis')
|
|
172
|
+
编译构建前端工程
|
|
173
|
+
fontenBuild(process.env._ENV)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 自定义页面扩展
|
|
177
|
+
* 在`app/pages` 目录下写入口 entry.xxx.js
|
|
178
|
+
|
|
179
|
+
### dashboard / custom-view 自定义页面扩展
|
|
180
|
+
* 在`app/pages/dashboard/xxx` 下写页面
|
|
181
|
+
|
|
182
|
+
### dashboard /schema-view /components 动态组件库
|
|
183
|
+
1 在`app/pages/dashboard/complex-view/schema-view/components` 下写组件
|
|
184
|
+
2 配置到 `app/pages/dashboard/complex-view/schema-view/components/conponent-config.js`
|
|
185
|
+
|
|
186
|
+
### schema-form 控件扩展
|
|
187
|
+
1 在 `app/widgets/schema-form/complex-view` 下写组件
|
|
188
|
+
2 配置到 `app/widgets/schema-form/form-item-config.js`
|
|
189
|
+
|
|
190
|
+
### schema-search-bar 控件扩展
|
|
191
|
+
1 在`app/widgets/schema-search-bar/complex-view` 下写组件
|
|
192
|
+
2 配置到 `app/widgets/schema-search-bar/search-item-config.js`
|
|
193
|
+
|
|
194
|
+
## 提交规范类型记录
|
|
195
|
+
feat: 新功能
|
|
196
|
+
fix: 修补bug
|
|
197
|
+
docs: 文档
|
|
198
|
+
style: 样式
|
|
199
|
+
refactor: 重构
|
|
200
|
+
test: 增加测试
|
|
201
|
+
chore: 构建过程或者辅助工具的变动
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const Ajv = require('ajv')
|
|
2
|
+
const ajv = new Ajv()
|
|
3
|
+
module.exports=(app)=> class BaseController {
|
|
4
|
+
/*
|
|
5
|
+
* controller 基类
|
|
6
|
+
* 统一收拢 controller 相关的公共方法
|
|
7
|
+
* */
|
|
8
|
+
constructor() {
|
|
9
|
+
this.app = app;
|
|
10
|
+
this.config = app.config;
|
|
11
|
+
}
|
|
12
|
+
/*
|
|
13
|
+
* 统一处理Api params参数的校验
|
|
14
|
+
* @params {object} ctx 上下文
|
|
15
|
+
* */
|
|
16
|
+
roterSchemaParamsValidate(ctx){
|
|
17
|
+
// 也可用更直接的:ctx.matched === '/api/project/list/:proj_key'
|
|
18
|
+
const {matched,method,params} = ctx
|
|
19
|
+
// ctx.matched 是 Layer 数组,不是路径字符串;要取 layer.path(路由模板)
|
|
20
|
+
const route = matched.find(layer => layer.path !== '*')?.path
|
|
21
|
+
const schema = app.routerSchema[route]?.[method.toLowerCase()]
|
|
22
|
+
|
|
23
|
+
if(!schema || !params){
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let valid = true;
|
|
28
|
+
// ajv 校验器
|
|
29
|
+
let validate;
|
|
30
|
+
// query / params:有数据的才校验;两边都空则用有 schema 的那侧做必填校验
|
|
31
|
+
const hasData = (obj) => obj && Object.keys(obj).length > 0
|
|
32
|
+
// 校验params
|
|
33
|
+
if(valid && hasData(params) && schema.params){
|
|
34
|
+
validate = ajv.compile(schema.params);
|
|
35
|
+
valid= validate(params)
|
|
36
|
+
}
|
|
37
|
+
if(!valid){
|
|
38
|
+
ctx.status=200;
|
|
39
|
+
ctx.body={
|
|
40
|
+
success:false,
|
|
41
|
+
message:`request validate fail: ${ajv.errorsText(validate.errors)}`,
|
|
42
|
+
code:442
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return valid
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
/*
|
|
50
|
+
* API 处理成功时统一返回结构
|
|
51
|
+
* @params {object} ctx 上下文
|
|
52
|
+
* @params {object} data 核心数据
|
|
53
|
+
* @params {object} metadata 附加数据
|
|
54
|
+
* */
|
|
55
|
+
success(ctx,data={},metadata={}){
|
|
56
|
+
ctx.status = 200;
|
|
57
|
+
ctx.body={
|
|
58
|
+
success: true,
|
|
59
|
+
data,
|
|
60
|
+
metadata,
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/*
|
|
65
|
+
* API 处理失败时统一返回结构
|
|
66
|
+
* @params {object} ctx 上下文
|
|
67
|
+
* @params {object} message 错误信息
|
|
68
|
+
* @params {object} code 错误码
|
|
69
|
+
* */
|
|
70
|
+
fail(ctx,message,code){
|
|
71
|
+
ctx.body={
|
|
72
|
+
success: false,
|
|
73
|
+
message,
|
|
74
|
+
code,
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module.exports = (app)=>{
|
|
2
|
+
const BaseController = require('./base')(app)
|
|
3
|
+
|
|
4
|
+
return class ProjectController extends BaseController {
|
|
5
|
+
/*
|
|
6
|
+
* 根据proj_key获取项目配置
|
|
7
|
+
* */
|
|
8
|
+
async get(ctx){
|
|
9
|
+
const {proj_key:projKey} = ctx.request.query;
|
|
10
|
+
const {project:ProjectService} = app.service;
|
|
11
|
+
const projConfig = await ProjectService.get(projKey)
|
|
12
|
+
if(!projConfig){
|
|
13
|
+
return this.fail(ctx,'获取项目异常',50000)
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
this.success(ctx,projConfig)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
/*
|
|
21
|
+
* 获取当前 projectKey 对应模型下的项目列表 (如果无projectKey,全量获取)
|
|
22
|
+
* */
|
|
23
|
+
async getList(ctx){
|
|
24
|
+
const{proj_key:projKey} = ctx.request.query;
|
|
25
|
+
|
|
26
|
+
const {project:ProjectService} = app.service;
|
|
27
|
+
|
|
28
|
+
const projectList = await ProjectService.getList({projKey});
|
|
29
|
+
|
|
30
|
+
const dtoProjectList = projectList.map(item=>{
|
|
31
|
+
const {modelKey,key, name,desc,homePage} = item;
|
|
32
|
+
return {modelKey,key,name,desc,homePage}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
this.success(ctx,dtoProjectList);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 获取所有与项目的结构化数据
|
|
39
|
+
* @param {object} ctx 上下文
|
|
40
|
+
* */
|
|
41
|
+
async getModelList(ctx){
|
|
42
|
+
const {project:ProjectService} = app.service;
|
|
43
|
+
const modelList = await ProjectService.getModelList(ProjectService)
|
|
44
|
+
// g构造返回结果 只返回关键数据
|
|
45
|
+
const dtoModelList = modelList.reduce((preList,item)=>{
|
|
46
|
+
const {model,project} = item;
|
|
47
|
+
// 构造model关键数据
|
|
48
|
+
const {key,name,desc} = model;
|
|
49
|
+
const dtoModel = {key,name,desc};
|
|
50
|
+
// 构造project 关键数据
|
|
51
|
+
const dtoProject = Object.keys(project).reduce((preObj,projKey)=>{
|
|
52
|
+
const {key,name,desc,homePage} = project[projKey];
|
|
53
|
+
preObj[projKey] = {key,name,desc,homePage}
|
|
54
|
+
return preObj;
|
|
55
|
+
},{})
|
|
56
|
+
|
|
57
|
+
// 整合返回结构
|
|
58
|
+
preList.push({
|
|
59
|
+
model:dtoModel,
|
|
60
|
+
project:dtoProject,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
return preList;
|
|
64
|
+
},[])
|
|
65
|
+
|
|
66
|
+
this.success(ctx, dtoModelList)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module.exports = (app)=> {
|
|
2
|
+
return class ViewController {
|
|
3
|
+
/*
|
|
4
|
+
* 渲染页面
|
|
5
|
+
* @param {object} ctx 上下文
|
|
6
|
+
* */
|
|
7
|
+
async renderPage(ctx){
|
|
8
|
+
const {query,params} = ctx
|
|
9
|
+
|
|
10
|
+
app.logger.info(`[ViewController] query: ${JSON.stringify(query)}]`);
|
|
11
|
+
app.logger.info(`[ViewController] params: ${JSON.stringify(params)}]`);
|
|
12
|
+
await ctx.render(`dist/entry.${ctx.params.page}`,{
|
|
13
|
+
projKey:ctx.query?.proj_key,
|
|
14
|
+
name:app.options?.name,
|
|
15
|
+
env:app.env.get(),
|
|
16
|
+
options:JSON.stringify(app.options),
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const log4js = require('log4js');
|
|
2
|
+
/*
|
|
3
|
+
* 日志工具
|
|
4
|
+
* 外部调用 app.logger.info app.logger.error
|
|
5
|
+
* */
|
|
6
|
+
module.exports= (app)=>{
|
|
7
|
+
let logger;
|
|
8
|
+
if(app.env.isLocal()){
|
|
9
|
+
// 打印在控制台即可
|
|
10
|
+
logger = console
|
|
11
|
+
}else {
|
|
12
|
+
// 把日志输出并落实到磁盘
|
|
13
|
+
log4js.configure({
|
|
14
|
+
appenders: {
|
|
15
|
+
console:{
|
|
16
|
+
type: 'console',
|
|
17
|
+
},
|
|
18
|
+
// 日志文件切分
|
|
19
|
+
dateFile:{
|
|
20
|
+
type: 'dateFile',
|
|
21
|
+
filename:'./logs/application.log',
|
|
22
|
+
pattern:'.yyyy-MM-dd',
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
categories: {
|
|
26
|
+
default:{
|
|
27
|
+
appenders: ['console','dateFile'],
|
|
28
|
+
level:'trace'
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
logger = log4js.getLogger()
|
|
33
|
+
}
|
|
34
|
+
return logger
|
|
35
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const Ajv = require('ajv')
|
|
2
|
+
const ajv = new Ajv()
|
|
3
|
+
/*
|
|
4
|
+
* API 参数校验
|
|
5
|
+
* */
|
|
6
|
+
module.exports = (app)=>{
|
|
7
|
+
const $schema = "http://json-schema.org/draft-07/schema#"
|
|
8
|
+
return async (ctx,next) => {
|
|
9
|
+
// 只对API做参数校验
|
|
10
|
+
if(ctx.path.indexOf('/api/')<0){
|
|
11
|
+
return await next();
|
|
12
|
+
}
|
|
13
|
+
// 获取请求参数
|
|
14
|
+
const {body,query,headers} = ctx.request;
|
|
15
|
+
const {params,path,method} = ctx;
|
|
16
|
+
|
|
17
|
+
app.logger.info(`[${method} ${path}] body:${JSON.stringify(body)}`);
|
|
18
|
+
app.logger.info(`[${method} ${path}] query:${JSON.stringify(query)}`);
|
|
19
|
+
app.logger.info(`[${method} ${path}] headers:${JSON.stringify(headers)}`);
|
|
20
|
+
app.logger.info(`[${method} ${params}] params:${JSON.stringify(params)}`);
|
|
21
|
+
|
|
22
|
+
const schema = app.routerSchema[path]?.[method.toLowerCase()];
|
|
23
|
+
|
|
24
|
+
if(!schema) {
|
|
25
|
+
return await next();
|
|
26
|
+
}
|
|
27
|
+
let valid = true;
|
|
28
|
+
// ajv 校验器
|
|
29
|
+
let validate;
|
|
30
|
+
|
|
31
|
+
// 校验headers
|
|
32
|
+
if(valid && headers &&schema.headers){
|
|
33
|
+
schema.headers.$schema = $schema;
|
|
34
|
+
validate = ajv.compile(schema.headers);
|
|
35
|
+
valid= validate(headers)
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 校验body
|
|
40
|
+
if(valid && body &&schema.body){
|
|
41
|
+
schema.body.$schema = $schema;
|
|
42
|
+
validate = ajv.compile(schema.body);
|
|
43
|
+
valid= validate(body)
|
|
44
|
+
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const hasData = (obj) => obj && Object.keys(obj).length > 0
|
|
48
|
+
|
|
49
|
+
// 校验query:有 query 数据才校验
|
|
50
|
+
if(valid && query && schema.query){
|
|
51
|
+
schema.query.$schema = $schema;
|
|
52
|
+
validate = ajv.compile(schema.query);
|
|
53
|
+
valid= validate(query)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 校验params:有 path params 数据才校验(空 {} 跳过)
|
|
57
|
+
if(valid && hasData(params) && schema.params){
|
|
58
|
+
schema.params.$schema = $schema;
|
|
59
|
+
validate = ajv.compile(schema.params);
|
|
60
|
+
valid= validate(params)
|
|
61
|
+
}
|
|
62
|
+
if(!valid){
|
|
63
|
+
ctx.status=200;
|
|
64
|
+
ctx.body={
|
|
65
|
+
success:false,
|
|
66
|
+
message:`request validate fail: ${ajv.errorsText(validate.errors)}`,
|
|
67
|
+
code:442
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await next();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const md5 =require('md5');
|
|
2
|
+
/*
|
|
3
|
+
* API 签名合法性校验
|
|
4
|
+
* */
|
|
5
|
+
module.exports =(app)=>{
|
|
6
|
+
return async(ctx, next)=>{
|
|
7
|
+
// 只对api请求进行校验
|
|
8
|
+
if(ctx.path.indexOf('/api') < 0){
|
|
9
|
+
return await next();
|
|
10
|
+
}
|
|
11
|
+
const {path,method} = ctx;
|
|
12
|
+
const {headers} = ctx.request;
|
|
13
|
+
const {s_sign:sSign,s_t:st} = headers;
|
|
14
|
+
const signKey = 'klx05hb3n1c9ujp8uhxbs2ikkiowp212';
|
|
15
|
+
|
|
16
|
+
const signature = md5(`${signKey}_${st}`)
|
|
17
|
+
|
|
18
|
+
app.logger.info(`[${method} ${path}] signature:${signature}`)
|
|
19
|
+
app.logger.error(`[${method} ${path}] signature:${signature}`)
|
|
20
|
+
|
|
21
|
+
if(!sSign || !st || signature!==sSign.toLowerCase() || Date.now() - st > 600000){
|
|
22
|
+
ctx.status = 200;
|
|
23
|
+
ctx.body = {
|
|
24
|
+
success:false,
|
|
25
|
+
message:'signature not correct!!',
|
|
26
|
+
code:445
|
|
27
|
+
}
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await next();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* 运行时异常错误处理,兜底所有异常
|
|
3
|
+
* @param {object} app koa 实例
|
|
4
|
+
* */
|
|
5
|
+
module.exports =(app)=>{
|
|
6
|
+
return async (ctx,next) => {
|
|
7
|
+
try{
|
|
8
|
+
await next();
|
|
9
|
+
}catch(err){
|
|
10
|
+
// 异常处理
|
|
11
|
+
const {status,message,detail} = err;
|
|
12
|
+
app.logger.info(JSON.stringify(err));
|
|
13
|
+
app.logger.error('[--exception--]:',err);
|
|
14
|
+
app.logger.error('[--exception--]:',status,message,detail);
|
|
15
|
+
// 页面重定向
|
|
16
|
+
if(message && message.indexOf('template not found') > -1){
|
|
17
|
+
|
|
18
|
+
ctx.status = 302;//临时重定向 301有缓存就会一直重定向
|
|
19
|
+
ctx.redirect(`${app.options?.homePath}`);
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
// 错误提示处理
|
|
23
|
+
const resBody={
|
|
24
|
+
success:false,
|
|
25
|
+
code:50000,
|
|
26
|
+
message:'网络异常 请稍后重试'
|
|
27
|
+
}
|
|
28
|
+
ctx.status = 200
|
|
29
|
+
ctx.body = resBody;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* projectHandler 相关项目处理内容
|
|
3
|
+
* */
|
|
4
|
+
|
|
5
|
+
module.exports = (app)=>{
|
|
6
|
+
return async (ctx, next)=>{
|
|
7
|
+
// 只对业务api进行proj_key处理
|
|
8
|
+
if(ctx.path.indexOf('/api/proj/')<0){
|
|
9
|
+
return await next();
|
|
10
|
+
}
|
|
11
|
+
// 获取projKey
|
|
12
|
+
const {proj_key:projKey} = ctx.request.headers;
|
|
13
|
+
if(!projKey){
|
|
14
|
+
ctx.status=200
|
|
15
|
+
ctx.body={
|
|
16
|
+
success:false,
|
|
17
|
+
message:'proj_key not found',
|
|
18
|
+
code:446
|
|
19
|
+
}
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
ctx.projKey = projKey
|
|
23
|
+
await next()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
module.exports =(app)=>{
|
|
3
|
+
// 配置静态根目录
|
|
4
|
+
const KoaStatic = require('koa-static');
|
|
5
|
+
app.use(KoaStatic(path.resolve(process.cwd(), './app/public')));
|
|
6
|
+
|
|
7
|
+
// 模板引擎渲染
|
|
8
|
+
const koaNunjucks = require('koa-nunjucks-2');
|
|
9
|
+
app.use(koaNunjucks({
|
|
10
|
+
ext: 'tpl',
|
|
11
|
+
path:path.resolve(process.cwd(),'./app/public') ,
|
|
12
|
+
nunjucksConfig: {
|
|
13
|
+
noCache:true,
|
|
14
|
+
trimBlocks: true
|
|
15
|
+
}
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
// 引入ctx.body 解析中间件
|
|
19
|
+
const bodyParser = require('koa-bodyparser');
|
|
20
|
+
app.use(bodyParser({
|
|
21
|
+
formList:'1000mb',
|
|
22
|
+
enableTypes:['form','json','text'],
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
// 引入异常捕获中间件
|
|
27
|
+
app.use(app.middlewares.errorHander)
|
|
28
|
+
|
|
29
|
+
// 签名合法性校验
|
|
30
|
+
app.use(app.middlewares.apiSignVerify)
|
|
31
|
+
|
|
32
|
+
// 引入api参数合法校验
|
|
33
|
+
app.use(app.middlewares.apiParamsVerify)
|
|
34
|
+
|
|
35
|
+
// 引入项目处理中间件
|
|
36
|
+
app.use(app.middlewares.projectHandler)
|
|
37
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {createApp} from "vue";
|
|
2
|
+
|
|
3
|
+
// 引入elementUI
|
|
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
|
+
import './asserts/custom.css'
|
|
8
|
+
|
|
9
|
+
import pinia from '$elpisStore'
|
|
10
|
+
// 引入路由
|
|
11
|
+
import setupRouter from '$elpisPages/router/index.js';
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* vue页面入口 用于启动VUE
|
|
15
|
+
* @params pageComponent vue入口组件
|
|
16
|
+
* @params routes 路由列表
|
|
17
|
+
* @params libs 页面依赖第三方的包
|
|
18
|
+
* */
|
|
19
|
+
|
|
20
|
+
export default (pageComponent,{routes,libs}={})=>{
|
|
21
|
+
const app = createApp(pageComponent);
|
|
22
|
+
// 引入element
|
|
23
|
+
app.use(ElementUI)
|
|
24
|
+
// 引入pinia
|
|
25
|
+
app.use(pinia)
|
|
26
|
+
|
|
27
|
+
// 引入第三方的包
|
|
28
|
+
if(libs && libs.length > 0){
|
|
29
|
+
for( let i=0; i<libs.length; i++){
|
|
30
|
+
app.use(libs[i])
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 页面路由
|
|
35
|
+
const router = setupRouter(routes)
|
|
36
|
+
if(router){
|
|
37
|
+
app.use(router)
|
|
38
|
+
router.isReady().then(()=> app.mount("#root"))
|
|
39
|
+
}else{
|
|
40
|
+
app.mount("#root")
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|