n20-common-lib 3.3.35 → 3.3.37

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.35",
3
+ "version": "3.3.37",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "vue-cli-service serve",
@@ -164,8 +164,9 @@ export default {
164
164
  this.otherAttData = this.normalizeData(data)
165
165
  this.$emit('loaded', this.otherAttData.length > 0)
166
166
  if (this.taskId) {
167
+ // 旧版工作流可能未提供节点自定义项接口,查询失败时关闭公共提示。
167
168
  axios
168
- .post(`/bems/admin/customization/${this.taskId}`, null, { loading: false })
169
+ .post(`/bems/admin/customization/${this.taskId}`, null, { loading: false, noMsg: true })
169
170
  .then(({ data }) => {
170
171
  if (data && data.length) {
171
172
  this.otherAttData = this.normalizeData(data)
@@ -1,140 +1,41 @@
1
- <template>
2
- <el-cascader
3
- ref="el-cascader"
4
- v-title
5
- :value="value"
6
- v-bind="$attrs"
7
- :options="areaTree"
8
- :filterable="filterable"
9
- :clearable="clearable"
10
- :props="propsAs"
11
- v-on="$listeners"
12
- />
13
- </template>
14
-
15
1
  <script>
16
- window._china_area_tree_ = undefined
2
+ import CascaderAreaV3 from '../v3/CascaderArea/index.vue'
3
+
17
4
  export default {
18
5
  name: 'CascaderArea',
6
+ extends: CascaderAreaV3,
19
7
  props: {
20
- value: {
21
- type: [String, Array],
22
- default: undefined
23
- },
24
- filterable: {
25
- type: Boolean,
26
- default: true
27
- },
28
- clearable: {
29
- type: Boolean,
30
- default: true
31
- },
32
-
33
- isUrban: {
34
- type: Boolean,
35
- default: false
36
- },
37
- selectAnyLevel: {
38
- type: Boolean,
39
- default: false
40
- },
41
- isStreet: {
42
- type: Boolean,
43
- default: false
44
- },
45
- labelSort: {
46
- type: Boolean,
47
- default: false
48
- },
49
- countryId: {
50
- type: String,
51
- default: 'CHN'
52
- },
53
- props: {
54
- type: Object,
55
- default: undefined
56
- }
57
- },
58
- data() {
59
- return {
60
- areaTree: []
61
- }
62
- },
63
- watch: {
64
- selectAnyLevel() {
65
- // 开关运行中切换时复用对应缓存,否则按新模式重新请求地区树。
66
- if (window[this.cacheKey]) {
67
- this.areaTree = window[this.cacheKey]
68
- } else {
69
- this.getAreaTree()
70
- }
71
- }
8
+ // 城市模式默认到二级,中国省或自治区的直辖县分组继续展开到三级。
9
+ isUrban: { type: Boolean, default: false },
10
+ isStreet: { type: Boolean, default: false },
11
+ labelSort: { type: Boolean, default: false }
72
12
  },
73
13
  computed: {
14
+ cacheKey() {
15
+ const country = this.countryId === 'CHN' ? 'china' : this.countryId
16
+ const mode = this.isUrban ? 'urban' : this.isStreet ? 'street' : 'area'
17
+ if (this.isUrban && !this.selectAnyLevel) return `_${country}_urban_city_tree_`
18
+ const key = `_${country}_${mode}_tree_`
19
+ return this.selectAnyLevel ? `${key}_select_any_level_` : key
20
+ },
21
+ queryDeeperLevels() {
22
+ return this.isStreet || this.selectAnyLevel
23
+ },
74
24
  propsAs() {
75
- let _prop = {
76
- value: 'regionNo',
77
- label: 'regionName',
78
- children: 'children',
79
- expandTrigger: 'hover',
80
- checkStrictly: !this.isUrban
25
+ const props = {
26
+ value: 'regionNo', label: 'regionName', children: 'children',
27
+ expandTrigger: 'hover', checkStrictly: !this.isUrban, ...this.props
81
28
  }
82
- const props = Object.assign(_prop, this.props)
83
- // 任意级模式必须允许非叶子节点被选中,避免调用方覆盖后出现不可选层级。
84
- if (this.selectAnyLevel) props.checkStrictly = true
29
+ if (this.selectAnyLevel || this.isUrban) props.checkStrictly = this.selectAnyLevel
85
30
  return props
86
- },
87
- areaKey() {
88
- return this.countryId === 'CHN' ? '_china_area_tree_' : `_${this.countryId}_area_tree_`
89
- },
90
- urbanKey() {
91
- return this.countryId === 'CHN' ? '_china_urban_tree_' : `_${this.countryId}_urban_tree_`
92
- },
93
- streetKey() {
94
- return this.countryId === 'CHN' ? '_china_street_tree_' : `_${this.countryId}_street_tree_`
95
- },
96
- cacheKey() {
97
- const modeKey = this.isUrban ? this.urbanKey : this.isStreet ? this.streetKey : this.areaKey
98
- // 两种模式的 disabled 标记及树深度不同,不能共享已处理的选项树。
99
- return this.selectAnyLevel ? `${modeKey}_select_any_level_` : modeKey
100
- }
101
- },
102
- mounted() {
103
- if (!window[this.cacheKey]) {
104
- this.getAreaTree()
105
- } else {
106
- this.areaTree = window[this.cacheKey]
107
31
  }
108
32
  },
109
33
  methods: {
110
- getAreaTree() {
111
- const cacheKey = this.cacheKey
112
- const isUrban = this.isUrban
113
- const isStreet = this.isStreet
114
- const selectAnyLevel = this.selectAnyLevel
115
- this.$axios
116
- .get(
117
- `/bems/1.0/area?t=${Math.random()}`,
118
- // 任意级模式需要请求下级地区;默认模式保持原先的请求范围。
119
- { countryId: this.countryId, isEnable: '1', resultType: 2, queryLeave4: isStreet || selectAnyLevel },
120
- { loading: false, noMsg: true }
121
- )
122
- .then(({ data }) => {
123
- if (data) {
124
- let result = JSON.parse(JSON.stringify(data))
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]
133
- }
134
- })
135
- },
136
- updateArea() {
137
- this.getAreaTree()
34
+ treeTransform() {
35
+ const { isUrban, selectAnyLevel } = this
36
+ // 老组件的任意级模式优先,继续开放接口返回的完整树。
37
+ if (isUrban && !selectAnyLevel) return CascaderAreaV3.methods.treeTransform.call(this)
38
+ return rows => treeFn(JSON.parse(JSON.stringify(rows)), selectAnyLevel)
138
39
  }
139
40
  }
140
41
  }
@@ -154,15 +55,4 @@ const treeFn = (data, selectAnyLevel = false) => {
154
55
  return res
155
56
  })
156
57
  }
157
-
158
- const isUrbanFn = (data) => {
159
- return data?.map((res) => {
160
- if (res.regionLevel === '2' || !res.children?.length) {
161
- res.children = null
162
- } else {
163
- res.children = isUrbanFn(res.children)
164
- }
165
- return res
166
- })
167
- }
168
58
  </script>
@@ -0,0 +1,135 @@
1
+ <template>
2
+ <el-cascader
3
+ ref="el-cascader"
4
+ :key="cacheKey"
5
+ v-title
6
+ :value="value"
7
+ v-bind="$attrs"
8
+ :options="areaTree"
9
+ :filterable="filterable"
10
+ :clearable="clearable"
11
+ :props="propsAs"
12
+ v-on="$listeners"
13
+ />
14
+ </template>
15
+
16
+ <script>
17
+ // 并行挂载的选择器共享同模式请求;失败后释放请求,允许再次获取。
18
+ const pendingTrees = new Map()
19
+
20
+ // 主数据中的直辖县二级分组:河南、湖北、海南、新疆。显示名称和下级节点仍取自接口。
21
+ const directCountyGroupCodes = new Set(['4190', '4290', '4690', '6590'])
22
+
23
+ export default {
24
+ name: 'CascaderAreaV3',
25
+ props: {
26
+ value: { type: [String, Array], default: undefined },
27
+ filterable: { type: Boolean, default: true },
28
+ clearable: { type: Boolean, default: true },
29
+ // 允许选择中间节点。
30
+ selectAnyLevel: { type: Boolean, default: false },
31
+ countryId: { type: String, default: 'CHN' },
32
+ props: { type: Object, default: undefined }
33
+ },
34
+ data() {
35
+ return { areaTree: [] }
36
+ },
37
+ computed: {
38
+ cacheKey() {
39
+ return `_area_v3_${this.countryId}_${this.selectAnyLevel}_`
40
+ },
41
+ queryDeeperLevels() {
42
+ return false
43
+ },
44
+ propsAs() {
45
+ return {
46
+ value: 'regionNo', label: 'regionName', children: 'children', expandTrigger: 'hover',
47
+ ...this.props,
48
+ checkStrictly: this.selectAnyLevel
49
+ }
50
+ }
51
+ },
52
+ watch: {
53
+ cacheKey: {
54
+ immediate: true,
55
+ handler() {
56
+ this.areaTree = window[this.cacheKey] || []
57
+ this.loadAreaTree().catch(() => {}) // 请求失败时保留空态,刷新或校验可重试。
58
+ }
59
+ }
60
+ },
61
+ methods: {
62
+ async loadAreaTree(refresh = false) {
63
+ const key = this.cacheKey
64
+ if (!refresh && window[key]) return window[key]
65
+ if (!pendingTrees.has(key)) {
66
+ // 在请求前固定转换规则,避免切换国家或模式后把结果写入错误的缓存。
67
+ const transform = this.treeTransform()
68
+ const request = this.fetchTree(key, transform)
69
+ pendingTrees.set(key, request)
70
+ }
71
+ const tree = await pendingTrees.get(key)
72
+ if (key === this.cacheKey) this.areaTree = tree
73
+ return tree
74
+ },
75
+ async fetchTree(key, transform) {
76
+ try {
77
+ const { data } = await this.$axios.get(
78
+ `/bems/1.0/area?t=${Math.random()}`,
79
+ { countryId: this.countryId, isEnable: '1', resultType: 2, queryLeave4: this.queryDeeperLevels },
80
+ { loading: false, noMsg: true }
81
+ )
82
+ if (!Array.isArray(data)) throw new Error('Invalid area tree')
83
+ window[key] = transform(data)
84
+ return window[key]
85
+ } finally {
86
+ pendingTrees.delete(key)
87
+ }
88
+ },
89
+ treeTransform() {
90
+ const chinese = this.countryId === 'CHN'
91
+ const selectAnyLevel = this.selectAnyLevel
92
+ return provinces => provinces.map(province => {
93
+ // 每个选项沿用接口节点的名称和编码,包括直辖市的二级节点。
94
+ const cities = (province.children || []).filter(item =>
95
+ String(item.regionLevel) === '2' && (!chinese || /^\d{4}$/.test(item.regionNo))
96
+ )
97
+ const children = cities.map(city => {
98
+ if (!chinese || !directCountyGroupCodes.has(String(city.regionNo))) return leaf(city)
99
+ // 父子关系以接口树为准,分组展开到实际的三级县市。
100
+ const counties = (city.children || []).filter(item =>
101
+ String(item.regionLevel) === '3' && /^\d{6}$/.test(item.regionNo)
102
+ )
103
+ return branch(city, counties.map(leaf), selectAnyLevel)
104
+ })
105
+ return branch(province, children, selectAnyLevel)
106
+ })
107
+ },
108
+ // 用当前启用的城市树校验历史单值。等待加载,避免编辑表单抢先提交。
109
+ async isCityEndpoint(code) {
110
+ const tree = await this.loadAreaTree()
111
+ return tree.some(province => !province.disabled && province.children?.some(city => {
112
+ if (city.disabled) return false
113
+ if (city.children) return city.children.some(county => !county.disabled && county.regionNo === code)
114
+ return city.regionNo === code && !(this.countryId === 'CHN' && directCountyGroupCodes.has(String(city.regionNo)))
115
+ }))
116
+ },
117
+ getAreaTree() {
118
+ return this.loadAreaTree(true)
119
+ },
120
+ updateArea() {
121
+ return this.getAreaTree()
122
+ }
123
+ }
124
+ }
125
+
126
+ function leaf(node) {
127
+ return { ...node, children: null }
128
+ }
129
+
130
+ function branch(node, children, selectAnyLevel) {
131
+ if (children.length) return { ...node, children }
132
+ // Element UI 会将空分组当作叶子,终点模式下必须显式禁用。
133
+ return { ...node, children: null, disabled: Boolean(node.disabled || !selectAnyLevel) }
134
+ }
135
+ </script>
package/src/index.js CHANGED
@@ -45,6 +45,7 @@ import BankIcon from './components/BankIcon/index.vue'
45
45
  import ButtonGroup from './components/Button/button-group.vue'
46
46
  import IconGroupButton from './components/Button/icon-group-button.vue'
47
47
  import Button from './components/Button/index.vue'
48
+ import CascaderAreaV3 from './components/v3/CascaderArea/index.vue'
48
49
  import CascaderArea from './components/CascaderArea/index.vue'
49
50
  import ChildRange from './components/ChildRange/index.vue'
50
51
  import ContentLoading from './components/ContentLoading/index.vue'
@@ -255,6 +256,7 @@ const components = [
255
256
  AnchorItem,
256
257
  FlowStep,
257
258
  CascaderArea,
259
+ CascaderAreaV3,
258
260
  FileExportAsync,
259
261
  FlowDialog,
260
262
  ChildRange,
@@ -377,6 +379,7 @@ export {
377
379
  Button,
378
380
  ButtonGroup,
379
381
  CascaderArea,
382
+ CascaderAreaV3,
380
383
  ChildRange,
381
384
 
382
385
  // 组件