index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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: 'label', children: 'children' } as any"
  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. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  24. <div v-show="showSearch" class="mb-[10px]">
  25. <el-card shadow="hover">
  26. <el-form v-show="showSearch" ref="queryFormRef" :model="queryParams" :inline="true">
  27. <el-form-item>
  28. <el-badge :value="userSelectCount" :max="10" class="item">
  29. <el-button type="primary" @click="openUserSelect">选择申请人</el-button>
  30. </el-badge>
  31. </el-form-item>
  32. <el-form-item label="任务名称" prop="nodeName">
  33. <el-input v-model="queryParams.nodeName" placeholder="请输入任务名称" @keyup.enter="handleQuery" />
  34. </el-form-item>
  35. <el-form-item label="流程定义名称" label-width="100" prop="flowName">
  36. <el-input v-model="queryParams.flowName" placeholder="请输入流程定义名称" @keyup.enter="handleQuery" />
  37. </el-form-item>
  38. <el-form-item label="流程定义编码" label-width="100" prop="flowCode">
  39. <el-input v-model="queryParams.flowCode" placeholder="请输入流程定义编码" @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:show-search="showSearch" @query-table="handleQuery"></right-toolbar>
  56. </el-row>
  57. </template>
  58. <el-tabs v-model="tab" @tab-click="changeTab">
  59. <el-tab-pane name="running" label="运行中"></el-tab-pane>
  60. <el-tab-pane name="finish" label="已完成"></el-tab-pane>
  61. <el-table v-loading="loading" border :data="processInstanceList" @selection-change="handleSelectionChange">
  62. <el-table-column type="selection" width="55" align="center" />
  63. <el-table-column align="center" type="index" label="序号" width="60"></el-table-column>
  64. <el-table-column :show-overflow-tooltip="true" align="center" label="流程定义名称">
  65. <template #default="scope">
  66. <span>{{ scope.row.flowName }}v{{ scope.row.version }}</span>
  67. </template>
  68. </el-table-column>
  69. <el-table-column align="center" prop="nodeName" label="任务名称"></el-table-column>
  70. <el-table-column align="center" prop="flowCode" label="流程定义编码"></el-table-column>
  71. <el-table-column align="center" prop="categoryName" label="流程分类"></el-table-column>
  72. <el-table-column align="center" prop="createByName" label="申请人"></el-table-column>
  73. <el-table-column align="center" prop="version" label="版本号" width="90">
  74. <template #default="scope"> v{{ scope.row.version }}.0</template>
  75. </el-table-column>
  76. <el-table-column v-if="tab === 'running'" align="center" prop="isSuspended" label="状态" min-width="70">
  77. <template #default="scope">
  78. <el-tag v-if="!scope.row.isSuspended" type="success">激活</el-tag>
  79. <el-tag v-else type="danger">挂起</el-tag>
  80. </template>
  81. </el-table-column>
  82. <el-table-column align="center" label="流程状态" min-width="70">
  83. <template #default="scope">
  84. <dict-tag :options="wf_business_status" :value="scope.row.flowStatus"></dict-tag>
  85. </template>
  86. </el-table-column>
  87. <el-table-column align="center" prop="createTime" label="启动时间" width="160"></el-table-column>
  88. <el-table-column v-if="tab === 'finish'" align="center" prop="updateTime" label="结束时间" width="160"></el-table-column>
  89. <el-table-column label="操作" align="center" :width="165">
  90. <template #default="scope">
  91. <el-row v-if="tab === 'running'" :gutter="10" class="mb8">
  92. <el-col :span="1.5">
  93. <el-popover :ref="`popoverRef${scope.$index}`" trigger="click" placement="left" :width="300">
  94. <el-input v-model="deleteReason" resize="none" :rows="3" type="textarea" placeholder="请输入作废原因" />
  95. <div style="text-align: right; margin: 5px 0px 0px 0px">
  96. <el-button size="small" text @click="cancelPopover(scope.$index)">取消</el-button>
  97. <el-button size="small" type="primary" @click="handleInvalid(scope.row)">确认</el-button>
  98. </div>
  99. <template #reference>
  100. <el-button type="danger" size="small" icon="CircleClose">作废</el-button>
  101. </template>
  102. </el-popover>
  103. </el-col>
  104. <el-col :span="1.5">
  105. <el-button type="danger" size="small" icon="Delete" @click="handleDelete(scope.row)">删除 </el-button>
  106. </el-col>
  107. </el-row>
  108. <el-row :gutter="10" class="mb8">
  109. <el-col :span="1.5">
  110. <el-button type="primary" size="small" icon="View" @click="handleView(scope.row)">查看</el-button>
  111. </el-col>
  112. <el-col :span="1.5">
  113. <el-button type="primary" size="small" icon="Document" @click="handleInstanceVariable(scope.row)"> 变量 </el-button>
  114. </el-col>
  115. </el-row>
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. <pagination
  120. v-show="total > 0"
  121. v-model:page="queryParams.pageNum"
  122. v-model:limit="queryParams.pageSize"
  123. :total="total"
  124. @pagination="handleQuery"
  125. />
  126. </el-tabs>
  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 fixed align="center" prop="nodeName" label="任务名称"></el-table-column>
  135. <el-table-column align="center" prop="key" label="标识Key"></el-table-column>
  136. <el-table-column align="center" prop="version" label="版本号" width="90">
  137. <template #default="scope"> v{{ scope.row.version }}.0</template>
  138. </el-table-column>
  139. <el-table-column align="center" prop="suspensionState" label="状态" min-width="70">
  140. <template #default="scope">
  141. <el-tag v-if="scope.row.suspensionState == 1" type="success">激活</el-tag>
  142. <el-tag v-else type="danger">挂起</el-tag>
  143. </template>
  144. </el-table-column>
  145. <el-table-column align="center" prop="deploymentTime" label="部署时间" :show-overflow-tooltip="true"></el-table-column>
  146. </el-table>
  147. </el-dialog>
  148. <!-- 流程变量开始 -->
  149. <el-dialog v-model="variableVisible" v-if="variableVisible" draggable title="流程变量" width="60%" :close-on-click-modal="false">
  150. <el-card v-loading="variableLoading">
  151. <template #header>
  152. <div class="clearfix">
  153. <span
  154. >流程定义名称:<el-tag>{{ processDefinitionName }}</el-tag></span
  155. >
  156. </div>
  157. </template>
  158. <div class="max-h-500px overflow-y-auto">
  159. <VueJsonPretty :data="formatToJsonObject(variables)" />
  160. </div>
  161. </el-card>
  162. <el-card v-loading="variableLoading">
  163. <el-form ref="ruleFormRef" :model="form" :inline="true" :rules="rules" label-width="120px">
  164. <el-form-item label="变量KEY" prop="key">
  165. <el-input v-model="form.key" placeholder="请输入变量KEY" />
  166. </el-form-item>
  167. <el-form-item label="变量值" prop="value">
  168. <el-input v-model="form.value" placeholder="请输入变量值" />
  169. </el-form-item>
  170. <el-form-item>
  171. <el-button type="primary" @click="handleVariable(ruleFormRef)">确认</el-button>
  172. </el-form-item>
  173. </el-form>
  174. </el-card>
  175. </el-dialog>
  176. <!-- 流程变量结束 -->
  177. <!-- 申请人 -->
  178. <UserSelect ref="userSelectRef" :multiple="true" :data="selectUserIds" @confirm-call-back="userSelectCallBack"></UserSelect>
  179. </div>
  180. </template>
  181. <script setup lang="ts">
  182. import {
  183. pageByRunning,
  184. pageByFinish,
  185. deleteByInstanceIds,
  186. deleteHisByInstanceIds,
  187. instanceVariable,
  188. invalid,
  189. updateVariable
  190. } from '@/api/workflow/instance';
  191. import { categoryTree } from '@/api/workflow/category';
  192. import { CategoryTreeVO } from '@/api/workflow/category/types';
  193. import { FlowInstanceQuery, FlowInstanceVO } from '@/api/workflow/instance/types';
  194. import workflowCommon from '@/api/workflow/workflowCommon';
  195. import { RouterJumpVo } from '@/api/workflow/workflowCommon/types';
  196. import VueJsonPretty from 'vue-json-pretty';
  197. import 'vue-json-pretty/lib/styles.css';
  198. import UserSelect from '@/components/UserSelect/index.vue';
  199. import { ElForm, FormInstance } from 'element-plus';
  200. //审批记录组件
  201. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  202. const { wf_business_status } = toRefs<any>(proxy?.useDict('wf_business_status'));
  203. const queryFormRef = ref<ElFormInstance>();
  204. const categoryTreeRef = ref<ElTreeInstance>();
  205. import { ref } from 'vue';
  206. import { UserVO } from '@/api/system/user/types';
  207. const form = ref<Record<string, any>>({
  208. instanceId: undefined,
  209. key: undefined,
  210. value: undefined
  211. });
  212. const ruleFormRef = ref<FormInstance>();
  213. const userSelectRef = ref<InstanceType<typeof UserSelect>>();
  214. // 遮罩层
  215. const loading = ref(true);
  216. // 选中数组
  217. const ids = ref<Array<any>>([]);
  218. // 选中实例id数组
  219. const instanceIds = ref<Array<number | string>>([]);
  220. // 非单个禁用
  221. const single = ref(true);
  222. // 非多个禁用
  223. const multiple = ref(true);
  224. // 显示搜索条件
  225. const showSearch = ref(true);
  226. // 总条数
  227. const total = ref(0);
  228. // 实例id
  229. const instanceId = ref(undefined);
  230. // 流程变量是否显示
  231. const variableVisible = ref(false);
  232. const variableLoading = ref(true);
  233. const variables = ref<string>('');
  234. //流程定义名称
  235. const processDefinitionName = ref();
  236. // 模型定义表格数据
  237. const processInstanceList = ref<FlowInstanceVO[]>([]);
  238. const processDefinitionHistoryList = ref<Array<any>>([]);
  239. const categoryOptions = ref<CategoryOption[]>([]);
  240. const categoryName = ref('');
  241. const processDefinitionDialog = reactive<DialogOption>({
  242. visible: false,
  243. title: '流程定义'
  244. });
  245. type CategoryOption = {
  246. id: string;
  247. categoryName: string;
  248. children?: CategoryOption[];
  249. };
  250. const tab = ref('running');
  251. // 作废原因
  252. const deleteReason = ref('');
  253. //申请人id
  254. const selectUserIds = ref<Array<number | string>>([]);
  255. //申请人选择数量
  256. const userSelectCount = ref(0);
  257. // 查询参数
  258. const queryParams = ref<FlowInstanceQuery>({
  259. pageNum: 1,
  260. pageSize: 10,
  261. nodeName: undefined,
  262. flowName: undefined,
  263. flowCode: undefined,
  264. createByIds: [],
  265. category: undefined
  266. });
  267. /** 节点单击事件 */
  268. const handleNodeClick = (data: CategoryTreeVO) => {
  269. queryParams.value.category = data.id;
  270. if (data.id === '0') {
  271. queryParams.value.category = '';
  272. }
  273. handleQuery();
  274. };
  275. /** 通过条件过滤节点 */
  276. const filterNode = (value: string, data: any) => {
  277. if (!value) return true;
  278. return data.categoryName.indexOf(value) !== -1;
  279. };
  280. /** 根据名称筛选部门树 */
  281. watchEffect(
  282. () => {
  283. categoryTreeRef.value.filter(categoryName.value);
  284. },
  285. {
  286. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  287. }
  288. );
  289. /** 查询流程分类下拉树结构 */
  290. const getTreeselect = async () => {
  291. const res = await categoryTree();
  292. categoryOptions.value = res.data;
  293. };
  294. /** 搜索按钮操作 */
  295. const handleQuery = () => {
  296. if ('running' === tab.value) {
  297. getProcessInstanceRunningList();
  298. } else {
  299. getProcessInstanceFinishList();
  300. }
  301. };
  302. /** 重置按钮操作 */
  303. const resetQuery = () => {
  304. queryFormRef.value?.resetFields();
  305. queryParams.value.category = '';
  306. queryParams.value.pageNum = 1;
  307. queryParams.value.pageSize = 10;
  308. queryParams.value.createByIds = [];
  309. userSelectCount.value = 0;
  310. handleQuery();
  311. };
  312. // 多选框选中数据
  313. const handleSelectionChange = (selection: FlowInstanceVO[]) => {
  314. ids.value = selection.map((item: any) => item.id);
  315. instanceIds.value = selection.map((item: FlowInstanceVO) => item.id);
  316. single.value = selection.length !== 1;
  317. multiple.value = !selection.length;
  318. };
  319. //分页
  320. const getProcessInstanceRunningList = () => {
  321. loading.value = true;
  322. pageByRunning(queryParams.value).then((resp) => {
  323. processInstanceList.value = resp.rows;
  324. total.value = resp.total;
  325. loading.value = false;
  326. });
  327. };
  328. //分页
  329. const getProcessInstanceFinishList = () => {
  330. loading.value = true;
  331. pageByFinish(queryParams.value).then((resp) => {
  332. processInstanceList.value = resp.rows;
  333. total.value = resp.total;
  334. loading.value = false;
  335. });
  336. };
  337. /** 删除按钮操作 */
  338. const handleDelete = async (row: FlowInstanceVO) => {
  339. const instanceIdList = row.id || instanceIds.value;
  340. await proxy?.$modal.confirm('是否确认删除?');
  341. loading.value = true;
  342. if ('running' === tab.value) {
  343. await deleteByInstanceIds(instanceIdList).finally(() => (loading.value = false));
  344. getProcessInstanceRunningList();
  345. } else {
  346. await deleteHisByInstanceIds(instanceIdList).finally(() => (loading.value = false));
  347. getProcessInstanceFinishList();
  348. }
  349. proxy?.$modal.msgSuccess('删除成功');
  350. };
  351. const changeTab = async (data: string) => {
  352. processInstanceList.value = [];
  353. queryParams.value.pageNum = 1;
  354. if ('running' === data.paneName) {
  355. getProcessInstanceRunningList();
  356. } else {
  357. getProcessInstanceFinishList();
  358. }
  359. };
  360. /** 作废按钮操作 */
  361. const handleInvalid = async (row: FlowInstanceVO) => {
  362. await proxy?.$modal.confirm('是否确认作废?');
  363. loading.value = true;
  364. if ('running' === tab.value) {
  365. const param = {
  366. id: row.id,
  367. comment: deleteReason.value
  368. };
  369. await invalid(param).finally(() => (loading.value = false));
  370. getProcessInstanceRunningList();
  371. proxy?.$modal.msgSuccess('操作成功');
  372. }
  373. };
  374. const cancelPopover = async (index: any) => {
  375. (proxy?.$refs[`popoverRef${index}`] as any).hide(); //关闭弹窗
  376. };
  377. /** 查看按钮操作 */
  378. const handleView = (row) => {
  379. const routerJumpVo = reactive<RouterJumpVo>({
  380. businessId: row.businessId,
  381. taskId: row.id,
  382. type: 'view',
  383. formCustom: row.formCustom,
  384. formPath: row.formPath
  385. });
  386. workflowCommon.routerJump(routerJumpVo, proxy);
  387. };
  388. //查询流程变量
  389. const handleInstanceVariable = async (row: FlowInstanceVO) => {
  390. instanceId.value = row.id;
  391. variableLoading.value = true;
  392. variableVisible.value = true;
  393. processDefinitionName.value = row.flowName;
  394. const data = await instanceVariable(row.id);
  395. variables.value = data.data.variable;
  396. variableLoading.value = false;
  397. form.value.instanceId = undefined;
  398. form.value.key = undefined;
  399. form.value.value = undefined;
  400. };
  401. /**
  402. * json转为对象
  403. * @param data 原始数据
  404. */
  405. function formatToJsonObject(data: string) {
  406. try {
  407. return JSON.parse(data);
  408. } catch (error) {
  409. return data;
  410. }
  411. }
  412. //打开申请人选择
  413. const openUserSelect = () => {
  414. userSelectRef.value.open();
  415. };
  416. //确认选择申请人
  417. const userSelectCallBack = (data: UserVO[]) => {
  418. userSelectCount.value = 0;
  419. selectUserIds.value = [];
  420. queryParams.value.createByIds = [];
  421. if (data && data.length > 0) {
  422. userSelectCount.value = data.length;
  423. selectUserIds.value = data.map((item) => item.userId);
  424. queryParams.value.createByIds = selectUserIds.value;
  425. }
  426. };
  427. const rules = reactive<Record<string, any>>({
  428. key: [
  429. {
  430. required: true,
  431. message: '请输入KEY',
  432. trigger: 'blur'
  433. }
  434. ],
  435. value: [
  436. {
  437. required: true,
  438. message: '请输入变量值',
  439. trigger: 'blur'
  440. }
  441. ]
  442. });
  443. const handleVariable = async (formEl: FormInstance | undefined) => {
  444. await formEl.validate(async (valid, fields) => {
  445. if (valid) {
  446. form.value.instanceId = instanceId.value;
  447. await proxy?.$modal.confirm('是否确认提交?');
  448. await updateVariable(form.value);
  449. proxy?.$modal.msgSuccess('操作成功');
  450. const data = await instanceVariable(instanceId.value);
  451. variables.value = data.data.variable;
  452. }
  453. });
  454. };
  455. onMounted(() => {
  456. getProcessInstanceRunningList();
  457. getTreeselect();
  458. });
  459. </script>