q-koa 8.6.7 → 8.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.
@@ -4,7 +4,7 @@ module.exports = {
4
4
  multiple: false,
5
5
  availableSort: true,
6
6
  order: [],
7
- select: [],
7
+ select: [{ key: 'parent_id' }],
8
8
  excludes: [],
9
9
  limit: 40,
10
10
  defaultOrder: [{ sort: 'ascending', type: 'sortOrder' }],
@@ -1,7 +1,6 @@
1
1
  const { getConfig, lodash } = require('q-koa')
2
2
  const formatPostFunction = (str) => `eval(${str})`
3
3
  const nodeVm = require('vm')
4
- const { is } = require('cheerio/lib/api/traversing')
5
4
 
6
5
  exports.initData = async ({ includes, excludes, app, ctx }) => {
7
6
  const appConfig = getConfig(app)
@@ -16,11 +16,37 @@ exports.getList = (config) => (type) => {
16
16
  }
17
17
 
18
18
  exports.getObject = (config, app) => async (type) => {
19
+ const obj = config.find((i) => i.code === type)
20
+ let flag = false
21
+ const temObj = {}
22
+ if (obj) {
23
+ const list = config.filter((i) => i.parent_id === obj.id)
24
+
25
+ for (let i = 0; i < list.length; i++) {
26
+ if (list[i].type === 'decimal') {
27
+ temObj[list[i].code] = Number(list[i].value)
28
+ } else if (list[i].type === 'switch') {
29
+ temObj[list[i].code] = Boolean(Number(list[i].value))
30
+ } else {
31
+ temObj[list[i].code] = list[i].value
32
+ }
33
+ }
34
+ flag = true
35
+ }
36
+
19
37
  const findConfig = (item) => item.config === type || item.pay_config === type
20
38
  if (app) {
21
39
  const applicationList = app.cache.get('application')
22
- if (applicationList && applicationList.find(findConfig)) {
23
- return applicationList.find(findConfig)
40
+ if (
41
+ applicationList &&
42
+ applicationList.find(findConfig) &&
43
+ applicationList.find(findConfig)
44
+ ) {
45
+ flag = true
46
+ return {
47
+ ...applicationList.find(findConfig),
48
+ ...temObj,
49
+ }
24
50
  }
25
51
 
26
52
  if (!applicationList) {
@@ -32,25 +58,17 @@ exports.getObject = (config, app) => async (type) => {
32
58
 
33
59
  const target = result.find(findConfig)
34
60
  if (target) {
35
- return target
61
+ flag = true
62
+ return {
63
+ ...target,
64
+ ...temObj,
65
+ }
36
66
  }
37
67
  }
38
68
  }
39
69
  }
40
70
  }
41
- const obj = config.find((i) => i.code === type)
42
- if (!obj) throw new Error(`找不到${type}相关设置`)
43
- const list = config.filter((i) => i.parent_id === obj.id)
44
- const temObj = {}
45
- for (let i = 0; i < list.length; i++) {
46
- if (list[i].type === 'decimal') {
47
- temObj[list[i].code] = Number(list[i].value)
48
- } else if (list[i].type === 'switch') {
49
- temObj[list[i].code] = Boolean(Number(list[i].value))
50
- } else {
51
- temObj[list[i].code] = list[i].value
52
- }
53
- }
71
+ if (!flag) throw new Error(`找不到${type}相关设置`)
54
72
  return temObj
55
73
  }
56
74
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q-koa",
3
- "version": "8.6.7",
3
+ "version": "8.7.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {