index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <doc-alert title="流程发起、取消、重新发起" url="https://doc.iocoder.cn/bpm/process-instance/" />
  3. <ContentWrap>
  4. <!-- 搜索工作栏 -->
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="流程名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入流程名称"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item label="所属流程" prop="processDefinitionKey">
  22. <el-input
  23. v-model="queryParams.processDefinitionKey"
  24. placeholder="请输入流程定义的标识"
  25. clearable
  26. @keyup.enter="handleQuery"
  27. class="!w-240px"
  28. />
  29. </el-form-item>
  30. <el-form-item label="流程分类" prop="category">
  31. <el-select
  32. v-model="queryParams.category"
  33. placeholder="请选择流程分类"
  34. clearable
  35. class="!w-240px"
  36. >
  37. <el-option
  38. v-for="category in categoryList"
  39. :key="category.code"
  40. :label="category.name"
  41. :value="category.code"
  42. />
  43. </el-select>
  44. </el-form-item>
  45. <el-form-item label="流程状态" prop="status">
  46. <el-select
  47. v-model="queryParams.status"
  48. placeholder="请选择流程状态"
  49. clearable
  50. class="!w-240px"
  51. >
  52. <el-option
  53. v-for="dict in getIntDictOptions(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS)"
  54. :key="dict.value"
  55. :label="dict.label"
  56. :value="dict.value"
  57. />
  58. </el-select>
  59. </el-form-item>
  60. <el-form-item label="发起时间" prop="createTime">
  61. <el-date-picker
  62. v-model="queryParams.createTime"
  63. value-format="YYYY-MM-DD HH:mm:ss"
  64. type="daterange"
  65. start-placeholder="开始日期"
  66. end-placeholder="结束日期"
  67. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  68. class="!w-240px"
  69. />
  70. </el-form-item>
  71. <el-form-item>
  72. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  73. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  74. <el-button
  75. type="primary"
  76. plain
  77. v-hasPermi="['bpm:process-instance:query']"
  78. @click="handleCreate(undefined)"
  79. >
  80. <Icon icon="ep:plus" class="mr-5px" /> 发起流程
  81. </el-button>
  82. </el-form-item>
  83. </el-form>
  84. </ContentWrap>
  85. <!-- 列表 -->
  86. <ContentWrap>
  87. <el-table v-loading="loading" :data="list">
  88. <el-table-column label="流程名称" align="center" prop="name" min-width="200px" fixed="left" />
  89. <el-table-column
  90. label="流程分类"
  91. align="center"
  92. prop="categoryName"
  93. min-width="100"
  94. fixed="left"
  95. />
  96. <el-table-column label="流程状态" prop="status" width="120">
  97. <template #default="scope">
  98. <dict-tag :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS" :value="scope.row.status" />
  99. </template>
  100. </el-table-column>
  101. <el-table-column
  102. label="发起时间"
  103. align="center"
  104. prop="startTime"
  105. width="180"
  106. :formatter="dateFormatter"
  107. />
  108. <el-table-column
  109. label="结束时间"
  110. align="center"
  111. prop="endTime"
  112. width="180"
  113. :formatter="dateFormatter"
  114. />
  115. <el-table-column align="center" label="耗时" prop="durationInMillis" width="160">
  116. <template #default="scope">
  117. {{ scope.row.durationInMillis > 0 ? formatPast2(scope.row.durationInMillis) : '-' }}
  118. </template>
  119. </el-table-column>
  120. <el-table-column label="当前审批任务" align="center" prop="tasks" min-width="120px">
  121. <template #default="scope">
  122. <el-button type="primary" v-for="task in scope.row.tasks" :key="task.id" link>
  123. <span>{{ task.name }}</span>
  124. </el-button>
  125. </template>
  126. </el-table-column>
  127. <el-table-column label="流程编号" align="center" prop="id" min-width="320px" />
  128. <el-table-column label="操作" align="center" fixed="right" width="180">
  129. <template #default="scope">
  130. <el-button
  131. link
  132. type="primary"
  133. v-hasPermi="['bpm:process-instance:cancel']"
  134. @click="handleDetail(scope.row)"
  135. >
  136. 详情
  137. </el-button>
  138. <el-button
  139. link
  140. type="primary"
  141. v-if="scope.row.status === 1"
  142. v-hasPermi="['bpm:process-instance:query']"
  143. @click="handleCancel(scope.row)"
  144. >
  145. 取消
  146. </el-button>
  147. <el-button link type="primary" v-else @click="handleCreate(scope.row)">
  148. 重新发起
  149. </el-button>
  150. </template>
  151. </el-table-column>
  152. </el-table>
  153. <!-- 分页 -->
  154. <Pagination
  155. :total="total"
  156. v-model:page="queryParams.pageNo"
  157. v-model:limit="queryParams.pageSize"
  158. @pagination="getList"
  159. />
  160. </ContentWrap>
  161. </template>
  162. <script lang="ts" setup>
  163. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  164. import { dateFormatter, formatPast2 } from '@/utils/formatTime'
  165. import { ElMessageBox } from 'element-plus'
  166. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  167. import { CategoryApi } from '@/api/bpm/category'
  168. import { ProcessInstanceVO } from '@/api/bpm/processInstance'
  169. import * as DefinitionApi from '@/api/bpm/definition'
  170. defineOptions({ name: 'BpmProcessInstanceMy' })
  171. const router = useRouter() // 路由
  172. const message = useMessage() // 消息弹窗
  173. const { t } = useI18n() // 国际化
  174. const loading = ref(true) // 列表的加载中
  175. const total = ref(0) // 列表的总页数
  176. const list = ref([]) // 列表的数据
  177. const queryParams = reactive({
  178. pageNo: 1,
  179. pageSize: 10,
  180. name: '',
  181. processDefinitionKey: undefined,
  182. category: undefined,
  183. status: undefined,
  184. createTime: []
  185. })
  186. const queryFormRef = ref() // 搜索的表单
  187. const categoryList = ref([]) // 流程分类列表
  188. /** 查询列表 */
  189. const getList = async () => {
  190. loading.value = true
  191. try {
  192. const data = await ProcessInstanceApi.getProcessInstanceMyPage(queryParams)
  193. list.value = data.list
  194. total.value = data.total
  195. } finally {
  196. loading.value = false
  197. }
  198. }
  199. /** 搜索按钮操作 */
  200. const handleQuery = () => {
  201. queryParams.pageNo = 1
  202. getList()
  203. }
  204. /** 重置按钮操作 */
  205. const resetQuery = () => {
  206. queryFormRef.value.resetFields()
  207. handleQuery()
  208. }
  209. /** 发起流程操作 **/
  210. const handleCreate = async (row?: ProcessInstanceVO) => {
  211. // 如果是【业务表单】,不支持重新发起
  212. if (row?.id) {
  213. const processDefinitionDetail = await DefinitionApi.getProcessDefinition(
  214. row.processDefinitionId
  215. )
  216. debugger
  217. if (processDefinitionDetail.formType === 20) {
  218. message.error('重新发起流程失败,原因:该流程使用业务表单,不支持重新发起')
  219. return
  220. }
  221. }
  222. // 跳转发起流程界面
  223. await router.push({
  224. name: 'BpmProcessInstanceCreate',
  225. query: { processInstanceId: row?.id }
  226. })
  227. }
  228. /** 查看详情 */
  229. const handleDetail = (row) => {
  230. router.push({
  231. name: 'BpmProcessInstanceDetail',
  232. query: {
  233. id: row.id
  234. }
  235. })
  236. }
  237. /** 取消按钮操作 */
  238. const handleCancel = async (row) => {
  239. // 二次确认
  240. const { value } = await ElMessageBox.prompt('请输入取消原因', '取消流程', {
  241. confirmButtonText: t('common.ok'),
  242. cancelButtonText: t('common.cancel'),
  243. inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
  244. inputErrorMessage: '取消原因不能为空'
  245. })
  246. // 发起取消
  247. await ProcessInstanceApi.cancelProcessInstanceByStartUser(row.id, value)
  248. message.success('取消成功')
  249. // 刷新列表
  250. await getList()
  251. }
  252. /** 激活时 **/
  253. onActivated(() => {
  254. getList()
  255. })
  256. /** 初始化 **/
  257. onMounted(async () => {
  258. await getList()
  259. categoryList.value = await CategoryApi.getCategorySimpleList()
  260. })
  261. </script>