imeik-bizui 2.2.5 → 2.2.7
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/dist/bizui/api/tagcenter.js +12 -1
- package/dist/bizui/src/CommonRegionCascader/index.vue +258 -0
- package/dist/imeik-bizui.common.js +398 -58
- package/dist/imeik-bizui.common.js.gz +0 -0
- package/dist/imeik-bizui.umd.js +398 -58
- package/dist/imeik-bizui.umd.js.gz +0 -0
- package/dist/imeik-bizui.umd.min.js +6 -6
- package/dist/imeik-bizui.umd.min.js.gz +0 -0
- package/package.json +1 -1
|
@@ -11,4 +11,15 @@ export function queryTagList(params) {
|
|
|
11
11
|
method: 'get',
|
|
12
12
|
params
|
|
13
13
|
})
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 获取省市区
|
|
18
|
+
*/
|
|
19
|
+
export function getRegionData(params) {
|
|
20
|
+
return request({
|
|
21
|
+
url: '/tagcenter-admin/dictionary/queryCityTree',
|
|
22
|
+
method: 'get',
|
|
23
|
+
params
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
区域级联选择器组件
|
|
3
|
+
|
|
4
|
+
用途:
|
|
5
|
+
1. 支持区域级联选择
|
|
6
|
+
2. 支持单选和多选
|
|
7
|
+
3. 支持展开收起
|
|
8
|
+
4. 支持指定某个区域节点
|
|
9
|
+
5. 支持指定某个区域节点以后是否展示根节点
|
|
10
|
+
|
|
11
|
+
属性说明:
|
|
12
|
+
value: 选择器的值
|
|
13
|
+
multiple: 是否多选
|
|
14
|
+
emitPath: 是否返回选中节点的完整路径
|
|
15
|
+
expandTrigger: 次级菜单的展开方式
|
|
16
|
+
checkStrictly: 是否严格的遵守父子节点不互相关联
|
|
17
|
+
isView: 是否仅展示文字
|
|
18
|
+
level: 指定层级,字符串类型,需要注意的是省对应的是‘2’
|
|
19
|
+
placeholder: 占位符
|
|
20
|
+
...attrs: 其他属性会透传给el-cascader
|
|
21
|
+
props: 级联选择器配置 默认值为:
|
|
22
|
+
{
|
|
23
|
+
label: 'name',
|
|
24
|
+
value: 'code',
|
|
25
|
+
children: 'subRegin',
|
|
26
|
+
expandTrigger: 'hover',
|
|
27
|
+
checkStrictly: true,
|
|
28
|
+
emitPath: false,
|
|
29
|
+
multiple: false
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
使用示例:
|
|
33
|
+
<CommonRegionCascader
|
|
34
|
+
v-model="formConfig.props.regionCodes"
|
|
35
|
+
multiple
|
|
36
|
+
:show-all-levels="false"
|
|
37
|
+
></CommonRegionCascader>
|
|
38
|
+
-->
|
|
39
|
+
<template>
|
|
40
|
+
<el-cascader v-if="!isView" v-model="myValue" :props="props" :options="options" :placeholder="placeholder" clearable filterable v-bind="$attrs" @change="handleChange"></el-cascader>
|
|
41
|
+
<div v-else>{{ myLabel || '-' }}</div>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
import { getRegionData } from '../../api/tagcenter'
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
name: 'RegionCascader',
|
|
49
|
+
props: {
|
|
50
|
+
value: {
|
|
51
|
+
type: [String, Array],
|
|
52
|
+
default: undefined
|
|
53
|
+
},
|
|
54
|
+
placeholder: {
|
|
55
|
+
type: String,
|
|
56
|
+
default: '请选择'
|
|
57
|
+
},
|
|
58
|
+
level: {
|
|
59
|
+
type: String,
|
|
60
|
+
default: undefined
|
|
61
|
+
},
|
|
62
|
+
checkStrictly: {
|
|
63
|
+
type: Boolean,
|
|
64
|
+
default: true
|
|
65
|
+
},
|
|
66
|
+
emitPath: {
|
|
67
|
+
type: Boolean,
|
|
68
|
+
default: false
|
|
69
|
+
},
|
|
70
|
+
multiple: {
|
|
71
|
+
type: Boolean,
|
|
72
|
+
default: false
|
|
73
|
+
},
|
|
74
|
+
props: {
|
|
75
|
+
type: Object,
|
|
76
|
+
default() {
|
|
77
|
+
return {
|
|
78
|
+
label: 'name',
|
|
79
|
+
value: 'code',
|
|
80
|
+
children: 'subRegin',
|
|
81
|
+
expandTrigger: 'hover',
|
|
82
|
+
checkStrictly: this.checkStrictly,
|
|
83
|
+
emitPath: this.emitPath,
|
|
84
|
+
multiple: this.multiple
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
data() {
|
|
90
|
+
return {
|
|
91
|
+
myValue: undefined,
|
|
92
|
+
options: []
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
computed: {
|
|
96
|
+
isView() {
|
|
97
|
+
return this.$attrs.isView
|
|
98
|
+
},
|
|
99
|
+
myLabel() {
|
|
100
|
+
return this.getLabel(this.options, this.myValue)
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
watch: {
|
|
104
|
+
value: {
|
|
105
|
+
immediate: true,
|
|
106
|
+
handler() {
|
|
107
|
+
this.setMyValue()
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
created() {
|
|
112
|
+
this.getOptions()
|
|
113
|
+
},
|
|
114
|
+
methods: {
|
|
115
|
+
setMyValue() {
|
|
116
|
+
try {
|
|
117
|
+
this.myValue = JSON.parse(JSON.stringify(this.value))
|
|
118
|
+
} catch (error) {
|
|
119
|
+
this.myValue = undefined
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
getOptions() {
|
|
124
|
+
getRegionData({}).then((res) => {
|
|
125
|
+
if (res.code === 200) {
|
|
126
|
+
this.options = res.data || []
|
|
127
|
+
this.formatData(this.options)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
formatData(regionData) {
|
|
133
|
+
for (let i = 0; i < regionData.length; i++) {
|
|
134
|
+
const item = regionData[i]
|
|
135
|
+
if (this.level && this.level === item.level) {
|
|
136
|
+
delete item.subRegin
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
if (item.subRegin && item.subRegin.length === 0) {
|
|
140
|
+
delete item.subRegin
|
|
141
|
+
}
|
|
142
|
+
if (item.subRegin && item.subRegin.length > 0) {
|
|
143
|
+
this.formatData(item.subRegin)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* 根据值获取标签文本
|
|
149
|
+
* @param {Array} options - 选项列表
|
|
150
|
+
* @param {String|Array} value - 选中的值,可能是单个值、数组或路径数组
|
|
151
|
+
* @returns {String} 标签文本
|
|
152
|
+
*/
|
|
153
|
+
getLabel(options, value) {
|
|
154
|
+
if (!value || !options || options.length === 0) {
|
|
155
|
+
return ''
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 如果 value 是数组(可能是多选或路径数组)
|
|
159
|
+
if (Array.isArray(value)) {
|
|
160
|
+
// 如果数组为空
|
|
161
|
+
if (value.length === 0) {
|
|
162
|
+
return ''
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// 判断是否是路径数组(emitPath为true时,value是路径数组,如['110000', '110100', '110101'])
|
|
166
|
+
// 路径数组的第一个元素是省份code,最后一个元素是选中的code
|
|
167
|
+
if (this.emitPath && value.length > 0) {
|
|
168
|
+
// 路径数组,需要找到路径上所有节点的名称
|
|
169
|
+
const labels = []
|
|
170
|
+
let currentOptions = options
|
|
171
|
+
|
|
172
|
+
for (let i = 0; i < value.length; i++) {
|
|
173
|
+
const code = value[i]
|
|
174
|
+
const item = this.findItemByCode(currentOptions, code)
|
|
175
|
+
if (item) {
|
|
176
|
+
labels.push(item.name)
|
|
177
|
+
if (item.subRegin && i < value.length - 1) {
|
|
178
|
+
currentOptions = item.subRegin
|
|
179
|
+
}
|
|
180
|
+
} else {
|
|
181
|
+
break
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return labels.join(' / ')
|
|
186
|
+
} else {
|
|
187
|
+
// 多选情况,value是code数组
|
|
188
|
+
const labels = []
|
|
189
|
+
value.forEach((code) => {
|
|
190
|
+
const label = this.findLabelByCode(options, code)
|
|
191
|
+
if (label) {
|
|
192
|
+
labels.push(label)
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
return labels.join(', ')
|
|
196
|
+
}
|
|
197
|
+
} else {
|
|
198
|
+
// 单选情况,value是单个code
|
|
199
|
+
return this.findLabelByCode(options, value) || ''
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
/**
|
|
203
|
+
* 根据code在options中查找对应的名称
|
|
204
|
+
* @param {Array} options - 选项列表
|
|
205
|
+
* @param {String} code - 要查找的code
|
|
206
|
+
* @returns {String} 对应的名称
|
|
207
|
+
*/
|
|
208
|
+
findLabelByCode(options, code) {
|
|
209
|
+
if (!code || !options || options.length === 0) {
|
|
210
|
+
return ''
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
for (let i = 0; i < options.length; i++) {
|
|
214
|
+
const item = options[i]
|
|
215
|
+
if (item.code === code) {
|
|
216
|
+
return item.name
|
|
217
|
+
}
|
|
218
|
+
if (item.subRegin && item.subRegin.length > 0) {
|
|
219
|
+
const result = this.findLabelByCode(item.subRegin, code)
|
|
220
|
+
if (result) {
|
|
221
|
+
return result
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return ''
|
|
226
|
+
},
|
|
227
|
+
/**
|
|
228
|
+
* 根据code在options中查找对应的项
|
|
229
|
+
* @param {Array} options - 选项列表
|
|
230
|
+
* @param {String} code - 要查找的code
|
|
231
|
+
* @returns {Object} 对应的项
|
|
232
|
+
*/
|
|
233
|
+
findItemByCode(options, code) {
|
|
234
|
+
if (!code || !options || options.length === 0) {
|
|
235
|
+
return null
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
for (let i = 0; i < options.length; i++) {
|
|
239
|
+
const item = options[i]
|
|
240
|
+
if (item.code === code) {
|
|
241
|
+
return item
|
|
242
|
+
}
|
|
243
|
+
if (item.subRegin && item.subRegin.length > 0) {
|
|
244
|
+
const result = this.findItemByCode(item.subRegin, code)
|
|
245
|
+
if (result) {
|
|
246
|
+
return result
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return null
|
|
251
|
+
},
|
|
252
|
+
handleChange() {
|
|
253
|
+
this.$emit('input', this.myValue)
|
|
254
|
+
this.$emit('change', this.myValue)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
</script>
|