index.vue 14 KB

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