@gingkoo/base-server 0.0.1-alpha.7 → 0.0.1-alpha.9

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.
@@ -21,19 +21,31 @@ class MappingFactory {
21
21
 
22
22
  async getMapping(module, dict_ids, extra) {
23
23
  let mapping = {};
24
+ let list = {};
24
25
 
25
- if (!Array.isArray(dict_ids)) return mapping;
26
- if (!dict_ids.length) return mapping;
26
+ if (!Array.isArray(dict_ids) || !dict_ids?.length) {
27
+ return {
28
+ dict: mapping,
29
+ list: list,
30
+ };
31
+ }
27
32
 
28
33
  let modulesMap = {
29
34
  async USER_LIST() {
30
35
  let res = await userService.getUsers();
31
- return res.reduce((mo, item) => {
36
+ let arr = [];
37
+ let dict = res.reduce((mo, item) => {
32
38
  if (item.USER_ID) {
39
+ arr.push({ value: item.USER_ID, label: item.USER_NAME });
33
40
  mo[item.USER_ID] = item.USER_NAME;
34
41
  }
35
42
  return mo;
36
43
  }, {});
44
+
45
+ return {
46
+ dict,
47
+ list: arr,
48
+ };
37
49
  },
38
50
  };
39
51
 
@@ -68,6 +80,12 @@ class MappingFactory {
68
80
  mo[value] = rest;
69
81
  return mo;
70
82
  }, {});
83
+ list[key] = value.map((item) => {
84
+ return {
85
+ label: item.label,
86
+ value: item.value,
87
+ };
88
+ });
71
89
  }
72
90
  });
73
91
  }
@@ -76,18 +94,30 @@ class MappingFactory {
76
94
  if (module_dict.length) {
77
95
  await module_dict.myforeach(async (dict_id) => {
78
96
  let fn = modulesMap[dict_id];
79
-
97
+ let result = {};
80
98
  if (isAsync(fn)) {
81
- mapping[dict_id] = await fn(extra);
99
+ result = await fn(extra);
82
100
  } else if (typeof fn === 'function') {
83
- mapping[dict_id] = fn(extra);
84
- } else if (isPlainObject(fn)) {
85
- mapping[dict_id] = fn;
101
+ result = fn(extra);
102
+ } else {
103
+ result = fn;
104
+ }
105
+
106
+ if (isPlainObject(result)) {
107
+ if (result['dict']) {
108
+ mapping[dict_id] = result['dict'];
109
+ }
110
+ if (result['list']) {
111
+ list[dict_id] = result['list'];
112
+ }
86
113
  }
87
114
  });
88
115
  }
89
116
 
90
- return mapping;
117
+ return {
118
+ dict: mapping,
119
+ list: list,
120
+ };
91
121
  }
92
122
  }
93
123
 
@@ -434,6 +434,7 @@ const dictService = {
434
434
  MODULE_ID,
435
435
  DICT_NAME,
436
436
  DICT_ID,
437
+ ORG_ID: global.orgid,
437
438
  });
438
439
  let result = await sqlExecutor(sql, params);
439
440
  return result;
@@ -18,7 +18,6 @@ function gConfig() {
18
18
  return _.merge(
19
19
  {
20
20
  isProd: true, // 纯当前开发用, 通过 npm 包 使用该组件的时候 他应该永远是 true
21
- orgid: 'GINGKOO',
22
21
  allowedIPs: [], // 不校验登录的 ip
23
22
  testUser: '', // 测试用户
24
23
  ip: '0.0.0.0', // 服务 host
package/backend/router.js CHANGED
@@ -17,10 +17,14 @@ var router = express.Router();
17
17
  // 后端
18
18
  router.get('/(:module/)?mapping', async (req, res) => {
19
19
  let { module } = req.params;
20
- let { list = '', ...extra } = req.query;
21
- res.sendOk({
22
- dict: await mapping.getMapping(module, list.split('|'), extra),
23
- });
20
+ let { list = '', type = 'dict', ...extra } = req.query;
21
+ let data = await mapping.getMapping(module, list.split('|'), extra);
22
+ if (type === 'dict') {
23
+ Reflect.deleteProperty(data, 'list');
24
+ } else if (type === 'list') {
25
+ Reflect.deleteProperty(data, 'dict');
26
+ }
27
+ res.sendOk(data);
24
28
  });
25
29
 
26
30
  router.use('/fss', fss);
@@ -5,11 +5,18 @@ const deptService = require('./common/services/dept');
5
5
  mapping.register('space', {
6
6
  async DEPT_LIST() {
7
7
  let res = await deptService.getDepts();
8
- return res.reduce((mo, item) => {
8
+ let list = [];
9
+ let dict = res.reduce((mo, item) => {
9
10
  if (item.DEPT_NO) {
10
11
  mo[item.DEPT_NO] = item.DEPT_NAME;
12
+ list.push({ value: item.DEPT_NO, label: item.DEPT_NAME });
11
13
  }
12
14
  return mo;
13
15
  }, {});
16
+
17
+ return {
18
+ dict,
19
+ list,
20
+ };
14
21
  },
15
22
  });