index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <div class="p-2">
  3. <el-row :gutter="20">
  4. <!-- 流程分类树 -->
  5. <el-col :lg="4" :xs="24" style="">
  6. <el-card shadow="hover">
  7. <el-input v-model="categoryName" placeholder="请输入流程分类名" prefix-icon="Search" clearable />
  8. <el-tree
  9. ref="categoryTreeRef"
  10. class="mt-2"
  11. node-key="id"
  12. :data="categoryOptions"
  13. :props="{ label: 'categoryName', children: 'children' }"
  14. :expand-on-click-node="false"
  15. :filter-node-method="filterNode"
  16. highlight-current
  17. default-expand-all
  18. @node-click="handleNodeClick"
  19. ></el-tree>
  20. </el-card>
  21. </el-col>
  22. <el-col :lg="20" :xs="24">
  23. <div class="mb-[10px]">
  24. <el-card shadow="hover" class="text-center">
  25. <el-radio-group v-model="tab" @change="changeTab(tab)">
  26. <el-radio-button label="running">运行中</el-radio-button>
  27. <el-radio-button label="finish">已完成</el-radio-button>
  28. </el-radio-group>
  29. </el-card>
  30. </div>
  31. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  32. <div v-show="showSearch" class="mb-[10px]">
  33. <el-card shadow="hover">
  34. <el-form v-show="showSearch" ref="queryFormRef" :model="queryParams" :inline="true" label-width="120px">
  35. <el-form-item label="流程定义名称" prop="name">
  36. <el-input v-model="queryParams.name" placeholder="请输入流程定义名称" @keyup.enter="handleQuery" />
  37. </el-form-item>
  38. <el-form-item label="流程定义KEY" prop="key">
  39. <el-input v-model="queryParams.key" placeholder="请输入流程定义KEY" @keyup.enter="handleQuery" />
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  43. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  44. </el-form-item>
  45. </el-form>
  46. </el-card>
  47. </div>
  48. </transition>
  49. <el-card shadow="hover">
  50. <template #header>
  51. <el-row :gutter="10" class="mb8">
  52. <el-col :span="1.5">
  53. <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete">删除</el-button>
  54. </el-col>
  55. <right-toolbar v-model:showSearch="showSearch" @query-table="handleQuery"></right-toolbar>
  56. </el-row>
  57. </template>
  58. <el-table v-loading="loading" border :data="processInstanceList" @selection-change="handleSelectionChange">
  59. <el-table-column type="selection" width="55" align="center" />
  60. <el-table-column align="center" type="index" label="序号" width="60"></el-table-column>
  61. <el-table-column align="center" prop="processDefinitionName" label="流程定义名称"></el-table-column>
  62. <el-table-column align="center" prop="processDefinitionKey" label="流程定义KEY"></el-table-column>
  63. <el-table-column align="center" prop="processDefinitionVersion" label="版本号" width="90">
  64. <template #default="scope"> v{{ scope.row.processDefinitionVersion }}.0</template>
  65. </el-table-column>
  66. <el-table-column v-if="tab === 'running'" align="center" prop="isSuspended" label="状态" min-width="70">
  67. <template #default="scope">
  68. <el-tag v-if="!scope.row.isSuspended" type="success">激活</el-tag>
  69. <el-tag v-else type="danger">挂起</el-tag>
  70. </template>
  71. </el-table-column>
  72. <el-table-column align="center" prop="businessStatusName" label="流程状态" min-width="70">
  73. <template #default="scope">
  74. <el-tag type="success">{{ scope.row.businessStatusName }}</el-tag>
  75. </template>
  76. </el-table-column>
  77. <el-table-column align="center" prop="startTime" label="启动时间" width="160"></el-table-column>
  78. <el-table-column v-if="tab === 'finish'" align="center" prop="endTime" label="结束时间" width="160"></el-table-column>
  79. <el-table-column label="操作" align="center" :width="tab === 'finish' ? '130' : '160'">
  80. <template #default="scope">
  81. <el-row v-if="tab === 'running'" :gutter="10" class="mb8">
  82. <el-col :span="1.5">
  83. <el-popover :ref="`popoverRef${scope.$index}`" trigger="click" placement="left" :width="300">
  84. <el-input v-model="deleteReason" resize="none" :rows="3" type="textarea" placeholder="请输入作废原因" />
  85. <div style="text-align: right; margin: 5px 0px 0px 0px">
  86. <el-button size="small" text @click="cancelPopover(scope.$index)">取消</el-button>
  87. <el-button size="small" type="primary" @click="handleInvalid(scope.row)">确认</el-button>
  88. </div>
  89. <template #reference>
  90. <el-button link type="primary" size="small" icon="CircleClose">作废</el-button>
  91. </template>
  92. </el-popover>
  93. </el-col>
  94. <el-col :span="1.5">
  95. <el-button
  96. link
  97. type="primary"
  98. size="small"
  99. icon="Sort"
  100. @click="getProcessDefinitionHitoryList(scope.row.processDefinitionId, scope.row.processDefinitionKey)"
  101. >切换版本</el-button
  102. >
  103. </el-col>
  104. </el-row>
  105. <el-row :gutter="10" class="mb8">
  106. <el-col :span="1.5">
  107. <el-button link type="primary" size="small" icon="View" @click="handleView(scope.row)">查看</el-button>
  108. </el-col>
  109. <el-col :span="1.5">
  110. <el-button link type="primary" size="small" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  111. </el-col>
  112. </el-row>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. <pagination
  117. v-show="total > 0"
  118. v-model:page="queryParams.pageNum"
  119. v-model:limit="queryParams.pageSize"
  120. :total="total"
  121. @pagination="handleQuery"
  122. />
  123. </el-card>
  124. </el-col>
  125. </el-row>
  126. <el-dialog v-if="processDefinitionDialog.visible" v-model="processDefinitionDialog.visible" :title="processDefinitionDialog.title" width="70%">
  127. <el-table v-loading="loading" :data="processDefinitionHistoryList">
  128. <el-table-column fixed align="center" type="index" label="序号" width="60"></el-table-column>
  129. <el-table-column fixed align="center" prop="name" label="流程定义名称"></el-table-column>
  130. <el-table-column align="center" prop="key" label="标识Key"></el-table-column>
  131. <el-table-column align="center" prop="version" label="版本号" width="90">
  132. <template #default="scope"> v{{ scope.row.version }}.0</template>
  133. </el-table-column>
  134. <el-table-column align="center" prop="suspensionState" label="状态" min-width="70">
  135. <template #default="scope">
  136. <el-tag v-if="scope.row.suspensionState == 1" type="success">激活</el-tag>
  137. <el-tag v-else type="danger">挂起</el-tag>
  138. </template>
  139. </el-table-column>
  140. <el-table-column align="center" prop="deploymentTime" label="部署时间" :show-overflow-tooltip="true"></el-table-column>
  141. <el-table-column fixed="right" label="操作" align="center" width="200" class-name="small-padding fixed-width">
  142. <template #default="scope">
  143. <el-button link type="primary" size="small" icon="Sort" @click="handleChange(scope.row.id)">切换</el-button>
  144. </template>
  145. </el-table-column>
  146. </el-table>
  147. </el-dialog>
  148. </div>
  149. </template>
  150. <script lang="ts" setup>
  151. import {
  152. getPageByRunning,
  153. getPageByFinish,
  154. deleteRunAndHisInstance,
  155. deleteFinishAndHisInstance,
  156. deleteRunInstance
  157. } from '@/api/workflow/processInstance';
  158. import { getListByKey, migrationDefinition } from '@/api/workflow/processDefinition';
  159. import { listCategory } from '@/api/workflow/category';
  160. import { CategoryVO } from '@/api/workflow/category/types';
  161. import { ProcessInstanceQuery, ProcessInstanceVO } from '@/api/workflow/processInstance/types';
  162. import workflowCommon from '@/api/workflow/workflowCommon';
  163. import { RouterJumpVo } from '@/api/workflow/workflowCommon/types';
  164. //审批记录组件
  165. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  166. const queryFormRef = ref<ElFormInstance>();
  167. const categoryTreeRef = ref<ElTreeInstance>();
  168. // 遮罩层
  169. const loading = ref(true);
  170. // 选中数组
  171. const ids = ref<Array<any>>([]);
  172. // 非单个禁用
  173. const single = ref(true);
  174. // 非多个禁用
  175. const multiple = ref(true);
  176. // 显示搜索条件
  177. const showSearch = ref(true);
  178. // 总条数
  179. const total = ref(0);
  180. // 流程定义id
  181. const processDefinitionId = ref<string>('');
  182. // 模型定义表格数据
  183. const processInstanceList = ref<ProcessInstanceVO[]>([]);
  184. const processDefinitionHistoryList = ref<Array<any>>([]);
  185. const categoryOptions = ref<CategoryOption[]>([]);
  186. const categoryName = ref('');
  187. const processDefinitionDialog = reactive<DialogOption>({
  188. visible: false,
  189. title: '流程定义'
  190. });
  191. type CategoryOption = {
  192. categoryCode: string;
  193. categoryName: string;
  194. children?: CategoryOption[];
  195. };
  196. const tab = ref('running');
  197. // 作废原因
  198. const deleteReason = ref('');
  199. // 查询参数
  200. const queryParams = ref<ProcessInstanceQuery>({
  201. pageNum: 1,
  202. pageSize: 10,
  203. name: undefined,
  204. key: undefined,
  205. categoryCode: undefined
  206. });
  207. /** 节点单击事件 */
  208. const handleNodeClick = (data: CategoryVO) => {
  209. queryParams.value.categoryCode = data.categoryCode;
  210. if (data.categoryCode === 'ALL') {
  211. queryParams.value.categoryCode = '';
  212. }
  213. handleQuery();
  214. };
  215. /** 通过条件过滤节点 */
  216. const filterNode = (value: string, data: any) => {
  217. if (!value) return true;
  218. return data.categoryName.indexOf(value) !== -1;
  219. };
  220. /** 根据名称筛选部门树 */
  221. watchEffect(
  222. () => {
  223. categoryTreeRef.value.filter(categoryName.value);
  224. },
  225. {
  226. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  227. }
  228. );
  229. /** 查询流程分类下拉树结构 */
  230. const getTreeselect = async () => {
  231. const res = await listCategory();
  232. categoryOptions.value = [];
  233. const data: CategoryOption = { categoryCode: 'ALL', categoryName: '顶级节点', children: [] };
  234. data.children = proxy?.handleTree<CategoryOption>(res.data, 'id', 'parentId');
  235. categoryOptions.value.push(data);
  236. };
  237. /** 搜索按钮操作 */
  238. const handleQuery = () => {
  239. if ('running' === tab.value) {
  240. getProcessInstanceRunningList();
  241. } else {
  242. getProcessInstanceFinishList();
  243. }
  244. };
  245. /** 重置按钮操作 */
  246. const resetQuery = () => {
  247. queryFormRef.value?.resetFields();
  248. queryParams.value.categoryCode = '';
  249. queryParams.value.pageNum = 1;
  250. queryParams.value.pageSize = 10;
  251. handleQuery();
  252. };
  253. // 多选框选中数据
  254. const handleSelectionChange = (selection: ProcessInstanceVO[]) => {
  255. ids.value = selection.map((item: any) => item.id);
  256. single.value = selection.length !== 1;
  257. multiple.value = !selection.length;
  258. };
  259. //分页
  260. const getProcessInstanceRunningList = () => {
  261. loading.value = true;
  262. getPageByRunning(queryParams.value).then((resp) => {
  263. processInstanceList.value = resp.rows;
  264. total.value = resp.total;
  265. loading.value = false;
  266. });
  267. };
  268. //分页
  269. const getProcessInstanceFinishList = () => {
  270. loading.value = true;
  271. getPageByFinish(queryParams.value).then((resp) => {
  272. processInstanceList.value = resp.rows;
  273. total.value = resp.total;
  274. loading.value = false;
  275. });
  276. };
  277. /** 删除按钮操作 */
  278. const handleDelete = async (row: any) => {
  279. const id = row.id || ids.value;
  280. await proxy?.$modal.confirm('是否确认删除id为【' + id + '】的数据项?');
  281. loading.value = true;
  282. if ('running' === tab.value) {
  283. await deleteRunAndHisInstance(id).finally(() => (loading.value = false));
  284. getProcessInstanceRunningList();
  285. } else {
  286. await deleteFinishAndHisInstance(id).finally(() => (loading.value = false));
  287. getProcessInstanceFinishList();
  288. }
  289. proxy?.$modal.msgSuccess('删除成功');
  290. };
  291. const changeTab = async (data: string) => {
  292. processInstanceList.value = []
  293. queryParams.value.pageNum = 1;
  294. if ('running' === data) {
  295. getProcessInstanceRunningList();
  296. } else {
  297. getProcessInstanceFinishList();
  298. }
  299. };
  300. /** 作废按钮操作 */
  301. const handleInvalid = async (row: ProcessInstanceVO) => {
  302. await proxy?.$modal.confirm('是否确认作废业务id为【' + row.businessKey + '】的数据项?');
  303. loading.value = true;
  304. if ('running' === tab.value) {
  305. let param = {
  306. processInstanceId: row.id,
  307. deleteReason: deleteReason.value
  308. };
  309. await deleteRunInstance(param).finally(() => (loading.value = false));
  310. getProcessInstanceRunningList();
  311. proxy?.$modal.msgSuccess('操作成功');
  312. }
  313. };
  314. const cancelPopover = async (index: any) => {
  315. (proxy?.$refs[`popoverRef${index}`] as any).hide(); //关闭弹窗
  316. };
  317. //获取流程定义
  318. const getProcessDefinitionHitoryList = (id: string, key: string) => {
  319. processDefinitionDialog.visible = true;
  320. processDefinitionId.value = id;
  321. loading.value = true;
  322. getListByKey(key).then((resp) => {
  323. if (resp.data && resp.data.length > 0) {
  324. processDefinitionHistoryList.value = resp.data.filter((item: any) => item.id !== id);
  325. }
  326. loading.value = false;
  327. });
  328. };
  329. //切换流程版本
  330. const handleChange = async (id: string) => {
  331. await proxy?.$modal.confirm('是否确认切换?');
  332. loading.value = true;
  333. migrationDefinition(processDefinitionId.value, id).then((resp) => {
  334. proxy?.$modal.msgSuccess('操作成功');
  335. getProcessInstanceRunningList();
  336. processDefinitionDialog.visible = false;
  337. loading.value = false;
  338. });
  339. };
  340. /** 查看按钮操作 */
  341. const handleView = (row) => {
  342. const routerJumpVo = reactive<RouterJumpVo>({
  343. wfDefinitionConfigVo: row.wfDefinitionConfigVo,
  344. wfNodeConfigVo: row.wfNodeConfigVo,
  345. businessKey: row.businessKey,
  346. taskId: row.id,
  347. type: 'view'
  348. });
  349. workflowCommon.routerJump(routerJumpVo,proxy)
  350. };
  351. onMounted(() => {
  352. getProcessInstanceRunningList();
  353. getTreeselect();
  354. });
  355. </script>