@pixel-shell/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.
Files changed (80) hide show
  1. package/.eslintgnore +1 -0
  2. package/.eslintrc +55 -0
  3. package/README.md +194 -0
  4. package/app/controller/base.js +40 -0
  5. package/app/controller/project.js +56 -0
  6. package/app/controller/view.js +18 -0
  7. package/app/extend/logger.js +37 -0
  8. package/app/middleware/api-params-verify.js +71 -0
  9. package/app/middleware/api-sign-verify.js +32 -0
  10. package/app/middleware/error-handler.js +33 -0
  11. package/app/middleware/project-handler.js +27 -0
  12. package/app/middleware.js +31 -0
  13. package/app/pages/asserts/custom.css +12 -0
  14. package/app/pages/boot.js +47 -0
  15. package/app/pages/common/curl.js +88 -0
  16. package/app/pages/common/utils.js +2 -0
  17. package/app/pages/dashboard/complex-view/header-view/complex-view/sub-menu/sub-menu.vue +17 -0
  18. package/app/pages/dashboard/complex-view/header-view/header-view.vue +129 -0
  19. package/app/pages/dashboard/complex-view/iframe-view/iframe-view.vue +43 -0
  20. package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/search-panel.vue +37 -0
  21. package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/table-panel.vue +114 -0
  22. package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +22 -0
  23. package/app/pages/dashboard/complex-view/schema-view/components/create-form/create-form.vue +85 -0
  24. package/app/pages/dashboard/complex-view/schema-view/components/detail-panel/detail-panel.vue +92 -0
  25. package/app/pages/dashboard/complex-view/schema-view/components/edit-form/edit-form.vue +106 -0
  26. package/app/pages/dashboard/complex-view/schema-view/hook/schema.js +123 -0
  27. package/app/pages/dashboard/complex-view/schema-view/schema-view.vue +88 -0
  28. package/app/pages/dashboard/complex-view/sider-view/complex-view/sub-menu/sub-menu.vue +18 -0
  29. package/app/pages/dashboard/complex-view/sider-view/sider-view.vue +117 -0
  30. package/app/pages/dashboard/dashboard.vue +89 -0
  31. package/app/pages/dashboard/entry.dashboard.js +42 -0
  32. package/app/pages/store/index.js +5 -0
  33. package/app/pages/store/menu.js +57 -0
  34. package/app/pages/store/project.js +15 -0
  35. package/app/pages/widgets/header-container/asserts/avatar.png +0 -0
  36. package/app/pages/widgets/header-container/asserts/logo.png +0 -0
  37. package/app/pages/widgets/header-container/header-container.vue +102 -0
  38. package/app/pages/widgets/schema-form/complex-view/input/input.vue +129 -0
  39. package/app/pages/widgets/schema-form/complex-view/input-number/input-number.vue +130 -0
  40. package/app/pages/widgets/schema-form/complex-view/select/select.vue +116 -0
  41. package/app/pages/widgets/schema-form/form-item-config.js +23 -0
  42. package/app/pages/widgets/schema-form/schema-form.vue +121 -0
  43. package/app/pages/widgets/schema-search-bar/complex-view/date-range/date-range.vue +41 -0
  44. package/app/pages/widgets/schema-search-bar/complex-view/dynamic-select/dynamic-select.vue +51 -0
  45. package/app/pages/widgets/schema-search-bar/complex-view/input/input.vue +34 -0
  46. package/app/pages/widgets/schema-search-bar/complex-view/select/select.vue +36 -0
  47. package/app/pages/widgets/schema-search-bar/schema-search-bar.vue +121 -0
  48. package/app/pages/widgets/schema-search-bar/search-item-config.js +27 -0
  49. package/app/pages/widgets/schema-table/schema-table.vue +227 -0
  50. package/app/pages/widgets/sider-container/sider-container.vue +29 -0
  51. package/app/public/static/logo.png +0 -0
  52. package/app/public/static/normalize.css +241 -0
  53. package/app/router/project.js +6 -0
  54. package/app/router/view.js +8 -0
  55. package/app/router-schema/project.js +30 -0
  56. package/app/service/base.js +10 -0
  57. package/app/service/project.js +40 -0
  58. package/app/view/entry.tpl +25 -0
  59. package/app/webpack/build.js +18 -0
  60. package/app/webpack/config/webpack.base.js +234 -0
  61. package/app/webpack/config/webpack.dev.js +58 -0
  62. package/app/webpack/config/webpack.prod.js +113 -0
  63. package/app/webpack/dev.js +60 -0
  64. package/app/webpack/libs/blank.js +1 -0
  65. package/app/webpack/prod.js +22 -0
  66. package/config/config.default.js +3 -0
  67. package/docs/dashboard-mode.js +141 -0
  68. package/elpis-core/env.js +16 -0
  69. package/elpis-core/index.js +70 -0
  70. package/elpis-core/loader/config.js +51 -0
  71. package/elpis-core/loader/controller.js +71 -0
  72. package/elpis-core/loader/extend.js +61 -0
  73. package/elpis-core/loader/middleware.js +69 -0
  74. package/elpis-core/loader/roter-schema.js +54 -0
  75. package/elpis-core/loader/router.js +42 -0
  76. package/elpis-core/loader/service.js +70 -0
  77. package/index.js +35 -0
  78. package/model/index.js +86 -0
  79. package/package.json +92 -0
  80. package/test/controller/project.test.js +194 -0
package/.eslintgnore ADDED
@@ -0,0 +1 @@
1
+ node_modules/
package/.eslintrc ADDED
@@ -0,0 +1,55 @@
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
+ "globals": {
51
+ "$": true,
52
+ "axios": true,
53
+ "Vue": true
54
+ }
55
+ }
package/README.md ADDED
@@ -0,0 +1,194 @@
1
+ # Elpis
2
+
3
+ # 一个企业级全栈应用框架
4
+
5
+ ### model配置
6
+
7
+ ```js
8
+ {
9
+ mode: "dashboard", //模板类型,不同模板类型对应不一样的模板数据结构
10
+ name: "", //名称
11
+ desc: "", //描述
12
+ icon: "", //图标
13
+ homePage: "", // 首页路径
14
+ // 头部菜单配置
15
+ menu: [
16
+ {
17
+ key: "", //唯一标识
18
+ name: "", //菜单名称
19
+ menuType: "", //菜单类型,枚举值:'group'、'module'
20
+ // 当menuType为'group'时,子菜单列表
21
+ subMenu: [{}, ...],
22
+ // 当menuType为'module'时,模块配置
23
+ moduleType: "", // 模块类型,枚举值:sider,iframe,custom,schema
24
+ // 当moduleType为sider时,模块配置
25
+ siderConfig: {
26
+ menu: [{}, ...], // 侧边栏菜单列表
27
+ },
28
+ // 当moduleType为iframe时,模块配置
29
+ iframeConfig: {
30
+ path: "", // iframe路径
31
+ },
32
+ // 当moduleType为custom时,模块配置
33
+ customConfig: {
34
+ path: "", // 自定义路径
35
+ },
36
+ // 当moduleType为schema时,模块配置
37
+ schemaConfig: {
38
+ api: "", // 数据源API(遵循RESTful API规范)
39
+ schema: {
40
+ type: "object",
41
+ properties: {
42
+ key: {
43
+ ...schema, // 标准schema配置
44
+ type: "", // 字段类型
45
+ label: "", // 字段中文名
46
+ // 字段在table中的相关配置
47
+ tableOption: {
48
+ ...elTableColumnConfig, //标准 el-table-column 配置
49
+ toFixed: 0, // 数值类型字段保留的小数位数
50
+ visible: true, // 是否在table中显示
51
+ },
52
+ // 字段在search-bar中的相关配置
53
+ searchOption: {
54
+ ...elComponentConfig, //标准 el-component-column 配置
55
+ comType: "", // 配置组件类型 ,枚举值:input,select 。。。
56
+ defaule: "", // 默认值
57
+
58
+ // comType === select 时,相关配置
59
+ enumList: [], // 下拉选项列表
60
+
61
+ // comType === dynamic-select 时,相关配置
62
+ api: "", // 下拉选项API
63
+ },
64
+ // 字段在component中的相关配置,前缀对应componentConfig中的键值
65
+ // 如:componentConfig.createForm,这里对应 createFormOption
66
+ // 字段在createFormz中的相关配置
67
+ createFormOption: {
68
+ ...elComponentConfig, //标准 el-component 配置
69
+ comType: "", // 控件类型,枚举值:input,select 。。。
70
+ visible: true, // 是否显示
71
+ disabled: false, // 是否禁用
72
+
73
+ // comType === select 时,相关配置
74
+ enumList: [], // 下拉选项列表
75
+ },
76
+ // 字段在editForm中的相关配置
77
+ editFormOption: {
78
+ ...elComponentConfig, //标准 el-component 配置
79
+ comType: "", // 控件类型,枚举值:input,select 。。。
80
+ visible: true, // 是否显示
81
+ disabled: false, // 是否禁用
82
+
83
+ // comType === select 时,相关配置
84
+ enumList: [], // 下拉选项列表
85
+ },
86
+ detailPanelOption: {
87
+ ...elComponentConfig, //标准 el-component 配置
88
+ }
89
+ },
90
+ },
91
+ required: [], // 必填字段列表
92
+ },
93
+ tableConfig: {
94
+ headerButtons: [
95
+ {
96
+ label: "", // 按钮中文名
97
+ eventKey: "", // 按钮事件名
98
+ // 按钮事件具体配置
99
+ eventOption: {
100
+ // 当eventKey === "showComponent"
101
+ comName: "", // 组件名称
102
+ },
103
+ ...elButtonConfig, // 标准 el-button 配置
104
+ }, ...
105
+ ], // 表格头部按钮列表
106
+ rowButtons: [
107
+ {
108
+ label: "", // 按钮中文名
109
+ eventKey: "", // 按钮事件名
110
+ eventOption: {
111
+ // 当eventKey === "showComponent"
112
+ comName: "", // 组件名称
113
+ // 当eventKey === 'remove
114
+ params: {
115
+ // paramKey = 参数的键值
116
+ // rowValueKey = 参数值(当格式为 schema::tableKey的时候, 到table中找相应的字段)
117
+ paramKey: rowValueKey
118
+ }
119
+ }, // 按钮事件具体配置
120
+ ...elButtonConfig, // 标准 el-button 配置
121
+ }, ...
122
+ ], // 表格行按钮列表
123
+ },
124
+ searchConfig: {},
125
+ // 动态组件相关配置
126
+ componentConfig: {
127
+ // create-form 表单相关配置
128
+ createForm: {
129
+ title: "", // 表单标题
130
+ saveBtnText: "", // 保存按钮文本
131
+ },
132
+ // edit-form 表单相关配置
133
+ editForm: {
134
+ mainKey: "", // 主键字段名,用于唯一标识要修改的数据对象
135
+ title: "", // 表单标题
136
+ saveBtnText: "", // 保存按钮文本
137
+ },
138
+ // detail-panel 相关配置
139
+ detailPanel: {
140
+ mainKey: "", // 主键字段名,用于唯一标识要修改的数据对象
141
+ title: "", // 表单标题
142
+ },
143
+ // ...支持用户动态扩展
144
+ },
145
+ },
146
+ }, ...
147
+ ],
148
+ }
149
+ ```
150
+
151
+ ### 服务端启动
152
+
153
+ ```js
154
+ const {
155
+ serverStart
156
+ } = require("@pixel-shell/elpis");
157
+
158
+ // 启动elpis服务
159
+ const app = serverStart({});
160
+ ```
161
+
162
+ ### 自定义服务端
163
+ - router-schema
164
+ - router
165
+ - controller
166
+ - service
167
+ - extend
168
+ - config
169
+
170
+ ### 前端构建
171
+ ```js
172
+ const { frontendBuild } = require("@pixel-shell/elpis");
173
+
174
+ // 编译构建前端工程
175
+ frontendBuild(process.env._ENV);
176
+ ```
177
+
178
+ ### 自定义页面扩展
179
+ * 在 `app/pages/` 目录下写入口 entry.xxx.js
180
+
181
+ ### dashboard / custom-view 自定义页面扩展
182
+ * 在 `app/pages/dashboard/xxxx` 下写页面
183
+
184
+ ### dashboard / schemaview / components 动态组件扩展
185
+ 1. 在 `app/pages/dashbpard/complex-view/schema-view/components` 下写组件
186
+ 2. 配置到 `app/pages/dashboard/complex-view/schema-view/components/component-config.js`
187
+
188
+ ### schema-form 控件扩展
189
+ 1. 在 `app/widgets/schema-form/complex-view` 下写控件
190
+ 2. 配置到 `app/widgets/schema-form/component-config.js`
191
+
192
+ ### schema-search-bar 控件扩展
193
+ 1. 在 `app/widgets/schema-search-bar/complex-view` 下写控件
194
+ 2. 配置到 `app/widgets/schema-search-bar/search-item-config.js`
@@ -0,0 +1,40 @@
1
+ module.exports = (app) =>
2
+ class BaseController {
3
+ /**
4
+ * controller 基类
5
+ * 统一收拢 controller 相关的公共方法
6
+ */
7
+ constructor() {
8
+ this.app = app;
9
+ this.config = app.config;
10
+ }
11
+
12
+ /**
13
+ * API 处理成功时统一返回结构
14
+ * @param {object} ctx 上下文
15
+ * @param {object} data data 核心数据
16
+ * @param {object} metadata metadata 附加数据
17
+ */
18
+ success(ctx, data = {}, metadata = {}) {
19
+ ctx.status = 200;
20
+ ctx.body = {
21
+ success: true,
22
+ data,
23
+ metadata,
24
+ };
25
+ }
26
+
27
+ /**
28
+ * API 处理失败时统一返回结构
29
+ * @param {object} ctx 上下文
30
+ * @param {object} message 错误信息
31
+ * @param {object} code 状态码
32
+ */
33
+ fail(ctx, message, code) {
34
+ ctx.body = {
35
+ success: false,
36
+ message,
37
+ code,
38
+ };
39
+ }
40
+ };
@@ -0,0 +1,56 @@
1
+ module.exports = (app) => {
2
+ const BaseController = require("./base")(app);
3
+ return class ProjectController extends BaseController {
4
+ /**
5
+ * 获取所有模型与项目的结构化数据
6
+ */
7
+ async getModelList(ctx) {
8
+ const { project: projectService } = app.service;
9
+ const modelList = await projectService.getModelList();
10
+ // 构造返回结果,只返回关键数据
11
+ const dtoModelList = modelList.reduce((preList, item) => {
12
+ const { model, project } = item;
13
+ // 构造 model 关键数据
14
+ const { key, name } = model;
15
+ const dtoModel = { key, name };
16
+ // 构造 project 关键数据
17
+ const dtoProject = Object.keys(project).reduce((preObj, projKey) => {
18
+ const { key, name, desc, homePage } = project[projKey];
19
+ preObj[projKey] = { key, name, desc, homePage };
20
+ return preObj;
21
+ }, {});
22
+ preList.push({ model: dtoModel, project: dtoProject });
23
+ return preList;
24
+ }, []);
25
+
26
+ this.success(ctx, dtoModelList);
27
+ };
28
+ /**
29
+ * 获取当前 projKey 下的项目列表(如果没有传projKey则全量获取)
30
+ */
31
+ async getProjectList(ctx) {
32
+ const { proj_key: projKey } = ctx.request.query;
33
+ const { project: projectService } = app.service;
34
+ const projectList = await projectService.getProjectList(projKey);
35
+ // 构造关键数据 list
36
+ const dtoProjectList = projectList.map((item)=>{
37
+ const { modelKey, key, name, desc, homePage } = item;
38
+ return { modelKey, key, name, desc, homePage };
39
+ });
40
+ this.success(ctx, dtoProjectList);
41
+ };
42
+ /**
43
+ * 获取当前 projKey 下的项目配置
44
+ */
45
+ async getProjectConfig(ctx) {
46
+ const { proj_key: projKey } = ctx.request.query;
47
+ const { project: projectService } = app.service;
48
+ const projConfig = await projectService.getProjectConfig(projKey);
49
+ if (!projConfig) {
50
+ this.fail(ctx, '获取项目异常', 50000);
51
+ return;
52
+ }
53
+ this.success(ctx, projConfig);
54
+ }
55
+ };
56
+ };
@@ -0,0 +1,18 @@
1
+ module.exports = (app) => {
2
+ return class ViewController {
3
+ /**
4
+ * 渲染页面
5
+ * @param {Object} ctx Koa上下文
6
+ */
7
+ async renderPage(ctx) {
8
+ const { query, params } = ctx.request;
9
+ app.logger.info(`[ViewController] query: ${JSON.stringify(query)}`);
10
+ app.logger.info(`[ViewController] params: ${JSON.stringify(params)}`);
11
+ await ctx.render(`dist/entry.${ctx.params.page}`, {
12
+ projKey: ctx.query?.proj_key,
13
+ name: app.options?.name,
14
+ env: app.env.get(),
15
+ })
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,37 @@
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
+
36
+ return logger;
37
+ };
@@ -0,0 +1,71 @@
1
+ const Ajv = require("ajv");
2
+ const ajv = new Ajv();
3
+
4
+ module.exports = (app) => {
5
+ const $schema = "http://json-schema.org/draft-07/schema#";
6
+ return async (ctx, next) => {
7
+ // 只对 API 请求做签名校验
8
+ if (ctx.path.indexOf("/api/") < 0) {
9
+ return await next();
10
+ }
11
+ // 获取请求参数
12
+ const { body, query, headers } = ctx.request;
13
+ const { params, path, method } = ctx;
14
+
15
+ app.logger.info(`[${method} ${path}] params: ${JSON.stringify(params)}`);
16
+ app.logger.info(`[${method} ${path}] query: ${JSON.stringify(query)}`);
17
+ app.logger.info(`[${method} ${path}] body: ${JSON.stringify(body)}`);
18
+ app.logger.info(`[${method} ${path}] headers: ${JSON.stringify(headers)}`);
19
+
20
+ const schema = app.routerSchema[path]?.[method.toLowerCase()];
21
+
22
+ if (!schema) {
23
+ return await next();
24
+ }
25
+
26
+ let valid = true;
27
+
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
+ // 检验query
39
+ if (valid && query && schema.query) {
40
+ schema.query.$schema = $schema;
41
+ validate = ajv.compile(schema.query);
42
+ valid = validate(query);
43
+ }
44
+
45
+ // 检验body
46
+ if (valid && body && schema.body) {
47
+ schema.body.$schema = $schema;
48
+ validate = ajv.compile(schema.body);
49
+ valid = validate(body);
50
+ }
51
+
52
+ // 检验params
53
+ if (valid && params && schema.params) {
54
+ schema.params.$schema = $schema;
55
+ validate = ajv.compile(schema.params);
56
+ valid = validate(params);
57
+ }
58
+
59
+ if (!valid) {
60
+ ctx.status = 200;
61
+ ctx.body = {
62
+ success: false,
63
+ message: `request validate fail: ${ajv.errorsText(validate.errors)}`,
64
+ code: 442
65
+ };
66
+ return;
67
+ }
68
+
69
+ await next();
70
+ };
71
+ };
@@ -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
+ const signKey = "hgy3ghj5gyu03ghjk2ghje3kgu4ghj";
18
+ const signature = md5(`${signKey}_${st}`);
19
+ app.logger.info(`[${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
+ await next();
31
+ }
32
+ }
@@ -0,0 +1,33 @@
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;
19
+ ctx.redirect(`${app.options?.homePage}`);
20
+ return;
21
+ }
22
+
23
+ const resBody = {
24
+ success: false,
25
+ code: 50000,
26
+ message: '服务器内部错误'
27
+ };
28
+
29
+ ctx.status = 200;
30
+ ctx.body = resBody;
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * projecthandler相关项目处理内容
3
+ */
4
+ module.exports = (app) => {
5
+ return async (ctx, next) => {
6
+ // 只对业务API 进行proj_key 处理
7
+ if (ctx.path.indexOf("/api/proj/") < 0) {
8
+ return await next();
9
+ }
10
+
11
+ // 获取 projKey
12
+ const { proj_key: projKey } = ctx.request.headers;
13
+
14
+ if (!projKey) {
15
+ ctx.status = 200;
16
+ ctx.body = {
17
+ success: false,
18
+ code: 446,
19
+ message: "proj_key not found",
20
+ };
21
+ return;
22
+ }
23
+
24
+ ctx.projKey = projKey;
25
+ await next();
26
+ };
27
+ };
@@ -0,0 +1,31 @@
1
+ const path = require("path");
2
+
3
+ module.exports = (app) => {
4
+ const koaStatic = require("koa-static");
5
+ app.use(koaStatic(path.resolve(process.cwd(), "./app/public")));
6
+ // 模板渲染引擎
7
+ const koaNunjucks = require("koa-nunjucks-2");
8
+ app.use(koaNunjucks({
9
+ ext: "tpl",
10
+ path: path.resolve(process.cwd(), "./app/public"),
11
+ nunjucksConfig: {
12
+ noCache: true,
13
+ trimBlocks: true,
14
+ },
15
+ }));
16
+
17
+ // 引入 ctx.body 解析中间件
18
+ const koaBodyParser = require("koa-bodyparser");
19
+ app.use(koaBodyParser({
20
+ formLimit: "1000mb",
21
+ enableTypes: ["json", "form", "text"],
22
+ }));
23
+ // 引入错误处理中间件
24
+ app.use(app.middlewares.errorHandler);
25
+ // 引入 API 签名校验中间件
26
+ app.use(app.middlewares.apiSignVerify);
27
+ // 引入 API 参数校验中间件
28
+ app.use(app.middlewares.apiParamsVerify);
29
+ // 引入项目处理中间件
30
+ app.use(app.middlewares.projectHandler);
31
+ }
@@ -0,0 +1,12 @@
1
+ html, body {
2
+ height: 100%;
3
+ }
4
+
5
+ #root {
6
+ height: 100%;
7
+ }
8
+
9
+ input:-webkit-autpfill {
10
+ /* 覆盖自动填充背景颜色 */
11
+ -webkit-box-shadow: 0 0 0px 1000px #121212 inset;
12
+ }
@@ -0,0 +1,47 @@
1
+ import { createApp } from "vue";
2
+
3
+ // 引入element-plus
4
+ import ElementPlus from "element-plus";
5
+ import "element-plus/theme-chalk/index.css";
6
+ import "element-plus/theme-chalk/dark/css-vars.css";
7
+
8
+ // 引入自定义样式
9
+ import "./asserts/custom.css";
10
+
11
+ import { pinia } from "$elpisStore"; // 引入pinia
12
+ import { createRouter, createWebHistory } from "vue-router";
13
+ /**
14
+ * vue 页面主入口,用于启动 vue
15
+ * @param pageComponent vue 入口组件
16
+ * @param routes 路由列表
17
+ * @param libs 页面使用的依赖的第三方包列表
18
+ */
19
+
20
+ export default (pageComponent, { routes, libs } = {}) => {
21
+ const app = createApp(pageComponent);
22
+ // 挂载element-plus
23
+ app.use(ElementPlus);
24
+ // 引入pinia
25
+ app.use(pinia);
26
+ // 挂载第三方包
27
+ if (libs && libs.length) {
28
+ for (let i = 0; i < libs.length; ++i) {
29
+ app.use(libs[i]);
30
+ }
31
+ }
32
+ // 页面路由
33
+ if (routes && routes.length) {
34
+ const router = createRouter({
35
+ history: createWebHistory(), // 历史记录模式
36
+ routes,
37
+ });
38
+ // 挂载路由
39
+ app.use(router);
40
+ router.isReady().then(() => {
41
+ // 挂载到页面根元素
42
+ app.mount("#root");
43
+ });
44
+ } else {
45
+ app.mount("#root");
46
+ }
47
+ };