ruoyi-plus-soybean/src/components/custom/post-select.vue

64 lines
1.3 KiB
Vue
Raw Normal View History

2024-09-12 16:16:38 +08:00
<script setup lang="ts">
import { ref, useAttrs, watch } from 'vue';
2025-04-23 16:02:41 +08:00
import type { SelectProps } from 'naive-ui';
import { useLoading } from '@sa/hooks';
2024-09-12 16:16:38 +08:00
import { fetchGetPostSelect } from '@/service/api/system';
defineOptions({
name: 'PostSelect'
});
interface Props {
2024-09-27 10:28:46 +08:00
deptId?: CommonType.IdType | null;
2024-09-12 16:16:38 +08:00
[key: string]: any;
}
const props = defineProps<Props>();
2024-09-27 10:28:46 +08:00
const value = defineModel<CommonType.IdType[] | null>('value', { required: false });
2024-09-12 16:16:38 +08:00
const attrs: SelectProps = useAttrs();
2024-11-04 11:16:53 +08:00
const { loading: postLoading, startLoading: startPostLoading, endLoading: endPostLoading } = useLoading();
2024-09-12 16:16:38 +08:00
/** the enabled role options */
const roleOptions = ref<CommonType.Option<CommonType.IdType>[]>([]);
watch(
() => props.deptId,
() => {
if (!props.deptId) {
roleOptions.value = [];
return;
}
2024-09-12 16:16:38 +08:00
getRoleOptions();
},
{ immediate: true }
);
async function getRoleOptions() {
2024-11-04 11:16:53 +08:00
startPostLoading();
2024-09-27 10:28:46 +08:00
const { error, data } = await fetchGetPostSelect(props.deptId!);
2024-09-12 16:16:38 +08:00
if (!error) {
roleOptions.value = data.map(item => ({
label: item.postName,
value: item.postId
}));
}
2024-11-04 11:16:53 +08:00
endPostLoading();
2024-09-12 16:16:38 +08:00
}
</script>
<template>
<NSelect
v-model:value="value"
2024-11-04 11:16:53 +08:00
:loading="postLoading"
2024-09-12 16:16:38 +08:00
:options="roleOptions"
v-bind="attrs"
placeholder="请选择岗位"
/>
</template>
<style scoped></style>