DictTag组件,当value没有匹配的值时,展示value

master
RuoYi 1 year ago
parent 4250792a2a
commit 8552850e2c
  1. 49
      src/components/DictTag/index.vue

@ -7,7 +7,8 @@
:key="item.value"
:index="index"
:class="item.elTagClass"
>{{ item.label }}</span>
>{{ item.label + " " }}</span
>
<el-tag
v-else
:disable-transitions="true"
@ -15,13 +16,20 @@
: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">
{{ unmatchArray | handleArray }}
</template>
</div>
</template>
<script setup>
// //
const unmatchArray = ref([]);
const props = defineProps({
//
options: {
@ -30,16 +38,47 @@ const props = defineProps({
},
//
value: [Number, String, Array],
})
// value
showValue: {
type: Boolean,
default: true,
},
});
const values = computed(() => {
if (props.value !== null && typeof props.value !== 'undefined') {
if (props.value !== null && typeof props.value !== "undefined") {
return Array.isArray(props.value) ? props.value : [String(props.value)];
} else {
return [];
}
})
});
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;
});
function handleArray(array) {
if (array.length === 0) return "";
return array.reduce((pre, cur) => {
return pre + " " + cur;
});
}
</script>
<style scoped>

Loading…
Cancel
Save