|
@ -2,7 +2,7 @@ |
|
|
import { defineComponent, PropType, ref } from 'vue' |
|
|
import { defineComponent, PropType, ref } from 'vue' |
|
|
import { isHexColor } from '@/utils/color' |
|
|
import { isHexColor } from '@/utils/color' |
|
|
import { ElTag } from 'element-plus' |
|
|
import { ElTag } from 'element-plus' |
|
|
import { DictDataType, getDictOptions } from '@/utils/dict' |
|
|
import { DictDataType, getStrDictOptions } from '@/utils/dict' |
|
|
|
|
|
|
|
|
export default defineComponent({ |
|
|
export default defineComponent({ |
|
|
name: 'DictTag', |
|
|
name: 'DictTag', |
|
@ -22,28 +22,13 @@ export default defineComponent({ |
|
|
const getDictObj = (dictType: string, value: string) => { |
|
|
const getDictObj = (dictType: string, value: string) => { |
|
|
// 判断 是否多个回显标签 |
|
|
// 判断 是否多个回显标签 |
|
|
if (value.indexOf(',') == -1) { |
|
|
if (value.indexOf(',') == -1) { |
|
|
const dictOptions = getDictOptions(dictType) |
|
|
const dictOptions = getStrDictOptions(dictType) |
|
|
dictOptions.forEach((dict: DictDataType) => { |
|
|
dictData.value = dictOptions.find(dictOptionsItem => (dictOptionsItem.value == value)) |
|
|
if (dict.value === value) { |
|
|
|
|
|
if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') { |
|
|
|
|
|
dict.colorType = '' |
|
|
|
|
|
} |
|
|
|
|
|
dictData.value = dict |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
dictDataList = [] |
|
|
dictDataList = [] |
|
|
value.split(',').forEach(item => { |
|
|
value.split(',').forEach(item => { |
|
|
const dictOptions = getDictOptions(dictType) |
|
|
const dictOptions = getStrDictOptions(dictType) |
|
|
dictOptions.forEach((dict: DictDataType) => { |
|
|
dictDataList.push(dictOptions.find(dictOptionsItem => (dictOptionsItem.value == item))) |
|
|
if (dict.value === item) { |
|
|
|
|
|
if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') { |
|
|
|
|
|
dict.colorType = '' |
|
|
|
|
|
} |
|
|
|
|
|
dictData.value = dict |
|
|
|
|
|
dictDataList.push(dictData.value) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -60,17 +45,17 @@ export default defineComponent({ |
|
|
// 根据 dictDataList 进行区分 是否多个 |
|
|
// 根据 dictDataList 进行区分 是否多个 |
|
|
if (dictDataList.length == 0) { |
|
|
if (dictDataList.length == 0) { |
|
|
return ( |
|
|
return ( |
|
|
<ElTag |
|
|
<ElTag |
|
|
style={dictData.value?.cssClass ? 'color: #fff' : ''} |
|
|
style={dictData.value?.cssClass ? 'color: #fff' : ''} |
|
|
type={dictData.value?.colorType} |
|
|
type={dictData.value?.colorType} |
|
|
color={ |
|
|
color={ |
|
|
dictData.value?.cssClass && isHexColor(dictData.value?.cssClass) |
|
|
dictData.value?.cssClass && isHexColor(dictData.value?.cssClass) |
|
|
? dictData.value?.cssClass |
|
|
? dictData.value?.cssClass |
|
|
: '' |
|
|
: '' |
|
|
} |
|
|
} |
|
|
disableTransitions={true} |
|
|
disableTransitions={true} |
|
|
> |
|
|
> |
|
|
{dictData.value?.label} |
|
|
{dictData.value?.label} |
|
|
</ElTag> |
|
|
</ElTag> |
|
|
) |
|
|
) |
|
|
} else { |
|
|
} else { |
|
|