@gingkoo/base-server 0.0.1-alpha.0 → 0.0.1-alpha.10

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 (122) hide show
  1. package/README.md +4 -0
  2. package/app.js +41 -40
  3. package/backend/common/entity.js +55 -0
  4. package/backend/common/enum.js +247 -0
  5. package/backend/common/fss/index.js +18 -0
  6. package/backend/common/fss/routers/attachment.js +45 -0
  7. package/backend/common/fss/routers/download.js +43 -0
  8. package/backend/common/fss/routers/import_export.js +113 -0
  9. package/backend/common/fss/routers/resources.js +149 -0
  10. package/backend/common/fss/routers/upload.js +81 -0
  11. package/backend/common/fss/services/import_export.js +159 -0
  12. package/backend/common/fss/services/index.js +92 -0
  13. package/backend/common/fss/utils.js +39 -0
  14. package/backend/common/ginfo/config.js +5 -0
  15. package/backend/common/ginfo/index.js +62 -0
  16. package/backend/common/index_template.html +28 -0
  17. package/backend/common/logger/index.js +96 -0
  18. package/backend/common/mapping.js +128 -0
  19. package/backend/common/middleware/auth.js +109 -0
  20. package/backend/common/middleware/cors.js +13 -0
  21. package/backend/common/middleware/response.js +25 -0
  22. package/backend/common/page_engine.js +487 -0
  23. package/backend/common/schedule.js +45 -0
  24. package/backend/common/services/dataCombine.js +67 -0
  25. package/backend/common/services/dept.js +37 -0
  26. package/backend/common/services/dict.js +488 -0
  27. package/backend/common/services/email.js +49 -0
  28. package/backend/common/services/generalConfig.js +137 -0
  29. package/backend/common/services/login.js +18 -0
  30. package/backend/common/services/notice.js +260 -0
  31. package/backend/common/services/permission.js +500 -0
  32. package/backend/common/services/roles.js +57 -0
  33. package/backend/common/services/send-notice.js +86 -0
  34. package/backend/common/services/task.js +259 -0
  35. package/backend/common/services/user.js +673 -0
  36. package/backend/common/socket.js +18 -0
  37. package/backend/common/sse/index.js +81 -0
  38. package/backend/common/sse/router.js +30 -0
  39. package/backend/common/task.js +75 -0
  40. package/backend/common/wechat/index.js +9 -0
  41. package/backend/common/wechat/routers/auth.js +238 -0
  42. package/{modules/user/frontend → backend/common/wechat/routers}/index.html +14 -7
  43. package/backend/common/wechat/services/auth.js +209 -0
  44. package/backend/common/wechat/services/notice.js +171 -0
  45. package/backend/config/index.js +61 -0
  46. package/backend/config/path.js +3 -0
  47. package/backend/router.js +100 -0
  48. package/backend/routers/app.js +222 -0
  49. package/backend/routers/automate.js +276 -0
  50. package/backend/routers/dict.js +370 -0
  51. package/backend/routers/email.js +85 -0
  52. package/backend/routers/generalConfig.js +276 -0
  53. package/backend/routers/idm.js +245 -0
  54. package/backend/routers/module.js +357 -0
  55. package/backend/routers/notice.js +138 -0
  56. package/backend/routers/pages.js +46 -0
  57. package/backend/routers/permission.js +985 -0
  58. package/backend/routers/setting.js +184 -0
  59. package/backend/routers/team/index.js +22 -0
  60. package/backend/routers/team/routers/mapping.js +29 -0
  61. package/backend/routers/team/routers/member.js +72 -0
  62. package/backend/routers/team/routers/membermanage.js +289 -0
  63. package/backend/routers/team/routers/pages.js +47 -0
  64. package/backend/routers/team/routers/roles.js +92 -0
  65. package/backend/routers/team/routers/teaminfo.js +27 -0
  66. package/backend/routers/team/routers/usergroup.js +213 -0
  67. package/backend/routers/team/services/mapping.js +101 -0
  68. package/backend/routers/team/services/member.js +206 -0
  69. package/backend/routers/team/services/roles.js +71 -0
  70. package/backend/routers/team/services/teaminfo.js +20 -0
  71. package/backend/routers/team/services/usergroup.js +128 -0
  72. package/backend/routers/user.js +436 -0
  73. package/backend/services/automate.js +60 -0
  74. package/backend/services/config.js +14 -0
  75. package/backend/services/module.js +298 -0
  76. package/backend/services/permission.js +192 -0
  77. package/backend/services/services.js +115 -0
  78. package/backend/services/setting.js +190 -0
  79. package/backend/services/token.js +42 -0
  80. package/backend/space.js +52 -0
  81. package/backend/space_mapping.js +22 -0
  82. package/backend/utils/avatar.js +48 -0
  83. package/backend/utils/color_gen_helper.js +20 -0
  84. package/backend/utils/date.js +66 -0
  85. package/backend/utils/excel.js +446 -0
  86. package/backend/utils/fs/doc.md +64 -0
  87. package/backend/utils/fs/index.js +127 -0
  88. package/backend/utils/jwt.js +54 -0
  89. package/backend/utils/modules/sequence.js +93 -0
  90. package/backend/utils/object.js +31 -0
  91. package/backend/utils/page-query-helper/index.js +61 -0
  92. package/backend/utils/path.js +123 -0
  93. package/backend/utils/run.js +25 -0
  94. package/backend/utils/tokenize.js +82 -0
  95. package/backend/utils/typeof.js +5 -0
  96. package/backend/utils/util.js +153 -0
  97. package/backend/views/api/index.js +32 -0
  98. package/backend/views/api/index.xml +49 -0
  99. package/backend/views/dict/index.js +80 -0
  100. package/backend/views/dict/index.xml +52 -0
  101. package/backend/views/index.js +32 -0
  102. package/backend/views/members_manage/index.js +68 -0
  103. package/backend/views/members_manage/index.xml +68 -0
  104. package/backend/views/roles/index.js +17 -0
  105. package/backend/views/roles/index.xml +47 -0
  106. package/backend/views/usergroup/index.js +68 -0
  107. package/backend/views/usergroup/index.xml +65 -0
  108. package/dist/base-assets/css/index-ffdb55a5.css +3 -0
  109. package/dist/base-assets/css/index-ffdb55a5.css.gz +0 -0
  110. package/dist/base-assets/js/index-b3998a47.js +762 -0
  111. package/dist/base-assets/js/index-b3998a47.js.gz +0 -0
  112. package/dist/base-assets/js/react-cropper.es-d5f06996.js +10 -0
  113. package/dist/base-assets/js/react-cropper.es-d5f06996.js.gz +0 -0
  114. package/dist/base-assets/png/u9-2348c304.png +0 -0
  115. package/dist/base-assets/woff2/materialicons-83be7b2f.woff2 +0 -0
  116. package/dist/index.html +162 -0
  117. package/package.json +62 -5
  118. package/common/router.js +0 -42
  119. package/modules/user/backend/index.js +0 -19
  120. package/modules/user/backend/routers/user.js +0 -11
  121. package/modules/user/frontend/index.js +0 -1
  122. package/serve.js +0 -9
@@ -0,0 +1,85 @@
1
+ 'use strict';
2
+ var express = require('express');
3
+ var router = express.Router();
4
+
5
+ const { checkLogin } = require('../common/middleware/auth');
6
+ const emailService = require('../common/services/email');
7
+
8
+ router.get('/template', checkLogin, async function (req, res) {
9
+ let config = await emailService.getEmailTempate();
10
+ if (!config || !Array.isArray(config)) {
11
+ return res.sendErr('');
12
+ }
13
+ let data = config.map((v) => {
14
+ return {
15
+ ...v,
16
+ DEAFULT: v?.DEAFULT ? JSON.parse(v?.DEAFULT) : null,
17
+ };
18
+ });
19
+ res.sendOk(data);
20
+ });
21
+
22
+ router.post('/template', checkLogin, async function (req, res) {
23
+ let userid = req.get('X-UserId');
24
+ let { TEMPLATE_ID, TEMPLATE_TYPE, TEMPLATE_TITLE, TEMPLATE_DESC, CONTENT, DEAFULT } = req.body;
25
+ let props = {
26
+ ORG_ID: global.orgid,
27
+ TEMPLATE_ID,
28
+ TEMPLATE_TYPE,
29
+ TEMPLATE_TITLE,
30
+ TEMPLATE_DESC,
31
+ CONTENT: CONTENT || null,
32
+ DEAFULT: DEAFULT || null,
33
+ DATA_CRT_USER: userid,
34
+ STATUS: '00',
35
+ };
36
+ let config = await emailService.postEailTempate(props);
37
+ if (!config) {
38
+ return res.sendErr('');
39
+ }
40
+ res.sendOk('创建成功');
41
+ });
42
+
43
+ router.put('/template', checkLogin, async function (req, res) {
44
+ let userid = req.get('X-UserId');
45
+ if (!req.body?.TEMPLATE_ID) {
46
+ return res.sendErr('缺少id');
47
+ }
48
+ let { TEMPLATE_ID, TEMPLATE_TYPE, TEMPLATE_TITLE, TEMPLATE_DESC, CONTENT, DEAFULT, STATUS } =
49
+ req.body;
50
+ const field = [
51
+ 'TEMPLATE_ID',
52
+ 'TEMPLATE_TYPE',
53
+ 'TEMPLATE_TITLE',
54
+ 'TEMPLATE_DESC',
55
+ 'CONTENT',
56
+ 'DEAFULT',
57
+ 'STATUS',
58
+ ];
59
+ let props = {
60
+ TEMPLATE_TYPE,
61
+ TEMPLATE_TITLE,
62
+ TEMPLATE_DESC,
63
+ CONTENT,
64
+ DEAFULT: DEAFULT ? JSON.stringify(DEAFULT) : null,
65
+ STATUS,
66
+ };
67
+ let content = field.reduce((x, y) => {
68
+ if (props[y] == null || props[y] == undefined) {
69
+ return x;
70
+ } else {
71
+ return {
72
+ ...x,
73
+ [y]: props[y],
74
+ };
75
+ }
76
+ }, {});
77
+ let list = await emailService.putEailTempate({ TEMPLATE_ID: TEMPLATE_ID }, content);
78
+
79
+ if (!list) {
80
+ return res.sendErr('');
81
+ }
82
+ res.sendOk('修改成功');
83
+ });
84
+
85
+ module.exports = router;
@@ -0,0 +1,276 @@
1
+ 'use strict';
2
+ var express = require('express');
3
+ const isPlainObject = require('lodash/isPlainObject');
4
+
5
+ const { checkLogin } = require('../common/middleware/auth');
6
+ const generalConfig = require('../common/services/generalConfig');
7
+ const dict = require('../common/services/dict');
8
+
9
+ var router = express.Router();
10
+
11
+ router.get('/', checkLogin, async function (req, res) {
12
+ let userid = req.get('X-UserId');
13
+ let config = await generalConfig.getConfig();
14
+ if (!config || !Array.isArray(config)) {
15
+ return res.sendErr('');
16
+ }
17
+ let data = config.map((v) => {
18
+ let value = v?.CONFIG_VALUE || '';
19
+ if (v?.CONFIG_TYPE == 'checkbox') {
20
+ value = v?.CONFIG_VALUE == '1' ? true : false;
21
+ }
22
+
23
+ return {
24
+ type: v?.CONFIG_TYPE || '',
25
+ id: v.CONFIG_ID || '',
26
+ title: v.CONFIG_TITLE || '',
27
+ desc: v.CONFIG_DESC,
28
+ placeholder: v.PLACEHOLDER,
29
+ disabled: v.DISABLED,
30
+ defaultValue: value || v.RAWDATA || '',
31
+ option: v.CONFIG_OPTIONS ? JSON.parse(v.CONFIG_OPTIONS) : null,
32
+ parent: v.GROUP_ID || '',
33
+ isnull: v.IS_NULL || null,
34
+ rawdata: v.RAWDATA || '',
35
+ project: v.PROJECT_ID || '',
36
+ module: v.MODULE_ID || '',
37
+ };
38
+ });
39
+
40
+ res.sendOk(data);
41
+ });
42
+
43
+ router.post('/', checkLogin, async function (req, res) {
44
+ let userid = req.get('X-UserId');
45
+ if (!req.body?.groupid || !req.body?.id) {
46
+ return res.sendErr('缺少组id');
47
+ }
48
+ let {
49
+ id,
50
+ type,
51
+ value,
52
+ option,
53
+ desc,
54
+ title,
55
+ groupid,
56
+ placeholder,
57
+ disabled,
58
+ isnull,
59
+ module,
60
+ project,
61
+ } = req.body;
62
+ let info = await generalConfig.getConfigInfo({ CONFIG_ID: id });
63
+ if (Array.isArray(info) && info.length != 0) {
64
+ return res.sendErr('当前id已存在');
65
+ }
66
+
67
+ option ? (option = JSON.stringify(option)) : null;
68
+ let props = {
69
+ ORG_ID: global.orgid,
70
+ CONFIG_ID: id,
71
+ CONFIG_TYPE: type,
72
+ CONFIG_VALUE: value,
73
+ CONFIG_OPTIONS: option,
74
+ CONFIG_DESC: desc,
75
+ CONFIG_TITLE: title,
76
+ PLACEHOLDER: placeholder,
77
+ DISABLED: disabled,
78
+ IS_NULL: isnull,
79
+ GROUP_ID: groupid,
80
+ DATA_CRT_USER: userid,
81
+ RAWDATA: value,
82
+ MODULE_ID: module,
83
+ PROJECT_ID: project,
84
+ STATUS: '00',
85
+ };
86
+ let config = await generalConfig.postConfig(props);
87
+ if (!config) {
88
+ return res.sendErr('');
89
+ }
90
+ res.sendOk('创建成功');
91
+ });
92
+
93
+ router.put('/', checkLogin, async function (req, res) {
94
+ let userid = req.get('X-UserId');
95
+ if (!req.body?.id) {
96
+ return res.sendErr('缺少组id');
97
+ }
98
+ let {
99
+ id,
100
+ type,
101
+ value,
102
+ option,
103
+ desc,
104
+ title,
105
+ groupid,
106
+ placeholder,
107
+ disabled,
108
+ isnull,
109
+ status,
110
+ rawdata,
111
+ module,
112
+ project,
113
+ } = req.body;
114
+ const field = [
115
+ 'CONFIG_TYPE',
116
+ 'CONFIG_VALUE',
117
+ 'CONFIG_OPTIONS',
118
+ 'CONFIG_DESC',
119
+ 'CONFIG_TITLE',
120
+ 'PLACEHOLDER',
121
+ 'DISABLED',
122
+ 'IS_NULL',
123
+ 'STATUS',
124
+ 'RAWDATA',
125
+ 'MODULE_ID',
126
+ 'PROJECT_ID',
127
+ ];
128
+ option ? (option = JSON.stringify(option)) : null;
129
+ let props = {
130
+ CONFIG_TYPE: type,
131
+ CONFIG_VALUE: value,
132
+ CONFIG_OPTIONS: option,
133
+ CONFIG_DESC: desc,
134
+ CONFIG_TITLE: title,
135
+ PLACEHOLDER: placeholder,
136
+ DISABLED: disabled,
137
+ IS_NULL: isnull,
138
+ STATUS: status,
139
+ RAWDATA: rawdata,
140
+ MODULE_ID: module,
141
+ PROJECT_ID: project,
142
+ };
143
+ let content = field.reduce((x, y) => {
144
+ if (props[y] == null || props[y] == undefined) {
145
+ return x;
146
+ } else {
147
+ return {
148
+ ...x,
149
+ [y]: props[y],
150
+ };
151
+ }
152
+ }, {});
153
+ let config = await generalConfig.putConfig({ CONFIG_ID: id }, content);
154
+ if (!config) {
155
+ return res.sendErr('');
156
+ }
157
+ res.sendOk('修改成功');
158
+ });
159
+
160
+ router.get('/group', checkLogin, async function (req, res) {
161
+ let userid = req.get('X-UserId');
162
+ let group = await generalConfig.getGroup();
163
+ if (!group || !Array.isArray(group)) {
164
+ return res.sendErr('查询失败');
165
+ }
166
+
167
+ let data = group.map((y) => {
168
+ return {
169
+ value: y.GROUP_ID,
170
+ label: y.GROUP_NAME,
171
+ desc: y.GROUP_DESC,
172
+ icon: y.GROUP_ICON,
173
+ parent: y.PARENT_ID,
174
+ };
175
+ });
176
+
177
+ res.sendOk(data);
178
+ });
179
+
180
+ /**
181
+ * 创建分组
182
+ */
183
+ router.post('/group', checkLogin, async function (req, res) {
184
+ let userid = req.get('X-UserId');
185
+ if (!req.body?.value) {
186
+ return res.sendErr('缺少id');
187
+ }
188
+ let { value, label, icon, desc, parent } = req.body;
189
+
190
+ let info = await generalConfig.getGroupInfo({ GROUP_ID: value });
191
+ if (Array.isArray(info) && info.length != 0) {
192
+ return res.sendErr('当前id已存在');
193
+ }
194
+
195
+ let props = {
196
+ ORG_ID: global.orgid,
197
+ PARENT_ID: parent || 'GINGKOO',
198
+ GROUP_ID: value,
199
+ GROUP_NAME: label,
200
+ GROUP_DESC: desc,
201
+ GROUP_ICON: icon,
202
+ STATUS: '00',
203
+ DATA_CRT_USER: userid,
204
+ };
205
+
206
+ let config = await generalConfig.postGroup(props);
207
+ if (!config) {
208
+ return res.sendErr('');
209
+ }
210
+ res.sendOk('创建成功');
211
+ });
212
+ router.put('/group', checkLogin, async function (req, res) {
213
+ if (!req.body?.value) {
214
+ return res.sendErr('缺少id');
215
+ }
216
+ let { value, label, icon, desc, status } = req.body;
217
+ const field = ['GROUP_NAME', 'GROUP_DESC', 'GROUP_ICON', 'STATUS'];
218
+ let props = {
219
+ GROUP_NAME: label,
220
+ GROUP_DESC: desc,
221
+ GROUP_ICON: icon,
222
+ STATUS: status,
223
+ };
224
+ let content = field.reduce((x, y) => {
225
+ if (props[y] == null || props[y] == undefined) {
226
+ return x;
227
+ } else {
228
+ return {
229
+ ...x,
230
+ [y]: props[y],
231
+ };
232
+ }
233
+ }, {});
234
+ let config = await generalConfig.putGroup({ GROUP_ID: value }, content);
235
+ if (!config) {
236
+ return res.sendErr('');
237
+ }
238
+ res.sendOk('修改成功');
239
+ });
240
+
241
+ /**
242
+ * 查询当前页面配置
243
+ * @query pageid 页面key
244
+ */
245
+ router.get('/page', checkLogin, async function (req, res) {
246
+ let { group_ids } = req.query;
247
+ if (!group_ids) {
248
+ return res.sendErr('缺少id');
249
+ }
250
+ let config = await generalConfig.getConfigInfo({ STATUS: '00', GROUP_ID: group_ids });
251
+ if (!config || !Array.isArray(config)) {
252
+ return res.sendErr('');
253
+ }
254
+ let data = config.map((v) => {
255
+ let value = v?.CONFIG_VALUE || '';
256
+ if (v?.CONFIG_TYPE == 'checkbox') {
257
+ value = v?.CONFIG_VALUE == '1' ? true : false;
258
+ }
259
+ return {
260
+ type: v?.CONFIG_TYPE || '',
261
+ id: v.CONFIG_ID || '',
262
+ channel: v?.CHANNEL || '',
263
+ title: v.CONFIG_TITLE || '',
264
+ desc: v.CONFIG_DESC,
265
+ placeholder: v.PLACEHOLDER,
266
+ disabled: v.DISABLED,
267
+ defaultValue: value || '',
268
+ option: v.CONFIG_OPTIONS ? JSON.parse(v.CONFIG_OPTIONS) : null,
269
+ groupid: v.GROUP_ID || '',
270
+ };
271
+ });
272
+
273
+ res.sendOk(data);
274
+ });
275
+
276
+ module.exports = router;
@@ -0,0 +1,245 @@
1
+ 'use strict';
2
+ const express = require('express');
3
+ const userService = require('../common/services/user');
4
+ const router = express.Router();
5
+
6
+ function Tree(data, isSelect = true) {
7
+ let newData = [];
8
+ data.map((v) => {
9
+ const { DEPT_PARENT } = v;
10
+ let preDept = DEPT_PARENT.split('/');
11
+ if (preDept.length == 2) {
12
+ let filter = data.filter((item) => {
13
+ let curDept = item.DEPT_PARENT.split('/');
14
+ return isEqule(curDept, preDept);
15
+ });
16
+ renderTree(filter, data, isSelect)
17
+ ? newData.push({
18
+ icon: 'folder',
19
+ label: v.DEPT_NAME,
20
+ value: v.DEPT_NO,
21
+ parentId: v.DEPT_PARENT,
22
+ creatable: true,
23
+ removable: isSelect ? false : true,
24
+ editable: isSelect ? false : true,
25
+ cannotSelect: isSelect,
26
+ children: renderTree(filter, data, isSelect),
27
+ DEPT_ID: v.DEPT_ID,
28
+ DEPT_NO: v.DEPT_NO,
29
+ })
30
+ : newData.push({
31
+ icon: 'folder',
32
+ parentId: v.DEPT_PARENT,
33
+ label: v.DEPT_NAME,
34
+ value: v.DEPT_NO,
35
+ creatable: true,
36
+ removable: isSelect ? false : true,
37
+ editable: isSelect ? false : true,
38
+ cannotSelect: isSelect,
39
+ DEPT_ID: v.DEPT_ID,
40
+ DEPT_NO: v.DEPT_NO,
41
+ });
42
+ }
43
+ });
44
+ return newData;
45
+ }
46
+
47
+ function renderTree(filter, data, isSelect) {
48
+ if (filter.length > 0) {
49
+ return filter.map((item) => {
50
+ let preDept = item.DEPT_PARENT.split('/');
51
+ let filters = data.filter((v) => {
52
+ let curDept = v.DEPT_PARENT.split('/');
53
+ return isEqule(curDept, preDept);
54
+ });
55
+ return renderTree(filters, data, isSelect)
56
+ ? {
57
+ label: item.DEPT_NAME,
58
+ value: item.DEPT_NO,
59
+ icon: 'folder',
60
+ creatable: true,
61
+ removable: isSelect ? false : true,
62
+ editable: isSelect ? false : true,
63
+ parentId: item.DEPT_PARENT,
64
+ cannotSelect: isSelect,
65
+ children: renderTree(filters, data, isSelect),
66
+ DEPT_ID: item.DEPT_ID,
67
+ DEPT_NO: item.DEPT_NO,
68
+ }
69
+ : {
70
+ label: item.DEPT_NAME,
71
+ value: item.DEPT_NO,
72
+ parentId: item.DEPT_PARENT,
73
+ creatable: true,
74
+ removable: isSelect ? false : true,
75
+ editable: isSelect ? false : true,
76
+ cannotSelect: isSelect,
77
+ icon: 'folder',
78
+ DEPT_ID: item.DEPT_ID,
79
+ DEPT_NO: item.DEPT_NO,
80
+ };
81
+ });
82
+ } else {
83
+ return null;
84
+ }
85
+ }
86
+
87
+ function isEqule(arr1, arr2) {
88
+ if (arr1.length == arr2.length) return false;
89
+ if (arr1.length - arr2.length !== 1) return false;
90
+ for (let i = 0; i < arr2.length; i++) {
91
+ if (arr1[i] !== arr2[i]) return false;
92
+ }
93
+
94
+ return true;
95
+ }
96
+
97
+ function renderGroup(data, idmGroupData) {
98
+ let newData = [];
99
+ let parentList = idmGroupData.filter((v) => v.DEPT_ID == global.orgid);
100
+ if (parentList.length > 0) {
101
+ parentList.map((v) => {
102
+ newData.push({
103
+ label: v.GROUP_NAME,
104
+ value: v.GROUP_ID,
105
+ creatable: false,
106
+ removable: true,
107
+ editable: true,
108
+ icon: 'teams',
109
+ });
110
+ });
111
+ }
112
+ data.map((cur) => {
113
+ const { DEPT_NO } = cur;
114
+ let filter = idmGroupData.filter((v) => v.DEPT_ID == DEPT_NO);
115
+ if (cur.children) {
116
+ newData.push({
117
+ ...cur,
118
+ children: renderGroupTree(cur.children, idmGroupData, DEPT_NO),
119
+ });
120
+ } else {
121
+ if (filter.length > 0) {
122
+ let filterChildren = filter.map((v) => {
123
+ return {
124
+ label: v.GROUP_NAME,
125
+ value: v.GROUP_ID,
126
+ creatable: false,
127
+ removable: true,
128
+ editable: true,
129
+ icon: 'teams',
130
+ };
131
+ });
132
+ newData.push({
133
+ ...cur,
134
+ children: filterChildren,
135
+ });
136
+ } else {
137
+ newData.push({ ...cur });
138
+ }
139
+ }
140
+ });
141
+ return newData;
142
+ }
143
+
144
+ function renderGroupTree(data, idmGroupData, DEPTNO) {
145
+ let newData = [];
146
+ let filters = idmGroupData.filter((item) => item.DEPT_ID == DEPTNO);
147
+ if (filters.length > 0) {
148
+ let childrenFilter = filters.map((v) => {
149
+ return {
150
+ label: v.GROUP_NAME,
151
+ value: v.GROUP_ID,
152
+ creatable: false,
153
+ removable: true,
154
+ editable: true,
155
+ icon: 'teams',
156
+ };
157
+ });
158
+ newData = newData.concat(childrenFilter);
159
+ }
160
+ data.map((v) => {
161
+ const { DEPT_NO } = v;
162
+ if (v.children) {
163
+ return newData.push({ ...v, children: renderGroupTree(v.children, idmGroupData, DEPT_NO) });
164
+ } else {
165
+ let filters = idmGroupData.filter((item) => item.DEPT_ID == DEPT_NO);
166
+ if (filters.length > 0) {
167
+ let childrenFilter = filters.map((v) => {
168
+ return {
169
+ label: v.GROUP_NAME,
170
+ value: v.GROUP_ID,
171
+ creatable: false,
172
+ removable: true,
173
+ editable: true,
174
+ icon: 'teams',
175
+ };
176
+ });
177
+ return newData.push({
178
+ ...v,
179
+ children: childrenFilter,
180
+ });
181
+ } else {
182
+ return newData.push({
183
+ ...v,
184
+ });
185
+ }
186
+ }
187
+ });
188
+ return newData;
189
+ }
190
+
191
+ router.get('/api/orgs', async function (req, res) {
192
+ let orgData = await userService.getOrgData();
193
+ let deptData = await userService.getDeptData();
194
+ if (!orgData || !deptData || !Array.isArray(deptData)) {
195
+ return res.sendErr('没有找到数据');
196
+ }
197
+ let data = {
198
+ options: [
199
+ {
200
+ label: orgData.ORG_NAME,
201
+ icon: 'folder',
202
+ unfolded: true,
203
+ value: global.orgid,
204
+ parentId: global.orgid,
205
+ creatable: true,
206
+ removable: false,
207
+ editable: false,
208
+ cannotSelect: true,
209
+ children: Tree(deptData, false),
210
+ },
211
+ ],
212
+ value: `BR01`,
213
+ };
214
+ res.sendOk(data);
215
+ });
216
+
217
+ router.get('/api/usergroup', async function (req, res) {
218
+ let orgData = await userService.getOrgData();
219
+ let deptData = await userService.getDeptData();
220
+ let groupData = await userService.getGroupData();
221
+ if (!orgData || !deptData || !groupData) {
222
+ return res.sendErr('没有找到数据');
223
+ }
224
+
225
+ let treeData = Tree(deptData, true);
226
+ let data = {
227
+ options: [
228
+ {
229
+ label: orgData.ORG_NAME,
230
+ icon: 'folder',
231
+ unfolded: true,
232
+ value: global.orgid,
233
+ creatable: true,
234
+ removable: false,
235
+ editable: false,
236
+ cannotSelect: true,
237
+ children: renderGroup(treeData, groupData),
238
+ },
239
+ ],
240
+ value: `DEV`,
241
+ };
242
+ res.sendOk(data);
243
+ });
244
+
245
+ module.exports = router;