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,27 @@
1
+ const { getAppByCtx } = require('multiple-quick-koa')
2
+
3
+ exports.edit = async (ctx) => {
4
+ const { app, appName } = getAppByCtx(ctx)
5
+
6
+ const { id, myPermissionList } = ctx.request.body
7
+
8
+ if (id === ctx.request[`${appName}-user`].id) {
9
+ throw new Error('您不能修改该权限')
10
+ }
11
+ await app.model.role_permission.destroy({
12
+ where: {
13
+ role_id: id,
14
+ },
15
+ })
16
+
17
+ await app.model.role_permission.bulkCreate(
18
+ myPermissionList.map((item) => {
19
+ return {
20
+ role_id: id,
21
+ permission_id: item.permission.id,
22
+ }
23
+ })
24
+ )
25
+
26
+ ctx.SUCCESS('ok')
27
+ }
@@ -0,0 +1,24 @@
1
+ const { Sequelize, Random } = require('multiple-quick-koa');
2
+
3
+
4
+ exports.role_id = {
5
+ type: Sequelize.MEDIUMINT.UNSIGNED,
6
+ comment: '管理员角色',
7
+ allowNull: false,
8
+ is_mock: true,
9
+ defaultValue: 0,
10
+ sortOrder: 1,
11
+ mock: () => Random.integer(1,5),
12
+ unique:'compositeIndex'
13
+ };
14
+
15
+ exports.permission_id = {
16
+ type: Sequelize.MEDIUMINT.UNSIGNED,
17
+ comment: '权限',
18
+ allowNull: false,
19
+ is_mock: true,
20
+ defaultValue: 0,
21
+ sortOrder: 2,
22
+ mock: () => Random.integer(1,5),
23
+ unique:'compositeIndex'
24
+ };
@@ -0,0 +1,17 @@
1
+ module.exports = {
2
+ name: '后台导航',
3
+ belongs: 'auth',
4
+ multiple: false,
5
+ availableSort: true,
6
+ order: [],
7
+ select: [],
8
+ excludes: [],
9
+ limit: 40,
10
+ defaultOrder: [{ sort: 'ascending', type: 'sortOrder' }],
11
+ comment: {},
12
+ sortOrder: 1,
13
+ reference: [],
14
+ excludeAuth: [],
15
+ initList: [],
16
+ personal: [{ key: 'init_routes', name: '初始化', width: 200, common: true }],
17
+ }
@@ -0,0 +1,153 @@
1
+ const { getAppByCtx, lodash } = require('multiple-quick-koa')
2
+
3
+ exports.bulkUpdate = async (ctx) => {
4
+ const { app, appName } = getAppByCtx(ctx)
5
+ const { list, type = 'key' } = ctx.request.body
6
+ if (type === 'key') {
7
+ await app.model.routes.bulkCreate(
8
+ list.map((item) => {
9
+ return {
10
+ id: item.id,
11
+ key: `${item.model.belongs}/${item.model.model}`,
12
+ }
13
+ }),
14
+ {
15
+ updateOnDuplicate: ['key'],
16
+ }
17
+ )
18
+ } else if (type === 'model') {
19
+ const modelList = await app.model.model.findAll()
20
+
21
+ await app.model.routes.bulkCreate(
22
+ list
23
+ .filter((item) => {
24
+ const target = modelList.find(
25
+ (m) => m.model === item.key.split('/')[1]
26
+ )
27
+ return target
28
+ })
29
+ .map((item) => {
30
+ const target = modelList.find(
31
+ (m) => m.model === item.key.split('/')[1]
32
+ )
33
+ return {
34
+ id: item.id,
35
+ model_id: target.id,
36
+ }
37
+ }),
38
+ {
39
+ updateOnDuplicate: ['model_id'],
40
+ }
41
+ )
42
+ }
43
+
44
+ ctx.SUCCESS('ok')
45
+ }
46
+
47
+ exports.init = async (ctx) => {
48
+ const { app, appName } = getAppByCtx(ctx)
49
+ const { list } = ctx.request.body
50
+
51
+ const result = await app.model.routes.bulkCreate(list)
52
+
53
+ ctx.SUCCESS(result)
54
+ }
55
+
56
+ exports.initRoute = async (ctx) => {
57
+ const { app, appName } = getAppByCtx(ctx)
58
+ if (!app.model.routes) return Promise.resolve()
59
+ const routesList = await app.model.routes.findAll()
60
+ await app.model.routes.sync({
61
+ force: true,
62
+ })
63
+
64
+ let list = [
65
+ {
66
+ id: 1,
67
+ name: '首页',
68
+ icon: 's-home',
69
+ parent_id: 0,
70
+ url: '/dashboard',
71
+ model_id: 0,
72
+ },
73
+ {
74
+ id: 2,
75
+ name: '项目管理',
76
+ icon: 's-operation',
77
+ parent_id: 0,
78
+ url: '',
79
+ model_id: 0,
80
+ },
81
+ {
82
+ id: 3,
83
+ name: '系统管理',
84
+ icon: 's-operation',
85
+ parent_id: 0,
86
+ url: '',
87
+ model_id: 0,
88
+ },
89
+ {
90
+ id: 4,
91
+ name: '管理设置',
92
+ icon: 's-operation',
93
+ parent_id: 0,
94
+ url: '',
95
+ model_id: 0,
96
+ },
97
+ ]
98
+
99
+ const permissionList = await app.model.permission.findAll()
100
+ const modelList = await app.model.model.findAll()
101
+ const roleList = await app.model.role.findAll()
102
+ const rolePermission = lodash.uniq(
103
+ roleList
104
+ .map((item) => item.toJSON())
105
+ .reduce((a, b) => [...a, ...b.permission_id], [])
106
+ )
107
+ for (let i = 0; i < permissionList.length; i++) {
108
+ const target = permissionList[i].toJSON()
109
+ if (target.controller === '') {
110
+ await app.model.permission.destroy({
111
+ where: {
112
+ id: target.id,
113
+ },
114
+ })
115
+ continue
116
+ }
117
+ const model = modelList.find((item) => item.model === target.controller)
118
+ if (!rolePermission.includes(target.id)) {
119
+ continue
120
+ }
121
+
122
+ let parent_id = 2
123
+ if (model && model.belongs === 'setting') {
124
+ parent_id = 3
125
+ } else if (model && model.belongs === 'auth') {
126
+ parent_id = 4
127
+ }
128
+ const is_project = !model
129
+ list = [
130
+ ...list,
131
+ {
132
+ name: target.name,
133
+ parent_id,
134
+ url: is_project ? `/project/${appName}/` + target.controller : '',
135
+ model_id: model ? model.id : 0,
136
+ key: is_project
137
+ ? ''
138
+ : model && model.belongs
139
+ ? `${model.belongs}/${model.model}`
140
+ : '',
141
+ },
142
+ ]
143
+ }
144
+ const sortList = list.map((item) => {
145
+ const sort = routesList.find((r) => r.name === item.name)
146
+ return {
147
+ ...item,
148
+ sortOrder: item.id ? item.id : sort ? sort.sortOrder : list.length,
149
+ }
150
+ })
151
+ await app.model.routes.bulkCreate(sortList)
152
+ ctx.SUCCESS('ok')
153
+ }
@@ -0,0 +1,70 @@
1
+ const { Sequelize, Random } = require('multiple-quick-koa')
2
+
3
+ exports.name = {
4
+ type: Sequelize.STRING,
5
+ comment: '名字',
6
+ allowNull: false,
7
+ is_mock: true,
8
+ defaultValue: '',
9
+ sortOrder: 1,
10
+ mock: () => Random.ctitle(),
11
+ }
12
+
13
+ exports.icon = {
14
+ type: Sequelize.STRING,
15
+ comment: '图标',
16
+ allowNull: false,
17
+ is_mock: true,
18
+ defaultValue: '',
19
+ sortOrder: 2,
20
+ mock: () => Random.ctitle(),
21
+ }
22
+
23
+ exports.parent_id = {
24
+ type: Sequelize.INTEGER.UNSIGNED,
25
+ comment: '上级',
26
+ allowNull: false,
27
+ is_mock: true,
28
+ defaultValue: 0,
29
+ sortOrder: 3,
30
+ mock: () => Random.integer(1, 3),
31
+ }
32
+
33
+ exports.url = {
34
+ type: Sequelize.STRING,
35
+ comment: '链接',
36
+ allowNull: false,
37
+ is_mock: true,
38
+ defaultValue: '',
39
+ sortOrder: 4,
40
+ mock: () => Random.ctitle(),
41
+ }
42
+
43
+ exports.model_id = {
44
+ type: Sequelize.MEDIUMINT.UNSIGNED,
45
+ comment: '模型',
46
+ allowNull: false,
47
+ is_mock: true,
48
+ defaultValue: 0,
49
+ sortOrder: 5,
50
+ mock: () => Random.integer(1, 5),
51
+ }
52
+
53
+ exports.sortOrder = {
54
+ type: Sequelize.MEDIUMINT.UNSIGNED,
55
+ comment: '排序',
56
+ allowNull: false,
57
+ is_mock: false,
58
+ defaultValue: 0,
59
+ sortOrder: 6,
60
+ }
61
+
62
+ exports.key = {
63
+ type: Sequelize.STRING,
64
+ comment: 'model_key',
65
+ allowNull: false,
66
+ is_mock: true,
67
+ defaultValue: '',
68
+ sortOrder: 7,
69
+ mock: () => Random.ctitle(),
70
+ }
@@ -0,0 +1,22 @@
1
+ exports.initRouter = async ({ app }) => {
2
+ console.log('initRouter start')
3
+ const routesList = await app.model.routes.findAll()
4
+ const modelList = await app.model.model.findAll()
5
+
6
+ const list = routesList.map((_item) => {
7
+ const item = _item.toJSON()
8
+ const target = modelList.find((m) => m.model === item.key.split('/')[1])
9
+ if (target) {
10
+ return {
11
+ ...item,
12
+ model_id: target.id,
13
+ }
14
+ } else {
15
+ return item
16
+ }
17
+ })
18
+ await app.model.routes.bulkCreate(list, {
19
+ updateOnDuplicate: ['model_id'],
20
+ })
21
+ console.log('initRouter success!')
22
+ }
@@ -0,0 +1,14 @@
1
+ const { getAppByCtx, getConfig } = require('multiple-quick-koa')
2
+
3
+ exports.upsert = async (ctx) => {
4
+ const { app } = getAppByCtx(ctx)
5
+ const appConfig = getConfig(app)
6
+ appConfig.update()
7
+ }
8
+
9
+ exports.bulkUpdate = async (ctx) => {
10
+ const { app } = getAppByCtx(ctx)
11
+
12
+ const appConfig = getConfig(app)
13
+ appConfig.update()
14
+ }
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ name: '设置',
3
+ belongs: 'setting',
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
+ };
@@ -0,0 +1,50 @@
1
+ const { getAppByCtx } = require('multiple-quick-koa')
2
+ const axios = require('axios')
3
+
4
+ exports.bulkUpdate = async (ctx) => {
5
+ const { app, appName } = getAppByCtx(ctx)
6
+ const { list } = ctx.request.body
7
+ const result = await app.model.setting.bulkCreate(list, {
8
+ updateOnDuplicate: ['id', 'value'],
9
+ })
10
+ ctx.SUCCESS(result)
11
+ }
12
+
13
+ exports.copyOther = async (ctx) => {
14
+ const { app, appName } = getAppByCtx(ctx)
15
+
16
+ const { type, source } = ctx.request.body
17
+
18
+ const { data } = await axios
19
+ .post(`http://localhost:3001/${source}/setting/findAll`)
20
+ .then((res) => res.data)
21
+
22
+ const copyType = data.find((item) => item.code === type)
23
+
24
+ if (!copyType) throw new Error('克隆方找不到')
25
+
26
+ const copyList = data.filter((item) => item.parent_id === copyType.id)
27
+
28
+ const list = await app.model.setting.findAll()
29
+
30
+ const findType = list.find((item) => item.code === type)
31
+ if (!findType) throw new Error('自己找不到')
32
+
33
+ await app.model.setting.destroy({
34
+ where: {
35
+ parent_id: findType.id,
36
+ },
37
+ })
38
+
39
+ await app.model.setting.bulkCreate(
40
+ copyList.map((item) => {
41
+ const { parent, id, ...rest } = item
42
+ return {
43
+ ...rest,
44
+ parent_id: findType.id,
45
+ }
46
+ })
47
+ )
48
+
49
+ ctx.SUCCESS('ok')
50
+ }
@@ -0,0 +1,118 @@
1
+ const { Sequelize, Random, lodash, moment } = 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.code = {
13
+ type: Sequelize.STRING(),
14
+ comment: 'key值',
15
+ allowNull: false,
16
+ is_mock: false,
17
+ defaultValue: '',
18
+ sortOrder: 2,
19
+ }
20
+
21
+ exports.type = {
22
+ type: Sequelize.ENUM(
23
+ 'switch',
24
+ 'input',
25
+ 'image',
26
+ 'decimal',
27
+ 'file',
28
+ 'textarea',
29
+ 'rich-text',
30
+ 'date',
31
+ 'datetime',
32
+ 'list'
33
+ ),
34
+ comment: 'type类型',
35
+ allowNull: true,
36
+ is_mock: false,
37
+ defaultValue: 'input',
38
+ sortOrder: 3,
39
+ }
40
+
41
+ exports.value = {
42
+ type: Sequelize.TEXT('long'),
43
+ comment: 'value值',
44
+ allowNull: true,
45
+ is_mock: false,
46
+ defaultValue: null,
47
+ sortOrder: 4,
48
+ get: function () {
49
+ const type = this.getDataValue('type')
50
+ switch (type) {
51
+ case 'switch':
52
+ return Boolean(Number(this.getDataValue('value')))
53
+ case 'list':
54
+ return JSON.parse(this.getDataValue('value'))
55
+ case 'input':
56
+ return this.getDataValue('value')
57
+ case 'decimal':
58
+ return lodash.isNaN(Number(this.getDataValue('value')))
59
+ ? 0
60
+ : Number(this.getDataValue('value'))
61
+ case 'datetime':
62
+ return moment(this.getDataValue('value')).format('YYYY-MM-DD HH:mm:ss')
63
+ case 'date':
64
+ return moment(this.getDataValue('value')).format('YYYY-MM-DD')
65
+ case 'image':
66
+ return this.getDataValue('value').startsWith('//')
67
+ ? `https:${this.getDataValue('value')}`
68
+ : this.getDataValue('value')
69
+ default:
70
+ return this.getDataValue('value')
71
+ }
72
+ },
73
+ }
74
+
75
+ exports.parent_id = {
76
+ type: Sequelize.TINYINT.UNSIGNED,
77
+ comment: '上级分类',
78
+ allowNull: false,
79
+ is_mock: false,
80
+ defaultValue: 0,
81
+ sortOrder: 5,
82
+ }
83
+
84
+ exports.is_front = {
85
+ type: Sequelize.BOOLEAN,
86
+ comment: '是否前端可用',
87
+ allowNull: false,
88
+ is_mock: false,
89
+ defaultValue: true,
90
+ sortOrder: 6,
91
+ extra: {
92
+ controlInline: true,
93
+ },
94
+ }
95
+
96
+ exports.is_cache = {
97
+ type: Sequelize.BOOLEAN,
98
+ comment: '是否后端缓存',
99
+ allowNull: false,
100
+ is_mock: false,
101
+ defaultValue: true,
102
+ sortOrder: 7,
103
+ extra: {
104
+ controlInline: true,
105
+ },
106
+ }
107
+
108
+ exports.is_control = {
109
+ type: Sequelize.BOOLEAN,
110
+ comment: '是否可控',
111
+ allowNull: false,
112
+ is_mock: false,
113
+ defaultValue: true,
114
+ sortOrder: 8,
115
+ extra: {
116
+ controlInline: true,
117
+ },
118
+ }
@@ -0,0 +1,42 @@
1
+ const { Validator,getAppByCtx } = require('multiple-quick-koa');
2
+
3
+
4
+ exports.bulkUpdate = async (ctx) => {
5
+ const params = {
6
+ list: {
7
+ type: 'array',
8
+ required: true,
9
+ message: '请输入list',
10
+ },
11
+ };
12
+ await new Validator(params).validate(ctx.request.body);
13
+ };
14
+
15
+ exports.upsert = async ctx => {
16
+ const {
17
+ app
18
+ } = getAppByCtx(ctx);
19
+
20
+ const {
21
+ id,
22
+ parent_id
23
+ } = ctx.request.body
24
+
25
+ if (id && parent_id && id === parent_id) throw new Error('不能分类到自己')
26
+ };
27
+
28
+ exports.copyOther = async (ctx) => {
29
+ const params = {
30
+ type: {
31
+ type: 'string',
32
+ required: true,
33
+ message: '请输入type, 需要复制哪个code',
34
+ },
35
+ source:{
36
+ type: 'string',
37
+ required: true,
38
+ message: '请输入source, 需要从哪个项目复制哪个(记得开启)',
39
+ }
40
+ };
41
+ await new Validator(params).validate(ctx.request.body);
42
+ };