index.vue 18 KB

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