index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <ContentWrap>
  3. <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  4. <template #toolbar_buttons>
  5. <XButton
  6. type="primary"
  7. preIcon="ep:zoom-in"
  8. :title="t('action.add')"
  9. v-hasPermi="['system:error-code:create']"
  10. @click="handleCreate()"
  11. />
  12. </template>
  13. <template #createTime_item="{ data }">
  14. <el-date-picker
  15. v-model="data.createTime"
  16. type="datetimerange"
  17. range-separator="-"
  18. :start-placeholder="t('common.startTimeText')"
  19. :end-placeholder="t('common.endTimeText')"
  20. />
  21. </template>
  22. <template #type_default="{ row }">
  23. <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
  24. </template>
  25. <template #actionbtns_default="{ row }">
  26. <XTextButton
  27. preIcon="ep:edit"
  28. :title="t('action.edit')"
  29. v-hasPermi="['system:error-code:update']"
  30. @click="handleUpdate(row.id)"
  31. />
  32. <XTextButton
  33. preIcon="ep:view"
  34. :title="t('action.detail')"
  35. v-hasPermi="['system:error-code:update']"
  36. @click="handleDetail(row)"
  37. />
  38. <XTextButton
  39. preIcon="ep:delete"
  40. :title="t('action.del')"
  41. v-hasPermi="['system:error-code:delete']"
  42. @click="handleDelete(row.id)"
  43. />
  44. </template>
  45. </vxe-grid>
  46. </ContentWrap>
  47. <XModal id="errorCodeModel" v-model="dialogVisible" :title="dialogTitle">
  48. <template #default>
  49. <!-- 对话框(添加 / 修改) -->
  50. <Form
  51. v-if="['create', 'update'].includes(actionType)"
  52. :schema="allSchemas.formSchema"
  53. :rules="rules"
  54. ref="formRef"
  55. />
  56. <!-- 对话框(详情) -->
  57. <Descriptions
  58. v-if="actionType === 'detail'"
  59. :schema="allSchemas.detailSchema"
  60. :data="detailRef"
  61. >
  62. <template #type="{ row }">
  63. <DictTag :type="DICT_TYPE.SYSTEM_ERROR_CODE_TYPE" :value="row.type" />
  64. </template>
  65. <template #createTime="{ row }">
  66. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  67. </template>
  68. </Descriptions>
  69. </template>
  70. <!-- 操作按钮 -->
  71. <template #footer>
  72. <XButton
  73. v-if="['create', 'update'].includes(actionType)"
  74. type="primary"
  75. :title="t('action.save')"
  76. :loading="actionLoading"
  77. @click="submitForm"
  78. />
  79. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  80. </template>
  81. </XModal>
  82. </template>
  83. <script setup lang="ts">
  84. import { ref, unref } from 'vue'
  85. import dayjs from 'dayjs'
  86. import { DICT_TYPE } from '@/utils/dict'
  87. import type { ErrorCodeVO } from '@/api/system/errorCode/types'
  88. import { rules, allSchemas } from './errorCode.data'
  89. import * as ErrorCodeApi from '@/api/system/errorCode'
  90. import { useI18n } from '@/hooks/web/useI18n'
  91. import { useMessage } from '@/hooks/web/useMessage'
  92. import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  93. import { VxeGridInstance } from 'vxe-table'
  94. import { FormExpose } from '@/components/Form'
  95. import { ElDatePicker } from 'element-plus'
  96. const { t } = useI18n() // 国际化
  97. const message = useMessage() // 消息弹窗
  98. const dialogVisible = ref(false) // 是否显示弹出层
  99. const dialogTitle = ref('edit') // 弹出层标题
  100. const actionType = ref('') // 操作按钮的类型
  101. const actionLoading = ref(false) // 按钮Loading
  102. const xGrid = ref<VxeGridInstance>() // grid Ref
  103. const formRef = ref<FormExpose>() // 表单 Ref
  104. const detailRef = ref() // 详情 Ref
  105. const { gridOptions } = useVxeGrid<ErrorCodeVO>({
  106. allSchemas: allSchemas,
  107. getListApi: ErrorCodeApi.getErrorCodePageApi
  108. })
  109. // 设置标题
  110. const setDialogTile = (type: string) => {
  111. dialogTitle.value = t('action.' + type)
  112. actionType.value = type
  113. dialogVisible.value = true
  114. }
  115. // 新增操作
  116. const handleCreate = () => {
  117. setDialogTile('create')
  118. // 重置表单
  119. unref(formRef)?.getElFormRef()?.resetFields()
  120. }
  121. // 详情操作
  122. const handleDetail = async (row: ErrorCodeVO) => {
  123. // 设置数据
  124. detailRef.value = row
  125. setDialogTile('detail')
  126. }
  127. // 修改操作
  128. const handleUpdate = async (rowId: number) => {
  129. setDialogTile('update')
  130. // 设置数据
  131. const res = await ErrorCodeApi.getErrorCodeApi(rowId)
  132. unref(formRef)?.setValues(res)
  133. }
  134. // 删除操作
  135. const handleDelete = async (rowId: number) => {
  136. message
  137. .delConfirm()
  138. .then(async () => {
  139. await ErrorCodeApi.deleteErrorCodeApi(rowId)
  140. message.success(t('common.delSuccess'))
  141. })
  142. .finally(() => {
  143. xGrid.value?.commitProxy('query')
  144. })
  145. }
  146. // 提交按钮
  147. const submitForm = async () => {
  148. const elForm = unref(formRef)?.getElFormRef()
  149. if (!elForm) return
  150. elForm.validate(async (valid) => {
  151. if (valid) {
  152. actionLoading.value = true
  153. // 提交请求
  154. try {
  155. const data = unref(formRef)?.formModel as ErrorCodeVO
  156. if (actionType.value === 'create') {
  157. await ErrorCodeApi.createErrorCodeApi(data)
  158. message.success(t('common.createSuccess'))
  159. } else {
  160. await ErrorCodeApi.updateErrorCodeApi(data)
  161. message.success(t('common.updateSuccess'))
  162. }
  163. dialogVisible.value = false
  164. } finally {
  165. actionLoading.value = false
  166. xGrid.value?.commitProxy('query')
  167. }
  168. }
  169. })
  170. }
  171. </script>