imeik-bizui 2.2.5 → 2.2.6
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 +215 -0
- package/dist/imeik-bizui.common.js +393 -58
- package/dist/imeik-bizui.common.js.gz +0 -0
- package/dist/imeik-bizui.umd.js +393 -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,215 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-cascader v-if="!isView" v-model="myValue" :props="props" :options="options" :placeholder="placeholder" clearable filterable v-bind="$attrs" @change="handleChange"></el-cascader>
|
|
3
|
+
<div v-else>{{ myLabel || '-' }}</div>
|
|
4
|
+
</template>
|
|
5
|
+
|
|
6
|
+
<script>
|
|
7
|
+
import { getRegionData } from '../../api/tagcenter'
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
name: 'RegionCascader',
|
|
11
|
+
props: {
|
|
12
|
+
value: {
|
|
13
|
+
type: [String, Array],
|
|
14
|
+
default: undefined
|
|
15
|
+
},
|
|
16
|
+
placeholder: {
|
|
17
|
+
type: String,
|
|
18
|
+
default: '请选择'
|
|
19
|
+
},
|
|
20
|
+
level: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: undefined
|
|
23
|
+
},
|
|
24
|
+
checkStrictly: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: true
|
|
27
|
+
},
|
|
28
|
+
emitPath: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: false
|
|
31
|
+
},
|
|
32
|
+
props: {
|
|
33
|
+
type: Object,
|
|
34
|
+
default() {
|
|
35
|
+
return {
|
|
36
|
+
label: 'name',
|
|
37
|
+
value: 'code',
|
|
38
|
+
children: 'subRegin',
|
|
39
|
+
expandTrigger: 'hover',
|
|
40
|
+
checkStrictly: this.checkStrictly,
|
|
41
|
+
emitPath: this.emitPath
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
data() {
|
|
47
|
+
return {
|
|
48
|
+
myValue: undefined,
|
|
49
|
+
options: []
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
computed: {
|
|
53
|
+
isView() {
|
|
54
|
+
return this.$attrs.isView
|
|
55
|
+
},
|
|
56
|
+
myLabel() {
|
|
57
|
+
return this.getLabel(this.options, this.myValue)
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
watch: {
|
|
61
|
+
value: {
|
|
62
|
+
immediate: true,
|
|
63
|
+
handler() {
|
|
64
|
+
this.setMyValue()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
created() {
|
|
69
|
+
this.getOptions()
|
|
70
|
+
},
|
|
71
|
+
methods: {
|
|
72
|
+
setMyValue() {
|
|
73
|
+
try {
|
|
74
|
+
this.myValue = JSON.parse(JSON.stringify(this.value))
|
|
75
|
+
} catch (error) {
|
|
76
|
+
this.myValue = undefined
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
getOptions() {
|
|
81
|
+
getRegionData({}).then((res) => {
|
|
82
|
+
if (res.code === 200) {
|
|
83
|
+
this.options = res.data || []
|
|
84
|
+
this.formatData(this.options)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
formatData(regionData) {
|
|
90
|
+
for (let i = 0; i < regionData.length; i++) {
|
|
91
|
+
const item = regionData[i]
|
|
92
|
+
if (this.level && this.level === item.level) {
|
|
93
|
+
delete item.subRegin
|
|
94
|
+
continue
|
|
95
|
+
}
|
|
96
|
+
if (item.subRegin && item.subRegin.length === 0) {
|
|
97
|
+
delete item.subRegin
|
|
98
|
+
}
|
|
99
|
+
if (item.subRegin && item.subRegin.length > 0) {
|
|
100
|
+
this.formatData(item.subRegin)
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* 根据值获取标签文本
|
|
106
|
+
* @param {Array} options - 选项列表
|
|
107
|
+
* @param {String|Array} value - 选中的值,可能是单个值、数组或路径数组
|
|
108
|
+
* @returns {String} 标签文本
|
|
109
|
+
*/
|
|
110
|
+
getLabel(options, value) {
|
|
111
|
+
if (!value || !options || options.length === 0) {
|
|
112
|
+
return ''
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 如果 value 是数组(可能是多选或路径数组)
|
|
116
|
+
if (Array.isArray(value)) {
|
|
117
|
+
// 如果数组为空
|
|
118
|
+
if (value.length === 0) {
|
|
119
|
+
return ''
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 判断是否是路径数组(emitPath为true时,value是路径数组,如['110000', '110100', '110101'])
|
|
123
|
+
// 路径数组的第一个元素是省份code,最后一个元素是选中的code
|
|
124
|
+
if (this.emitPath && value.length > 0) {
|
|
125
|
+
// 路径数组,需要找到路径上所有节点的名称
|
|
126
|
+
const labels = []
|
|
127
|
+
let currentOptions = options
|
|
128
|
+
|
|
129
|
+
for (let i = 0; i < value.length; i++) {
|
|
130
|
+
const code = value[i]
|
|
131
|
+
const item = this.findItemByCode(currentOptions, code)
|
|
132
|
+
if (item) {
|
|
133
|
+
labels.push(item.name)
|
|
134
|
+
if (item.subRegin && i < value.length - 1) {
|
|
135
|
+
currentOptions = item.subRegin
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
break
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return labels.join(' / ')
|
|
143
|
+
} else {
|
|
144
|
+
// 多选情况,value是code数组
|
|
145
|
+
const labels = []
|
|
146
|
+
value.forEach(code => {
|
|
147
|
+
const label = this.findLabelByCode(options, code)
|
|
148
|
+
if (label) {
|
|
149
|
+
labels.push(label)
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
return labels.join(', ')
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
// 单选情况,value是单个code
|
|
156
|
+
return this.findLabelByCode(options, value) || ''
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
/**
|
|
160
|
+
* 根据code在options中查找对应的名称
|
|
161
|
+
* @param {Array} options - 选项列表
|
|
162
|
+
* @param {String} code - 要查找的code
|
|
163
|
+
* @returns {String} 对应的名称
|
|
164
|
+
*/
|
|
165
|
+
findLabelByCode(options, code) {
|
|
166
|
+
if (!code || !options || options.length === 0) {
|
|
167
|
+
return ''
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (let i = 0; i < options.length; i++) {
|
|
171
|
+
const item = options[i]
|
|
172
|
+
if (item.code === code) {
|
|
173
|
+
return item.name
|
|
174
|
+
}
|
|
175
|
+
if (item.subRegin && item.subRegin.length > 0) {
|
|
176
|
+
const result = this.findLabelByCode(item.subRegin, code)
|
|
177
|
+
if (result) {
|
|
178
|
+
return result
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return ''
|
|
183
|
+
},
|
|
184
|
+
/**
|
|
185
|
+
* 根据code在options中查找对应的项
|
|
186
|
+
* @param {Array} options - 选项列表
|
|
187
|
+
* @param {String} code - 要查找的code
|
|
188
|
+
* @returns {Object} 对应的项
|
|
189
|
+
*/
|
|
190
|
+
findItemByCode(options, code) {
|
|
191
|
+
if (!code || !options || options.length === 0) {
|
|
192
|
+
return null
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
for (let i = 0; i < options.length; i++) {
|
|
196
|
+
const item = options[i]
|
|
197
|
+
if (item.code === code) {
|
|
198
|
+
return item
|
|
199
|
+
}
|
|
200
|
+
if (item.subRegin && item.subRegin.length > 0) {
|
|
201
|
+
const result = this.findItemByCode(item.subRegin, code)
|
|
202
|
+
if (result) {
|
|
203
|
+
return result
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return null
|
|
208
|
+
},
|
|
209
|
+
handleChange() {
|
|
210
|
+
this.$emit('input', this.myValue)
|
|
211
|
+
this.$emit('change', this.myValue)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
</script>
|