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
| <script lang="ts" setup>
| import type { InfraStudentApi } from '#/api/infra/demo';
|
| import { computed, ref, h, onMounted,watch,nextTick } from 'vue';
|
| import { $t } from '#/locales';
|
| import { useVbenForm } from '#/adapter/form';
| import { useStudentTeacherFormSchema } from '../data';
| import { getStudentTeacherByStudentId } from '#/api/infra/demo';
|
| const props = defineProps<{
| studentId?: number // 学生编号(主表的关联字段)
| }>()
|
| const [Form, formApi] = useVbenForm({
| commonConfig: {
| componentProps: {
| class: 'w-full',
| },
| formItemClass: 'col-span-2',
| labelWidth: 80,
| },
| layout: 'horizontal',
| schema: useStudentTeacherFormSchema(),
| showDefaultActions: false
| });
|
| /** 暴露出表单校验方法和表单值获取方法 */
| defineExpose({
| validate: async () => {
| const { valid } = await formApi.validate();
| return valid;
| },
| getValues: formApi.getValues,
| });
|
| /** 监听主表的关联字段的变化,加载对应的子表数据 */
| watch(
| () => props.studentId,
| async (val) => {
| if (!val) {
| return;
| }
| await nextTick();
| await formApi.setValues(await getStudentTeacherByStudentId(props.studentId!));
| },
| { immediate: true },
| );
| </script>
|
| <template>
| <Form class="mx-4" />
| </template>
|
|