index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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 { pageByRunning, pageByFinish, deleteByInstanceIds, instanceVariable, invalid, updateVariable } from '@/api/workflow/instance';
  183. import { categoryTree } from '@/api/workflow/category';
  184. import { CategoryTreeVO } from '@/api/workflow/category/types';
  185. import { FlowInstanceQuery, FlowInstanceVO } from '@/api/workflow/instance/types';
  186. import workflowCommon from '@/api/workflow/workflowCommon';
  187. import { RouterJumpVo } from '@/api/workflow/workflowCommon/types';
  188. import VueJsonPretty from 'vue-json-pretty';
  189. import 'vue-json-pretty/lib/styles.css';
  190. import UserSelect from '@/components/UserSelect/index.vue';
  191. import { ElForm, FormInstance } from 'element-plus';
  192. //审批记录组件
  193. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  194. const { wf_business_status } = toRefs<any>(proxy?.useDict('wf_business_status'));
  195. const queryFormRef = ref<ElFormInstance>();
  196. const categoryTreeRef = ref<ElTreeInstance>();
  197. import { ref } from 'vue';
  198. import { UserVO } from '@/api/system/user/types';
  199. const form = ref<Record<string, any>>({
  200. instanceId: undefined,
  201. key: undefined,
  202. value: undefined
  203. });
  204. const ruleFormRef = ref<FormInstance>();
  205. const userSelectRef = ref<InstanceType<typeof UserSelect>>();
  206. // 遮罩层
  207. const loading = ref(true);
  208. // 选中数组
  209. const ids = ref<Array<any>>([]);
  210. // 选中实例id数组
  211. const instanceIds = ref<Array<number | string>>([]);
  212. // 非单个禁用
  213. const single = ref(true);
  214. // 非多个禁用
  215. const multiple = ref(true);
  216. // 显示搜索条件
  217. const showSearch = ref(true);
  218. // 总条数
  219. const total = ref(0);
  220. // 实例id
  221. const instanceId = ref(undefined);
  222. // 流程变量是否显示
  223. const variableVisible = ref(false);
  224. const variableLoading = ref(true);
  225. const variables = ref<string>('');
  226. //流程定义名称
  227. const processDefinitionName = ref();
  228. // 模型定义表格数据
  229. const processInstanceList = ref<FlowInstanceVO[]>([]);
  230. const processDefinitionHistoryList = ref<Array<any>>([]);
  231. const categoryOptions = ref<CategoryOption[]>([]);
  232. const categoryName = ref('');
  233. const processDefinitionDialog = reactive<DialogOption>({
  234. visible: false,
  235. title: '流程定义'
  236. });
  237. type CategoryOption = {
  238. id: string;
  239. categoryName: string;
  240. children?: CategoryOption[];
  241. };
  242. const tab = ref('running');
  243. // 作废原因
  244. const deleteReason = ref('');
  245. //申请人id
  246. const selectUserIds = ref<Array<number | string>>([]);
  247. //申请人选择数量
  248. const userSelectCount = ref(0);
  249. // 查询参数
  250. const queryParams = ref<FlowInstanceQuery>({
  251. pageNum: 1,
  252. pageSize: 10,
  253. nodeName: undefined,
  254. flowName: undefined,
  255. flowCode: undefined,
  256. createByIds: [],
  257. category: undefined
  258. });
  259. /** 节点单击事件 */
  260. const handleNodeClick = (data: CategoryTreeVO) => {
  261. queryParams.value.category = data.id;
  262. if (data.id === '0') {
  263. queryParams.value.category = '';
  264. }
  265. handleQuery();
  266. };
  267. /** 通过条件过滤节点 */
  268. const filterNode = (value: string, data: any) => {
  269. if (!value) return true;
  270. return data.categoryName.indexOf(value) !== -1;
  271. };
  272. /** 根据名称筛选部门树 */
  273. watchEffect(
  274. () => {
  275. categoryTreeRef.value.filter(categoryName.value);
  276. },
  277. {
  278. flush: 'post' // watchEffect会在DOM挂载或者更新之前就会触发,此属性控制在DOM元素更新后运行
  279. }
  280. );
  281. /** 查询流程分类下拉树结构 */
  282. const getTreeselect = async () => {
  283. const res = await categoryTree();
  284. categoryOptions.value = res.data;
  285. };
  286. /** 搜索按钮操作 */
  287. const handleQuery = () => {
  288. if ('running' === tab.value) {
  289. getProcessInstanceRunningList();
  290. } else {
  291. getProcessInstanceFinishList();
  292. }
  293. };
  294. /** 重置按钮操作 */
  295. const resetQuery = () => {
  296. queryFormRef.value?.resetFields();
  297. queryParams.value.category = '';
  298. queryParams.value.pageNum = 1;
  299. queryParams.value.pageSize = 10;
  300. queryParams.value.createByIds = [];
  301. userSelectCount.value = 0;
  302. handleQuery();
  303. };
  304. // 多选框选中数据
  305. const handleSelectionChange = (selection: FlowInstanceVO[]) => {
  306. ids.value = selection.map((item: any) => item.id);
  307. instanceIds.value = selection.map((item: FlowInstanceVO) => item.id);
  308. single.value = selection.length !== 1;
  309. multiple.value = !selection.length;
  310. };
  311. //分页
  312. const getProcessInstanceRunningList = () => {
  313. loading.value = true;
  314. pageByRunning(queryParams.value).then((resp) => {
  315. processInstanceList.value = resp.rows;
  316. total.value = resp.total;
  317. loading.value = false;
  318. });
  319. };
  320. //分页
  321. const getProcessInstanceFinishList = () => {
  322. loading.value = true;
  323. pageByFinish(queryParams.value).then((resp) => {
  324. processInstanceList.value = resp.rows;
  325. total.value = resp.total;
  326. loading.value = false;
  327. });
  328. };
  329. /** 删除按钮操作 */
  330. const handleDelete = async (row: FlowInstanceVO) => {
  331. const instanceIdList = row.id || instanceIds.value;
  332. await proxy?.$modal.confirm('是否确认删除?');
  333. loading.value = true;
  334. if ('running' === tab.value) {
  335. await deleteByInstanceIds(instanceIdList).finally(() => (loading.value = false));
  336. getProcessInstanceRunningList();
  337. } else {
  338. await deleteByInstanceIds(instanceIdList).finally(() => (loading.value = false));
  339. getProcessInstanceFinishList();
  340. }
  341. proxy?.$modal.msgSuccess('删除成功');
  342. };
  343. const changeTab = async (data: string) => {
  344. processInstanceList.value = [];
  345. queryParams.value.pageNum = 1;
  346. if ('running' === data.paneName) {
  347. getProcessInstanceRunningList();
  348. } else {
  349. getProcessInstanceFinishList();
  350. }
  351. };
  352. /** 作废按钮操作 */
  353. const handleInvalid = async (row: FlowInstanceVO) => {
  354. await proxy?.$modal.confirm('是否确认作废?');
  355. loading.value = true;
  356. if ('running' === tab.value) {
  357. const param = {
  358. id: row.id,
  359. comment: deleteReason.value
  360. };
  361. await invalid(param).finally(() => (loading.value = false));
  362. getProcessInstanceRunningList();
  363. proxy?.$modal.msgSuccess('操作成功');
  364. }
  365. };
  366. const cancelPopover = async (index: any) => {
  367. (proxy?.$refs[`popoverRef${index}`] as any).hide(); //关闭弹窗
  368. };
  369. /** 查看按钮操作 */
  370. const handleView = (row) => {
  371. const routerJumpVo = reactive<RouterJumpVo>({
  372. businessId: row.businessId,
  373. taskId: row.id,
  374. type: 'view',
  375. formCustom: row.formCustom,
  376. formPath: row.formPath
  377. });
  378. workflowCommon.routerJump(routerJumpVo, proxy);
  379. };
  380. //查询流程变量
  381. const handleInstanceVariable = async (row: FlowInstanceVO) => {
  382. instanceId.value = row.id;
  383. variableLoading.value = true;
  384. variableVisible.value = true;
  385. processDefinitionName.value = row.flowName;
  386. const data = await instanceVariable(row.id);
  387. variables.value = data.data.variable;
  388. variableLoading.value = false;
  389. form.value.instanceId = undefined;
  390. form.value.key = undefined;
  391. form.value.value = undefined;
  392. };
  393. /**
  394. * json转为对象
  395. * @param data 原始数据
  396. */
  397. function formatToJsonObject(data: string) {
  398. try {
  399. return JSON.parse(data);
  400. } catch (error) {
  401. return data;
  402. }
  403. }
  404. //打开申请人选择
  405. const openUserSelect = () => {
  406. userSelectRef.value.open();
  407. };
  408. //确认选择申请人
  409. const userSelectCallBack = (data: UserVO[]) => {
  410. userSelectCount.value = 0;
  411. selectUserIds.value = [];
  412. queryParams.value.createByIds = [];
  413. if (data && data.length > 0) {
  414. userSelectCount.value = data.length;
  415. selectUserIds.value = data.map((item) => item.userId);
  416. queryParams.value.createByIds = selectUserIds.value;
  417. }
  418. };
  419. const rules = reactive<Record<string, any>>({
  420. key: [
  421. {
  422. required: true,
  423. message: '请输入KEY',
  424. trigger: 'blur'
  425. }
  426. ],
  427. value: [
  428. {
  429. required: true,
  430. message: '请输入变量值',
  431. trigger: 'blur'
  432. }
  433. ]
  434. });
  435. const handleVariable = async (formEl: FormInstance | undefined) => {
  436. await formEl.validate(async (valid, fields) => {
  437. if (valid) {
  438. form.value.instanceId = instanceId.value;
  439. await proxy?.$modal.confirm('是否确认提交?');
  440. await updateVariable(form.value);
  441. proxy?.$modal.msgSuccess('操作成功');
  442. const data = await instanceVariable(instanceId.value);
  443. variables.value = data.data.variable;
  444. }
  445. });
  446. };
  447. onMounted(() => {
  448. getProcessInstanceRunningList();
  449. getTreeselect();
  450. });
  451. </script>