n20-common-lib 3.3.12 → 3.3.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n20-common-lib",
3
- "version": "3.3.12",
3
+ "version": "3.3.14",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -1,3 +1,4 @@
1
+ <!-- 自定义审批项填写表单 -->
1
2
  <template>
2
3
  <div class="w-100p">
3
4
  <div v-for="(item, i) in otherAttData" :key="i" class="flex-box m-l-m m-r-m">
@@ -139,27 +140,35 @@ export default {
139
140
  // JSON解析失败时忽略
140
141
  }
141
142
  },
142
- getData(data) {
143
- if (data.length) {
144
- this.otherAttData = data
145
- }
143
+ // 两个数据入口统一初始化,保证多选控件首次渲染时绑定响应式数组。
144
+ normalizeData(data = []) {
145
+ return data.map((sourceItem) => {
146
+ const item = { ...sourceItem }
147
+ const selectedValues = Array.isArray(item.cfgVal)
148
+ ? [...item.cfgVal]
149
+ : item.cfgVal === undefined || item.cfgVal === null || item.cfgVal === ''
150
+ ? []
151
+ : String(item.cfgVal).split(',')
152
+
153
+ if (item.cfgType === '32') {
154
+ item.checkList = Array.isArray(item.checkList) ? [...item.checkList] : selectedValues
155
+ }
156
+ if (item.cfgType === '31') {
157
+ item.selectList = Array.isArray(item.selectList) ? [...item.selectList] : selectedValues
158
+ }
159
+ this.setDefaultValue(item)
160
+ return item
161
+ })
162
+ },
163
+ getData(data = []) {
164
+ this.otherAttData = this.normalizeData(data)
146
165
  this.$emit('loaded', this.otherAttData.length > 0)
147
166
  if (this.taskId) {
148
167
  axios
149
168
  .post(`/bems/admin/customization/${this.taskId}`, null, { loading: false })
150
169
  .then(({ data }) => {
151
170
  if (data && data.length) {
152
- this.otherAttData =
153
- data?.map((item) => {
154
- if (['32'].includes(item.cfgType)) {
155
- item.checkList = item.checkList ? item.checkList : []
156
- }
157
- if (['31'].includes(item.cfgType)) {
158
- item.selectList = item.selectList ? item.selectList : []
159
- }
160
- this.setDefaultValue(item)
161
- return item
162
- }) || []
171
+ this.otherAttData = this.normalizeData(data)
163
172
  }
164
173
  this.$emit('loaded', this.otherAttData.length > 0)
165
174
  })
@@ -57,13 +57,17 @@ export default {
57
57
  }
58
58
  },
59
59
  computed: {
60
+ isChinaUrban() {
61
+ return this.isUrban && this.countryId === 'CHN'
62
+ },
60
63
  propsAs() {
61
64
  let _prop = {
62
65
  value: 'regionNo',
63
66
  label: 'regionName',
64
67
  children: 'children',
65
68
  expandTrigger: 'hover',
66
- checkStrictly: !this.isUrban
69
+ // 保留二级城市的子节点后,允许独立选择二级城市和三级地区。
70
+ checkStrictly: this.isChinaUrban || !this.isUrban
67
71
  }
68
72
  return Object.assign(_prop, this.props)
69
73
  },
@@ -75,17 +79,17 @@ export default {
75
79
  },
76
80
  streetKey() {
77
81
  return this.countryId === 'CHN' ? '_china_street_tree_' : `_${this.countryId}_street_tree_`
82
+ },
83
+ cacheKey() {
84
+ // 按当前模式检查缓存,避免普通地区缓存存在时误用尚未加载的城市缓存。
85
+ return this.isUrban ? this.urbanKey : this.isStreet ? this.streetKey : this.areaKey
78
86
  }
79
87
  },
80
88
  mounted() {
81
- if (!window[this.areaKey]) {
89
+ if (!window[this.cacheKey]) {
82
90
  this.getAreaTree()
83
91
  } else {
84
- this.areaTree = this.isUrban
85
- ? window[this.urbanKey]
86
- : this.isStreet
87
- ? window[this.streetKey]
88
- : window[this.areaKey]
92
+ this.areaTree = window[this.cacheKey]
89
93
  }
90
94
  },
91
95
  methods: {
@@ -100,7 +104,7 @@ export default {
100
104
  if (data) {
101
105
  let result = JSON.parse(JSON.stringify(data))
102
106
  if (this.isUrban) {
103
- window[this.urbanKey] = isUrbanFn(result)
107
+ window[this.urbanKey] = isUrbanFn(result, this.isChinaUrban)
104
108
  this.areaTree = window[this.urbanKey]
105
109
  } else if (this.isStreet) {
106
110
  window[this.streetKey] = treeFn(result)
@@ -133,12 +137,21 @@ const treeFn = (data) => {
133
137
  })
134
138
  }
135
139
 
136
- const isUrbanFn = (data) => {
140
+ const isUrbanFn = (data, isChinaUrban = false) => {
137
141
  return data?.map((res) => {
138
- if (res.regionLevel === '2' || !res.children?.length) {
142
+ const regionLevel = String(res.regionLevel)
143
+ // 直辖市只保留一级节点,直接返回接口原有的两位 regionNo,不伪造下级编码。
144
+ const isMunicipality =
145
+ isChinaUrban && regionLevel === '1' && ['11', '12', '31', '50'].includes(String(res.regionNo))
146
+ if (isChinaUrban && regionLevel === '1' && !isMunicipality) {
147
+ // 普通省份仅用于展开;checkStrictly 模式下禁用父节点不影响子节点选择。
148
+ res.disabled = true
149
+ }
150
+ if (isMunicipality || (!isChinaUrban && regionLevel === '2') || !res.children?.length) {
139
151
  res.children = null
140
152
  } else {
141
- res.children = isUrbanFn(res.children)
153
+ // 保留省代管县级市等三级节点,解除原先在二级统一截断的限制。
154
+ res.children = isUrbanFn(res.children, isChinaUrban)
142
155
  }
143
156
  return res
144
157
  })