index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <script setup lang="ts">
  2. import { ref, unref } from 'vue'
  3. import dayjs from 'dayjs'
  4. import { ElMessage } from 'element-plus'
  5. import { DICT_TYPE } from '@/utils/dict'
  6. import { useTable } from '@/hooks/web/useTable'
  7. import { useI18n } from '@/hooks/web/useI18n'
  8. import { FormExpose } from '@/components/Form'
  9. import type { SmsChannelVO } from '@/api/system/sms/smsChannel/types'
  10. import { rules, allSchemas } from './sms.channel.data'
  11. import * as SmsChannelApi from '@/api/system/sms/smsChannel'
  12. const { t } = useI18n() // 国际化
  13. // ========== 列表相关 ==========
  14. const { register, tableObject, methods } = useTable<SmsChannelVO>({
  15. getListApi: SmsChannelApi.getSmsChannelPageApi,
  16. delListApi: SmsChannelApi.deleteSmsChannelApi
  17. })
  18. const { getList, setSearchParams, delList } = methods
  19. // ========== CRUD 相关 ==========
  20. const loading = ref(false) // 遮罩层
  21. const actionType = ref('') // 操作按钮的类型
  22. const dialogVisible = ref(false) // 是否显示弹出层
  23. const dialogTitle = ref('edit') // 弹出层标题
  24. const formRef = ref<FormExpose>() // 表单 Ref
  25. // 设置标题
  26. const setDialogTile = (type: string) => {
  27. dialogTitle.value = t('action.' + type)
  28. actionType.value = type
  29. dialogVisible.value = true
  30. }
  31. // 新增操作
  32. const handleCreate = () => {
  33. setDialogTile('create')
  34. }
  35. // 修改操作
  36. const handleUpdate = async (row: SmsChannelVO) => {
  37. setDialogTile('update')
  38. // 设置数据
  39. const res = await SmsChannelApi.getSmsChannelApi(row.id)
  40. unref(formRef)?.setValues(res)
  41. }
  42. // 提交按钮
  43. const submitForm = async () => {
  44. const elForm = unref(formRef)?.getElFormRef()
  45. if (!elForm) return
  46. elForm.validate(async (valid) => {
  47. if (valid) {
  48. loading.value = true
  49. // 提交请求
  50. try {
  51. const data = unref(formRef)?.formModel as SmsChannelVO
  52. if (actionType.value === 'create') {
  53. await SmsChannelApi.createSmsChannelApi(data)
  54. ElMessage.success(t('common.createSuccess'))
  55. } else {
  56. await SmsChannelApi.updateSmsChannelApi(data)
  57. ElMessage.success(t('common.updateSuccess'))
  58. }
  59. // 操作成功,重新加载列表
  60. dialogVisible.value = false
  61. await getList()
  62. } finally {
  63. loading.value = false
  64. }
  65. }
  66. })
  67. }
  68. // ========== 详情相关 ==========
  69. const detailRef = ref() // 详情 Ref
  70. // 详情操作
  71. const handleDetail = async (row: SmsChannelVO) => {
  72. // 设置数据
  73. detailRef.value = row
  74. setDialogTile('detail')
  75. }
  76. // ========== 初始化 ==========
  77. getList()
  78. </script>
  79. <template>
  80. <!-- 搜索工作区 -->
  81. <ContentWrap>
  82. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  83. </ContentWrap>
  84. <ContentWrap>
  85. <!-- 操作工具栏 -->
  86. <div class="mb-10px">
  87. <el-button type="primary" v-hasPermi="['system:sms-channel:create']" @click="handleCreate">
  88. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
  89. </el-button>
  90. </div>
  91. <!-- 列表 -->
  92. <Table
  93. :columns="allSchemas.tableColumns"
  94. :selection="false"
  95. :data="tableObject.tableList"
  96. :loading="tableObject.loading"
  97. :pagination="{
  98. total: tableObject.total
  99. }"
  100. v-model:pageSize="tableObject.pageSize"
  101. v-model:currentPage="tableObject.currentPage"
  102. @register="register"
  103. >
  104. <template #code="{ row }">
  105. <DictTag :type="DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE" :value="row.code" />
  106. </template>
  107. <template #status="{ row }">
  108. <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
  109. </template>
  110. <template #createTime="{ row }">
  111. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  112. </template>
  113. <template #action="{ row }">
  114. <el-button
  115. link
  116. type="primary"
  117. v-hasPermi="['system:sms-channel:update']"
  118. @click="handleUpdate(row)"
  119. >
  120. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  121. </el-button>
  122. <el-button
  123. link
  124. type="primary"
  125. v-hasPermi="['system:sms-channel:update']"
  126. @click="handleDetail(row)"
  127. >
  128. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  129. </el-button>
  130. <el-button
  131. link
  132. type="primary"
  133. v-hasPermi="['system:sms-channel:delete']"
  134. @click="delList(row.id, false)"
  135. >
  136. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  137. </el-button>
  138. </template>
  139. </Table>
  140. </ContentWrap>
  141. <XModal v-model="dialogVisible" :title="dialogTitle">
  142. <!-- 对话框(添加 / 修改) -->
  143. <Form
  144. v-if="['create', 'update'].includes(actionType)"
  145. :schema="allSchemas.formSchema"
  146. :rules="rules"
  147. ref="formRef"
  148. />
  149. <!-- 对话框(详情) -->
  150. <Descriptions
  151. v-if="actionType === 'detail'"
  152. :schema="allSchemas.detailSchema"
  153. :data="detailRef"
  154. />
  155. <!-- 操作按钮 -->
  156. <template #footer>
  157. <el-button
  158. v-if="['create', 'update'].includes(actionType)"
  159. type="primary"
  160. :loading="loading"
  161. @click="submitForm"
  162. >
  163. {{ t('action.save') }}
  164. </el-button>
  165. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  166. </template>
  167. </XModal>
  168. </template>