index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <script setup lang="ts" name="Model">
  2. import dayjs from 'dayjs'
  3. import { DICT_TYPE } from '@/utils/dict'
  4. import { useTable } from '@/hooks/web/useTable'
  5. import type { FormExpose } from '@/components/Form'
  6. import type { ModelVO } from '@/api/bpm/model/types'
  7. import { rules, allSchemas } from './model.data'
  8. import * as ModelApi from '@/api/bpm/model'
  9. const { t } = useI18n() // 国际化
  10. const message = useMessage()
  11. // ========== 列表相关 ==========
  12. const { register, tableObject, methods } = useTable<ModelVO>({
  13. getListApi: ModelApi.getModelPageApi,
  14. delListApi: ModelApi.deleteModelApi
  15. })
  16. const { getList, setSearchParams, delList } = methods
  17. // ========== CRUD 相关 ==========
  18. const actionLoading = ref(false) // 遮罩层
  19. const actionType = ref('') // 操作按钮的类型
  20. const dialogVisible = ref(false) // 是否显示弹出层
  21. const dialogTitle = ref('edit') // 弹出层标题
  22. const formRef = ref<FormExpose>() // 表单 Ref
  23. // 设置标题
  24. const setDialogTile = (type: string) => {
  25. dialogTitle.value = t('action.' + type)
  26. actionType.value = type
  27. dialogVisible.value = true
  28. }
  29. // 新增操作
  30. const handleCreate = () => {
  31. setDialogTile('create')
  32. }
  33. // 修改操作
  34. const handleUpdate = async (row: ModelVO) => {
  35. setDialogTile('update')
  36. // 设置数据
  37. const res = await ModelApi.getModelApi(row.id)
  38. unref(formRef)?.setValues(res)
  39. }
  40. // 提交按钮
  41. const submitForm = async () => {
  42. const elForm = unref(formRef)?.getElFormRef()
  43. if (!elForm) return
  44. elForm.validate(async (valid) => {
  45. if (valid) {
  46. actionLoading.value = true
  47. // 提交请求
  48. try {
  49. const data = unref(formRef)?.formModel as ModelVO
  50. if (actionType.value === 'create') {
  51. await ModelApi.createModelApi(data)
  52. message.success(t('common.createSuccess'))
  53. } else {
  54. await ModelApi.updateModelApi(data)
  55. message.success(t('common.updateSuccess'))
  56. }
  57. // 操作成功,重新加载列表
  58. dialogVisible.value = false
  59. await getList()
  60. } finally {
  61. actionLoading.value = false
  62. }
  63. }
  64. })
  65. }
  66. /** 流程表单的详情按钮操作 */
  67. const handleChangeState = async (row: ModelVO) => {
  68. const state = row.processDefinition.suspensionState
  69. const statusState = state === 1 ? '激活' : '挂起'
  70. message
  71. .confirm(
  72. '是否确认' + statusState + '流程名字为"' + row.name + '"的数据项?',
  73. t('common.reminder')
  74. )
  75. .then(async () => {
  76. ModelApi.updateModelStateApi(row.id, state).then(() => {
  77. message.success(t('common.updateSuccess'))
  78. getList()
  79. })
  80. })
  81. .catch(() => {})
  82. }
  83. // ========== 详情相关 ==========
  84. const detailData = ref() // 详情 Ref
  85. // 详情操作
  86. const handleDetail = async (row: ModelVO) => {
  87. // 设置数据
  88. detailData.value = row
  89. setDialogTile('detail')
  90. }
  91. // ========== 初始化 ==========
  92. getList()
  93. </script>
  94. <template>
  95. <!-- 搜索工作区 -->
  96. <ContentWrap>
  97. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  98. </ContentWrap>
  99. <ContentWrap>
  100. <!-- 操作工具栏 -->
  101. <div class="mb-10px">
  102. <el-button type="primary" v-hasPermi="['bpm:model:create']" @click="handleCreate()">
  103. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
  104. </el-button>
  105. </div>
  106. <!-- 列表 -->
  107. <Table
  108. :columns="allSchemas.tableColumns"
  109. :selection="false"
  110. :data="tableObject.tableList"
  111. :loading="tableObject.loading"
  112. :pagination="{
  113. total: tableObject.total
  114. }"
  115. v-model:pageSize="tableObject.pageSize"
  116. v-model:currentPage="tableObject.currentPage"
  117. @register="register"
  118. >
  119. <template #category="{ row }">
  120. <DictTag :type="DICT_TYPE.BPM_MODEL_CATEGORY" :value="row.category" />
  121. </template>
  122. <template #formId="{ row }">
  123. <span>{{ row.formName }}</span>
  124. </template>
  125. <template #processDefinition>
  126. <el-table-column label="流程版本" prop="processDefinition.version">
  127. <template #default="{ row }">
  128. <el-tag v-if="row.processDefinition">
  129. {{ 'v' + row.processDefinition.version }}
  130. </el-tag>
  131. <el-tag type="warning" v-else>未部署</el-tag>
  132. </template>
  133. </el-table-column>
  134. <el-table-column label="激活状态" prop="processDefinition.suspensionState">
  135. <template #default="{ row }">
  136. <el-switch
  137. v-if="row.processDefinition"
  138. v-model="row.processDefinition.suspensionState"
  139. :active-value="1"
  140. :inactive-value="2"
  141. @change="handleChangeState(row)"
  142. />
  143. </template>
  144. </el-table-column>
  145. <el-table-column label="部署时间" prop="processDefinition.deploymentTime">
  146. <template #default="{ row }">
  147. <span>
  148. {{ dayjs(row.processDefinition.deploymentTime).format('YYYY-MM-DD HH:mm:ss') }}
  149. </span>
  150. </template>
  151. </el-table-column>
  152. </template>
  153. <template #createTime="{ row }">
  154. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  155. </template>
  156. <template #action="{ row }">
  157. <el-button link type="primary" v-hasPermi="['bpm:model:update']" @click="handleUpdate(row)">
  158. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  159. </el-button>
  160. <el-button link type="primary" v-hasPermi="['bpm:model:update']" @click="handleDetail(row)">
  161. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  162. </el-button>
  163. <el-button
  164. link
  165. type="primary"
  166. v-hasPermi="['bpm:model:delete']"
  167. @click="delList(row.id, false)"
  168. >
  169. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  170. </el-button>
  171. </template>
  172. </Table>
  173. </ContentWrap>
  174. <XModal v-model="dialogVisible" :title="dialogTitle">
  175. <!-- 对话框(添加 / 修改) -->
  176. <Form
  177. v-if="['create', 'update'].includes(actionType)"
  178. :schema="allSchemas.formSchema"
  179. :rules="rules"
  180. ref="formRef"
  181. />
  182. <!-- 对话框(详情) -->
  183. <Descriptions
  184. v-if="actionType === 'detail'"
  185. :schema="allSchemas.detailSchema"
  186. :data="detailData"
  187. />
  188. <!-- 操作按钮 -->
  189. <template #footer>
  190. <!-- 按钮:保存 -->
  191. <XButton
  192. v-if="['create', 'update'].includes(actionType)"
  193. type="primary"
  194. :title="t('action.save')"
  195. :loading="actionLoading"
  196. @click="submitForm()"
  197. />
  198. <!-- 按钮:关闭 -->
  199. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  200. </template>
  201. </XModal>
  202. </template>