index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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="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="processDefinitionId">
  22. <el-input
  23. v-model="queryParams.processDefinitionId"
  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()"
  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="120">
  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.id)">
  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. defineOptions({ name: 'BpmProcessInstanceMy' })
  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. name: '',
  179. processDefinitionId: undefined,
  180. category: undefined,
  181. status: undefined,
  182. createTime: []
  183. })
  184. const queryFormRef = ref() // 搜索的表单
  185. const categoryList = ref([]) // 流程分类列表
  186. /** 查询列表 */
  187. const getList = async () => {
  188. loading.value = true
  189. try {
  190. const data = await ProcessInstanceApi.getProcessInstanceMyPage(queryParams)
  191. list.value = data.list
  192. total.value = data.total
  193. } finally {
  194. loading.value = false
  195. }
  196. }
  197. /** 搜索按钮操作 */
  198. const handleQuery = () => {
  199. queryParams.pageNo = 1
  200. getList()
  201. }
  202. /** 重置按钮操作 */
  203. const resetQuery = () => {
  204. queryFormRef.value.resetFields()
  205. handleQuery()
  206. }
  207. /** 发起流程操作 **/
  208. const handleCreate = (id) => {
  209. router.push({
  210. name: 'BpmProcessInstanceCreate',
  211. query: { processInstanceId: id }
  212. })
  213. }
  214. /** 查看详情 */
  215. const handleDetail = (row) => {
  216. router.push({
  217. name: 'BpmProcessInstanceDetail',
  218. query: {
  219. id: row.id
  220. }
  221. })
  222. }
  223. /** 取消按钮操作 */
  224. const handleCancel = async (row) => {
  225. // 二次确认
  226. const { value } = await ElMessageBox.prompt('请输入取消原因', '取消流程', {
  227. confirmButtonText: t('common.ok'),
  228. cancelButtonText: t('common.cancel'),
  229. inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
  230. inputErrorMessage: '取消原因不能为空'
  231. })
  232. // 发起取消
  233. await ProcessInstanceApi.cancelProcessInstanceByStartUser(row.id, value)
  234. message.success('取消成功')
  235. // 刷新列表
  236. await getList()
  237. }
  238. /** 激活时 **/
  239. onActivated(() => {
  240. getList()
  241. })
  242. /** 初始化 **/
  243. onMounted(async () => {
  244. await getList()
  245. categoryList.value = await CategoryApi.getCategorySimpleList()
  246. })
  247. </script>