mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat: 新增数据字典下拉选项组件
This commit is contained in:
24
src/components/custom/boolean-tag.vue
Normal file
24
src/components/custom/boolean-tag.vue
Normal 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>
|
39
src/components/custom/dict-select.vue
Normal file
39
src/components/custom/dict-select.vue
Normal 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>
|
31
src/components/custom/status-tag.vue
Normal file
31
src/components/custom/status-tag.vue
Normal 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>
|
Reference in New Issue
Block a user