index.vue 10 KB

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