:sparks:DictTag组件新增自定义标签
This commit is contained in:
parent
53ca3df03f
commit
ad87248ab3
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<template v-for="(item, index) in props.options">
|
||||
<template v-for="(item, index) in dataList">
|
||||
<template v-if="values.includes(item.dictValue)">
|
||||
<span v-if="item.listClass == 'default' || item.listClass == ''" :key="item.dictValue" :index="index" :class="item.cssClass">
|
||||
<template v-if="item.langKey">
|
||||
@ -42,9 +42,28 @@ const props = defineProps({
|
||||
split: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
//自定义属性值 例如:{ label: 'name', value: 'id'}
|
||||
config: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
})
|
||||
const dataList = computed(() => {
|
||||
if (props.config) {
|
||||
let config = props.config
|
||||
var newList = []
|
||||
|
||||
for (let d of props.options) {
|
||||
let label = d[config.label]
|
||||
let value = d[config.value]
|
||||
|
||||
newList.push({ dictLabel: label, dictValue: value, ...d })
|
||||
}
|
||||
return newList
|
||||
}
|
||||
return props.options
|
||||
})
|
||||
const values = computed(() => {
|
||||
if (props.value !== null && typeof props.value !== 'undefined') {
|
||||
if (props.split != null && props.split != '') {
|
||||
|
||||
@ -180,6 +180,29 @@ export function handleTree(data, id, parentId, children) {
|
||||
}
|
||||
return tree
|
||||
}
|
||||
/**
|
||||
* 将自定义数据转换成字典
|
||||
* @param {*} data 数据源
|
||||
* @param {*} dictLabel dictLabel
|
||||
* @param {*} dictValue dictValue
|
||||
*/
|
||||
export function toDict(data, dictLabel, dictValue) {
|
||||
let config = {
|
||||
label: dictLabel || 'dictLabel',
|
||||
value: dictValue || 'dictValue'
|
||||
}
|
||||
|
||||
var tree = []
|
||||
|
||||
for (let d of data) {
|
||||
let label = d[config.label]
|
||||
let value = d[config.value]
|
||||
|
||||
tree.push({ dictLabel: label, dictValue: value })
|
||||
}
|
||||
|
||||
return tree
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数处理
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user