zhangwencui
11 分钟以前 5f3dea3fd930afde720677fba10b6bfb2e836a18
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 type { Demo03StudentApi } from '#/api/infra/demo/demo03/normal';
 
import { nextTick, ref, watch } from 'vue';
 
import { ContentWrap } from '@vben/common-ui';
import { formatDateTime } from '@vben/utils';
 
import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
import { getDemo03CourseListByStudentId } from '#/api/infra/demo/demo03/normal';
 
const props = defineProps<{
  studentId?: number; // 学生编号(主表的关联字段)
}>();
 
const loading = ref(true); // 列表的加载中
const list = ref<Demo03StudentApi.Demo03Course[]>([]); // 列表的数据
/** 查询列表 */
async function getList() {
  loading.value = true;
  try {
    if (!props.studentId) {
      return [];
    }
    list.value = await getDemo03CourseListByStudentId(props.studentId!);
  } finally {
    loading.value = false;
  }
}
 
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
  () => props.studentId,
  async (val) => {
    if (!val) {
      return;
    }
    await nextTick();
    await getList();
  },
  { immediate: true },
);
</script>
 
<template>
  <ContentWrap 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="score" title="分数" align="center" />
      <VxeColumn field="createTime" title="创建时间" align="center">
        <template #default="{ row }">
          {{ formatDateTime(row.createTime) }}
        </template>
      </VxeColumn>
    </VxeTable>
  </ContentWrap>
</template>