index.vue 9.7 KB

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