index.vue 14 KB

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