index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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-220px"
  79. />
  80. </el-form-item>
  81. </el-form>
  82. </ContentWrap>
  83. <!-- 列表 -->
  84. <ContentWrap>
  85. <el-table v-loading="loading" :data="list">
  86. <el-table-column label="流程名称" align="center" prop="name" min-width="200px" fixed="left" />
  87. <el-table-column
  88. label="流程分类"
  89. align="center"
  90. prop="categoryName"
  91. min-width="100"
  92. fixed="left"
  93. />
  94. <el-table-column label="流程发起人" align="center" prop="startUser.nickname" width="120" />
  95. <el-table-column label="发起部门" align="center" prop="startUser.deptName" width="120" />
  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="169">
  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. </template>
  148. </el-table-column>
  149. </el-table>
  150. <!-- 分页 -->
  151. <Pagination
  152. :total="total"
  153. v-model:page="queryParams.pageNo"
  154. v-model:limit="queryParams.pageSize"
  155. @pagination="getList"
  156. />
  157. </ContentWrap>
  158. </template>
  159. <script lang="ts" setup>
  160. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  161. import { dateFormatter, formatPast2 } from '@/utils/formatTime'
  162. import { ElMessageBox } from 'element-plus'
  163. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  164. import { CategoryApi } from '@/api/bpm/category'
  165. import * as UserApi from '@/api/system/user'
  166. import { cancelProcessInstanceByAdmin } from '@/api/bpm/processInstance'
  167. // 它和【我的流程】的差异是,该菜单可以看全部的流程实例
  168. defineOptions({ name: 'BpmProcessInstanceManager' })
  169. const router = useRouter() // 路由
  170. const message = useMessage() // 消息弹窗
  171. const { t } = useI18n() // 国际化
  172. const loading = ref(true) // 列表的加载中
  173. const total = ref(0) // 列表的总页数
  174. const list = ref([]) // 列表的数据
  175. const queryParams = reactive({
  176. pageNo: 1,
  177. pageSize: 10,
  178. startUserId: undefined,
  179. name: '',
  180. processDefinitionId: undefined,
  181. category: undefined,
  182. status: undefined,
  183. createTime: []
  184. })
  185. const queryFormRef = ref() // 搜索的表单
  186. const categoryList = ref([]) // 流程分类列表
  187. const userList = ref<any[]>([]) // 用户列表
  188. /** 查询列表 */
  189. const getList = async () => {
  190. loading.value = true
  191. try {
  192. const data = await ProcessInstanceApi.getProcessInstanceManagerPage(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 handleDetail = (row) => {
  211. router.push({
  212. name: 'BpmProcessInstanceDetail',
  213. query: {
  214. id: row.id
  215. }
  216. })
  217. }
  218. /** 取消按钮操作 */
  219. const handleCancel = async (row) => {
  220. // 二次确认
  221. const { value } = await ElMessageBox.prompt('请输入取消原因', '取消流程', {
  222. confirmButtonText: t('common.ok'),
  223. cancelButtonText: t('common.cancel'),
  224. inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
  225. inputErrorMessage: '取消原因不能为空'
  226. })
  227. // 发起取消
  228. await ProcessInstanceApi.cancelProcessInstanceByAdmin(row.id, value)
  229. message.success('取消成功')
  230. // 刷新列表
  231. await getList()
  232. }
  233. /** 激活时 **/
  234. onActivated(() => {
  235. getList()
  236. })
  237. /** 初始化 **/
  238. onMounted(async () => {
  239. await getList()
  240. categoryList.value = await CategoryApi.getCategorySimpleList()
  241. userList.value = await UserApi.getSimpleUserList()
  242. })
  243. </script>