优化字典标签支持数组和多标签

This commit is contained in:
抓蛙师 2023-09-08 18:35:17 +08:00
parent 6c16d023f4
commit 14538ce399
2 changed files with 26 additions and 37 deletions

View File

@ -2,7 +2,8 @@
<div>
<template v-for="(item, index) in options">
<template v-if="values.includes(item.value)">
<span v-if="item.elTagType == 'default' || item.elTagType == ''" :key="item.value" :index="index" :class="item.elTagClass">
<span v-if="item.elTagType == 'default' || item.elTagType == ''" :key="item.value" :index="index"
:class="item.elTagClass">
{{ item.label + " " }}
</span>
<el-tag
@ -24,7 +25,7 @@
</template>
<script setup lang="ts">
import { propTypes } from '@/utils/propTypes';
import {propTypes} from '@/utils/propTypes';
const props = defineProps({
@ -37,46 +38,38 @@ const props = defineProps({
value: [Number, String, Array] as PropType<number | string | Array<number | string>>,
// value
showValue: propTypes.bool.def(true),
});
const values = computed(() => {
if (props.value !== null && typeof props.value !== "undefined") {
return Array.isArray(props.value) ? props.value : [String(props.value)];
} else {
return [];
separator: {
type: String,
default: ','
}
});
const values = computed(() => {
if (props.value === '' || props.value === null || typeof props.value === "undefined") return []
let valu= Array.isArray(props.value) ? props.value.map(item => '' + item) : String(props.value).split(props.separator);
console.log("valu",valu)
return valu
});
const unmatch = computed(() => {
if (props.value !== null && typeof props.value !== "undefined") {
//
if (!Array.isArray(props.value)) {
if (props.options.some((v) => v.value == props.value)) {
return false;
}
return true;
if (props.options?.length == 0 || props.value === '' || props.value === null || typeof props.value === "undefined") return false
//
values.value.forEach(item => {
if (!props.options.some(v => v.value === item)) {
return true // true
}
return true;
}
// value
return false;
})
return false //
});
const unmatchArray = computed(() => {
//
const itemUnmatchArray: Array<string | number> = [];
if (props.value !== null && typeof props.value !== "undefined") {
//
if (!Array.isArray(props.value)) {
itemUnmatchArray.push(props.value);
} else {
// Array
props.value.forEach((item) => {
if (!props.options.some((v) => v.value == item)) {
itemUnmatchArray.push(item);
}
});
}
if (props.value !== '' && props.value !== null && typeof props.value !== "undefined") {
values.value.forEach(item => {
if (!props.options.some(v => v.value === item)) {
itemUnmatchArray.push(item);
}
})
}
// value
return handleArray(itemUnmatchArray);

View File

@ -53,11 +53,7 @@
<el-table-column label="客户端秘钥" align="center" prop="clientSecret" />
<el-table-column label="授权类型" align="center">
<template #default="scope">
<div>
<template v-for="(type, index) in scope.row.grantTypeList" :key="index">
<dict-tag class="el-check-tag" :options="sys_grant_type" :value="type" />
</template>
</div>
<dict-tag :options="sys_grant_type" :value="scope.row.grantTypeList" />
</template>
</el-table-column>
<el-table-column label="设备类型" align="center">