vue2-client 1.18.68 → 1.19.0

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.
@@ -1,131 +1,146 @@
1
- import { manageApi, post } from '@vue2-client/services/api'
1
+ import { manageApi } from '@vue2-client/services/api'
2
2
  import { handleTree } from '@vue2-client/utils/util'
3
3
  import { indexedDB } from '@vue2-client/utils/indexedDB'
4
4
  import { getConfigByName } from '@vue2-client/services/api/common'
5
5
 
6
+ // 字典缓存
7
+ const dictCache = new Map()
8
+
6
9
  const GetAppDataService = {
7
10
  install (Vue) {
8
- // 给vue增添对话框显示方法
9
11
  Vue.$appdata = Vue.prototype.$appdata = GetAppDataService
10
12
  },
13
+
11
14
  async load () {
12
- const params = {}
13
- await post(manageApi.getDictionaryValue, {}).then((res) => {
14
- Object.assign(params, res)
15
- const badgeItemArray = {}
16
- for (const key of Object.keys(params)) {
17
- badgeItemArray[key] = {}
18
- for (const item of params[key]) {
19
- let status
20
- if (!item.status) {
21
- status = 'none'
22
- } else {
23
- status = item.status
24
- }
25
- badgeItemArray[key][item.value] = {
26
- status: status,
27
- text: item.text
28
- }
29
- }
30
- }
31
- // 追加参数
32
- localStorage.setItem(process.env.VUE_APP_DICTIONARY_KEY, JSON.stringify(params))
33
- localStorage.setItem(process.env.VUE_APP_BADGE_KEY, JSON.stringify(badgeItemArray))
34
- })
15
+ localStorage.setItem(
16
+ process.env.VUE_APP_DICTIONARY_KEY,
17
+ JSON.stringify({})
18
+ )
19
+ localStorage.setItem(
20
+ process.env.VUE_APP_BADGE_KEY,
21
+ JSON.stringify({})
22
+ )
35
23
  },
24
+
36
25
  // 返回树形省市区
37
26
  async getDivisionsOhChinaForTree () {
38
- // 获取省市区数据
39
27
  return new Promise((resolve, reject) => {
40
28
  try {
41
- indexedDB.getByWeb('divisionsOhChina', manageApi.getDivisionsOhChina, {}, res => {
42
- resolve(res)
43
- }, processRes => {
44
- return handleTree(processRes, 'code', 'parentcode')
45
- })
29
+ indexedDB.getByWeb(
30
+ 'divisionsOhChina',
31
+ manageApi.getDivisionsOhChina,
32
+ {},
33
+ res => resolve(res),
34
+ processRes => handleTree(processRes, 'code', 'parentcode')
35
+ )
46
36
  } catch (e) {
47
37
  reject(e)
48
38
  }
49
39
  })
50
40
  },
51
- // 旧版获取配置中心字典
52
- getDictionaryList (key) {
53
- const str = localStorage.getItem(process.env.VUE_APP_DICTIONARY_KEY)
54
- const object = JSON.parse(str)
55
- return object[key]
56
- },
57
- async getDictValue (dictKey, value, func, isDev = false, serviceName = process.env.VUE_APP_SYSTEM_NAME) {
58
- const processResult = (result) => {
59
- if (!result.value) {
60
- return {
61
- status: 'none',
62
- text: value
63
- }
64
- }
65
- const item = result.value.find(item => item.value == value)
66
- if (item) {
67
- return {
68
- status: item.status || 'none',
69
- text: item.label
70
- }
71
- }
41
+ // 用于徽标解析字典值
42
+ parseDictValue (dictList, value) {
43
+ if (!Array.isArray(dictList)) {
72
44
  return {
73
45
  status: 'none',
74
46
  text: value
75
47
  }
76
48
  }
77
- if (func) {
78
- getConfigByName(dictKey, serviceName, result => {
79
- func(processResult(result))
80
- }, isDev)
49
+
50
+ const item = dictList.find(i => i.value == value)
51
+ if (item) {
52
+ return {
53
+ status: item.status || 'none',
54
+ text: item.label
55
+ }
56
+ }
57
+
58
+ return {
59
+ status: 'none',
60
+ text: value
61
+ }
62
+ },
63
+
64
+ // 获取徽标字典值
65
+ async getDictValue (
66
+ dictKey,
67
+ value,
68
+ callback,
69
+ isDev = false,
70
+ serviceName = process.env.VUE_APP_SYSTEM_NAME
71
+ ) {
72
+ const dictList = await this.getDictByKeyAsync(
73
+ dictKey,
74
+ serviceName,
75
+ isDev
76
+ )
77
+ const result = this.parseDictValue(dictList, value)
78
+
79
+ if (typeof callback === 'function') {
80
+ callback(result)
81
81
  } else {
82
- const result = await new Promise((resolve) => {
83
- getConfigByName(dictKey, serviceName, resolve, isDev)
84
- })
85
- return processResult(result)
82
+ return result
86
83
  }
87
84
  },
85
+
88
86
  // 获取琉璃字典(Callback 版本)
89
- getDictByKey(dictKey, serviceName, callback, isDev) {
90
- this.getDictByKeyAsync(dictKey, serviceName, isDev).then(callback)
91
- },
92
- // 获取琉璃字典(Promise 版本)
93
- getDictByKeyAsync(dictKey, serviceName = process.env.VUE_APP_SYSTEM_NAME, isDev) {
94
- return new Promise(resolve => {
95
- getConfigByName(dictKey, serviceName, res => resolve(res.value), isDev)
96
- })
87
+ getDictByKey (dictKey, serviceName, callback, isDev) {
88
+ this.getDictByKeyAsync(dictKey, serviceName, isDev)
89
+ .then(res => {
90
+ if (typeof callback === 'function') {
91
+ callback(res)
92
+ }
93
+ })
97
94
  },
98
95
 
99
- getParam (key, value, callback) {
100
- const str = localStorage.getItem(process.env.VUE_APP_BADGE_KEY)
101
- const object = JSON.parse(str)
102
- if (object && object[key]) {
103
- const result = object[key]
104
- if (Object.prototype.hasOwnProperty.call(result, value)) {
105
- return result[value]
106
- } else {
107
- return { status: 'none', text: value }
108
- }
96
+ // 获取琉璃字典(Promise 版本,核心实现)
97
+ async getDictByKeyAsync (
98
+ dictKey,
99
+ serviceName = process.env.VUE_APP_SYSTEM_NAME,
100
+ isDev = false
101
+ ) {
102
+ const cacheKey = `${serviceName}:${dictKey}`
103
+
104
+ if (dictCache.has(cacheKey)) {
105
+ return dictCache.get(cacheKey)
109
106
  }
110
- return null
107
+
108
+ const dictList = await new Promise(resolve => {
109
+ getConfigByName(
110
+ dictKey,
111
+ serviceName,
112
+ res => resolve(res?.value || []),
113
+ isDev
114
+ )
115
+ })
116
+
117
+ dictCache.set(cacheKey, dictList)
118
+ return dictList
111
119
  },
120
+
112
121
  getParams () {
113
122
  const str = localStorage.getItem(process.env.VUE_APP_DICTIONARY_KEY)
114
- return JSON.parse(str)
123
+ return str ? JSON.parse(str) : {}
115
124
  },
125
+
116
126
  getSingleValues () {
117
127
  const str = localStorage.getItem(process.env.VUE_APP_BADGE_KEY)
118
- return JSON.parse(str)
128
+ return str ? JSON.parse(str) : {}
119
129
  },
130
+
120
131
  getWebConfigByKey (key) {
121
132
  const str = localStorage.getItem(process.env.VUE_APP_WEB_CONFIG_KEY)
133
+ if (!str) return undefined
122
134
  const object = JSON.parse(str)
123
- return object[key]
135
+ return object?.[key]
124
136
  },
137
+
125
138
  getStylesByKey (key) {
126
139
  const str = localStorage.getItem(process.env.VUE_APP_WEB_STYLES_KEY)
140
+ if (!str) return undefined
127
141
  const object = JSON.parse(str)
128
- return object[key]
129
- },
142
+ return object?.[key]
143
+ }
130
144
  }
145
+
131
146
  export default GetAppDataService
@@ -1125,7 +1125,7 @@ export default {
1125
1125
  if (stepDefine.formType === 'select') {
1126
1126
  let dictList
1127
1127
  if (stepDefine.selectType === 'key') {
1128
- dictList = this.$appdata.getDictionaryList(stepDefine.selectKey)
1128
+ dictList = []
1129
1129
  } else if (stepDefine.selectType === 'config') {
1130
1130
  const configName = stepDefine.selectKey.substring(7)
1131
1131
  dictList = await this.$appdata.getDictByKeyAsync(configName)
@@ -787,7 +787,7 @@ export default {
787
787
  if (stepDefine.formType === 'select') {
788
788
  let dictList
789
789
  if (stepDefine.selectType === 'key') {
790
- dictList = this.$appdata.getDictionaryList(stepDefine.selectKey)
790
+ dictList = []
791
791
  } else if (stepDefine.selectType === 'config') {
792
792
  const configName = stepDefine.selectKey.substring(7)
793
793
  dictList = await this.$appdata.getDictByKeyAsync(configName)
@@ -1,45 +0,0 @@
1
- <template>
2
- <div id="xreport-hosp-demo">
3
- <a-space style="margin-bottom: 12px;">
4
- <a-button type="primary" @click="doInit">手动初始化</a-button>
5
- </a-space>
6
- <XReport
7
- ref="reportRef"
8
- :edit-mode="true"
9
- :show-save-button="true"
10
- :show-img-in-cell="false"
11
- :use-oss-for-img="false"
12
- server-name="af-his"
13
- @updateImg="onUpdateImg"/>
14
- </div>
15
- </template>
16
-
17
- <script setup>
18
- import { ref } from 'vue'
19
- import XReport from '@vue2-client/base-client/components/common/XReport'
20
-
21
- const reportRef = ref(null)
22
-
23
- const payload = {
24
- arr: [
25
- { BQ: '病房区', RY: 0, CY: 0, CW: 0, SW: 0, SS: 0, ZC: 0, ZR: 0, ZY: 0 },
26
- { BQ: '感染科', RY: 0, CY: 0, CW: 0, SW: 0, SS: 0, ZC: 0, ZR: 0, ZY: 0 },
27
- { BQ: '骨科病区', RY: 0, CY: 0, CW: 0, SW: 0, SS: 0, ZC: 0, ZR: 0, ZY: 0 },
28
- { BQ: '呼吸科病区', RY: 0, CY: 0, CW: 0, SW: 0, SS: 0, ZC: 0, ZR: 0, ZY: 0 },
29
- { BQ: '急症科病区', RY: 0, CY: 0, CW: 0, SW: 0, SS: 0, ZC: 0, ZR: 0, ZY: 0 },
30
- { BQ: '内科二病区', RY: 0, CY: 0, CW: 0, SW: 0, SS: 0, ZC: 0, ZR: 0, ZY: 0 }
31
- ]
32
- }
33
-
34
- const doInit = async () => {
35
- if (!reportRef.value || !reportRef.value.init) return
36
- await reportRef.value.init({
37
- configName: 'hospitalizationStatsReport',
38
- configData: payload
39
- })
40
- }
41
-
42
- const onUpdateImg = data => {
43
- console.warn('updateImg:', data)
44
- }
45
- </script>
File without changes