index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="full flex direction-column exam-manage-view">
  3. <div class="p-t-base p-l-base fill-blank">
  4. <base-form :items="items" :model="model" :label-width="useVW(66)" size="small">
  5. <template #form-item-button>
  6. <el-button type="primary" @click="onSearch">查询</el-button>
  7. <el-button special @click="onCreateExam">创建考试</el-button>
  8. </template>
  9. </base-form>
  10. </div>
  11. <div class="p-base">
  12. <div class="p-base fill-blank">
  13. <base-table :data="data" :columns="columns">
  14. <template #column-operation="{ row }">
  15. <el-button type="primary" link @click="onEdit(row)">编辑</el-button>
  16. <el-popconfirm
  17. :width="useVW(220)"
  18. hide-icon
  19. :title="`确认${row.enable ? '禁用' : '启用'}考试?`"
  20. @confirm="toggleEnable(row)"
  21. >
  22. <template #reference>
  23. <el-button type="primary" link>
  24. {{ row.enable ? '禁用' : '启用' }}
  25. </el-button>
  26. </template>
  27. </el-popconfirm>
  28. <el-popconfirm :width="useVW(220)" hide-icon :title="`确认删除考试?`" @confirm="onDelete(row)">
  29. <template #reference>
  30. <el-button type="primary" link>删除</el-button>
  31. </template>
  32. </el-popconfirm>
  33. </template>
  34. </base-table>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script setup lang="ts" name="ExamManage">
  40. /** 考试批次管理 */
  41. import { reactive, ref } from 'vue'
  42. import { useRouter } from 'vue-router'
  43. import { ElButton, ElPopconfirm } from 'element-plus'
  44. import BaseForm from '@/components/element/BaseForm.vue'
  45. import BaseTable from '@/components/element/BaseTable.vue'
  46. import useForm from '@/hooks/useForm'
  47. import useTable from '@/hooks/useTable'
  48. import useFetch from '@/hooks/useFetch'
  49. import useVW from '@/hooks/useVW'
  50. import { StatusMap } from '@/constants/dicts'
  51. import type { EpFormItem, EpTableColumn } from 'global-type'
  52. import type { ExtractMultipleApiParams, ExtractMultipleApiResponse } from '@/api/api'
  53. const { push } = useRouter()
  54. const model = reactive<ExtractMultipleApiParams<'getExamList'>>({ name: '', enable: void 0 })
  55. const { defineColumn, _ } = useForm()
  56. const onRow = defineColumn(_, 'row-1', { span: 5 })
  57. const items: EpFormItem[] = [
  58. onRow({ label: '考试名称', slotType: 'input', prop: 'name', slot: { clearable: true } }),
  59. onRow({ label: '状态', slotType: 'select', prop: 'enable', slot: { clearable: true, options: StatusMap } }),
  60. onRow({ slotName: 'button' }),
  61. ]
  62. const requestModel = reactive<ExtractMultipleApiParams<'getExamList'>>({ ...model })
  63. /** 查询 */
  64. function onSearch() {
  65. Object.assign(requestModel, { ...model })
  66. }
  67. /** 创建考试 */
  68. function onCreateExam() {
  69. push({ name: 'EditExam' })
  70. }
  71. const { data, fetchTable } = useTable('getExamList', requestModel)
  72. const columns: EpTableColumn<ExtractMultipleApiResponse<'getExamList'>>[] = [
  73. { prop: 'id', label: 'ID' },
  74. { prop: 'name', label: '考试名称' },
  75. { prop: 'enable', label: '状态', formatter: (row) => (row.enable ? '启用' : '禁用') },
  76. { prop: 'updateTime', label: '更新时间' },
  77. { label: '操作', slotName: 'operation' },
  78. ]
  79. function onEdit(row: ExtractMultipleApiResponse<'getExamList'>) {
  80. push({ name: 'EditExam', params: { id: row.id } })
  81. }
  82. const { fetch: toggleEnableExam } = useFetch('toggleEnableExam')
  83. function toggleEnable(row: ExtractMultipleApiResponse<'getExamList'>) {
  84. row.id && toggleEnableExam({ ids: [row.id], enable: !row.enable }).then(fetchTable)
  85. }
  86. const { fetch: deleteExam } = useFetch('deleteExam')
  87. function onDelete(row: ExtractMultipleApiResponse<'getExamList'>) {
  88. row.id && deleteExam({ id: row.id }).then(fetchTable)
  89. }
  90. </script>
  91. <style scoped lang="scss">
  92. .exam-manage-view {
  93. }
  94. </style>