mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
chore: 优化字典hooks使用
This commit is contained in:
@ -9,7 +9,7 @@ interface Props {
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
immediate: true
|
||||
immediate: false
|
||||
});
|
||||
|
||||
const value = defineModel<string | null>('value', { required: false });
|
||||
|
@ -12,7 +12,7 @@ interface Props {
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
immediate: true
|
||||
immediate: false
|
||||
});
|
||||
|
||||
const value = defineModel<string | null>('value', { required: true });
|
||||
|
30
src/components/custom/dict-tag.vue
Normal file
30
src/components/custom/dict-tag.vue
Normal 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>
|
Reference in New Issue
Block a user