2024-09-12 16:16:38 +08:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { useLoading } from '@sa/hooks';
|
|
|
|
import type { SelectProps } from 'naive-ui';
|
|
|
|
import { ref, useAttrs, watch } from 'vue';
|
|
|
|
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) return;
|
|
|
|
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>
|