Browse Source

table下拉框多选回显

master
陈薪名 12 months ago
parent
commit
68ec32eedf
  1. 83
      src/components/DictTag/src/DictTag.vue

83
src/components/DictTag/src/DictTag.vue

@ -18,16 +18,34 @@ export default defineComponent({
},
setup(props) {
const dictData = ref<DictDataType>()
let dictDataList:any[] = []
const getDictObj = (dictType: string, value: string) => {
const dictOptions = getDictOptions(dictType)
dictOptions.forEach((dict: DictDataType) => {
if (dict.value === value) {
if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') {
dict.colorType = ''
//
if (value.indexOf(',') == -1) {
const dictOptions = getDictOptions(dictType)
dictOptions.forEach((dict: DictDataType) => {
if (dict.value === value) {
if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') {
dict.colorType = ''
}
dictData.value = dict
}
dictData.value = dict
}
})
})
} else {
dictDataList = []
value.split(',').forEach(item => {
const dictOptions = getDictOptions(dictType)
dictOptions.forEach((dict: DictDataType) => {
if (dict.value === item) {
if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') {
dict.colorType = ''
}
dictData.value = dict
dictDataList.push(dictData.value)
}
})
})
}
}
const rederDictTag = () => {
if (!props.type) {
@ -39,20 +57,41 @@ export default defineComponent({
}
getDictObj(props.type, props.value.toString())
//
return (
<ElTag
style={dictData.value?.cssClass ? 'color: #fff' : ''}
type={dictData.value?.colorType}
color={
dictData.value?.cssClass && isHexColor(dictData.value?.cssClass)
? dictData.value?.cssClass
: ''
}
disableTransitions={true}
>
{dictData.value?.label}
</ElTag>
)
// dictDataList
if (!dictDataList) {
return (
<ElTag
style={dictData.value?.cssClass ? 'color: #fff' : ''}
type={dictData.value?.colorType}
color={
dictData.value?.cssClass && isHexColor(dictData.value?.cssClass)
? dictData.value?.cssClass
: ''
}
disableTransitions={true}
>
{dictData.value?.label}
</ElTag>
)
} else {
return (
dictDataList.map(item => {
return <ElTag
style={item?.cssClass ? 'color: #fff' : ''}
type={item?.colorType}
color={
item?.cssClass && isHexColor(item?.cssClass)
? item?.cssClass
: ''
}
disableTransitions={true}
>
{item?.label}
</ElTag>
})
)
}
}
return () => rederDictTag()
}

Loading…
Cancel
Save