style: 字典类型数据结构体变更
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import { computed, PropType } from 'vue';
|
||||
const props = defineProps({
|
||||
/**数据 */
|
||||
options: {
|
||||
type: Array,
|
||||
type: Array as PropType<DictType[]>,
|
||||
},
|
||||
/**当前的值对应数据中的项字段 */
|
||||
valueField: {
|
||||
type: String,
|
||||
type: String as PropType<keyof DictType>,
|
||||
default: 'value',
|
||||
},
|
||||
/**当前的值 */
|
||||
@@ -16,7 +16,7 @@ const props = defineProps({
|
||||
default: '',
|
||||
},
|
||||
/**数据默认值,当前值不存在时 */
|
||||
valueOption: {
|
||||
valueDefault: {
|
||||
type: [Number, String],
|
||||
},
|
||||
});
|
||||
@@ -24,13 +24,13 @@ const props = defineProps({
|
||||
/**遍历找到对应值数据项 */
|
||||
const item = computed(() => {
|
||||
if (Array.isArray(props.options) && props.options.length > 0) {
|
||||
let option = (props.options as any[]).find(
|
||||
let option = props.options.find(
|
||||
item => `${item[props.valueField]}` === `${props.value}`
|
||||
);
|
||||
// 数据默认值
|
||||
if (props.valueOption != undefined && !option) {
|
||||
option = (props.options as any[]).find(
|
||||
item => `${item[props.valueField]}` === `${props.valueOption }`
|
||||
if (!option && props.valueDefault != undefined) {
|
||||
option = props.options.find(
|
||||
item => `${item[props.valueField]}` === `${props.valueDefault}`
|
||||
);
|
||||
}
|
||||
return option;
|
||||
@@ -41,14 +41,10 @@ const item = computed(() => {
|
||||
|
||||
<template>
|
||||
<template v-if="item">
|
||||
<a-tag
|
||||
v-if="item.elTagType"
|
||||
:class="item.elTagClass"
|
||||
:color="item.elTagType"
|
||||
>
|
||||
<a-tag v-if="item.tagType" :class="item.tagClass" :color="item.tagType">
|
||||
{{ item.label }}
|
||||
</a-tag>
|
||||
<span v-else :class="item.elTagClass">
|
||||
<span v-else :class="item.tagClass">
|
||||
{{ item.label }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user