chore: 优化字典hooks使用

This commit is contained in:
xlsea
2024-09-11 16:37:35 +08:00
parent 2b14b84c67
commit 9cbbaff297
13 changed files with 94 additions and 52 deletions

View File

@ -9,7 +9,7 @@ interface Props {
}
const props = withDefaults(defineProps<Props>(), {
immediate: true
immediate: false
});
const value = defineModel<string | null>('value', { required: false });

View File

@ -12,7 +12,7 @@ interface Props {
}
const props = withDefaults(defineProps<Props>(), {
immediate: true
immediate: false
});
const value = defineModel<string | null>('value', { required: true });

View File

@ -0,0 +1,30 @@
<script setup lang="ts">
import { computed, useAttrs } from 'vue';
import type { TagProps } from 'naive-ui';
import { useDict } from '@/hooks/business/dict';
defineOptions({ name: 'DictTag' });
interface Props {
value: string;
dictCode: string;
immediate?: boolean;
[key: string]: any;
}
const props = withDefaults(defineProps<Props>(), {
immediate: false
});
const attrs: TagProps = useAttrs();
const { transformDictData } = useDict(props.dictCode, props.immediate);
const dictData = computed(() => transformDictData(props.value));
</script>
<template>
<NTag v-if="dictData" :class="dictData.cssClass" :type="dictData.listClass" v-bind="attrs">
{{ dictData.dictLabel }}
</NTag>
</template>
<style scoped></style>