index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item>
  12. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  13. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  14. <el-button
  15. type="primary"
  16. plain
  17. @click="openForm('create')"
  18. v-hasPermi="['infra:demo-student:create']"
  19. >
  20. <Icon icon="ep:plus" class="mr-5px" /> 新增
  21. </el-button>
  22. <el-button
  23. type="success"
  24. plain
  25. @click="handleExport"
  26. :loading="exportLoading"
  27. v-hasPermi="['infra:demo-student:export']"
  28. >
  29. <Icon icon="ep:download" class="mr-5px" /> 导出
  30. </el-button>
  31. </el-form-item>
  32. </el-form>
  33. </ContentWrap>
  34. <!-- 列表 -->
  35. <ContentWrap>
  36. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  37. <el-table-column label="编号" align="center" prop="id">
  38. <template #default="scope">
  39. <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" />
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="操作" align="center">
  43. <template #default="scope">
  44. <el-button
  45. link
  46. type="primary"
  47. @click="openForm('update', scope.row.id)"
  48. v-hasPermi="['infra:demo-student:update']"
  49. >
  50. 编辑
  51. </el-button>
  52. <el-button
  53. link
  54. type="danger"
  55. @click="handleDelete(scope.row.id)"
  56. v-hasPermi="['infra:demo-student:delete']"
  57. >
  58. 删除
  59. </el-button>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. <!-- 分页 -->
  64. <Pagination
  65. :total="total"
  66. v-model:page="queryParams.pageNo"
  67. v-model:limit="queryParams.pageSize"
  68. @pagination="getList"
  69. />
  70. </ContentWrap>
  71. <!-- 表单弹窗:添加/修改 -->
  72. <DemoStudentForm ref="formRef" @success="getList" />
  73. </template>
  74. <script setup lang="ts">
  75. import download from '@/utils/download'
  76. import * as DemoStudentApi from '@/api/infra/demo02'
  77. import DemoStudentForm from './DemoStudentForm.vue'
  78. defineOptions({ name: 'InfraDemoStudent' })
  79. const message = useMessage() // 消息弹窗
  80. const { t } = useI18n() // 国际化
  81. const loading = ref(true) // 列表的加载中
  82. const total = ref(0) // 列表的总页数
  83. const list = ref([]) // 列表的数据
  84. const queryParams = reactive({
  85. pageNo: 1,
  86. pageSize: 10
  87. })
  88. const queryFormRef = ref() // 搜索的表单
  89. const exportLoading = ref(false) // 导出的加载中
  90. /** 查询列表 */
  91. const getList = async () => {
  92. loading.value = true
  93. try {
  94. const data = await DemoStudentApi.getDemoStudentPage(queryParams)
  95. list.value = data.list
  96. total.value = data.total
  97. } finally {
  98. loading.value = false
  99. }
  100. }
  101. /** 搜索按钮操作 */
  102. const handleQuery = () => {
  103. queryParams.pageNo = 1
  104. getList()
  105. }
  106. /** 重置按钮操作 */
  107. const resetQuery = () => {
  108. queryFormRef.value.resetFields()
  109. handleQuery()
  110. }
  111. /** 添加/修改操作 */
  112. const formRef = ref()
  113. const openForm = (type: string, id?: number) => {
  114. formRef.value.open(type, id)
  115. }
  116. /** 删除按钮操作 */
  117. const handleDelete = async (id: number) => {
  118. try {
  119. // 删除的二次确认
  120. await message.delConfirm()
  121. // 发起删除
  122. await DemoStudentApi.deleteDemoStudent(id)
  123. message.success(t('common.delSuccess'))
  124. // 刷新列表
  125. await getList()
  126. } catch {}
  127. }
  128. /** 导出按钮操作 */
  129. const handleExport = async () => {
  130. try {
  131. // 导出的二次确认
  132. await message.exportConfirm()
  133. // 发起导出
  134. exportLoading.value = true
  135. const data = await DemoStudentApi.exportDemoStudent(queryParams)
  136. download.excel(data, '学生.xls')
  137. } catch {
  138. } finally {
  139. exportLoading.value = false
  140. }
  141. }
  142. /** 初始化 **/
  143. onMounted(() => {
  144. getList()
  145. })
  146. </script>