字典的值都为字符串类型,当有Boolean类型时会匹配失败,导致展示异常

pull/351/head
gugu-L 2 years ago
parent b7abcd8374
commit 5ced98f9ad

@ -1,92 +1,97 @@
<template> <template>
<div> <div>
<template v-for="(item, index) in options"> <template v-for="(item, index) in options">
<template v-if="values.includes(item.value)"> <template v-if="values.includes(item.value)">
<span <span
v-if="(item.raw.listClass == 'default' || item.raw.listClass == '') && (item.raw.cssClass == '' || item.raw.cssClass == null)" v-if="(item.raw.listClass == 'default' || item.raw.listClass == '') && (item.raw.cssClass == '' || item.raw.cssClass == null)"
:key="item.value" :key="item.value"
:index="index" :index="index"
:class="item.raw.cssClass" :class="item.raw.cssClass"
>{{ item.label + " " }}</span >{{ item.label + " " }}</span
> >
<el-tag <el-tag
v-else v-else
:disable-transitions="true" :disable-transitions="true"
:key="item.value" :key="item.value"
:index="index" :index="index"
:type="item.raw.listClass == 'primary' ? '' : item.raw.listClass" :type="item.raw.listClass == 'primary' ? '' : item.raw.listClass"
:class="item.raw.cssClass" :class="item.raw.cssClass"
> >
{{ item.label + " " }} {{ item.label + " " }}
</el-tag> </el-tag>
</template> </template>
</template> </template>
<template v-if="unmatch && showValue"> <template v-if="unmatch && showValue">
{{ unmatchArray | handleArray }} {{ unmatchArray | handleArray }}
</template> </template>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: "DictTag", name: "DictTag",
props: { props: {
options: { options: {
type: Array, type: Array,
default: null, default: null,
}, },
value: [Number, String, Array], value: [Number, String, Array],
// value // value
showValue: { showValue: {
type: Boolean, type: Boolean,
default: true, default: true,
} }
}, },
data() { data() {
return { return {
unmatchArray: [], // unmatchArray: [], //
} }
}, },
computed: { computed: {
values() { values() {
if (this.value !== null && typeof this.value !== "undefined") { if (this.value !== null && typeof this.value !== "undefined") {
return Array.isArray(this.value) ? this.value : [String(this.value)]; return Array.isArray(this.value) ? this.value : [String(this.value)];
} else { } else {
return []; return [];
} }
}, },
unmatch() { unmatch() {
this.unmatchArray = []; this.unmatchArray = [];
if (this.value !== null && typeof this.value !== "undefined") { if (this.value !== null && typeof this.value !== "undefined") {
// // Boolean
if (!Array.isArray(this.value)) { // truefalse
if (this.options.some((v) => v.value == this.value)) return false; if (this.value === true || this.value === false) {
this.unmatchArray.push(this.value); this.value = String(this.value);
return true; }
} //
// Array if (!Array.isArray(this.value)) {
this.value.forEach((item) => { if (this.options.some((v) => v.value == this.value)) return false;
if (!this.options.some((v) => v.value == item)) this.unmatchArray.push(this.value);
this.unmatchArray.push(item); return true;
}); }
return true; // Array
} this.value.forEach((item) => {
// value if (!this.options.some((v) => v.value == item))
return false; this.unmatchArray.push(item);
}, });
}, return true;
filters: { }
handleArray(array) { // value
if (array.length === 0) return ""; return false;
return array.reduce((pre, cur) => { },
return pre + " " + cur; },
}) filters: {
} handleArray(array) {
} if (array.length === 0) return "";
}; return array.reduce((pre, cur) => {
</script> return pre + " " + cur;
<style scoped> })
.el-tag + .el-tag { }
margin-left: 10px; }
} };
</style> </script>
<style scoped>
.el-tag + .el-tag {
margin-left: 10px;
}
</style>

Loading…
Cancel
Save