@slice_cy/mint 1.2.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 (98) hide show
  1. package/README.md +697 -0
  2. package/app/common/base-response.js +10 -0
  3. package/app/common/business-error.js +10 -0
  4. package/app/common/error-code.js +22 -0
  5. package/app/common/return-utils.js +40 -0
  6. package/app/common/router-schema-validator.js +25 -0
  7. package/app/controller/base.js +24 -0
  8. package/app/controller/project.js +90 -0
  9. package/app/controller/view.js +13 -0
  10. package/app/docs/dsl-doc.js +148 -0
  11. package/app/extend/logger.js +30 -0
  12. package/app/extend/params-valid.js +6 -0
  13. package/app/extend/return-utils.js +9 -0
  14. package/app/middleware/api-sign-verify.js +25 -0
  15. package/app/middleware/err-handler.js +18 -0
  16. package/app/middleware/project-handler.js +25 -0
  17. package/app/pages/boot.js +34 -0
  18. package/app/pages/dashboard/complex-view/header-view/index.vue +108 -0
  19. package/app/pages/dashboard/complex-view/iframe-view/index.vue +37 -0
  20. package/app/pages/dashboard/complex-view/schema-view/complex-view/search-panel/index.vue +36 -0
  21. package/app/pages/dashboard/complex-view/schema-view/complex-view/table-panel/index.vue +123 -0
  22. package/app/pages/dashboard/complex-view/schema-view/components/component-config.js +14 -0
  23. package/app/pages/dashboard/complex-view/schema-view/components/createForm/index.vue +72 -0
  24. package/app/pages/dashboard/complex-view/schema-view/components/detailPanel/index.vue +52 -0
  25. package/app/pages/dashboard/complex-view/schema-view/components/editForm/index.vue +87 -0
  26. package/app/pages/dashboard/complex-view/schema-view/hook/use-schema.js +113 -0
  27. package/app/pages/dashboard/complex-view/schema-view/index.vue +114 -0
  28. package/app/pages/dashboard/complex-view/sider-view/index.vue +116 -0
  29. package/app/pages/dashboard/entry.dashboard.js +44 -0
  30. package/app/pages/dashboard/index.vue +60 -0
  31. package/app/pages/service/index.js +70 -0
  32. package/app/pages/store/index.js +4 -0
  33. package/app/pages/store/menu.js +86 -0
  34. package/app/pages/store/project.js +9 -0
  35. package/app/pages/utils/index.js +26 -0
  36. package/app/pages/widgets/header-container/assets/avatar.png +0 -0
  37. package/app/pages/widgets/header-container/assets/icon.png +0 -0
  38. package/app/pages/widgets/header-container/index.vue +108 -0
  39. package/app/pages/widgets/schema-form/components/input/index.vue +155 -0
  40. package/app/pages/widgets/schema-form/components/input-number/index.vue +148 -0
  41. package/app/pages/widgets/schema-form/components/select/index.vue +132 -0
  42. package/app/pages/widgets/schema-form/form-item-cofnig.js +18 -0
  43. package/app/pages/widgets/schema-form/index.vue +137 -0
  44. package/app/pages/widgets/schema-search-bar/component/date-range-picker/index.vue +55 -0
  45. package/app/pages/widgets/schema-search-bar/component/dynamic-select/index.vue +70 -0
  46. package/app/pages/widgets/schema-search-bar/component/input/index.vue +54 -0
  47. package/app/pages/widgets/schema-search-bar/component/select/index.vue +65 -0
  48. package/app/pages/widgets/schema-search-bar/index.vue +143 -0
  49. package/app/pages/widgets/schema-search-bar/search-item-config.js +20 -0
  50. package/app/pages/widgets/schema-table/index.vue +198 -0
  51. package/app/pages/widgets/sider-container/index.vue +30 -0
  52. package/app/post-router.js +9 -0
  53. package/app/pre-middleware.js +37 -0
  54. package/app/public/dist/entry.dashboard.tpl +2 -0
  55. package/app/public/dist/entry.project-list.tpl +2 -0
  56. package/app/public/dist/prod/css/async.609.bcbe5779.css +1 -0
  57. package/app/public/dist/prod/css/async.952.9bc7c180.css +1 -0
  58. package/app/public/dist/prod/css/common.1a98227b.css +1 -0
  59. package/app/public/dist/prod/css/entry.project-list.14f64dd9.css +1 -0
  60. package/app/public/dist/prod/js/142.56646c73.bundle.js +1 -0
  61. package/app/public/dist/prod/js/609.8270b20d.bundle.js +1 -0
  62. package/app/public/dist/prod/js/68.2813fafe.bundle.js +1 -0
  63. package/app/public/dist/prod/js/952.c76c04fb.bundle.js +1 -0
  64. package/app/public/dist/prod/js/common.9985f827.bundle.js +1 -0
  65. package/app/public/dist/prod/js/entry.dashboard.cd7591e4.bundle.js +1 -0
  66. package/app/public/dist/prod/js/entry.project-list.beb0fa9d.bundle.js +1 -0
  67. package/app/public/dist/prod/js/runtime.5602b906.bundle.js +1 -0
  68. package/app/public/dist/prod/js/vendor.709fbf32.bundle.js +53 -0
  69. package/app/public/dist/prod/static/images/avatar.78e68eaa.png +0 -0
  70. package/app/public/dist/static/logo.png +0 -0
  71. package/app/public/dist/static/normalize.css +1 -0
  72. package/app/public/static/logo.png +0 -0
  73. package/app/public/static/normalize.css +267 -0
  74. package/app/router/project.js +6 -0
  75. package/app/router/view.js +5 -0
  76. package/app/router-schema/project.js +14 -0
  77. package/app/service/base.js +22 -0
  78. package/app/service/project.js +49 -0
  79. package/app/view/entry.tpl +18 -0
  80. package/app/webpack/config/webpack.base.js +288 -0
  81. package/app/webpack/config/webpack.dev.js +53 -0
  82. package/app/webpack/config/webpack.prod.js +106 -0
  83. package/app/webpack/dev.js +34 -0
  84. package/app/webpack/libs/block.js +1 -0
  85. package/app/webpack/prod.js +21 -0
  86. package/config/config.default.js +5 -0
  87. package/index.js +37 -0
  88. package/mint-core/env.js +23 -0
  89. package/mint-core/index.js +101 -0
  90. package/mint-core/loader/config.js +59 -0
  91. package/mint-core/loader/controller.js +59 -0
  92. package/mint-core/loader/extend.js +42 -0
  93. package/mint-core/loader/middleware.js +54 -0
  94. package/mint-core/loader/router-schema.js +39 -0
  95. package/mint-core/loader/router.js +36 -0
  96. package/mint-core/loader/service.js +57 -0
  97. package/model/index.js +94 -0
  98. package/package.json +93 -0
package/README.md ADDED
@@ -0,0 +1,697 @@
1
+ # @slice_cy/mint
2
+
3
+ `@slice_cy/mint` 是一个基于 Koa、Vue、Webpack 的约定式中后台框架包。业务应用安装这个包后,主要做三件事:
4
+
5
+ - 用 `start()` 启动 Node 服务。
6
+ - 用 `frontendBuild()` 构建前端页面。
7
+ - 在约定目录下编写后端模块、前端扩展和 DSL 模型。
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ pnpm add @slice_cy/mint
13
+ ```
14
+
15
+ 安装 mint 后,业务项目可以在 mint 的前端构建体系里直接写 Ant Design Vue 组件。mint 已经把 `ant-design-vue` 放在生产依赖里,并在 webpack 中配置了解析别名,用来保证软链接、pnpm workspace 等场景下也能解析到正确包目录。
16
+
17
+ ## 启动
18
+
19
+ 业务项目根目录创建 `index.js`:
20
+
21
+ ```js
22
+ const { start } = require("@slice_cy/mint");
23
+
24
+ start({
25
+ name: "mint-demo",
26
+ });
27
+ ```
28
+
29
+ 创建 `build.js`:
30
+
31
+ ```js
32
+ const { frontendBuild } = require("@slice_cy/mint");
33
+
34
+ frontendBuild(process.env.NODE_ENV);
35
+ ```
36
+
37
+ `package.json` 建议脚本:
38
+
39
+ ```json
40
+ {
41
+ "scripts": {
42
+ "start": "nodemon index.js",
43
+ "build:dev": "cross-env NODE_ENV=development node build.js",
44
+ "build:prod": "cross-env NODE_ENV=production node build.js"
45
+ }
46
+ }
47
+ ```
48
+
49
+ 常用命令:
50
+
51
+ ```bash
52
+ pnpm start
53
+ pnpm build:dev
54
+ pnpm build:prod
55
+ ```
56
+
57
+ 运行时环境变量:
58
+
59
+ - `PORT`:Node 服务端口,默认 `8080`。
60
+ - `HOST`:Node 服务监听地址,默认 `0.0.0.0`。
61
+ - `_ENV`:配置环境,支持 `local`、`beta`、`production`,默认按本地环境处理。
62
+
63
+ ## 目录约定
64
+
65
+ 业务项目推荐结构:
66
+
67
+ ```text
68
+ .
69
+ ├── index.js
70
+ ├── build.js
71
+ ├── config/
72
+ │ ├── config.default.js
73
+ │ ├── config.local.js
74
+ │ ├── config.beta.js
75
+ │ └── config.production.js
76
+ ├── model/
77
+ │ └── <modelKey>/
78
+ │ ├── model.js
79
+ │ └── project/
80
+ │ └── <projectKey>.js
81
+ └── app/
82
+ ├── controller/
83
+ ├── service/
84
+ ├── middleware/
85
+ ├── router/
86
+ ├── router-schema/
87
+ ├── pre-middleware.js
88
+ ├── post-router.js
89
+ ├── webpack.config.js
90
+ ├── public/
91
+ └── pages/
92
+ ├── <page>/
93
+ │ └── entry.<page>.js
94
+ ├── dashboard/
95
+ │ ├── router.js
96
+ │ └── schema-view/
97
+ │ └── components/
98
+ │ └── component-cofnig.js
99
+ └── widgets/
100
+ ├── schema-form/
101
+ │ └── form-item-cofnig.js
102
+ └── schema-search-bar/
103
+ └── search-item-cofnig.js
104
+ ```
105
+
106
+ 注意:当前 webpack 约定里 `component-cofnig.js`、`form-item-cofnig.js`、`search-item-cofnig.js` 的文件名就是这样拼写。业务扩展文件如果写成 `*-config.js`,不会被Mint自动扫描
107
+
108
+ ## 后端约定
109
+
110
+ ### 配置
111
+
112
+ 配置文件放在 `config/`:
113
+
114
+ ```text
115
+ config/config.default.js
116
+ config/config.local.js
117
+ config/config.beta.js
118
+ config/config.production.js
119
+ ```
120
+
121
+ 每个配置文件导出函数:
122
+
123
+ ```js
124
+ module.exports = (app) => ({
125
+ // config
126
+ });
127
+ ```
128
+
129
+ 最终配置会挂载到 `app.config`,环境配置会覆盖 `config.default.js`。
130
+
131
+ ### Controller
132
+
133
+ 业务 Controller 放在 `app/controller/**/*.js`,会合并到 `app.controller`。
134
+
135
+ ```js
136
+ module.exports = (app) => {
137
+ const BaseController = require("@slice_cy/mint").Controller.Base(app);
138
+
139
+ return class UserController extends BaseController {
140
+ async list(ctx) {
141
+ ctx.body = { success: true };
142
+ }
143
+ };
144
+ };
145
+ ```
146
+
147
+ 路径会转换为对象路径,例如:
148
+
149
+ ```text
150
+ app/controller/user.js -> app.controller.user
151
+ app/controller/admin/user-profile.js -> app.controller.admin.userProfile
152
+ ```
153
+
154
+ ### Service
155
+
156
+ 业务 Service 放在 `app/service/**/*.js`,会合并到 `app.service`。
157
+
158
+ ```js
159
+ module.exports = (app) => {
160
+ const BaseService = require("@slice_cy/mint").Service.Base(app);
161
+
162
+ return class UserService extends BaseService {
163
+ async list() {
164
+ return [];
165
+ }
166
+ };
167
+ };
168
+ ```
169
+
170
+ 路径转换规则和 Controller 一致。
171
+
172
+ ### Middleware
173
+
174
+ 业务中间件放在 `app/middleware/**/*.js`,会加载到 `app.middlewares`,但不会自动 `app.use()`。
175
+
176
+ ```js
177
+ module.exports = (app) => {
178
+ return async (ctx, next) => {
179
+ await next();
180
+ };
181
+ };
182
+ ```
183
+
184
+ 需要全局注册时,在 `app/pre-middleware.js` 中使用:
185
+
186
+ ```js
187
+ module.exports = (app) => {
188
+ app.use(app.middlewares.errHandler);
189
+ };
190
+ ```
191
+
192
+ ### Router
193
+
194
+ 业务路由放在 `app/router/**/*.js`。router loader 会创建同一个 `router` 实例,并把 `app` 和 `router` 传给每个路由文件:
195
+
196
+ ```js
197
+ module.exports = (app, router) => {
198
+ router.get("/api/user/list", app.controller.user.list.bind(app.controller.user));
199
+ };
200
+ ```
201
+
202
+ 如果需要在所有业务路由注册后追加兜底逻辑,放在 `app/post-router.js`:
203
+
204
+ ```js
205
+ module.exports = (app, router) => {
206
+ router.all("(.*)", async (ctx) => {
207
+ ctx.status = 404;
208
+ ctx.body = { success: false, message: "Not Found" };
209
+ });
210
+ };
211
+ ```
212
+
213
+ 接口参数校验 schema 放在 `app/router-schema/**/*.js`,会合并到 `app.routerSchema`。业务可以结合 `app.paramsValid` 或自己的中间件使用。
214
+
215
+ ## 前端约定
216
+
217
+ ### 页面入口
218
+
219
+ mint 会扫描两类入口:
220
+
221
+ ```text
222
+ @slice_cy/mint/app/pages/**/entry.*.js
223
+ 业务项目/app/pages/**/entry.*.js
224
+ ```
225
+
226
+ 例如:
227
+
228
+ ```text
229
+ app/pages/project-list/entry.project-list.js
230
+ ```
231
+
232
+ 构建后会输出模板:
233
+
234
+ ```text
235
+ app/public/dist/entry.project-list.tpl
236
+ ```
237
+
238
+ ### webpack 扩展
239
+
240
+ 业务项目可以创建 `app/webpack.config.js` 扩展 mint 的 webpack 配置:
241
+
242
+ ```js
243
+ module.exports = {
244
+ resolve: {
245
+ alias: {
246
+ demo: "demo",
247
+ },
248
+ },
249
+ };
250
+ ```
251
+
252
+ mint 内置常用 alias:
253
+
254
+ - `$mintPage`
255
+ - `$mintService`
256
+ - `$mintWidgets`
257
+ - `$mintHeaderContainer`
258
+ - `$mintSchemaForm`
259
+ - `$mintSchemaSearchBar`
260
+ - `$mintSchemaTable`
261
+ - `$mintSiderContainer`
262
+ - `$mintBootstrap`
263
+ - `$mintStore`
264
+ - `$mintUtils`
265
+
266
+ ### Dashboard 扩展
267
+
268
+ dashboard 支持以下业务扩展文件:
269
+
270
+ ```text
271
+ app/pages/dashboard/router.js
272
+ app/pages/dashboard/schema-view/components/component-cofnig.js
273
+ app/pages/widgets/schema-form/form-item-cofnig.js
274
+ app/pages/widgets/schema-search-bar/search-item-cofnig.js
275
+ ```
276
+
277
+ 用途:
278
+
279
+ - `router.js`:扩展 dashboard 内的前端路由。
280
+ - `component-cofnig.js`:扩展 schema-view 的动态业务组件。
281
+ - `form-item-cofnig.js`:扩展 schema-form 的表单控件。
282
+ - `search-item-cofnig.js`:扩展 schema-search-bar 的搜索控件。
283
+
284
+ 这些配置文件建议导出对象。组件建议使用异步导入,避免业务组件被同步打进首屏包:
285
+
286
+ ```js
287
+ const { defineAsyncComponent } = require("vue");
288
+
289
+ module.exports = {
290
+ demoForm: {
291
+ component: defineAsyncComponent(() => import("./demoForm/index.vue")),
292
+ },
293
+ };
294
+ ```
295
+
296
+ ## DSL 模型
297
+
298
+ DSL 放在业务项目的 `model/` 目录下,用来描述站点、菜单、schema 页面、表格、搜索、表单和动态组件。
299
+
300
+ ### 模型目录
301
+
302
+ ```text
303
+ model/
304
+ └── business/
305
+ ├── model.js
306
+ └── project/
307
+ ├── taobao.js
308
+ └── pdd.js
309
+ ```
310
+
311
+ 含义:
312
+
313
+ - `model/<modelKey>/model.js`:领域模型基础配置。
314
+ - `model/<modelKey>/project/<projectKey>.js`:项目模型配置。
315
+ - 项目模型会继承并覆盖领域模型。
316
+ - 数组合并时会按 `key` 匹配,同 key 合并,不同 key 追加。
317
+
318
+ 访问项目列表和项目模型的内置接口:
319
+
320
+ ```text
321
+ GET /api/project/modelList
322
+ GET /api/project/list?project_key=<modelKey>
323
+ GET /api/project?project_key=<projectKey>
324
+ ```
325
+
326
+ ### 顶层结构
327
+
328
+ ```js
329
+ module.exports = {
330
+ model: "dashboard",
331
+ name: "电商领域模型",
332
+ desc: "",
333
+ icon: "",
334
+ homePage: "",
335
+ menu: [],
336
+ };
337
+ ```
338
+
339
+ 字段说明:
340
+
341
+ - `model`:渲染模板标识,目前 dashboard 页面使用 `dashboard`。
342
+ - `name`:站点或模型名称。
343
+ - `desc`:描述。
344
+ - `icon`:图标。
345
+ - `homePage`:首页路由。
346
+ - `menu`:菜单和功能模块配置。
347
+
348
+ ### Menu 配置
349
+
350
+ ```js
351
+ {
352
+ key: "user",
353
+ name: "用户管理",
354
+ menuType: "module",
355
+ moduleType: "schema",
356
+ schemaConfig: {}
357
+ }
358
+ ```
359
+
360
+ 字段说明:
361
+
362
+ - `key`:菜单唯一标识,同一份 DSL 中不要重复。
363
+ - `name`:菜单展示名称。
364
+ - `menuType`:`group` 或 `module`。
365
+ - `moduleType`:`custom`、`schema`、`iframe`、`sider`。
366
+ - `subMenu`:`menuType: "group"` 时使用。
367
+
368
+ 不同模块类型的配置:
369
+
370
+ ```js
371
+ {
372
+ moduleType: "custom",
373
+ customConfig: {
374
+ path: "/todo"
375
+ }
376
+ }
377
+ ```
378
+
379
+ ```js
380
+ {
381
+ moduleType: "iframe",
382
+ iframeConfig: {
383
+ path: "https://example.com"
384
+ }
385
+ }
386
+ ```
387
+
388
+ ```js
389
+ {
390
+ moduleType: "sider",
391
+ siderConfig: {
392
+ menu: []
393
+ }
394
+ }
395
+ ```
396
+
397
+ ```js
398
+ {
399
+ moduleType: "schema",
400
+ schemaConfig: {}
401
+ }
402
+ ```
403
+
404
+ ### Schema 页面配置
405
+
406
+ `schemaConfig` 描述标准 CRUD 页面:
407
+
408
+ ```js
409
+ schemaConfig: {
410
+ api: "/api/proj/user",
411
+ schema: {
412
+ type: "object",
413
+ properties: {},
414
+ required: []
415
+ },
416
+ tableConfig: {
417
+ antdTableConfig: {},
418
+ headerButtons: [],
419
+ rowButtons: []
420
+ },
421
+ searchBarConfig: {},
422
+ componentConfig: {}
423
+ }
424
+ ```
425
+
426
+ 接口约定:
427
+
428
+ - `GET <api>/list`:列表查询。
429
+ - `GET <api>/:id`:详情。
430
+ - `POST <api>`:新增。
431
+ - `PUT <api>/:id`:编辑。
432
+ - `DELETE <api>/:id`:删除。
433
+
434
+ ### 字段配置
435
+
436
+ `schema.properties` 中每个字段描述一个业务字段:
437
+
438
+ ```js
439
+ id: {
440
+ type: "string",
441
+ label: "用户ID",
442
+ tableOption: {
443
+ uiTableColumnConfig: {},
444
+ visible: true
445
+ },
446
+ searchOption: {
447
+ comType: "input",
448
+ default: ""
449
+ },
450
+ createFormOption: {
451
+ comType: "input",
452
+ default: "",
453
+ disabled: false
454
+ },
455
+ editFormOption: {
456
+ comType: "input"
457
+ },
458
+ detailPanelOption: {
459
+ comType: "input",
460
+ disabled: true
461
+ }
462
+ }
463
+ ```
464
+
465
+ 通用字段:
466
+
467
+ - `type`:字段类型。
468
+ - `label`:展示名称。
469
+ - `tableOption`:字段在表格中的展示配置;不配置则不展示。
470
+ - `searchOption`:字段在搜索栏中的展示配置;不配置则不展示。
471
+ - `[comName]Option`:字段在动态组件中的展示配置,例如 `createFormOption`、`editFormOption`、`detailPanelOption`。
472
+ - `required`:写在 `schema.required` 数组中,会影响表单必填校验。
473
+
474
+ `tableOption` 常用配置:
475
+
476
+ - `uiTableColumnConfig`:透传给 Ant Design Vue Table column 的配置。
477
+ - `visible`:显式为 `false` 时隐藏。
478
+ - `toFixed`:数字字段小数位处理。
479
+
480
+ `searchOption` 常用配置:
481
+
482
+ - `comType`:搜索控件类型,内置 `input`、`select`、`dynamicSelect`、`dateRangePicker`。
483
+ - `uiComponentConfig`:透传给控件的 UI 配置。
484
+ - `enumList`:`select` 选项。
485
+ - `api`:`dynamicSelect` 拉取选项的接口。
486
+ - `default`:默认值。
487
+ - `visible`:显式为 `false` 时隐藏。
488
+
489
+ 表单动态组件内置 `comType`:
490
+
491
+ - `input`
492
+ - `select`
493
+ - `inputNumber`
494
+
495
+ 需要更多控件时,放到 `app/pages/widgets/schema-form/form-item-cofnig.js` 扩展。
496
+
497
+ ### 表格按钮
498
+
499
+ ```js
500
+ tableConfig: {
501
+ headerButtons: [
502
+ {
503
+ label: "新增",
504
+ eventKey: "showComponent",
505
+ eventOption: {
506
+ comName: "createForm"
507
+ },
508
+ uiButtonConfig: {
509
+ type: "primary"
510
+ }
511
+ }
512
+ ],
513
+ rowButtons: [
514
+ {
515
+ label: "删除",
516
+ eventKey: "remove",
517
+ eventOption: {
518
+ params: {
519
+ id: "schema::id"
520
+ }
521
+ },
522
+ uiButtonConfig: {
523
+ type: "link",
524
+ danger: true
525
+ }
526
+ }
527
+ ]
528
+ }
529
+ ```
530
+
531
+ 内置事件:
532
+
533
+ - `showComponent`:打开 `componentConfig` 中指定的动态组件。
534
+ - `remove`:按 `eventOption.params` 取当前行参数并调用删除接口。
535
+
536
+ `eventOption.params` 支持:
537
+
538
+ - 固定值:直接写值。
539
+ - 行字段:`schema::id` 表示取当前行的 `id` 字段。
540
+
541
+ ### 动态组件
542
+
543
+ `componentConfig` 描述 schema-view 的动态区域:
544
+
545
+ ```js
546
+ componentConfig: {
547
+ createForm: {
548
+ title: "新增用户",
549
+ saveBtnText: "保存",
550
+ eventKey: "loadTableList"
551
+ },
552
+ editForm: {
553
+ title: "编辑用户",
554
+ saveBtnText: "保存",
555
+ eventKey: "loadTableList",
556
+ mainKey: "id"
557
+ },
558
+ detailPanel: {
559
+ title: "查看用户",
560
+ mainKey: "id"
561
+ },
562
+ demoForm: {}
563
+ }
564
+ ```
565
+
566
+ 内置组件名:
567
+
568
+ - `createForm`
569
+ - `editForm`
570
+ - `detailPanel`
571
+
572
+ 业务自定义组件需要在 `app/pages/dashboard/schema-view/components/component-cofnig.js` 中注册。
573
+
574
+ ## 最小 DSL 示例
575
+
576
+ ```js
577
+ module.exports = {
578
+ model: "dashboard",
579
+ name: "电商领域模型",
580
+ menu: [
581
+ {
582
+ key: "user",
583
+ name: "用户管理",
584
+ menuType: "module",
585
+ moduleType: "schema",
586
+ schemaConfig: {
587
+ api: "/api/proj/user",
588
+ schema: {
589
+ type: "object",
590
+ properties: {
591
+ id: {
592
+ type: "string",
593
+ label: "用户ID",
594
+ tableOption: {},
595
+ searchOption: {
596
+ comType: "input",
597
+ },
598
+ createFormOption: {
599
+ comType: "input",
600
+ },
601
+ editFormOption: {
602
+ comType: "input",
603
+ },
604
+ detailPanelOption: {
605
+ comType: "input",
606
+ disabled: true,
607
+ },
608
+ },
609
+ role: {
610
+ type: "string",
611
+ label: "角色",
612
+ tableOption: {},
613
+ searchOption: {
614
+ comType: "select",
615
+ enumList: [
616
+ { label: "管理员", value: "admin" },
617
+ { label: "普通用户", value: "user" },
618
+ ],
619
+ },
620
+ },
621
+ },
622
+ required: ["id"],
623
+ },
624
+ tableConfig: {
625
+ headerButtons: [
626
+ {
627
+ label: "新增",
628
+ eventKey: "showComponent",
629
+ eventOption: {
630
+ comName: "createForm",
631
+ },
632
+ uiButtonConfig: {
633
+ type: "primary",
634
+ },
635
+ },
636
+ ],
637
+ rowButtons: [
638
+ {
639
+ label: "查看",
640
+ eventKey: "showComponent",
641
+ eventOption: {
642
+ comName: "detailPanel",
643
+ },
644
+ uiButtonConfig: {
645
+ type: "link",
646
+ },
647
+ },
648
+ ],
649
+ },
650
+ componentConfig: {
651
+ createForm: {
652
+ title: "新增用户",
653
+ saveBtnText: "保存",
654
+ eventKey: "loadTableList",
655
+ },
656
+ detailPanel: {
657
+ title: "查看用户",
658
+ mainKey: "id",
659
+ },
660
+ },
661
+ },
662
+ },
663
+ ],
664
+ };
665
+ ```
666
+
667
+ 项目覆盖示例:
668
+
669
+ ```js
670
+ module.exports = {
671
+ name: "淘宝项目",
672
+ homePage: "/dashboard/user",
673
+ menu: [
674
+ {
675
+ key: "user",
676
+ schemaConfig: {
677
+ schema: {
678
+ properties: {
679
+ role: {
680
+ searchOption: {
681
+ visible: false,
682
+ },
683
+ },
684
+ },
685
+ },
686
+ },
687
+ },
688
+ ],
689
+ };
690
+ ```
691
+
692
+ ## 开发建议
693
+
694
+ - 领域通用配置写在 `model/<modelKey>/model.js`,项目差异写在 `model/<modelKey>/project/<projectKey>.js`。
695
+ - 表格、搜索、表单都围绕同一份 `schema.properties` 描述,避免在页面组件里重复写字段。
696
+ - 业务自定义组件、搜索控件、表单控件优先使用异步导入,降低首屏包体积。
697
+ - 不需要覆盖 mint 内部 webpack 时,不要创建过多业务 webpack 配置;需要覆盖时集中写在 `app/webpack.config.js`。
@@ -0,0 +1,10 @@
1
+ class BaseResponse {
2
+ constructor({ code, message, data = null, metaData = {} } = {}) {
3
+ this.code = code;
4
+ this.message = message;
5
+ this.data = data;
6
+ this.metaData = metaData;
7
+ }
8
+ }
9
+
10
+ module.exports = BaseResponse;
@@ -0,0 +1,10 @@
1
+ class BusinessError extends Error {
2
+ constructor(code, message) {
3
+ super(message);
4
+ this.name = "BusinessError";
5
+ this.code = code;
6
+ this.isBusinessError = true;
7
+ }
8
+ }
9
+
10
+ module.exports = BusinessError;