index.vue 9.8 KB

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