index.vue 15 KB

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