Browse Source

table下拉框多选回显

master
陈薪名 1 year ago
parent
commit
68ec32eedf
  1. 39
      src/components/DictTag/src/DictTag.vue

39
src/components/DictTag/src/DictTag.vue

@ -18,7 +18,10 @@ export default defineComponent({
}, },
setup(props) { setup(props) {
const dictData = ref<DictDataType>() const dictData = ref<DictDataType>()
let dictDataList:any[] = []
const getDictObj = (dictType: string, value: string) => { const getDictObj = (dictType: string, value: string) => {
//
if (value.indexOf(',') == -1) {
const dictOptions = getDictOptions(dictType) const dictOptions = getDictOptions(dictType)
dictOptions.forEach((dict: DictDataType) => { dictOptions.forEach((dict: DictDataType) => {
if (dict.value === value) { if (dict.value === value) {
@ -28,6 +31,21 @@ export default defineComponent({
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 = () => { const rederDictTag = () => {
if (!props.type) { if (!props.type) {
@ -39,6 +57,8 @@ export default defineComponent({
} }
getDictObj(props.type, props.value.toString()) getDictObj(props.type, props.value.toString())
// //
// dictDataList
if (!dictDataList) {
return ( return (
<ElTag <ElTag
style={dictData.value?.cssClass ? 'color: #fff' : ''} style={dictData.value?.cssClass ? 'color: #fff' : ''}
@ -53,6 +73,25 @@ export default defineComponent({
{dictData.value?.label} {dictData.value?.label}
</ElTag> </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() return () => rederDictTag()
} }

Loading…
Cancel
Save