index.vue
1.69 KB
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
52
53
54
55
56
57
58
59
<script lang="ts" setup>
import { ApiTreeSelect } from '/@/components/Form';
import { Button } from 'ant-design-vue';
import { getOrganizationList } from '/@/api/system/system';
import { computed, ref, unref } from 'vue';
import OrganizationDrawer from '/@/views/system/organization/OrganizationDrawer.vue';
import { useDrawer } from '/@/components/Drawer';
const [registerDrawer, { openDrawer }] = useDrawer();
const props = withDefaults(
defineProps<{
value?: string | string[];
apiTreeSelectProps?: Recordable;
showCreate?: boolean;
}>(),
{
showCreate: true,
}
);
const emit = defineEmits(['change']);
const handleOpenCreate = () => {
openDrawer(true, { isUpdate: false });
};
const timespan = ref(Date.now());
const getBindProps = computed(() => {
const { value, apiTreeSelectProps = {} } = props;
const { params = {} } = apiTreeSelectProps;
return {
replaceFields: { children: 'children', key: 'id', title: 'name', value: 'id' },
getPopupContainer: () => document.body,
placeholder: '请选择所属组织',
maxLength: 250,
...apiTreeSelectProps,
value,
api: getOrganizationList,
params: { ...params, _t: unref(timespan) },
onChange: (...args: any[]) => {
emit('change', ...args);
},
};
});
const handleReload = () => {
timespan.value = Date.now();
};
</script>
<template>
<section class="flex">
<ApiTreeSelect v-bind="getBindProps" />
<Button v-if="showCreate" type="link" @click="handleOpenCreate">新增组织</Button>
<OrganizationDrawer v-if="showCreate" @register="registerDrawer" @success="handleReload" />
</section>
</template>