index.vue 7.9 KB

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