index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. :title="t('action.add')"
  11. v-hasPermi="['pay:merchant:create']"
  12. @click="handleCreate()"
  13. />
  14. <!-- 操作:导出 -->
  15. <XButton
  16. type="warning"
  17. preIcon="ep:download"
  18. :title="t('action.export')"
  19. v-hasPermi="['pay:merchant:export']"
  20. @click="handleExport()"
  21. />
  22. </template>
  23. <template #actionbtns_default="{ row }">
  24. <!-- 操作:修改 -->
  25. <XTextButton
  26. preIcon="ep:edit"
  27. :title="t('action.edit')"
  28. v-hasPermi="['pay:merchant:update']"
  29. @click="handleUpdate(row.id)"
  30. />
  31. <!-- 操作:详情 -->
  32. <XTextButton
  33. preIcon="ep:view"
  34. :title="t('action.detail')"
  35. v-hasPermi="['pay:merchant:query']"
  36. @click="handleDetail(row.id)"
  37. />
  38. <!-- 操作:删除 -->
  39. <XTextButton
  40. preIcon="ep:delete"
  41. :title="t('action.del')"
  42. v-hasPermi="['pay:merchant:delete']"
  43. @click="handleDelete(row.id)"
  44. />
  45. </template>
  46. </vxe-grid>
  47. </ContentWrap>
  48. <XModal v-model="dialogVisible" :title="dialogTitle">
  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="detailData"
  61. />
  62. <!-- 操作按钮 -->
  63. <template #footer>
  64. <!-- 按钮:保存 -->
  65. <XButton
  66. v-if="['create', 'update'].includes(actionType)"
  67. type="primary"
  68. :title="t('action.save')"
  69. :loading="actionLoading"
  70. @click="submitForm()"
  71. />
  72. <!-- 按钮:关闭 -->
  73. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  74. </template>
  75. </XModal>
  76. </template>
  77. <script setup lang="ts" name="Merchant">
  78. import { ref, unref } from 'vue'
  79. import { useI18n } from '@/hooks/web/useI18n'
  80. import { useMessage } from '@/hooks/web/useMessage'
  81. import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  82. import { VxeGridInstance } from 'vxe-table'
  83. import { FormExpose } from '@/components/Form'
  84. import { rules, allSchemas } from './merchant.data'
  85. import * as MerchantApi from '@/api/pay/merchant'
  86. const { t } = useI18n() // 国际化
  87. const message = useMessage() // 消息弹窗
  88. // 列表相关的变量
  89. const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  90. const { gridOptions, getList, deleteData, exportList } = useVxeGrid<MerchantApi.MerchantVO>({
  91. allSchemas: allSchemas,
  92. getListApi: MerchantApi.getMerchantPageApi,
  93. deleteApi: MerchantApi.deleteMerchantApi,
  94. exportListApi: MerchantApi.exportMerchantApi
  95. })
  96. // ========== CRUD 相关 ==========
  97. const actionLoading = ref(false) // 遮罩层
  98. const actionType = ref('') // 操作按钮的类型
  99. const dialogVisible = ref(false) // 是否显示弹出层
  100. const dialogTitle = ref('edit') // 弹出层标题
  101. const formRef = ref<FormExpose>() // 表单 Ref
  102. const detailData = ref() // 详情 Ref
  103. // 设置标题
  104. const setDialogTile = (type: string) => {
  105. dialogTitle.value = t('action.' + type)
  106. actionType.value = type
  107. dialogVisible.value = true
  108. }
  109. // 新增操作
  110. const handleCreate = () => {
  111. setDialogTile('create')
  112. }
  113. // 导出操作
  114. const handleExport = async () => {
  115. await exportList(xGrid, '商户列表.xls')
  116. }
  117. // 修改操作
  118. const handleUpdate = async (rowId: number) => {
  119. setDialogTile('update')
  120. // 设置数据
  121. const res = await MerchantApi.getMerchantApi(rowId)
  122. unref(formRef)?.setValues(res)
  123. }
  124. // 详情操作
  125. const handleDetail = async (rowId: number) => {
  126. setDialogTile('detail')
  127. const res = await MerchantApi.getMerchantApi(rowId)
  128. detailData.value = res
  129. }
  130. // 删除操作
  131. const handleDelete = async (rowId: number) => {
  132. await deleteData(xGrid, rowId)
  133. }
  134. // 提交按钮
  135. const submitForm = async () => {
  136. const elForm = unref(formRef)?.getElFormRef()
  137. if (!elForm) return
  138. elForm.validate(async (valid) => {
  139. if (valid) {
  140. actionLoading.value = true
  141. // 提交请求
  142. try {
  143. const data = unref(formRef)?.formModel as MerchantApi.MerchantVO
  144. if (actionType.value === 'create') {
  145. await MerchantApi.createMerchantApi(data)
  146. message.success(t('common.createSuccess'))
  147. } else {
  148. await MerchantApi.updateMerchantApi(data)
  149. message.success(t('common.updateSuccess'))
  150. }
  151. dialogVisible.value = false
  152. } finally {
  153. actionLoading.value = false
  154. // 刷新列表
  155. await getList(xGrid)
  156. }
  157. }
  158. })
  159. }
  160. </script>