From d42de6f1c591f89b7a02a822273b6db4110acaf0 Mon Sep 17 00:00:00 2001 From: ssc <273702440@qq.com> Date: Mon, 3 Apr 2023 08:56:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=A0=B9=E6=8D=AEprocessDefKey?= =?UTF-8?q?=E5=8F=91=E8=B5=B7=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/plugin/workflow/process.js | 11 +++ src/views/plugin/workflow/mixins/ex-form.js | 100 +++++++++++++------- 2 files changed, 77 insertions(+), 34 deletions(-) diff --git a/src/api/plugin/workflow/process.js b/src/api/plugin/workflow/process.js index c94739b..ff8e3af 100644 --- a/src/api/plugin/workflow/process.js +++ b/src/api/plugin/workflow/process.js @@ -173,6 +173,17 @@ export const startProcess = (data) => { }) } +/** + * 发起流程 - 根据流程定义key + */ + export const startProcessByKey = (data) => { + return request({ + url: `${prefix}/startProcessByKey`, + method: 'post', + data + }) +} + /** * 任务审批 */ diff --git a/src/views/plugin/workflow/mixins/ex-form.js b/src/views/plugin/workflow/mixins/ex-form.js index d68a329..d582b96 100644 --- a/src/views/plugin/workflow/mixins/ex-form.js +++ b/src/views/plugin/workflow/mixins/ex-form.js @@ -1,4 +1,4 @@ -import { getFormByProcessId, getFormByProcessDefKey, startProcess, detail, completeTask, transferTask, delegateTask, rollbackTask, terminateProcess, addMultiInstance, withdrawTask } from '@/api/plugin/workflow/process' +import { getFormByProcessId, getFormByProcessDefKey, startProcess, startProcessByKey, detail, completeTask, transferTask, delegateTask, rollbackTask, terminateProcess, addMultiInstance, withdrawTask } from '@/api/plugin/workflow/process' import Layout from '@/page/index/' import defaultValues from './default-values' @@ -37,31 +37,31 @@ export default { processDefKey })).toString('base64') - if (formKey && formKey.startsWith('wf_ex_')) { - if (formUrl) { // 配置了自定义路由 - this.$router.push(formUrl + `?p=${param}`) - } else { // 动态添加路由 - this.$router.addRoutes([{ - path: `/workflow/process/external`, - component: Layout, - children: [{ - path: `${formKey.substring(6)}/${type}`, - name: type == 'start' ? '发起流程' : '流程详情', - component: () => - import( /* webpackChunkName: "views" */ `@/views/plugin/workflow/process/external/${formKey.substring(6)}/${type}.vue`), - }] - }]) - this.$router.push(`/workflow/process/external/${formKey.substring(6)}/${type}?p=${param}`) - } - } else { - if (async) { - return new Promise((resolve) => { - resolve({ row, type, param }) - }) + return new Promise((resolve) => { + if (formKey && formKey.startsWith('wf_ex_')) { + if (formUrl) { // 配置了自定义路由 + this.$router.push(formUrl + `?p=${param}`) + } else { // 动态添加路由 + this.$router.addRoutes([{ + path: `/workflow/process/external`, + component: Layout, + children: [{ + path: `${formKey.substring(6)}/${type}`, + name: type == 'start' ? '发起流程' : '流程详情', + component: () => + import( /* webpackChunkName: "views" */ `@/views/plugin/workflow/process/external/${formKey.substring(6)}/${type}.vue`), + }] + }]) + this.$router.push(`/workflow/process/external/${formKey.substring(6)}/${type}?p=${param}`) + } } else { - this.$router.push(`/workflow/process/${type}/${param}`) + if (async) { + resolve({ row, type, param }) + } else { + this.$router.push(`/workflow/process/${type}/${param}`) + } } - } + }) }, // 根据可读可写,过滤avue column filterAvueColumn(column, taskForm, isExForm = false, props = { label: 'label', prop: 'prop' }) { @@ -74,15 +74,8 @@ export default { column.forEach(col => { let c = taskForm.find(s => s.id == col[props.prop]) if (c && c.readable) { - // /** - // * @deprecated 与节点配置可读可写冲突 - // */ - // if (!c) { // 未重新点击节点设计表单字段可读可写。 - // if ((this.process.isOwner && this.process.status == 'todo') || !this.process.hasOwnProperty('isOwner')) c = { readable: true, writable: true } - // else c = { readable: true, writable: false } - // } if (!isExForm) { // 非外置表单 处理事件 - let event = ['change', 'blur', 'click', 'focus'] + let event = ['change', 'blur', 'click', 'focus', 'lazyLoad'] event.forEach(e => { if (col[e]) col[e] = eval((col[e] + '').replace(/this/g, '_this')) }) @@ -168,9 +161,48 @@ export default { form = { ...form, copyUser, assignee } } if (valid) { - startProcess(form).then(() => { + startProcess(form).then(res => { + if (isExForm === true) { + resolve(res, done) + } else { + this.$message.success("发起成功") + this.handleCloseTag('/plugin/workflow/process/send') + done() + this.loading = false + } + }).catch(() => { + done() + this.loading = false + }) + } else { + done() + this.loading = false + if (msg) { + const key = Object.keys(msg)[0] + const rules = msg[key] + this.$message.error(rules.map(r => r.message).join(' | ')) + } + } + }) + }) + }, + /** + * 发起流程 + * @param form {"processDefKey": "流程定义key", ...表单自定义字段变量} + */ + handleStartProcessByKey(isExForm = false) { + return new Promise((resolve) => { + this.loading = true + this.$refs.form.validate((valid, done, msg) => { + let form = this.deepClone(this.form) + if (this.$refs.examineForm && this.$refs.examineForm.examineForm) { + const { copyUser, assignee } = this.$refs.examineForm.examineForm + form = { ...form, copyUser, assignee } + } + if (valid) { + startProcessByKey(form).then(res => { if (isExForm === true) { - resolve(done) + resolve(res, done) } else { this.$message.success("发起成功") this.handleCloseTag('/plugin/workflow/process/send')