index.vue 4.8 KB

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