广丰卷烟厂数采质量分析系统
zhuguifei
2026-03-06 b12c9e77a6b6a7b410ac421c5a3d68da88823460
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script setup lang="tsx">
import { useAttrs } from 'vue';
import type { TreeSelectProps } from 'naive-ui';
import { useLoading } from '@sa/hooks';
import { fetchGetDeptTree } from '@/service/api/system';
 
defineOptions({ name: 'DeptTreeSelect' });
 
interface Props {
  [key: string]: any;
}
 
defineProps<Props>();
 
const value = defineModel<CommonType.IdType | null>('value', { required: false });
const options = defineModel<Api.Common.CommonTreeRecord>('options', { required: false, default: [] });
const expandedKeys = defineModel<CommonType.IdType[]>('expandedKeys', { required: false, default: [] });
 
const attrs: TreeSelectProps = useAttrs();
const { loading, startLoading, endLoading } = useLoading();
 
async function getDeptList() {
  startLoading();
  const { error, data } = await fetchGetDeptTree();
  if (error) return;
  options.value = data;
  // 设置默认展开的节点
  if (data?.length && !expandedKeys.value.length) {
    expandedKeys.value = [data[0].id];
  }
  endLoading();
}
 
getDeptList();
</script>
 
<template>
  <NTreeSelect
    v-model:value="value"
    v-model:expanded-keys="expandedKeys"
    filterable
    class="h-full"
    :loading="loading"
    key-field="id"
    label-field="label"
    :options="options as []"
    v-bind="attrs"
  />
</template>
 
<style scoped></style>