index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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
  128. label="流程分类"
  129. align="center"
  130. prop="categoryName"
  131. min-width="100"
  132. fixed="left"
  133. />
  134. <!-- TODO @芋艿:摘要 -->
  135. <!-- TODO tuituiji:参考钉钉;1)审批中时,展示审批任务;2)非审批中,展示状态 -->
  136. <el-table-column label="流程状态" prop="status" width="120">
  137. <template #default="scope">
  138. <dict-tag :type="DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS" :value="scope.row.status" />
  139. </template>
  140. </el-table-column>
  141. <el-table-column
  142. label="发起时间"
  143. align="center"
  144. prop="startTime"
  145. width="180"
  146. :formatter="dateFormatter"
  147. />
  148. <el-table-column
  149. label="结束时间"
  150. align="center"
  151. prop="endTime"
  152. width="180"
  153. :formatter="dateFormatter"
  154. />
  155. <!--<el-table-column align="center" label="耗时" prop="durationInMillis" width="160">
  156. <template #default="scope">
  157. {{ scope.row.durationInMillis > 0 ? formatPast2(scope.row.durationInMillis) : '-' }}
  158. </template>
  159. </el-table-column>
  160. <el-table-column label="当前审批任务" align="center" prop="tasks" min-width="120px">
  161. <template #default="scope">
  162. <el-button type="primary" v-for="task in scope.row.tasks" :key="task.id" link>
  163. <span>{{ task.name }}</span>
  164. </el-button>
  165. </template>
  166. </el-table-column>
  167. -->
  168. <el-table-column label="操作" align="center" fixed="right" width="180">
  169. <template #default="scope">
  170. <el-button
  171. link
  172. type="primary"
  173. v-hasPermi="['bpm:process-instance:cancel']"
  174. @click="handleDetail(scope.row)"
  175. >
  176. 详情
  177. </el-button>
  178. <el-button
  179. link
  180. type="primary"
  181. v-if="scope.row.status === 1"
  182. v-hasPermi="['bpm:process-instance:query']"
  183. @click="handleCancel(scope.row)"
  184. >
  185. 取消
  186. </el-button>
  187. <el-button link type="primary" v-else @click="handleCreate(scope.row)">
  188. 重新发起
  189. </el-button>
  190. </template>
  191. </el-table-column>
  192. </el-table>
  193. <!-- 分页 -->
  194. <Pagination
  195. :total="total"
  196. v-model:page="queryParams.pageNo"
  197. v-model:limit="queryParams.pageSize"
  198. @pagination="getList"
  199. />
  200. </ContentWrap>
  201. </template>
  202. <script lang="ts" setup>
  203. // TODO @tuituji:List 改成 <Icon icon="ep:plus" class="mr-5px" /> 类似这种组件哈。 RE:done & to check
  204. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  205. import { dateFormatter } from '@/utils/formatTime'
  206. import { ElMessageBox } from 'element-plus'
  207. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  208. import { CategoryApi, CategoryVO } from '@/api/bpm/category'
  209. import { ProcessInstanceVO } from '@/api/bpm/processInstance'
  210. import * as DefinitionApi from '@/api/bpm/definition'
  211. defineOptions({ name: 'BpmProcessInstanceMy' })
  212. const router = useRouter() // 路由
  213. const message = useMessage() // 消息弹窗
  214. const { t } = useI18n() // 国际化
  215. const loading = ref(true) // 列表的加载中
  216. const total = ref(0) // 列表的总页数
  217. const list = ref([]) // 列表的数据
  218. const queryParams = reactive({
  219. pageNo: 1,
  220. pageSize: 10,
  221. name: '',
  222. processDefinitionKey: undefined,
  223. category: undefined,
  224. status: undefined,
  225. createTime: []
  226. })
  227. const queryFormRef = ref() // 搜索的表单
  228. const categoryList = ref<CategoryVO[]>([]) // 流程分类列表
  229. /** 查询列表 */
  230. const getList = async () => {
  231. loading.value = true
  232. try {
  233. const data = await ProcessInstanceApi.getProcessInstanceMyPage(queryParams)
  234. list.value = data.list
  235. total.value = data.total
  236. } finally {
  237. loading.value = false
  238. }
  239. }
  240. const showPopover = ref(false)
  241. /** 搜索按钮操作 */
  242. const handleQuery = () => {
  243. queryParams.pageNo = 1
  244. getList()
  245. }
  246. /** 重置按钮操作 */
  247. const resetQuery = () => {
  248. queryFormRef.value.resetFields()
  249. handleQuery()
  250. }
  251. /** 发起流程操作 **/
  252. const handleCreate = async (row?: ProcessInstanceVO) => {
  253. // 如果是【业务表单】,不支持重新发起
  254. if (row?.id) {
  255. const processDefinitionDetail = await DefinitionApi.getProcessDefinition(
  256. row.processDefinitionId
  257. )
  258. if (processDefinitionDetail.formType === 20) {
  259. message.error('重新发起流程失败,原因:该流程使用业务表单,不支持重新发起')
  260. return
  261. }
  262. }
  263. // 跳转发起流程界面
  264. await router.push({
  265. name: 'BpmProcessInstanceCreate',
  266. query: { processInstanceId: row?.id }
  267. })
  268. }
  269. /** 查看详情 */
  270. const handleDetail = (row: ProcessInstanceVO) => {
  271. router.push({
  272. name: 'BpmProcessInstanceDetail',
  273. query: {
  274. id: row.id
  275. }
  276. })
  277. }
  278. /** 取消按钮操作 */
  279. const handleCancel = async (row: ProcessInstanceVO) => {
  280. // 二次确认
  281. const { value } = await ElMessageBox.prompt('请输入取消原因', '取消流程', {
  282. confirmButtonText: t('common.ok'),
  283. cancelButtonText: t('common.cancel'),
  284. inputPattern: /^[\s\S]*.*\S[\s\S]*$/, // 判断非空,且非空格
  285. inputErrorMessage: '取消原因不能为空'
  286. })
  287. // 发起取消
  288. await ProcessInstanceApi.cancelProcessInstanceByStartUser(row.id, value)
  289. message.success('取消成功')
  290. // 刷新列表
  291. await getList()
  292. }
  293. /** 激活时 **/
  294. onActivated(() => {
  295. getList()
  296. })
  297. /** 初始化 **/
  298. onMounted(async () => {
  299. await getList()
  300. categoryList.value = await CategoryApi.getCategorySimpleList()
  301. })
  302. </script>
  303. <style>
  304. .bold-label .el-form-item__label {
  305. font-weight: bold; /* 将字体加粗 */
  306. }
  307. </style>