index.vue 15 KB

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