2026-06-26 20b96473f2520590a0dca6b775b81e3ea06a77a0
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<script lang="ts" setup>
import type { StudentApi } from '#/api/infra/demo';
import type { VxeTableInstance } from '#/adapter/vxe-table';
 
import { reactive, ref, h, nextTick, watch, onMounted } from 'vue';
 
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
 
import { DictTag } from '#/components/dict-tag';
import { getRangePickerDefaultProps } from '#/utils/rangePickerProps';
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
import { formatDateTime } from '@vben/utils';
 
 
import { getStudentTeacherByStudentId } from '#/api/infra/demo';
 
const props = defineProps<{
  studentId?: number // 学生编号(主表的关联字段)
}>()
 
 
const loading = ref(true) // 列表的加载中
const list = ref<StudentApi.StudentTeacher[]>([]) // 列表的数据
  /** 查询列表 */
async function getList() {
  loading.value = true
  try {
    if (!props.studentId){
      return []
    }
                 list.value = [await getStudentTeacherByStudentId(props.studentId!)];
  } finally {
    loading.value = false
  }
}
 
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
  () => props.studentId,
  async (val) => {
    if (!val) {
      return;
    }
    await nextTick();
    await getList()
  },
  { immediate: true },
);
 
</script>
 
<template>
    <Card title="学生班主任列表">
      <VxeTable
          :data="list"
          show-overflow
          :loading="loading"
      >
                    <VxeColumn field="id" title="编号" align="center" />
                    <VxeColumn field="studentId" title="学生编号" align="center" />
                    <VxeColumn field="name" title="名字" align="center" />
                    <VxeColumn field="description" title="简介" align="center" />
                    <VxeColumn field="birthday" title="出生日期" align="center">
                      <template #default="{row}">
                        {{formatDateTime(row.birthday)}}
                      </template>
                    </VxeColumn>
                    <VxeColumn field="sex" title="性别" align="center">
                      <template #default="{row}">
                        <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="row.sex" />
                      </template>
                    </VxeColumn>
                    <VxeColumn field="enabled" title="是否有效" align="center">
                      <template #default="{row}">
                        <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.enabled" />
                      </template>
                    </VxeColumn>
                    <VxeColumn field="avatar" title="头像" align="center" />
                    <VxeColumn field="video" title="附件" align="center" />
                    <VxeColumn field="memo" title="备注" align="center" />
                    <VxeColumn field="createTime" title="创建时间" align="center">
                      <template #default="{row}">
                        {{formatDateTime(row.createTime)}}
                      </template>
                    </VxeColumn>
      </VxeTable>
    </Card>
</template>