Browse Source

table下拉框多选回显

master
陈薪名 1 year 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) { 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) => {
const dictOptions = getDictOptions(dictType) //
dictOptions.forEach((dict: DictDataType) => { if (value.indexOf(',') == -1) {
if (dict.value === value) { const dictOptions = getDictOptions(dictType)
if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') { dictOptions.forEach((dict: DictDataType) => {
dict.colorType = '' 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 = () => { const rederDictTag = () => {
if (!props.type) { if (!props.type) {
@ -39,20 +57,41 @@ export default defineComponent({
} }
getDictObj(props.type, props.value.toString()) getDictObj(props.type, props.value.toString())
// //
return ( // dictDataList
<ElTag if (!dictDataList) {
style={dictData.value?.cssClass ? 'color: #fff' : ''} return (
type={dictData.value?.colorType} <ElTag
color={ style={dictData.value?.cssClass ? 'color: #fff' : ''}
dictData.value?.cssClass && isHexColor(dictData.value?.cssClass) type={dictData.value?.colorType}
? dictData.value?.cssClass color={
: '' dictData.value?.cssClass && isHexColor(dictData.value?.cssClass)
} ? dictData.value?.cssClass
disableTransitions={true} : ''
> }
{dictData.value?.label} disableTransitions={true}
</ElTag> >
) {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() return () => rederDictTag()
} }

Loading…
Cancel
Save