Demo03CourseList.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  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. <script lang="ts" setup>
  57. import { dateFormatter } from '@/utils/formatTime'
  58. import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp'
  59. import Demo03CourseForm from './Demo03CourseForm.vue'
  60. const { t } = useI18n() // 国际化
  61. const message = useMessage() // 消息弹窗
  62. const props = defineProps<{
  63. studentId?: number // 学生编号(主表的关联字段)
  64. }>()
  65. const loading = ref(false) // 列表的加载中
  66. const list = ref([]) // 列表的数据
  67. const total = ref(0) // 列表的总页数
  68. const queryParams = reactive({
  69. pageNo: 1,
  70. pageSize: 10,
  71. studentId: undefined as unknown
  72. })
  73. /** 监听主表的关联字段的变化,加载对应的子表数据 */
  74. watch(
  75. () => props.studentId,
  76. (val: number) => {
  77. if (!val) {
  78. return
  79. }
  80. queryParams.studentId = val
  81. handleQuery()
  82. },
  83. { immediate: true, deep: true }
  84. )
  85. /** 查询列表 */
  86. const getList = async () => {
  87. loading.value = true
  88. try {
  89. const data = await Demo03StudentApi.getDemo03CoursePage(queryParams)
  90. list.value = data.list
  91. total.value = data.total
  92. } finally {
  93. loading.value = false
  94. }
  95. }
  96. /** 搜索按钮操作 */
  97. const handleQuery = () => {
  98. queryParams.pageNo = 1
  99. getList()
  100. }
  101. /** 添加/修改操作 */
  102. const formRef = ref()
  103. const openForm = (type: string, id?: number) => {
  104. if (!props.studentId) {
  105. message.error('请选择一个学生')
  106. return
  107. }
  108. formRef.value.open(type, id, props.studentId)
  109. }
  110. /** 删除按钮操作 */
  111. const handleDelete = async (id: number) => {
  112. try {
  113. // 删除的二次确认
  114. await message.delConfirm()
  115. // 发起删除
  116. await Demo03StudentApi.deleteDemo03Course(id)
  117. message.success(t('common.delSuccess'))
  118. // 刷新列表
  119. await getList()
  120. } catch {}
  121. }
  122. </script>