n20-common-lib 3.3.13 → 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.13",
3
+ "version": "3.3.14",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -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
  })