index.vue 4.7 KB

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