feat: 新增数据字典下拉选项组件
This commit is contained in:
parent
3d426fb8e1
commit
c4d959d133
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>
|
5
src/typings/components.d.ts
vendored
5
src/typings/components.d.ts
vendored
@ -9,10 +9,11 @@ declare module 'vue' {
|
|||||||
export interface GlobalComponents {
|
export interface GlobalComponents {
|
||||||
AppProvider: typeof import('./../components/common/app-provider.vue')['default']
|
AppProvider: typeof import('./../components/common/app-provider.vue')['default']
|
||||||
BetterScroll: typeof import('./../components/custom/better-scroll.vue')['default']
|
BetterScroll: typeof import('./../components/custom/better-scroll.vue')['default']
|
||||||
BooleanTag: typeof import('./../components/common/boolean-tag.vue')['default']
|
BooleanTag: typeof import('./../components/custom/boolean-tag.vue')['default']
|
||||||
ButtonIcon: typeof import('./../components/custom/button-icon.vue')['default']
|
ButtonIcon: typeof import('./../components/custom/button-icon.vue')['default']
|
||||||
CountTo: typeof import('./../components/custom/count-to.vue')['default']
|
CountTo: typeof import('./../components/custom/count-to.vue')['default']
|
||||||
DarkModeContainer: typeof import('./../components/common/dark-mode-container.vue')['default']
|
DarkModeContainer: typeof import('./../components/common/dark-mode-container.vue')['default']
|
||||||
|
DictSelect: typeof import('./../components/custom/dict-select.vue')['default']
|
||||||
ExceptionBase: typeof import('./../components/common/exception-base.vue')['default']
|
ExceptionBase: typeof import('./../components/common/exception-base.vue')['default']
|
||||||
FullScreen: typeof import('./../components/common/full-screen.vue')['default']
|
FullScreen: typeof import('./../components/common/full-screen.vue')['default']
|
||||||
IconAntDesignEnterOutlined: typeof import('~icons/ant-design/enter-outlined')['default']
|
IconAntDesignEnterOutlined: typeof import('~icons/ant-design/enter-outlined')['default']
|
||||||
@ -103,7 +104,7 @@ declare module 'vue' {
|
|||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
RouterView: typeof import('vue-router')['RouterView']
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
SoybeanAvatar: typeof import('./../components/custom/soybean-avatar.vue')['default']
|
SoybeanAvatar: typeof import('./../components/custom/soybean-avatar.vue')['default']
|
||||||
StatusTag: typeof import('./../components/common/status-tag.vue')['default']
|
StatusTag: typeof import('./../components/custom/status-tag.vue')['default']
|
||||||
SvgIcon: typeof import('./../components/custom/svg-icon.vue')['default']
|
SvgIcon: typeof import('./../components/custom/svg-icon.vue')['default']
|
||||||
SystemLogo: typeof import('./../components/common/system-logo.vue')['default']
|
SystemLogo: typeof import('./../components/common/system-logo.vue')['default']
|
||||||
TableColumnSetting: typeof import('./../components/advanced/table-column-setting.vue')['default']
|
TableColumnSetting: typeof import('./../components/advanced/table-column-setting.vue')['default']
|
||||||
|
@ -10,7 +10,7 @@ import { menuTypeRecord } from '@/constants/business';
|
|||||||
import ButtonIcon from '@/components/custom/button-icon.vue';
|
import ButtonIcon from '@/components/custom/button-icon.vue';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import { handleMenuTree } from '@/utils/ruoyi';
|
import { handleMenuTree } from '@/utils/ruoyi';
|
||||||
import StatusTag from '@/components/common/status-tag.vue';
|
import StatusTag from '@/components/custom/status-tag.vue';
|
||||||
import { useDict } from '@/hooks/business/dict';
|
import { useDict } from '@/hooks/business/dict';
|
||||||
import MenuOperateDrawer from './modules/menu-operate-drawer.vue';
|
import MenuOperateDrawer from './modules/menu-operate-drawer.vue';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user