index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <!-- <doc-alert title="代码生成(主子表)" url="https://doc.iocoder.cn/new-feature/master-sub/" /> -->
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="名字" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入名字"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item label="性别" prop="sex">
  22. <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable class="!w-240px">
  23. <el-option
  24. v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
  25. :key="dict.value"
  26. :label="dict.label"
  27. :value="dict.value"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="创建时间" prop="createTime">
  32. <el-date-picker
  33. v-model="queryParams.createTime"
  34. value-format="YYYY-MM-DD HH:mm:ss"
  35. type="daterange"
  36. start-placeholder="开始日期"
  37. end-placeholder="结束日期"
  38. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  39. class="!w-240px"
  40. />
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  44. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  45. <el-button
  46. type="primary"
  47. plain
  48. @click="openForm('create')"
  49. v-hasPermi="['infra:demo03-student:create']"
  50. >
  51. <Icon icon="ep:plus" class="mr-5px" /> 新增
  52. </el-button>
  53. <el-button
  54. type="success"
  55. plain
  56. @click="handleExport"
  57. :loading="exportLoading"
  58. v-hasPermi="['infra:demo03-student:export']"
  59. >
  60. <Icon icon="ep:download" class="mr-5px" /> 导出
  61. </el-button>
  62. </el-form-item>
  63. </el-form>
  64. </ContentWrap>
  65. <!-- 列表 -->
  66. <ContentWrap>
  67. <el-table
  68. v-loading="loading"
  69. :data="list"
  70. :stripe="true"
  71. :show-overflow-tooltip="true"
  72. highlight-current-row
  73. @current-change="handleCurrentChange"
  74. >
  75. <el-table-column label="编号" align="center" prop="id" />
  76. <el-table-column label="名字" align="center" prop="name" />
  77. <el-table-column label="性别" align="center" prop="sex">
  78. <template #default="scope">
  79. <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" />
  80. </template>
  81. </el-table-column>
  82. <el-table-column
  83. label="出生日期"
  84. align="center"
  85. prop="birthday"
  86. :formatter="dateFormatter"
  87. width="180px"
  88. />
  89. <el-table-column label="简介" align="center" prop="description" />
  90. <el-table-column
  91. label="创建时间"
  92. align="center"
  93. prop="createTime"
  94. :formatter="dateFormatter"
  95. width="180px"
  96. />
  97. <el-table-column label="操作" align="center">
  98. <template #default="scope">
  99. <el-button
  100. link
  101. type="primary"
  102. @click="openForm('update', scope.row.id)"
  103. v-hasPermi="['infra:demo03-student:update']"
  104. >
  105. 编辑
  106. </el-button>
  107. <el-button
  108. link
  109. type="danger"
  110. @click="handleDelete(scope.row.id)"
  111. v-hasPermi="['infra:demo03-student:delete']"
  112. >
  113. 删除
  114. </el-button>
  115. </template>
  116. </el-table-column>
  117. </el-table>
  118. <!-- 分页 -->
  119. <Pagination
  120. :total="total"
  121. v-model:page="queryParams.pageNo"
  122. v-model:limit="queryParams.pageSize"
  123. @pagination="getList"
  124. />
  125. </ContentWrap>
  126. <!-- 表单弹窗:添加/修改 -->
  127. <Demo03StudentForm ref="formRef" @success="getList" />
  128. <!-- 子表的列表 -->
  129. <ContentWrap>
  130. <el-tabs model-value="demo03Course">
  131. <el-tab-pane label="学生课程" name="demo03Course">
  132. <Demo03CourseList :student-id="currentRow.id" />
  133. </el-tab-pane>
  134. <el-tab-pane label="学生班级" name="demo03Grade">
  135. <Demo03GradeList :student-id="currentRow.id" />
  136. </el-tab-pane>
  137. </el-tabs>
  138. </ContentWrap>
  139. </template>
  140. <script setup lang="ts">
  141. import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
  142. import { dateFormatter } from '@/utils/formatTime'
  143. import download from '@/utils/download'
  144. import * as Demo03StudentApi from '@/api/infra/demo/demo03/erp'
  145. import Demo03StudentForm from './Demo03StudentForm.vue'
  146. import Demo03CourseList from './components/Demo03CourseList.vue'
  147. import Demo03GradeList from './components/Demo03GradeList.vue'
  148. defineOptions({ name: 'Demo03Student' })
  149. const message = useMessage() // 消息弹窗
  150. const { t } = useI18n() // 国际化
  151. const loading = ref(true) // 列表的加载中
  152. const list = ref([]) // 列表的数据
  153. const total = ref(0) // 列表的总页数
  154. const queryParams = reactive({
  155. pageNo: 1,
  156. pageSize: 10,
  157. name: null,
  158. sex: null,
  159. description: null,
  160. createTime: []
  161. })
  162. const queryFormRef = ref() // 搜索的表单
  163. const exportLoading = ref(false) // 导出的加载中
  164. /** 查询列表 */
  165. const getList = async () => {
  166. loading.value = true
  167. try {
  168. const data = await Demo03StudentApi.getDemo03StudentPage(queryParams)
  169. list.value = data.list
  170. total.value = data.total
  171. } finally {
  172. loading.value = false
  173. }
  174. }
  175. /** 搜索按钮操作 */
  176. const handleQuery = () => {
  177. queryParams.pageNo = 1
  178. getList()
  179. }
  180. /** 重置按钮操作 */
  181. const resetQuery = () => {
  182. queryFormRef.value.resetFields()
  183. handleQuery()
  184. }
  185. /** 添加/修改操作 */
  186. const formRef = ref()
  187. const openForm = (type: string, id?: number) => {
  188. formRef.value.open(type, id)
  189. }
  190. /** 删除按钮操作 */
  191. const handleDelete = async (id: number) => {
  192. try {
  193. // 删除的二次确认
  194. await message.delConfirm()
  195. // 发起删除
  196. await Demo03StudentApi.deleteDemo03Student(id)
  197. message.success(t('common.delSuccess'))
  198. // 刷新列表
  199. await getList()
  200. } catch {}
  201. }
  202. /** 导出按钮操作 */
  203. const handleExport = async () => {
  204. try {
  205. // 导出的二次确认
  206. await message.exportConfirm()
  207. // 发起导出
  208. exportLoading.value = true
  209. const data = await Demo03StudentApi.exportDemo03Student(queryParams)
  210. download.excel(data, '学生.xls')
  211. } catch {
  212. } finally {
  213. exportLoading.value = false
  214. }
  215. }
  216. /** 选中行操作 */
  217. const currentRow = ref({}) // 选中行
  218. const handleCurrentChange = (row) => {
  219. currentRow.value = row
  220. }
  221. /** 初始化 **/
  222. onMounted(() => {
  223. getList()
  224. })
  225. </script>