index.vue 11 KB

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