优化字典标签支持自定义分隔符

master
RuoYi 10 months ago
parent 438cb0d1dd
commit cb80de3742
  1. 44
      src/components/DictTag/index.vue

@ -7,8 +7,7 @@
:key="item.value"
:index="index"
:class="item.elTagClass"
>{{ item.label + " " }}</span
>
>{{ item.label + " " }}</span>
<el-tag
v-else
:disable-transitions="true"
@ -16,8 +15,7 @@
:index="index"
:type="item.elTagType === 'primary' ? '' : item.elTagType"
:class="item.elTagClass"
>{{ item.label + " " }}</el-tag
>
>{{ item.label + " " }}</el-tag>
</template>
</template>
<template v-if="unmatch && showValue">
@ -27,7 +25,7 @@
</template>
<script setup>
// //
//
const unmatchArray = ref([]);
const props = defineProps({
@ -43,34 +41,30 @@ const props = defineProps({
type: Boolean,
default: true,
},
separator: {
type: String,
default: ",",
}
});
const values = computed(() => {
if (props.value !== null && typeof props.value !== "undefined") {
return Array.isArray(props.value) ? props.value : [String(props.value)];
} else {
return [];
}
if (props.value === null || typeof props.value === 'undefined' || props.value === '') return [];
return Array.isArray(props.value) ? props.value.map(item => '' + item) : String(props.value).split(props.separator);
});
const unmatch = computed(() => {
unmatchArray.value = [];
if (props.value !== null && typeof props.value !== "undefined") {
//
if (!Array.isArray(props.value)) {
if (props.options.some((v) => v.value == props.value)) return false;
unmatchArray.value.push(props.value);
return true;
}
// Array
props.value.forEach((item) => {
if (!props.options.some((v) => v.value == item))
unmatchArray.value.push(item);
});
return true;
}
// value
return false;
if (props.value === null || typeof props.value === 'undefined' || props.value === '' || props.options.length === 0) return false
//
let unmatch = false //
values.value.forEach(item => {
if (!props.options.some(v => v.value === item)) {
unmatchArray.value.push(item)
unmatch = true // true
}
})
return unmatch //
});
function handleArray(array) {

Loading…
Cancel
Save