提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<!-- 列表 --> |
|
3 |
<ContentWrap> |
|
4 |
<el-button |
|
5 |
v-hasPermi="['infra:demo03-student:create']" |
|
6 |
plain |
|
7 |
type="primary" |
|
8 |
@click="openForm('create')" |
|
9 |
> |
|
10 |
<Icon class="mr-5px" icon="ep:plus" /> |
|
11 |
新增 |
|
12 |
</el-button> |
|
13 |
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true"> |
|
14 |
<el-table-column align="center" label="编号" prop="id" /> |
|
15 |
<el-table-column align="center" label="名字" prop="name" /> |
|
16 |
<el-table-column align="center" label="分数" prop="score" /> |
|
17 |
<el-table-column |
|
18 |
:formatter="dateFormatter" |
|
19 |
align="center" |
|
20 |
label="创建时间" |
|
21 |
prop="createTime" |
|
22 |
width="180px" |
|
23 |
/> |
|
24 |
<el-table-column align="center" label="操作"> |
|
25 |
<template #default="scope"> |
|
26 |
<el-button |
|
27 |
v-hasPermi="['infra:demo03-student:update']" |
|
28 |
link |
|
29 |
type="primary" |
|
30 |
@click="openForm('update', scope.row.id)" |
|
31 |
> |
|
32 |
编辑 |
|
33 |
</el-button> |
|
34 |
<el-button |
|
35 |
v-hasPermi="['infra:demo03-student:delete']" |
|
36 |
link |
|
37 |
type="danger" |
|
38 |
@click="handleDelete(scope.row.id)" |
|
39 |
> |
|
40 |
删除 |
|
41 |
</el-button> |
|
42 |
</template> |
|
43 |
</el-table-column> |
|
44 |
</el-table> |
|
45 |
<!-- 分页 --> |
|
46 |
<Pagination |
|
47 |
v-model:limit="queryParams.pageSize" |
|
48 |
v-model:page="queryParams.pageNo" |
|
49 |
:total="total" |
|
50 |
@pagination="getList" |
|
51 |
/> |
|
52 |
</ContentWrap> |
|
53 |
<!-- 表单弹窗:添加/修改 --> |
|
54 |
<Demo03CourseForm ref="formRef" @success="getList" /> |
|
55 |
</template> |
|
56 |
|
|
57 |
<script lang="ts" setup> |
|
58 |
import { dateFormatter } from '@/utils/formatTime' |
|
59 |
import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp' |
|
60 |
import Demo03CourseForm from './Demo03CourseForm.vue' |
|
61 |
|
|
62 |
const { t } = useI18n() // 国际化 |
|
63 |
const message = useMessage() // 消息弹窗 |
|
64 |
|
|
65 |
const props = defineProps<{ |
|
66 |
studentId?: number // 学生编号(主表的关联字段) |
|
67 |
}>() |
|
68 |
const loading = ref(false) // 列表的加载中 |
|
69 |
const list = ref([]) // 列表的数据 |
|
70 |
const total = ref(0) // 列表的总页数 |
|
71 |
const queryParams = reactive({ |
|
72 |
pageNo: 1, |
|
73 |
pageSize: 10, |
|
74 |
studentId: undefined as unknown |
|
75 |
}) |
|
76 |
|
|
77 |
/** 监听主表的关联字段的变化,加载对应的子表数据 */ |
|
78 |
watch( |
|
79 |
() => props.studentId, |
|
80 |
(val: number) => { |
|
81 |
if (!val) { |
|
82 |
return |
|
83 |
} |
|
84 |
queryParams.studentId = val |
|
85 |
handleQuery() |
|
86 |
}, |
|
87 |
{ immediate: true, deep: true } |
|
88 |
) |
|
89 |
|
|
90 |
/** 查询列表 */ |
|
91 |
const getList = async () => { |
|
92 |
loading.value = true |
|
93 |
try { |
|
94 |
const data = await Demo03StudentApi.getDemo03CoursePage(queryParams) |
|
95 |
list.value = data.list |
|
96 |
total.value = data.total |
|
97 |
} finally { |
|
98 |
loading.value = false |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
/** 搜索按钮操作 */ |
|
103 |
const handleQuery = () => { |
|
104 |
queryParams.pageNo = 1 |
|
105 |
getList() |
|
106 |
} |
|
107 |
|
|
108 |
/** 添加/修改操作 */ |
|
109 |
const formRef = ref() |
|
110 |
const openForm = (type: string, id?: number) => { |
|
111 |
if (!props.studentId) { |
|
112 |
message.error('请选择一个学生') |
|
113 |
return |
|
114 |
} |
|
115 |
formRef.value.open(type, id, props.studentId) |
|
116 |
} |
|
117 |
|
|
118 |
/** 删除按钮操作 */ |
|
119 |
const handleDelete = async (id: number) => { |
|
120 |
try { |
|
121 |
// 删除的二次确认 |
|
122 |
await message.delConfirm() |
|
123 |
// 发起删除 |
|
124 |
await Demo03StudentApi.deleteDemo03Course(id) |
|
125 |
message.success(t('common.delSuccess')) |
|
126 |
// 刷新列表 |
|
127 |
await getList() |
|
128 |
} catch {} |
|
129 |
} |
|
130 |
</script> |