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

Merge pull request !40 from 抓蛙师/ts
This commit is contained in:
疯狂的狮子Li 2023-09-09 03:42:40 +00:00 committed by Gitee
commit cb6cbc4f40
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 26 additions and 37 deletions

View File

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

View File

@ -53,11 +53,7 @@
<el-table-column label="客户端秘钥" align="center" prop="clientSecret" /> <el-table-column label="客户端秘钥" align="center" prop="clientSecret" />
<el-table-column label="授权类型" align="center"> <el-table-column label="授权类型" align="center">
<template #default="scope"> <template #default="scope">
<div> <dict-tag :options="sys_grant_type" :value="scope.row.grantTypeList" />
<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>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="设备类型" align="center"> <el-table-column label="设备类型" align="center">