feat: 新增数据字典下拉选项组件

This commit is contained in:
xlsea
2024-09-04 09:18:46 +08:00
parent 3d426fb8e1
commit c4d959d133
5 changed files with 43 additions and 3 deletions

View File

@ -0,0 +1,24 @@
<script setup lang="ts">
import type { TagProps } from 'naive-ui';
import { useAttrs } from 'vue';
import { isNotNull } from '@/utils/common';
defineOptions({
name: 'BooleanTag'
});
const value = defineModel<'0' | '1'>('value', { required: true });
const tagMap: Record<'0' | '1', NaiveUI.ThemeColor> = {
0: 'success',
1: 'error'
};
const attrs: TagProps = useAttrs();
</script>
<template>
<NTag v-if="isNotNull(value)" :type="tagMap[value]" v-bind="attrs">{{ value === '0' ? '' : '' }}</NTag>
</template>
<style scoped></style>

View File

@ -0,0 +1,39 @@
<script setup lang="tsx">
import { ref, useAttrs, watch } from 'vue';
import { useLoading } from '@sa/hooks';
import type { SelectProps } from 'naive-ui';
import { useDict } from '@/hooks/business/dict';
defineOptions({ name: 'DictSelect' });
const dictType = defineModel<string>('value', { required: true });
const attrs: SelectProps = useAttrs();
const { getDictOptions } = useDict();
const options = ref<Array<CommonType.Option>>([]);
const { loading, startLoading, endLoading } = useLoading();
async function getDeptOptions() {
if (!dictType.value) {
return;
}
startLoading();
const dictData = await getDictOptions(dictType.value);
options.value = dictData[dictType.value];
endLoading();
}
watch(
() => dictType.value,
() => {
getDeptOptions();
},
{ immediate: true }
);
</script>
<template>
<NSelect :loading="loading" :options="options" :clear-filter-after-select="false" v-bind="attrs" />
</template>
<style scoped></style>

View File

@ -0,0 +1,31 @@
<script setup lang="ts">
import type { TagProps } from 'naive-ui';
import { useAttrs } from 'vue';
import { enableStatusRecord } from '@/constants/business';
import { isNotNull } from '@/utils/common';
defineOptions({
name: 'StatusTag'
});
interface Props {
[key: string]: any;
}
defineProps<Props>();
const status = defineModel<Api.Common.EnableStatus>('value', { required: true });
const tagMap: Record<Api.Common.EnableStatus, NaiveUI.ThemeColor> = {
'0': 'success',
'1': 'warning'
};
const attrs: TagProps = useAttrs();
</script>
<template>
<NTag v-if="isNotNull(status)" :type="tagMap[status]" v-bind="attrs">{{ enableStatusRecord[status] }}</NTag>
</template>
<style scoped></style>