q-koa 7.7.2

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 (116) hide show
  1. package/core/app.js +1813 -0
  2. package/core/config.js +124 -0
  3. package/core/file/plugins/administrator/config.js +17 -0
  4. package/core/file/plugins/administrator/controller.js +264 -0
  5. package/core/file/plugins/administrator/model.js +53 -0
  6. package/core/file/plugins/administrator/validate.js +41 -0
  7. package/core/file/plugins/alipay/controller.js +68 -0
  8. package/core/file/plugins/alipay/validate.js +9 -0
  9. package/core/file/plugins/cache/service.js +16 -0
  10. package/core/file/plugins/cloudfunction/config.js +4 -0
  11. package/core/file/plugins/cloudfunction/model.js +15 -0
  12. package/core/file/plugins/common/controller.js +398 -0
  13. package/core/file/plugins/common/validate.js +47 -0
  14. package/core/file/plugins/douyin/config.js +3 -0
  15. package/core/file/plugins/douyin/controller.js +521 -0
  16. package/core/file/plugins/douyin/validate.js +40 -0
  17. package/core/file/plugins/douyin_user/config.js +15 -0
  18. package/core/file/plugins/douyin_user/model.js +72 -0
  19. package/core/file/plugins/good_sku/controller.js +80 -0
  20. package/core/file/plugins/h5_user/config.js +19 -0
  21. package/core/file/plugins/h5_user/model.js +71 -0
  22. package/core/file/plugins/lang/config.js +4 -0
  23. package/core/file/plugins/lang/model.js +15 -0
  24. package/core/file/plugins/language/config.js +5 -0
  25. package/core/file/plugins/language/model.js +54 -0
  26. package/core/file/plugins/log/config.js +25 -0
  27. package/core/file/plugins/log/controller.js +31 -0
  28. package/core/file/plugins/log/model.js +51 -0
  29. package/core/file/plugins/model/config.js +12 -0
  30. package/core/file/plugins/model/controller.js +69 -0
  31. package/core/file/plugins/model/model.js +169 -0
  32. package/core/file/plugins/model/service.js +218 -0
  33. package/core/file/plugins/model/validate.js +42 -0
  34. package/core/file/plugins/model_attributes/config.js +12 -0
  35. package/core/file/plugins/model_attributes/model.js +114 -0
  36. package/core/file/plugins/mp_user/config.js +19 -0
  37. package/core/file/plugins/mp_user/model.js +59 -0
  38. package/core/file/plugins/permission/config.js +15 -0
  39. package/core/file/plugins/permission/model.js +91 -0
  40. package/core/file/plugins/role/config.js +27 -0
  41. package/core/file/plugins/role/controller.js +26 -0
  42. package/core/file/plugins/role/model.js +58 -0
  43. package/core/file/plugins/role_permission/config.js +12 -0
  44. package/core/file/plugins/role_permission/controller.js +27 -0
  45. package/core/file/plugins/role_permission/model.js +24 -0
  46. package/core/file/plugins/routes/config.js +17 -0
  47. package/core/file/plugins/routes/controller.js +153 -0
  48. package/core/file/plugins/routes/model.js +70 -0
  49. package/core/file/plugins/routes/service.js +22 -0
  50. package/core/file/plugins/setting/afterExecute.js +14 -0
  51. package/core/file/plugins/setting/config.js +14 -0
  52. package/core/file/plugins/setting/controller.js +50 -0
  53. package/core/file/plugins/setting/model.js +118 -0
  54. package/core/file/plugins/setting/validate.js +42 -0
  55. package/core/file/plugins/system/controller.js +501 -0
  56. package/core/file/plugins/system/service.js +148 -0
  57. package/core/file/plugins/system/validate.js +40 -0
  58. package/core/file/plugins/todolist/config.js +31 -0
  59. package/core/file/plugins/todolist/model.js +69 -0
  60. package/core/file/plugins/toutiao/controller.js +201 -0
  61. package/core/file/plugins/toutiao_user/config.js +15 -0
  62. package/core/file/plugins/toutiao_user/model.js +66 -0
  63. package/core/file/plugins/user/afterExecute.js +38 -0
  64. package/core/file/plugins/user/config.js +9 -0
  65. package/core/file/plugins/user/controller.js +329 -0
  66. package/core/file/plugins/user/model.js +96 -0
  67. package/core/file/plugins/user/test.js +71 -0
  68. package/core/file/plugins/user/validate.js +44 -0
  69. package/core/file/plugins/video/config.js +3 -0
  70. package/core/file/plugins/video/controller.js +15 -0
  71. package/core/file/plugins/video/validate.js +12 -0
  72. package/core/file/plugins/weixin/config.js +3 -0
  73. package/core/file/plugins/weixin/controller.js +994 -0
  74. package/core/file/plugins/weixin/service.js +105 -0
  75. package/core/file/plugins/weixin/validate.js +111 -0
  76. package/core/file/services/aliSms.js +45 -0
  77. package/core/file/services/alipay.js +123 -0
  78. package/core/file/services/amap.js +95 -0
  79. package/core/file/services/card.js +24 -0
  80. package/core/file/services/config.js +38 -0
  81. package/core/file/services/douyin.js +151 -0
  82. package/core/file/services/email.js +45 -0
  83. package/core/file/services/express.js +37 -0
  84. package/core/file/services/geo.js +71 -0
  85. package/core/file/services/qqVideo.js +64 -0
  86. package/core/file/services/toutiao.js +102 -0
  87. package/core/file/services/weixin.js +79 -0
  88. package/core/file/services/weixinArticle.js +53 -0
  89. package/core/file/services/weixinCrypt.js +34 -0
  90. package/core/file/services/weixinMP.js +435 -0
  91. package/core/file/services/weixinPay.js +35 -0
  92. package/core/file/services/xml.js +33 -0
  93. package/core/file/task/shop/index.js +589 -0
  94. package/core/file/task/shop/static/562e45760a44632de6fa7219bab78cce.png +0 -0
  95. package/core/file/task/shop/static/d7aeaeb6bfd68f71a00a83c0f5548363.png +0 -0
  96. package/core/file/utils/index.js +61 -0
  97. package/core/middlewares.js +120 -0
  98. package/core/restc/.npminstall.done +1 -0
  99. package/core/restc/LICENSE +21 -0
  100. package/core/restc/README.md +48 -0
  101. package/core/restc/faas/index.html +1112 -0
  102. package/core/restc/faas/index.txt +31 -0
  103. package/core/restc/faas/install_production.sh +6 -0
  104. package/core/restc/index.d.ts +7 -0
  105. package/core/restc/index.js +9 -0
  106. package/core/restc/lib/express.js +7 -0
  107. package/core/restc/lib/hapi.js +17 -0
  108. package/core/restc/lib/hapiLegacy.js +15 -0
  109. package/core/restc/lib/index.js +46 -0
  110. package/core/restc/lib/koa.js +9 -0
  111. package/core/restc/lib/koa2.js +9 -0
  112. package/core/restc/lib/utils/gateway.js +51 -0
  113. package/core/restc/package.json +41 -0
  114. package/core/validator.js +15 -0
  115. package/index.js +1 -0
  116. package/package.json +65 -0
@@ -0,0 +1,218 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ exports.loadModel = async ({ app, appName }) => {
5
+ const data = fs.readdirSync(
6
+ path.resolve(__dirname, `${process.cwd()}/app/${appName}/plugins`)
7
+ )
8
+
9
+ const modelList = await app.model.model.findAll({ raw: true })
10
+
11
+ await Promise.all(
12
+ ['model', 'model_attributes'].map((item) =>
13
+ app.model[item].sync({
14
+ force: true,
15
+ })
16
+ )
17
+ )
18
+
19
+ const dataList = []
20
+ const result = data.filter(
21
+ (item) => !['model', 'model_attributes'].includes(item)
22
+ )
23
+ for (let i = 0; i < result.length; i++) {
24
+ const filePath = path.resolve(
25
+ __dirname,
26
+ `${process.cwd()}/app/${appName}/plugins/${result[i]}/model.js`
27
+ )
28
+ const configPath = path.resolve(
29
+ __dirname,
30
+ `${process.cwd()}/app/${appName}/plugins/${result[i]}/config.js`
31
+ )
32
+ const defaultFilePath = path.resolve(__dirname, `../${result[i]}/model.js`)
33
+ const defaultConfigPath = path.resolve(
34
+ __dirname,
35
+ `../${result[i]}/config.js`
36
+ )
37
+
38
+ const modelExist = fs.existsSync(filePath)
39
+ const defaultModelExist = fs.existsSync(defaultFilePath)
40
+ const configExist = fs.existsSync(configPath)
41
+ if (configExist) {
42
+ const config = fs.readFileSync(configPath, 'utf-8')
43
+ ? require(configPath)
44
+ : require(defaultConfigPath)
45
+
46
+ const modelFile =
47
+ defaultModelExist || modelExist
48
+ ? fs.readFileSync(filePath, 'utf-8')
49
+ ? fs.readFileSync(filePath, 'utf-8')
50
+ : fs.readFileSync(defaultFilePath, 'utf-8')
51
+ : null
52
+
53
+ const model = modelFile
54
+ ? fs.readFileSync(filePath, 'utf-8')
55
+ ? require(filePath)
56
+ : require(defaultFilePath)
57
+ : {}
58
+ const attributes = modelFile ? modelFile.match(/exports.(.*)=/g) : []
59
+ const types = modelFile ? modelFile.match(/Sequelize.(.*),\n/g) : {}
60
+
61
+ const ori_target = modelList.find((m) => m.model === result[i])
62
+ const id = ori_target ? ori_target.id : null
63
+ const obj = {
64
+ id,
65
+ model: result[i],
66
+ name: config.name,
67
+ belongs: config.belongs || 'page',
68
+ order: config.order,
69
+ multiple: config.multiple,
70
+ availableSort: config.availableSort,
71
+ limit: config.limit || 20,
72
+ select: config.select,
73
+ excludes: config.excludes,
74
+ initList: config.initList,
75
+ defaultOrder: config.defaultOrder,
76
+ excludeAuth: config.excludeAuth,
77
+ comment: config.comment,
78
+ reference: config.reference,
79
+ include: config.include,
80
+ sortOrder: config.sortOrder,
81
+ personal: config.personal,
82
+ autoData: config.autoData,
83
+ is_split: config.is_split,
84
+ is_split_count: config.is_split_count,
85
+ show_virtual: config.show_virtual,
86
+ modelQuery: config.modelQuery,
87
+ editInline: config.editInline,
88
+ deleteCheckList: config.deleteCheckList,
89
+ list: attributes.map((attr, index) => {
90
+ const name = attr.match(/exports.(.*)=/)[1].trim()
91
+ let defaultValue = ''
92
+ if (model[name] && model[name].hasOwnProperty('defaultValue')) {
93
+ if (
94
+ typeof model[name].defaultValue === 'boolean' &&
95
+ model[name].defaultValue === true
96
+ ) {
97
+ defaultValue = 'true'
98
+ }
99
+ if (
100
+ typeof model[name].defaultValue === 'boolean' &&
101
+ model[name].defaultValue === false
102
+ ) {
103
+ defaultValue = 'false'
104
+ }
105
+ if (typeof model[name].defaultValue === 'number') {
106
+ defaultValue = `${model[name].defaultValue}`
107
+ }
108
+ if (Array.isArray(model[name].defaultValue)) {
109
+ defaultValue = '[]'
110
+ }
111
+ if (
112
+ Object.prototype.toString.call(model[name].defaultValue) ===
113
+ '[object Object]'
114
+ ) {
115
+ defaultValue = '{}'
116
+ }
117
+ if (
118
+ typeof model[name].defaultValue === 'string' &&
119
+ model[name].defaultValue === ''
120
+ ) {
121
+ defaultValue = "''"
122
+ }
123
+ if (
124
+ typeof model[name].defaultValue === 'string' &&
125
+ model[name].defaultValue !== ''
126
+ ) {
127
+ defaultValue = `'${model[name].defaultValue}'`
128
+ }
129
+ if (
130
+ !model[name].defaultValue &&
131
+ typeof model[name].defaultValue !== 'undefined' &&
132
+ model[name].defaultValue != 0
133
+ ) {
134
+ defaultValue = 'null'
135
+ }
136
+ if (
137
+ types[index] &&
138
+ types[index].includes('DATE') &&
139
+ model[name].allowNull === true
140
+ ) {
141
+ defaultValue = 'null'
142
+ }
143
+ } else if (
144
+ model[name] &&
145
+ !model[name].hasOwnProperty('defaultValue')
146
+ ) {
147
+ defaultValue = "''"
148
+ }
149
+
150
+ return {
151
+ model_id: id || i + 1,
152
+ name,
153
+ type: types[index] ? types[index].replace(/,\n/, '') : '',
154
+ comment: model[name] ? model[name].comment : '',
155
+ is_mock:
156
+ model[name] && model[name].is_mock
157
+ ? model[name].is_mock
158
+ : !!(model[name] && model[name].mock),
159
+ allowNull:
160
+ model[name] && model[name].allowNull
161
+ ? model[name].allowNull
162
+ : false,
163
+ defaultValue,
164
+ sortOrder:
165
+ model[name] && model[name].sortOrder
166
+ ? Number(model[name].sortOrder)
167
+ : 1,
168
+ mock:
169
+ model[name] && model[name].mock
170
+ ? model[name].mock.toString()
171
+ : '',
172
+ set:
173
+ model[name] && model[name].set ? model[name].set.toString() : '',
174
+ get:
175
+ model[name] && model[name].get ? model[name].get.toString() : '',
176
+ belongsTo: model[name] ? model[name].belongsTo : '',
177
+ unique: !!(model[name] && model[name].hasOwnProperty('unique')),
178
+ hasOne: !!(model[name] && model[name].hasOwnProperty('hasOne')),
179
+ validate:
180
+ model[name] && model[name].validate
181
+ ? JSON.stringify(model[name].validate)
182
+ : null,
183
+ extra:
184
+ model[name] && model[name].extra
185
+ ? JSON.stringify(model[name].extra)
186
+ : null,
187
+ }
188
+ }),
189
+ }
190
+ // if (obj.model === 'user_free') {
191
+ // console.log(obj)
192
+ // }
193
+ dataList.push(obj)
194
+ }
195
+ }
196
+
197
+ const promise1 = app.model.model.bulkCreate(
198
+ dataList.map((item) => {
199
+ return {
200
+ ...item,
201
+ list: item.list.filter((t) => t.type),
202
+ }
203
+ })
204
+ )
205
+ const promise2 = app.model.model_attributes.bulkCreate(
206
+ dataList
207
+ .filter((item) => item.list.every((t) => t.type))
208
+ .reduce((a, b) => [...a, ...b.list], [])
209
+ )
210
+
211
+ await Promise.all([promise1, promise2])
212
+ console.log('lodaModel success!')
213
+ if (app.service.routes && app.model.routes) {
214
+ await app.service.routes.initRouter({ app })
215
+ } else {
216
+ console.warn('routes可能没有service.js')
217
+ }
218
+ }
@@ -0,0 +1,42 @@
1
+ const {
2
+ Validator
3
+ } = require('multiple-quick-koa');
4
+
5
+ exports.getModel = async (ctx) => {
6
+ const params = {
7
+ model: {
8
+ type: 'string',
9
+ required: true,
10
+ message: '请输入model',
11
+ },
12
+ };
13
+ await new Validator(params).validate(ctx.request.body);
14
+ };
15
+
16
+ exports.createModel = async (ctx) => {
17
+ const params = {
18
+ model: {
19
+ type: 'string',
20
+ required: true,
21
+ message: '请输入model',
22
+ },
23
+ desc: {
24
+ type: 'string',
25
+ required: true,
26
+ message: '请输入desc详情',
27
+ },
28
+ };
29
+ await new Validator(params).validate(ctx.request.body);
30
+ };
31
+
32
+
33
+ exports.createFile = async (ctx) => {
34
+ const params = {
35
+ plugin: {
36
+ type: 'string',
37
+ required: true,
38
+ message: '请输入plugin',
39
+ },
40
+ };
41
+ await new Validator(params).validate(ctx.request.body);
42
+ };
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ name: '模型属性',
3
+ belongs: 'auth',
4
+ multiple: false,
5
+ order: [],
6
+ select: [],
7
+ excludes: [],
8
+ defaultOrder: [],
9
+ comment: {},
10
+ reference: [],
11
+
12
+ };
@@ -0,0 +1,114 @@
1
+ const { Sequelize, Random } = require('multiple-quick-koa')
2
+
3
+ exports.model_id = {
4
+ type: Sequelize.INTEGER(11),
5
+ allowNull: false,
6
+ defaultValue: 0,
7
+ comment: '模型',
8
+ }
9
+
10
+ exports.name = {
11
+ type: Sequelize.STRING,
12
+ comment: '属性',
13
+ allowNull: false,
14
+ defaultValue: '',
15
+ mock: () => Random.csentence(),
16
+ }
17
+
18
+ exports.type = {
19
+ type: Sequelize.STRING,
20
+ comment: '类型',
21
+ allowNull: false,
22
+ defaultValue: 'STRING',
23
+ }
24
+
25
+ exports.comment = {
26
+ type: Sequelize.STRING,
27
+ comment: '注释',
28
+ allowNull: false,
29
+ defaultValue: '注释',
30
+ }
31
+
32
+ exports.allowNull = {
33
+ type: Sequelize.BOOLEAN,
34
+ comment: '允许null',
35
+ allowNull: false,
36
+ defaultValue: false,
37
+ }
38
+
39
+ exports.defaultValue = {
40
+ type: Sequelize.STRING,
41
+ comment: '默认值',
42
+ allowNull: false,
43
+ defaultValue: '默认值',
44
+ }
45
+
46
+ exports.mock = {
47
+ type: Sequelize.TEXT,
48
+ comment: '模拟数据',
49
+ allowNull: false,
50
+ defaultValue: '',
51
+ }
52
+
53
+ exports.is_mock = {
54
+ type: Sequelize.BOOLEAN,
55
+ comment: '是否mock',
56
+ allowNull: false,
57
+ defaultValue: false,
58
+ }
59
+
60
+ exports.set = {
61
+ type: Sequelize.TEXT,
62
+ comment: 'set',
63
+ allowNull: false,
64
+ defaultValue: '',
65
+ }
66
+
67
+ exports.get = {
68
+ type: Sequelize.TEXT,
69
+ comment: 'set',
70
+ allowNull: false,
71
+ defaultValue: '',
72
+ }
73
+
74
+ exports.unique = {
75
+ type: Sequelize.BOOLEAN,
76
+ comment: '唯一值',
77
+ allowNull: false,
78
+ defaultValue: false,
79
+ }
80
+
81
+ exports.hasOne = {
82
+ type: Sequelize.BOOLEAN,
83
+ comment: '关联唯一',
84
+ allowNull: false,
85
+ defaultValue: false,
86
+ }
87
+
88
+ exports.validate = {
89
+ type: Sequelize.JSON,
90
+ comment: '验证',
91
+ allowNull: true,
92
+ defaultValue: {},
93
+ }
94
+
95
+ exports.sortOrder = {
96
+ type: Sequelize.INTEGER,
97
+ comment: '排序',
98
+ allowNull: false,
99
+ defaultValue: 1,
100
+ }
101
+
102
+ exports.belongsTo = {
103
+ type: Sequelize.STRING,
104
+ comment: '关联原型',
105
+ allowNull: false,
106
+ defaultValue: '',
107
+ }
108
+
109
+ exports.extra = {
110
+ type: Sequelize.JSON,
111
+ comment: '默认配置',
112
+ allowNull: true,
113
+ defaultValue: {},
114
+ }
@@ -0,0 +1,19 @@
1
+ module.exports = {
2
+ name: '微信小程序用户',
3
+ belongs: 'page',
4
+ multiple: false,
5
+ availableSort: false,
6
+ order: ['created_at'],
7
+ select: [{ key: 'user_id' }, { key: 'nick_name' }, { key: 'openid' }],
8
+ excludes: [],
9
+ limit: 20,
10
+ defaultOrder: [{ sort: 'descending', type: 'id' }],
11
+ comment: {
12
+ created_at: {
13
+ comment: '创建时间',
14
+ },
15
+ },
16
+ sortOrder: 1,
17
+ reference: [],
18
+ excludeAuth: [],
19
+ }
@@ -0,0 +1,59 @@
1
+ const { Sequelize, Random } = require('multiple-quick-koa')
2
+
3
+ exports.openid = {
4
+ type: Sequelize.STRING,
5
+ comment: 'openid',
6
+ allowNull: false,
7
+ is_mock: false,
8
+ defaultValue: '',
9
+ sortOrder: 1,
10
+ unique: true,
11
+ }
12
+
13
+ exports.user_id = {
14
+ type: Sequelize.MEDIUMINT.UNSIGNED,
15
+ comment: '用户',
16
+ allowNull: false,
17
+ is_mock: false,
18
+ defaultValue: 0,
19
+ sortOrder: 2,
20
+ hasOne: true,
21
+ }
22
+
23
+ exports.nick_name = {
24
+ type: Sequelize.STRING,
25
+ comment: '昵称',
26
+ allowNull: false,
27
+ is_mock: false,
28
+ defaultValue: '',
29
+ sortOrder: 3,
30
+ }
31
+
32
+ exports.avatar = {
33
+ type: Sequelize.STRING(1000),
34
+ comment: '头像',
35
+ allowNull: false,
36
+ is_mock: false,
37
+ defaultValue: '',
38
+ sortOrder: 8,
39
+ }
40
+
41
+ exports.appid = {
42
+ type: Sequelize.STRING,
43
+ comment: 'APP_ID',
44
+ allowNull: false,
45
+ is_mock: true,
46
+ defaultValue: '',
47
+ sortOrder: 10,
48
+ mock: () => Random.ctitle(),
49
+ }
50
+
51
+ exports.unionid = {
52
+ type: Sequelize.STRING,
53
+ comment: 'unionid',
54
+ allowNull: false,
55
+ is_mock: true,
56
+ defaultValue: '',
57
+ sortOrder: 11,
58
+ mock: () => Random.ctitle(),
59
+ }
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ name: '权限',
3
+ belongs: 'auth',
4
+ multiple: false,
5
+ availableSort: false,
6
+ order: [],
7
+ select: [],
8
+ excludes: [],
9
+ limit: 20,
10
+ defaultOrder: [],
11
+ comment: {},
12
+ sortOrder: 1,
13
+ reference: [],
14
+ excludeAuth: [],
15
+ };
@@ -0,0 +1,91 @@
1
+ const { Sequelize } = require('multiple-quick-koa')
2
+
3
+ exports.name = {
4
+ type: Sequelize.STRING,
5
+ comment: '描述',
6
+ allowNull: false,
7
+ is_mock: false,
8
+ defaultValue: '',
9
+ sortOrder: 1,
10
+ }
11
+
12
+ exports.controller = {
13
+ type: Sequelize.STRING,
14
+ comment: '控制器',
15
+ allowNull: false,
16
+ is_mock: false,
17
+ defaultValue: '',
18
+ sortOrder: 2,
19
+ }
20
+
21
+ exports.is_exports = {
22
+ type: Sequelize.BOOLEAN,
23
+ comment: '能否导出',
24
+ allowNull: false,
25
+ is_mock: false,
26
+ defaultValue: false,
27
+ sortOrder: 3,
28
+ }
29
+
30
+ exports.is_imports = {
31
+ type: Sequelize.BOOLEAN,
32
+ comment: '能否导入',
33
+ allowNull: false,
34
+ is_mock: false,
35
+ defaultValue: false,
36
+ sortOrder: 4,
37
+ }
38
+
39
+ exports.is_view = {
40
+ type: Sequelize.BOOLEAN,
41
+ comment: '能否查看',
42
+ allowNull: false,
43
+ is_mock: false,
44
+ defaultValue: false,
45
+ sortOrder: 5,
46
+ }
47
+
48
+ exports.is_delete = {
49
+ type: Sequelize.BOOLEAN,
50
+ comment: '能否删除',
51
+ allowNull: false,
52
+ is_mock: false,
53
+ defaultValue: false,
54
+ sortOrder: 6,
55
+ }
56
+
57
+ exports.is_insert = {
58
+ type: Sequelize.BOOLEAN,
59
+ comment: '能否新增',
60
+ allowNull: false,
61
+ is_mock: false,
62
+ defaultValue: false,
63
+ sortOrder: 7,
64
+ }
65
+
66
+ exports.is_update = {
67
+ type: Sequelize.BOOLEAN,
68
+ comment: '能否修改',
69
+ allowNull: false,
70
+ is_mock: false,
71
+ defaultValue: false,
72
+ sortOrder: 8,
73
+ }
74
+
75
+ exports.is_updateInline = {
76
+ type: Sequelize.BOOLEAN,
77
+ comment: '能否局部修改',
78
+ allowNull: false,
79
+ is_mock: false,
80
+ defaultValue: false,
81
+ sortOrder: 9,
82
+ }
83
+
84
+ exports.is_mock = {
85
+ type: Sequelize.BOOLEAN,
86
+ comment: '能否mock',
87
+ allowNull: false,
88
+ is_mock: false,
89
+ defaultValue: false,
90
+ sortOrder: 10,
91
+ }
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ name: '角色',
3
+ belongs: 'auth',
4
+ multiple: false,
5
+ order: [],
6
+ select: [],
7
+ excludes: ['query', 'post', 'is_diy_router'],
8
+ limit: 20,
9
+ defaultOrder: [],
10
+ comment: {},
11
+ sortOrder: 1,
12
+ reference: [
13
+ {
14
+ common: true,
15
+ name: '管理权限',
16
+ key: 'operate_permission',
17
+ width: 150,
18
+ },
19
+ {
20
+ common: true,
21
+ admin: true,
22
+ name: '过滤器',
23
+ key: 'operate_filter',
24
+ width: 150,
25
+ },
26
+ ],
27
+ }
@@ -0,0 +1,26 @@
1
+ const { getAppByCtx } = require('multiple-quick-koa')
2
+
3
+ exports.init = async (ctx) => {
4
+ const { app } = getAppByCtx(ctx)
5
+
6
+ const roleList = await app.model.role.findAll({
7
+ include: [
8
+ {
9
+ model: app.model.role_permission,
10
+ },
11
+ ],
12
+ })
13
+
14
+ for (let i = 0; i < roleList.length; i++) {
15
+ const item = roleList[i].toJSON()
16
+ const permission_id = item.role_permissions.map((item) => {
17
+ return item.permission_id
18
+ })
19
+ await app.model.role.upsert({
20
+ id: item.id,
21
+ permission_id,
22
+ })
23
+ }
24
+
25
+ ctx.SUCCESS('ok')
26
+ }
@@ -0,0 +1,58 @@
1
+ const { Sequelize, Random } = require('multiple-quick-koa')
2
+
3
+ exports.name = {
4
+ type: Sequelize.STRING,
5
+ comment: '名字',
6
+ allowNull: false,
7
+ is_mock: false,
8
+ defaultValue: '',
9
+ sortOrder: 1,
10
+ }
11
+
12
+ exports.query = {
13
+ type: Sequelize.JSON,
14
+ comment: '查询条件',
15
+ allowNull: false,
16
+ is_mock: false,
17
+ defaultValue: {},
18
+ sortOrder: 2,
19
+ }
20
+
21
+ exports.post = {
22
+ type: Sequelize.JSON,
23
+ comment: '增改条件',
24
+ allowNull: false,
25
+ is_mock: false,
26
+ defaultValue: {},
27
+ sortOrder: 3,
28
+ }
29
+
30
+ exports.is_diy_router = {
31
+ type: Sequelize.BOOLEAN,
32
+ comment: '是否自定义路由',
33
+ allowNull: false,
34
+ is_mock: true,
35
+ defaultValue: false,
36
+ sortOrder: 4,
37
+ mock: () => Random.boolean(),
38
+ extra: {
39
+ controlInline: true,
40
+ },
41
+ }
42
+
43
+ exports.permission_id = {
44
+ type: Sequelize.JSON,
45
+ comment: '权限',
46
+ allowNull: false,
47
+ is_mock: true,
48
+ defaultValue: [],
49
+ sortOrder: 5,
50
+ get: function () {
51
+ return this.getDataValue('permission_id') === null
52
+ ? []
53
+ : this.getDataValue('permission_id')
54
+ },
55
+ extra: {
56
+ tableWidth: 500,
57
+ },
58
+ }
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ name: '管理员权限',
3
+ belongs: 'auth',
4
+ multiple: false,
5
+ order: [],
6
+ select: [],
7
+ excludes: [],
8
+ defaultOrder: [],
9
+ comment: {},
10
+ sortOrder: 1,
11
+ reference: [],
12
+ };