Vben
authored
|
1
2
3
4
5
6
7
8
9
|
<template>
<BasicDrawer
v-bind="$attrs"
@register="registerDrawer"
showFooter
:title="getTitle"
width="500px"
@ok="handleSubmit"
>
|
Vben
authored
|
10
|
<BasicForm @register="registerForm">
|
sanmu
authored
|
11
|
<!-- <template #menu="{ model, field }">
|
Vben
authored
|
12
13
14
|
<BasicTree
v-model:value="model[field]"
:treeData="treeData"
|
vben
authored
|
15
|
:fieldNames="{ title: 'menuName', key: 'id' }"
|
Vben
authored
|
16
17
18
19
|
checkable
toolbar
title="菜单分配"
/>
|
sanmu
authored
|
20
|
</template> -->
|
Vben
authored
|
21
|
</BasicForm>
|
Vben
authored
|
22
23
|
</BasicDrawer>
</template>
|
|
24
25
|
<script lang="ts" setup>
import { ref, computed, unref } from 'vue';
|
Vben
authored
|
26
27
28
|
import { BasicForm, useForm } from '/@/components/Form/index';
import { formSchema } from './role.data';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
Vben
authored
|
29
|
import { BasicTree, TreeItem } from '/@/components/Tree';
|
Vben
authored
|
30
31
32
|
import { getMenuList } from '/@/api/demo/system';
|
|
33
34
35
|
const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const treeData = ref<TreeItem[]>([]);
|
Vben
authored
|
36
|
|
|
37
38
39
40
41
42
|
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
labelWidth: 90,
baseColProps: { span: 24 },
schemas: formSchema,
showActionButtonGroup: false,
});
|
Vben
authored
|
43
|
|
|
44
45
46
47
48
49
50
51
|
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
resetFields();
setDrawerProps({ confirmLoading: false });
// 需要在setFieldsValue之前先填充treeData,否则Tree组件可能会报key not exist警告
if (unref(treeData).length === 0) {
treeData.value = (await getMenuList()) as any as TreeItem[];
}
isUpdate.value = !!data?.isUpdate;
|
Vben
authored
|
52
|
|
|
53
54
55
|
if (unref(isUpdate)) {
setFieldsValue({
...data.record,
|
Vben
authored
|
56
|
});
|
|
57
58
|
}
});
|
Vben
authored
|
59
|
|
|
60
|
const getTitle = computed(() => (!unref(isUpdate) ? '新增角色' : '编辑角色'));
|
Vben
authored
|
61
|
|
|
62
63
64
65
66
67
68
69
70
71
72
73
|
async function handleSubmit() {
try {
const values = await validate();
setDrawerProps({ confirmLoading: true });
// TODO custom api
console.log(values);
closeDrawer();
emit('success');
} finally {
setDrawerProps({ confirmLoading: false });
}
}
|
Vben
authored
|
74
|
</script>
|