n20-common-lib 3.3.18 → 3.3.20
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 +1 -1
- package/src/components/CascaderArea/index.vue +43 -34
- package/src/i18n.json +557 -413
package/package.json
CHANGED
|
@@ -34,6 +34,10 @@ export default {
|
|
|
34
34
|
type: Boolean,
|
|
35
35
|
default: false
|
|
36
36
|
},
|
|
37
|
+
selectAnyLevel: {
|
|
38
|
+
type: Boolean,
|
|
39
|
+
default: false
|
|
40
|
+
},
|
|
37
41
|
isStreet: {
|
|
38
42
|
type: Boolean,
|
|
39
43
|
default: false
|
|
@@ -56,20 +60,29 @@ export default {
|
|
|
56
60
|
areaTree: []
|
|
57
61
|
}
|
|
58
62
|
},
|
|
63
|
+
watch: {
|
|
64
|
+
selectAnyLevel() {
|
|
65
|
+
// 开关运行中切换时复用对应缓存,否则按新模式重新请求地区树。
|
|
66
|
+
if (window[this.cacheKey]) {
|
|
67
|
+
this.areaTree = window[this.cacheKey]
|
|
68
|
+
} else {
|
|
69
|
+
this.getAreaTree()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
59
73
|
computed: {
|
|
60
|
-
isChinaUrban() {
|
|
61
|
-
return this.isUrban && this.countryId === 'CHN'
|
|
62
|
-
},
|
|
63
74
|
propsAs() {
|
|
64
75
|
let _prop = {
|
|
65
76
|
value: 'regionNo',
|
|
66
77
|
label: 'regionName',
|
|
67
78
|
children: 'children',
|
|
68
79
|
expandTrigger: 'hover',
|
|
69
|
-
|
|
70
|
-
checkStrictly: this.isChinaUrban || !this.isUrban
|
|
80
|
+
checkStrictly: !this.isUrban
|
|
71
81
|
}
|
|
72
|
-
|
|
82
|
+
const props = Object.assign(_prop, this.props)
|
|
83
|
+
// 任意级模式必须允许非叶子节点被选中,避免调用方覆盖后出现不可选层级。
|
|
84
|
+
if (this.selectAnyLevel) props.checkStrictly = true
|
|
85
|
+
return props
|
|
73
86
|
},
|
|
74
87
|
areaKey() {
|
|
75
88
|
return this.countryId === 'CHN' ? '_china_area_tree_' : `_${this.countryId}_area_tree_`
|
|
@@ -81,8 +94,9 @@ export default {
|
|
|
81
94
|
return this.countryId === 'CHN' ? '_china_street_tree_' : `_${this.countryId}_street_tree_`
|
|
82
95
|
},
|
|
83
96
|
cacheKey() {
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
const modeKey = this.isUrban ? this.urbanKey : this.isStreet ? this.streetKey : this.areaKey
|
|
98
|
+
// 两种模式的 disabled 标记及树深度不同,不能共享已处理的选项树。
|
|
99
|
+
return this.selectAnyLevel ? `${modeKey}_select_any_level_` : modeKey
|
|
86
100
|
}
|
|
87
101
|
},
|
|
88
102
|
mounted() {
|
|
@@ -94,25 +108,28 @@ export default {
|
|
|
94
108
|
},
|
|
95
109
|
methods: {
|
|
96
110
|
getAreaTree() {
|
|
111
|
+
const cacheKey = this.cacheKey
|
|
112
|
+
const isUrban = this.isUrban
|
|
113
|
+
const isStreet = this.isStreet
|
|
114
|
+
const selectAnyLevel = this.selectAnyLevel
|
|
97
115
|
this.$axios
|
|
98
116
|
.get(
|
|
99
117
|
`/bems/1.0/area?t=${Math.random()}`,
|
|
100
|
-
|
|
118
|
+
// 任意级模式需要请求下级地区;默认模式保持原先的请求范围。
|
|
119
|
+
{ countryId: this.countryId, isEnable: '1', resultType: 2, queryLeave4: isStreet || selectAnyLevel },
|
|
101
120
|
{ loading: false, noMsg: true }
|
|
102
121
|
)
|
|
103
122
|
.then(({ data }) => {
|
|
104
123
|
if (data) {
|
|
105
124
|
let result = JSON.parse(JSON.stringify(data))
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.areaTree = window[this.areaKey]
|
|
115
|
-
}
|
|
125
|
+
// 旧城市模式仍在二级截断;任意级模式统一保留接口返回的完整树。
|
|
126
|
+
window[cacheKey] = selectAnyLevel
|
|
127
|
+
? treeFn(result, true)
|
|
128
|
+
: isUrban
|
|
129
|
+
? isUrbanFn(result)
|
|
130
|
+
: treeFn(result)
|
|
131
|
+
// 若请求期间切换了模式,不用旧请求覆盖当前显示。
|
|
132
|
+
if (cacheKey === this.cacheKey) this.areaTree = window[cacheKey]
|
|
116
133
|
}
|
|
117
134
|
})
|
|
118
135
|
},
|
|
@@ -122,36 +139,28 @@ export default {
|
|
|
122
139
|
}
|
|
123
140
|
}
|
|
124
141
|
|
|
125
|
-
const treeFn = (data) => {
|
|
142
|
+
const treeFn = (data, selectAnyLevel = false) => {
|
|
126
143
|
return data?.map((res) => {
|
|
127
|
-
|
|
144
|
+
// 默认仍只开放原先可选的层级;开关开启时保留接口已有的禁用状态。
|
|
145
|
+
if (!selectAnyLevel && !['3', '4', '5'].includes(res.regionLevel) && res.hasChildren) {
|
|
128
146
|
res.disabled = true
|
|
129
147
|
}
|
|
130
148
|
|
|
131
149
|
if (!res.children?.length) {
|
|
132
150
|
res.children = null
|
|
133
151
|
} else {
|
|
134
|
-
res.children = treeFn(res.children)
|
|
152
|
+
res.children = treeFn(res.children, selectAnyLevel)
|
|
135
153
|
}
|
|
136
154
|
return res
|
|
137
155
|
})
|
|
138
156
|
}
|
|
139
157
|
|
|
140
|
-
const isUrbanFn = (data
|
|
158
|
+
const isUrbanFn = (data) => {
|
|
141
159
|
return data?.map((res) => {
|
|
142
|
-
|
|
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) {
|
|
160
|
+
if (res.regionLevel === '2' || !res.children?.length) {
|
|
151
161
|
res.children = null
|
|
152
162
|
} else {
|
|
153
|
-
|
|
154
|
-
res.children = isUrbanFn(res.children, isChinaUrban)
|
|
163
|
+
res.children = isUrbanFn(res.children)
|
|
155
164
|
}
|
|
156
165
|
return res
|
|
157
166
|
})
|