index.vue 10 KB

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