@ -43,12 +43,7 @@
< el -col :span ="8" >
< el -col :span ="8" >
< el -form -item label = "润滑级别" prop = "lubeLevel" >
< el -form -item label = "润滑级别" prop = "lubeLevel" >
< el -select v -model = " form.lubeLevel " placeholder = "润滑级别" disabled >
< el -select v -model = " form.lubeLevel " placeholder = "润滑级别" disabled >
< el -option
< el -option v-for ="dict in lube_level" :key="dict.value" :label="dict.label" :value="dict.value" > < / el -option >
v - for = "dict in lube_level"
: key = "dict.value"
: label = "dict.label"
: value = "dict.value" >
< / e l - o p t i o n >
< / e l - s e l e c t >
< / e l - s e l e c t >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
@ -65,50 +60,30 @@
< / e l - r o w >
< / e l - r o w >
<!-- 中间步骤 ( 已处理的后续节点 ) -- >
<!-- 中间步骤 ( 已处理的后续节点 ) -- >
< template v-for =" ( activity) in dmsBillsLubeInstanceActivityList" :key="activity.instanceActivityId">
< template v-for =" activity in dmsBillsLubeInstanceActivityList" :key="activity.instanceActivityId">
< div v-if ="activity.processStepOrder && activity.processStepOrder > 1" >
< div v-if ="activity.processStepOrder && activity.processStepOrder > 1" >
< h4 class = "form-header h4" > { { ` 已处理节点:步骤 ${ activity . processStepOrder } ( 实际参数)` } } < / h4 >
< h4 class = "form-header h4" > { { ` 已处理节点:步骤 ${ activity . processStepOrder } ( ${ activity . processStepOrder === 2 ? ' 实际参数' : '工单完成' } ) ` } } < / h4 >
< el -row >
< el -row >
< el -col :span ="8" >
< el -col :span ="8" >
< el -form -item label = "润滑级别" >
< el -form -item label = "润滑级别" >
< el -select
< el -select v -model = " activity.lubeLevel " placeholder = "润滑级别" disabled >
v - model = "activity.lubeLevel"
< el -option v-for ="dict in lube_level" :key="dict.value" :label="dict.label" :value="dict.value" > < / el -option >
placeholder = "润滑级别"
disabled >
< el -option
v - for = "dict in lube_level"
: key = "dict.value"
: label = "dict.label"
: value = "dict.value" >
< / e l - o p t i o n >
< / e l - s e l e c t >
< / e l - s e l e c t >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< el -col :span ="8" >
< el -col :span ="8" >
< el -form -item label = "润滑组别" >
< el -form -item label = "润滑组别" >
< el -input
< el -input v-model ="activity.lubeGroup" disabled placeholder="润滑组别" > < / el -input >
v - model = "activity.lubeGroup"
disabled
placeholder = "润滑组别" >
< / e l - i n p u t >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< el -col :span ="8" >
< el -col :span ="8" >
< el -form -item label = "润滑负责人" >
< el -form -item label = "润滑负责人" >
< el -input
< el -input v-model ="activity.lubeSupervisor" disabled placeholder="润滑负责人" > < / el -input >
v - model = "activity.lubeSupervisor"
disabled
placeholder = "润滑负责人" >
< / e l - i n p u t >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< el -col :span ="24" >
< el -col :span ="24" >
< el -form -item label = "处理意见" >
< el -form -item label = "处理意见" >
< el -input
< el -input v-model ="activity.processHandleResolution" disabled placeholder="处理意见" > < / el -input >
v - model = "activity.processHandleResolution"
disabled
placeholder = "处理意见" >
< / e l - i n p u t >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< / e l - r o w >
< / e l - r o w >
@ -117,40 +92,51 @@
<!-- 当前步骤表单 ( 用于提交新节点 ) -- >
<!-- 当前步骤表单 ( 用于提交新节点 ) -- >
< div v-if ="isUpdate" >
< div v-if ="isUpdate" >
< h4 class = "form-header h4" > 当前处理节点 : 步骤 { { nextStepOrder } } { { nextStepOrder === 2 ? '(实际参数)' : '' } } < / h4 >
< h4 class = "form-header h4" >
{ {
isCreatingWorkflow && dmsBillsLubeInstanceActivityList . length === 0
? ` 创建工单: 步骤1( 要求参数) `
: ` 当前处理节点:步骤 ${ nextStepOrder } ${ nextStepOrder === 2 ? '(实际参数)' : nextStepOrder === 3 ? '(工单完成)' : '' } `
} }
< / h4 >
< el -form ref = "nextStepFormRef" :model ="nextStepForm" :rules ="nextStepFormRules" label -width = " 100px " >
< el -form ref = "nextStepFormRef" :model ="nextStepForm" :rules ="nextStepFormRules" label -width = " 100px " >
< el -row >
< el -row >
< el -col :span ="8" >
< el -col :span ="8" >
< el -form -item label = "润滑级别" prop = "lubeLevel" >
< el -form -item label = "润滑级别" prop = "lubeLevel" >
< el -select v-model ="nextStepForm.lubeLevel" placeholder="润滑级别" >
< el -select v-model ="nextStepForm.lubeLevel" placeholder="润滑级别" :disabled="nextStepOrder === 3" >
< el -option
< el -option v-for ="dict in lube_level" :key="dict.value" :label="dict.label" :value="dict.value" > < / el -option >
v - for = "dict in lube_level"
: key = "dict.value"
: label = "dict.label"
: value = "dict.value" >
< / e l - o p t i o n >
< / e l - s e l e c t >
< / e l - s e l e c t >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< el -col :span ="8" >
< el -col :span ="8" >
< el -form -item label = "润滑组别" prop = "lubeGroup" >
< el -form -item label = "润滑组别" prop = "lubeGroup" >
< el -input v-model ="nextStepForm.lubeGroup" placeholder="润滑组别" > < / el -input >
< el -input v-model ="nextStepForm.lubeGroup" placeholder="润滑组别" :disabled="nextStepOrder === 3" > < / el -input >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< el -col :span ="8" >
< el -col :span ="8" >
< el -form -item label = "润滑负责人" prop = "lubeSupervisor" >
< el -form -item label = "润滑负责人" prop = "lubeSupervisor" >
< el -input v-model ="nextStepForm.lubeSupervisor" placeholder="润滑负责人" > < / el -input >
< el -input v-model ="nextStepForm.lubeSupervisor" placeholder="润滑负责人" :disabled="nextStepOrder === 3" > < / el -input >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< el -col :span ="24" v-if =" nextStepOrder > 1 ">
< el -col :span ="24" v-if =" !(isCreatingWorkflow && dmsBillsLubeInstanceActivityList.length === 0) ">
< el -form -item label = "处理意见" prop = "processHandleResolution" >
< el -form -item label = "处理意见" prop = "processHandleResolution" >
< el -input v-model ="nextStepForm.processHandleResolution" placeholder="处理意见" > < / el -input >
< el -input v-model ="nextStepForm.processHandleResolution" placeholder="处理意见" > < / el -input >
< / e l - f o r m - i t e m >
< / e l - f o r m - i t e m >
< / e l - c o l >
< / e l - c o l >
< el -col :span ="24" class = "text-center mt-4" >
< el -col :span ="24" class = "text-center mt-4" >
< el -button type = "primary" @click ="submitForm" > 提 交 < / el -button >
< el -button
< el -button v -if = " billsInfo & & billsInfo.lubeInstanceId ! = = null & & billsInfo.status ! = = ' draft ' " type = 'primary'
type = "primary"
@ click = 'handleApprovalRecord' >
@ click = "submitForm"
: loading = "buttonLoading"
: disabled = "buttonLoading || (!currentTaskId && !isCreatingWorkflow)"
>
{ { buttonText } }
< / e l - b u t t o n >
< el -button
v - if = "billsInfo && billsInfo.lubeInstanceId !== null && billsInfo.status !== 'draft'"
type = "primary"
@ click = "handleApprovalRecord"
>
流程进度
流程进度
< / e l - b u t t o n >
< / e l - b u t t o n >
< / e l - c o l >
< / e l - c o l >
@ -164,8 +150,7 @@
< el -card shadow = "never" >
< el -card shadow = "never" >
< h4 class = "form-header h4 text-center" > 润滑计划详细信息 < / h4 >
< h4 class = "form-header h4 text-center" > 润滑计划详细信息 < / h4 >
< el -table v-loading ="loading" :data ="planLubeDetail" >
< el -table v-loading ="loading" :data ="planLubeDetail" >
< el -table -column label = "计划ID" align = "center" prop = "planLubeId" / >
< el -table -column label = "设备名称" align = "center" prop = "machineName" / >
< el -table -column label = "设备名称" align = "center" prop = "deviceName" / >
< el -table -column label = "润滑部位" align = "center" prop = "lubeStationName" / >
< el -table -column label = "润滑部位" align = "center" prop = "lubeStationName" / >
< el -table -column label = "润滑标准" align = "center" prop = "lubeStandardCode" / >
< el -table -column label = "润滑标准" align = "center" prop = "lubeStandardCode" / >
< el -table -column label = "操作描述" align = "center" prop = "operationDescription" / >
< el -table -column label = "操作描述" align = "center" prop = "operationDescription" / >
@ -173,9 +158,9 @@
< / e l - c a r d >
< / e l - c a r d >
<!-- 提交组件 -- >
<!-- 提交组件 -- >
< submitVerify ref = 'submitVerifyRef' : task -variables = " taskVariables as any " @ submit -callback = ' submitCallback ' / >
< submitVerify ref = "submitVerifyRef" : task -variables = " taskVariables as any " @submit-callback ="submitCallback" @cancel-callback ="cancelCallback" / >
<!-- 审批记录 -- >
<!-- 审批记录 -- >
< approvalRecord ref = 'approvalRecordRef' / >
< approvalRecord ref = "approvalRecordRef" / >
< / div >
< / div >
< / template >
< / template >
@ -185,20 +170,24 @@ import { useRoute, useRouter } from 'vue-router';
import type { FormInstance , FormRules } from 'element-plus' ; / / 引 入 F o r m I n s t a n c e 和 F o r m R u l e s 类 型
import type { FormInstance , FormRules } from 'element-plus' ; / / 引 入 F o r m I n s t a n c e 和 F o r m R u l e s 类 型
import {
import {
listDmsBillsLubeInstanceActivity ,
listDmsBillsLubeInstanceActivity ,
addDmsBillsLubeInstanceActivity
addDmsBillsLubeInstanceActivity ,
updateDmsBillsLubeInstanceActivity
} from '@/api/dms/dmsBillsLubeInstanceActivity' ;
} from '@/api/dms/dmsBillsLubeInstanceActivity' ;
import {
import {
DmsBillsLubeInstanceActivityVO ,
DmsBillsLubeInstanceActivityVO ,
DmsBillsLubeInstanceActivityForm
DmsBillsLubeInstanceActivityForm
} from '@/api/dms/dmsBillsLubeInstanceActivity/types' ;
} from '@/api/dms/dmsBillsLubeInstanceActivity/types' ;
import { getDmsBillsLubeInstance } from '@/api/dms/dmsBillsLubeInstance' ;
import { getDmsBillsLubeInstance } from '@/api/dms/dmsBillsLubeInstance' ;
import { getDmsPlanLubeDetail } from '@/api/dms/dmsPlanLubeDetail' ;
import { getDmsPlanLubeDetail List } from '@/api/dms/dmsPlanLubeDetail' ;
import { DmsPlanLubeDetailVO } from "@/api/dms/dmsPlanLubeDetail/types" ;
import { DmsPlanLubeDetailVO } from "@/api/dms/dmsPlanLubeDetail/types" ;
/ / 引 入 工 作 流 相 关 组 件 和 A P I
/ / 引 入 工 作 流 相 关 组 件 和 A P I
import { startWorkFlow } from '@/api/workflow/task' ;
import { startWorkFlow , pageByTaskWait } from '@/api/workflow/task' ;
import { pageByCurrent } from '@/api/workflow/instance' ;
import SubmitVerify from '@/components/Process/submitVerify.vue' ;
import SubmitVerify from '@/components/Process/submitVerify.vue' ;
import ApprovalRecord from '@/components/Process/approvalRecord.vue' ;
import ApprovalRecord from '@/components/Process/approvalRecord.vue' ;
import { StartProcessBo } from '@/api/workflow/workflowCommon/types' ;
import { StartProcessBo } from '@/api/workflow/workflowCommon/types' ;
import { FlowInstanceQuery , FlowInstanceVO } from '@/api/workflow/instance/types' ;
import { TaskQuery , FlowTaskVO } from '@/api/workflow/task/types' ;
const { proxy } = getCurrentInstance ( ) as ComponentInternalInstance ;
const { proxy } = getCurrentInstance ( ) as ComponentInternalInstance ;
const { lube _level , process _handle _status } = toRefs < any > ( proxy ? . useDict ( 'lube_level' , 'process_handle_status' ) ) ;
const { lube _level , process _handle _status } = toRefs < any > ( proxy ? . useDict ( 'lube_level' , 'process_handle_status' ) ) ;
@ -229,6 +218,14 @@ const planLubeId = ref(''); // 润滑计划ID, 从工单信息中获取
const lubeInstanceId = route . params . lubeInstanceId as string ; / / 类 型 断 言
const lubeInstanceId = route . params . lubeInstanceId as string ; / / 类 型 断 言
const buttonLoading = ref ( false ) ;
const buttonLoading = ref ( false ) ;
/ / 新 增 状 态
const currentTaskId = ref < string | number | null > ( null ) ;
const isCreatingWorkflow = ref ( false ) ; / / t r u e 表 示 在 走 创 建 流 程 的 第 一 步 ( s t a r t W o r k F l o w )
const buttonText = ref ( '创建工单并提交' ) ;
/ / 暂 存 业 务 数 据 , 等 待 工 作 流 提 交 成 功 后 再 保 存
const pendingActivityData = ref < DmsBillsLubeInstanceActivityForm | null > ( null ) ;
/ / 计 算 下 一 步 序 号
/ / 计 算 下 一 步 序 号
const nextStepOrder = computed ( ( ) => {
const nextStepOrder = computed ( ( ) => {
return dmsBillsLubeInstanceActivityList . value . length + 1 ;
return dmsBillsLubeInstanceActivityList . value . length + 1 ;
@ -267,19 +264,19 @@ const nextStepFormRules = reactive<FormRules>({
lubeLevel : [ { required : true , message : "润滑级别不能为空" , trigger : "change" } ] ,
lubeLevel : [ { required : true , message : "润滑级别不能为空" , trigger : "change" } ] ,
lubeGroup : [ { required : true , message : "润滑组别不能为空" , trigger : "blur" } ] ,
lubeGroup : [ { required : true , message : "润滑组别不能为空" , trigger : "blur" } ] ,
lubeSupervisor : [ { required : true , message : "润滑负责人不能为空" , trigger : "blur" } ] ,
lubeSupervisor : [ { required : true , message : "润滑负责人不能为空" , trigger : "blur" } ] ,
/ / 处 理 意 见 仅在 第 二 步 及 以 后 验 证
/ / 处 理 意 见 的校 验 会 由 u p d a t e B u t t o n A n d F o r m S t a t e 动 态 设 置
processHandleResolution : [ { required : nextStepOrder . value > 1 , message : "处理意见不能为空" , trigger : "blur" } ] ,
processHandleResolution : [ { required : false , message : "处理意见不能为空" , trigger : "blur" } ] ,
} ) ;
} ) ;
/ / 查 询 参 数
/ / 查 询 参 数
const queryParams = reactive ( {
const queryParams = reactive ( {
pageNum : 1 ,
pageNum : 1 ,
pageSize : 50,
pageSize : 1 50,
lubeInstanceId : lubeInstanceId ,
lubeInstanceId : lubeInstanceId ,
} ) ;
} ) ;
/ / 初 始 化 数 据
/ / 初 始 化 数 据
onMounted ( ( ) => {
onMounted ( async ( ) => {
/ / 判 断 当 前 页 面 是 查 看 还 是 编 辑
/ / 判 断 当 前 页 面 是 查 看 还 是 编 辑
if ( route . name === 'childDmsBillsLubeInstanceActivity' ) {
if ( route . name === 'childDmsBillsLubeInstanceActivity' ) {
isUpdate . value = true ;
isUpdate . value = true ;
@ -287,23 +284,235 @@ onMounted(() => {
isUpdate . value = false ;
isUpdate . value = false ;
}
}
/ / 加 载 工 单 实 例 数 据
if ( isUpdate . value ) { / / 仅 在 编 辑 模 式 下 加 载 数 据 和 设 置 状 态
dmsBillsLubeInstance ( ) ;
await loadData ( ) ;
/ / 加 载 工 单 实 例 节 点 数 据
} else {
getList ( ) ;
/ / 查 看 模 式 也 需 要 加 载 工 单 信 息 和 已 处 理 节 点
await dmsBillsLubeInstance ( ) ;
await getList ( ) ;
loading . value = false ;
}
} ) ;
} ) ;
async function loadData ( ) {
loading . value = true ;
try {
/ / 先 清 除 表 单 验 证 状 态 , 避 免 在 数 据 加 载 过 程 中 触 发 不 必 要 的 表 单 验 证 错 误
if ( nextStepFormRef . value ) {
nextStepFormRef . value . clearValidate ( ) ;
}
await dmsBillsLubeInstance ( ) ;
await getList ( ) ; / / 获 取 已 处 理 节 点 会 影 响 n e x t S t e p O r d e r 和 n e x t S t e p F o r m 的 初 始 化
if ( dmsBillsLubeInstanceActivityList . value . length === 0 ) {
currentTaskId . value = null ;
isCreatingWorkflow . value = true ;
} else {
isCreatingWorkflow . value = false ;
currentTaskId . value = null ; / / 重 置 当 前 任 务 I D , 准 备 从 流 程 引 擎 获 取
const completedSteps = dmsBillsLubeInstanceActivityList . value . length ;
/ / 如 果 流 程 业 务 步 骤 少 于 3 步 ( 工 单 创 建 、 工 单 处 理 、 工 单 完 成 ) , 则 尝 试 获 取 当 前 活 动 任 务
if ( completedSteps < 3 ) {
proxy ? . $modal . loading ( "正在获取最新流程任务..." ) ;
let expectedNodeName = '' ;
if ( completedSteps === 1 ) expectedNodeName = '工单处理' ;
else if ( completedSteps === 2 ) expectedNodeName = '工单完成' ;
console . log ( ` [loadData] Attempting to find current task. Completed steps: ${ completedSteps } , Expected next node: ' ${ expectedNodeName } ' for businessId: ${ lubeInstanceId } ` ) ;
try {
let tasks : FlowTaskVO [ ] = [ ] ;
/ / 尝 试 使 用 期 望 的 节 点 名 称 进 行 精 确 查 找
if ( expectedNodeName ) {
const taskRes = await pageByTaskWait ( {
pageNum : 1 ,
pageSize : 10 , / / 通 常 特 定 业 务 I D 和 节 点 名 称 的 任 务 不 会 很 多
flowCode : 'Lube01' , / / 从 s u b m i t F o r m D a t a 获 取 或 确 认 此 编 码 正 确
nodeName : expectedNodeName
} ) ;
if ( taskRes . rows ) {
tasks = taskRes . rows . filter ( task => task . businessId === lubeInstanceId ) ;
if ( tasks . length > 0 ) {
console . log ( ` [loadData] Found ${ tasks . length } task(s) using specific nodeName ' ${ expectedNodeName } ' and businessId ' ${ lubeInstanceId } '. ` ) ;
} else {
console . log ( ` [loadData] No tasks found using specific nodeName ' ${ expectedNodeName } ' for businessId ' ${ lubeInstanceId } '. Will try broader search. ` ) ;
}
}
}
let foundTask : FlowTaskVO | undefined = tasks . length > 0 ? tasks [ 0 ] : undefined ; / / 如 果 有 多 个 , 暂 时 取 第 一 个
if ( tasks . length > 1 ) {
console . warn ( ` [loadData] Multiple tasks ( ${ tasks . length } ) found with specific nodeName ' ${ expectedNodeName } ' and businessId ' ${ lubeInstanceId } '. Using the first one found: ${ foundTask ? . id } . ` ) ;
}
/ / 如 果 未 通 过 特 定 节 点 名 称 找 到 , 则 尝 试 仅 通 过 f l o w C o d e 查 找 , 然 后 匹 配 b u s i n e s s I d
if ( ! foundTask ) {
console . log ( ` [loadData] Task not found with specific nodeName. Fetching all waiting tasks for flowCode 'Lube01' to filter by businessId ' ${ lubeInstanceId } '. ` ) ;
const taskResAll = await pageByTaskWait ( {
pageNum : 1 ,
pageSize : 50 , / / 获 取 更 多 任 务 以 便 筛 选
flowCode : 'Lube01'
} ) ;
if ( taskResAll . rows && taskResAll . rows . length > 0 ) {
const businessTasks = taskResAll . rows . filter ( task => task . businessId === lubeInstanceId ) ;
if ( businessTasks . length === 1 ) {
foundTask = businessTasks [ 0 ] ;
console . log ( ` [loadData] Found single task by businessId from all waiting tasks: ${ foundTask . id } , Node: ${ foundTask . nodeName } ` ) ;
} else if ( businessTasks . length > 1 ) {
console . warn ( ` [loadData] Multiple tasks ( ${ businessTasks . length } ) found for businessId ' ${ lubeInstanceId } ' from all waiting tasks. Attempting to match with expectedNodeName ' ${ expectedNodeName } '. ` ) ;
if ( expectedNodeName ) {
foundTask = businessTasks . find ( task => task . nodeName === expectedNodeName ) ;
}
if ( foundTask ) {
console . log ( ` [loadData] Matched task by expectedNodeName from multiple: ${ foundTask . id } ` ) ;
} else {
/ / F a l l b a c k : 如 果 仍 有 多 个 或 无 法 通 过 e x p e c t e d N o d e N a m e 匹 配 , 则 取 第 一 个 ( 或 记 录 更 严 重 的 警 告 )
foundTask = businessTasks [ 0 ] ;
console . warn ( ` [loadData] Could not specifically match by nodeName among multiple tasks for businessId ' ${ lubeInstanceId } '. Using the first one found: ${ foundTask ? . id } , Node: ${ foundTask ? . nodeName } . Review workflow design if this is not correct. ` ) ;
}
} else {
console . log ( ` [loadData] No tasks found for businessId ' ${ lubeInstanceId } ' even after broader search by flowCode 'Lube01'. ` ) ;
}
}
}
if ( foundTask ) {
currentTaskId . value = foundTask . id ;
console . log ( ` [loadData] Successfully set currentTaskId via pageByTaskWait to: ${ currentTaskId . value } (Node: ${ foundTask . nodeName } , BusinessID: ${ foundTask . businessId } ) ` ) ;
} else {
console . warn ( ` [loadData] No suitable waiting task found for businessId ${ lubeInstanceId } with flowCode Lube01. Button may show '暂无操作'. ` ) ;
}
} catch ( error ) {
console . error ( "[loadData] Error fetching current task via pageByTaskWait:" , error ) ;
proxy ? . $modal . msgError ( "获取最新流程任务失败" ) ;
} finally {
proxy ? . $modal . closeLoading ( ) ;
}
} else {
console . log ( "[loadData] All expected business steps completed (>=3) or initial creation. No active task to fetch from workflow via pageByTaskWait for middle steps." ) ;
}
}
updateButtonAndFormState ( ) ;
/ / 数 据 加 载 后 再 次 清 除 表 单 验 证 状 态 , 确 保 U I 渲 染 正 确
setTimeout ( ( ) => {
if ( nextStepFormRef . value ) {
nextStepFormRef . value . clearValidate ( ) ;
}
} , 100 ) ;
} catch ( error ) {
console . error ( "Failed to load initial data" , error ) ;
proxy ? . $modal . msgError ( "加载数据失败" ) ;
/ / 出 错 时 , 尝 试 恢 复 到 一 个 相 对 安 全 的 状 态
currentTaskId . value = null ;
isCreatingWorkflow . value = dmsBillsLubeInstanceActivityList . value . length === 0 ;
updateButtonAndFormState ( ) ;
} finally {
loading . value = false ;
}
}
function updateButtonAndFormState ( ) {
const activitiesCount = dmsBillsLubeInstanceActivityList . value . length ;
/ / 第 一 步 : 创 建 工 单 ( 工 单 创 建 )
if ( activitiesCount === 0 && isCreatingWorkflow . value ) {
buttonText . value = '创建工单并提交' ;
nextStepFormRules . processHandleResolution = [ { required : false , message : "处理意见不能为空" , trigger : "blur" } ] ;
/ / 清 理 n e x t S t e p F o r m
Object . assign ( nextStepForm , {
instanceActivityId : undefined , / / 重 置 I D
lubeInstanceId : lubeInstanceId , / / 确 保 l u b e I n s t a n c e I d 正 确
lubeGroup : undefined ,
lubeSupervisor : undefined ,
lubeLevel : undefined ,
processHandleResolution : undefined ,
processHandleStatus : undefined ,
processStepOrder : undefined ,
startTime : undefined ,
endTime : undefined ,
handleUserId : undefined ,
handleBy : undefined ,
handleTime : undefined ,
transferUserId : undefined ,
attr1 : undefined ,
remark : undefined ,
} ) ;
}
/ / 有 待 办 任 务 I D , 且 非 创 建 模 式
else if ( currentTaskId . value && ! isCreatingWorkflow . value ) {
const currentStepBasedOnActivities = activitiesCount + 1 ; / / 下 一 步 是 第 几 步
if ( currentStepBasedOnActivities === 2 ) {
/ / 第 二 步 : 工 单 处 理
buttonText . value = '工单处理' ;
nextStepFormRules . processHandleResolution = [ { required : true , message : "处理意见不能为空" , trigger : "blur" } ] ;
} else if ( currentStepBasedOnActivities === 3 ) {
/ / 第 三 步 : 工 单 完 成
buttonText . value = '工单完成' ;
nextStepFormRules . processHandleResolution = [ { required : true , message : "处理意见不能为空" , trigger : "blur" } ] ;
} else {
buttonText . value = '提交处理' ;
nextStepFormRules . processHandleResolution = [ { required : true , message : "处理意见不能为空" , trigger : "blur" } ] ;
}
if ( activitiesCount > 0 ) {
if ( currentStepBasedOnActivities === 3 ) {
/ / 第 三 步 应 复 制 第 一 步 的 数 据
const firstActivity = dmsBillsLubeInstanceActivityList . value [ 0 ] ;
Object . assign ( nextStepForm , {
instanceActivityId : undefined , / / 新 节 点 I D 为 空
lubeInstanceId : lubeInstanceId ,
lubeGroup : firstActivity . lubeGroup , / / 复 制 第 一 步 的 数 据
lubeSupervisor : firstActivity . lubeSupervisor , / / 复 制 第 一 步 的 数 据
lubeLevel : firstActivity . lubeLevel , / / 复 制 第 一 步 的 数 据
processHandleResolution : '' , / / 清 空 处 理 意 见
remark : '' , / / 清 空 备 注
processHandleStatus : undefined ,
processStepOrder : undefined ,
} ) ;
} else {
/ / 其 他 步 骤 使 用 最 后 一 个 节 点 的 数 据
const lastActivity = dmsBillsLubeInstanceActivityList . value [ activitiesCount - 1 ] ;
Object . assign ( nextStepForm , {
instanceActivityId : undefined , / / 新 节 点 I D 为 空
lubeInstanceId : lubeInstanceId ,
lubeGroup : lastActivity . lubeGroup ,
lubeSupervisor : lastActivity . lubeSupervisor ,
lubeLevel : lastActivity . lubeLevel ,
processHandleResolution : '' , / / 清 空 处 理 意 见
remark : '' , / / 清 空 备 注
processHandleStatus : undefined ,
processStepOrder : undefined ,
} ) ;
}
} else { / / 有 c u r r e n t T a s k I d 但 没 有 历 史 活 动 , 这 通 常 不 应 该 发 生 , 但 为 了 健 壮 性 处 理
Object . assign ( nextStepForm , {
instanceActivityId : undefined ,
lubeInstanceId : lubeInstanceId ,
processHandleResolution : '' ,
remark : '' ,
} ) ;
}
} else { / / 没 有 待 办 任 务 ( 可 能 已 结 束 、 非 处 理 人 打 开 、 或 查 看 模 式 ) 或 状 态 不 明 确
buttonText . value = '暂无操作' ;
if ( isUpdate . value ) { / / 如 果 是 编 辑 模 式 但 无 操 作 , 则 禁 用 提 交 相 关 的 校 验
nextStepFormRules . processHandleResolution = [ { required : false } ] ;
}
}
}
/ / 获 取 工 单 实 例 数 据
/ / 获 取 工 单 实 例 数 据
const dmsBillsLubeInstance = async ( ) => {
const dmsBillsLubeInstance = async ( ) => {
/ / c o n s t r e s = a w a i t l i s t D m s B i l l s L u b e I n s t a n c e ( q u e r y P a r a m s ) ;
/ / b i l l s I n f o . v a l u e = r e s . r o w s [ 0 ] ;
const _lubeInstanceId = lubeInstanceId ;
const _lubeInstanceId = lubeInstanceId ;
const res = await getDmsBillsLubeInstance ( _lubeInstanceId ) ;
const res = await getDmsBillsLubeInstance ( _lubeInstanceId ) ;
billsInfo . value = res . data ;
billsInfo . value = res . data ;
/ / 确 保 p l a n L u b e I d 是 字 符 串 类 型
/ / 确 保 p l a n L u b e I d 是 字 符 串 类 型
/ / c o n s t l u b e I d F r o m S e r v e r = r e s . r o w s [ 0 ] . p l a n L u b e I d ;
const lubeIdFromServer = res . data . planLubeId ;
const lubeIdFromServer = res . data . planLubeId ;
planLubeId . value = typeof lubeIdFromServer === 'number' ? String ( lubeIdFromServer ) : lubeIdFromServer ;
planLubeId . value = typeof lubeIdFromServer === 'number' ? String ( lubeIdFromServer ) : lubeIdFromServer ;
@ -325,13 +534,8 @@ const dmsBillsLubeInstance = async () => {
const getPlanLubeDetailData = async ( ) => {
const getPlanLubeDetailData = async ( ) => {
if ( ! planLubeId . value ) return ;
if ( ! planLubeId . value ) return ;
loading . value = true ;
loading . value = true ;
try {
const res = await getDmsPlanLubeDetailList ( { planLubeId : planLubeId . value } ) ;
const res = await getDmsPlanLubeDetail ( planLubeId . value ) ;
planLubeDetail . value = res . data ;
planLubeDetail . value = res && res . rows ? [ res . rows ] : [ ] ;
} catch ( error ) {
console . error ( '获取润滑计划详情失败' , error ) ;
proxy ? . $modal . msgError ( "获取润滑计划详情失败" ) ;
}
} ;
} ;
/ / 获 取 工 单 实 例 节 点 数 据
/ / 获 取 工 单 实 例 节 点 数 据
@ -360,8 +564,18 @@ const getList = async () => {
processHandleResolution : null , / / 第 二 步 需 要 填 写 处 理 意 见
processHandleResolution : null , / / 第 二 步 需 要 填 写 处 理 意 见
remark : ''
remark : ''
} ) ;
} ) ;
} else if ( nextStepOrder . value > 2 ) {
} else if ( nextStepOrder . value === 3 ) {
/ / 第 三 步 及 以 后 , 使 用 最 后 一 个 节 点 的 数 据
/ / 第 三 步 , 复 制 第 一 步 的 润 滑 组 别 和 润 滑 负 责 人
const firstActivity = res . rows [ 0 ] ;
Object . assign ( nextStepForm , {
lubeGroup : firstActivity . lubeGroup , / / 复 制 第 一 步 数 据
lubeSupervisor : firstActivity . lubeSupervisor , / / 复 制 第 一 步 数 据
lubeLevel : firstActivity . lubeLevel , / / 复 制 第 一 步 数 据
processHandleResolution : null , / / 清 空 处 理 意 见
remark : ''
} ) ;
} else if ( nextStepOrder . value > 3 ) {
/ / 第 四 步 及 以 后 , 使 用 最 后 一 个 节 点 的 数 据 ( 正 常 不 会 有 这 种 情 况 )
const lastActivity = res . rows [ res . rows . length - 1 ] ;
const lastActivity = res . rows [ res . rows . length - 1 ] ;
Object . assign ( nextStepForm , {
Object . assign ( nextStepForm , {
lubeGroup : lastActivity . lubeGroup ,
lubeGroup : lastActivity . lubeGroup ,
@ -400,52 +614,98 @@ const getList = async () => {
/ / 提 交 表 单
/ / 提 交 表 单
const submitForm = async ( ) => {
const submitForm = async ( ) => {
if ( ! nextStepFormRef . value ) return ;
if ( ! nextStepFormRef . value ) return ;
await nextStepFormRef . value . validate ( async ( valid ) => {
try {
/ / 清 空 之 前 的 错 误 状 态
buttonLoading . value = false ;
pendingActivityData . value = null ;
/ / 触 发 一 次 校 验 更 新 , 确 保 最 新 的 r u l e s 生 效
nextStepFormRef . value . clearValidate ( ) ;
const valid = await nextStepFormRef . value . validate ( ) . catch ( errors => {
console . error ( "表单验证错误:" , errors ) ;
return false ;
} ) ;
if ( valid ) {
if ( valid ) {
buttonLoading . value = true ;
try {
try {
buttonLoading . value = true ;
nextStepForm . processStepOrder = dmsBillsLubeInstanceActivityList . value . length + 1 ;
/ / 设 置 流 程 步 骤 顺 序
nextStepForm . processStepOrder = nextStepOrder . value ;
nextStepForm . lubeInstanceId = lubeInstanceId ;
nextStepForm . lubeInstanceId = lubeInstanceId ;
/ / 在 第 一 步 时 不 需 要 处 理 意 见
/ / 确保 处 理 意 见 有 值 , 避 免 数 据 库 N O T N U L L 约 束 异 常
if ( nextStepOrder . value === 1 ) {
if ( nextStep Form. processHandleResolution === undefined || nextStepForm . processHandleResolution === null ) {
nextStepForm . processHandleResolution = null ;
nextStepForm . processHandleResolution = '' ;
}
}
/ / 提 交
/ / 复制 一 份 表 单 数 据 用 于 后 续 保 存
const res = await addDmsBillsLubeInstanceActivity ( nextStepForm ) ;
pendingActivityData . value = JSON . parse ( JSON . stringify ( nextStepForm ) ) ;
/ / 启 动 工 作 流
/ / 将 当 前 表 单 的 数 据 放 入 流 程 变 量 - 仅 传 递 简 单 必 要 字 段 而 不 是 整 个 对 象
await handleStartWorkFlow ( res . data ) ;
taskVariables . value = {
entity : {
lubeInstanceId : pendingActivityData . value . lubeInstanceId ,
lubeGroup : pendingActivityData . value . lubeGroup ,
lubeSupervisor : pendingActivityData . value . lubeSupervisor ,
lubeLevel : pendingActivityData . value . lubeLevel ,
processHandleResolution : pendingActivityData . value . processHandleResolution ,
processStepOrder : pendingActivityData . value . processStepOrder
}
} ;
} catch ( error ) {
if ( isCreatingWorkflow . value && dmsBillsLubeInstanceActivityList . value . length === 0 ) {
console . error ( '提交失败' , error ) ;
/ / 步 骤 一 : 创 建 工 单 , 启 动 工 作 流
proxy ? . $modal . msgError ( "提交失败,请检查数据或联系管理员" ) ;
submitFormData . value . businessId = lubeInstanceId ;
submitFormData . value . variables = taskVariables . value ;
console . log ( "[submitForm] 开始启动工作流, businessId:" , lubeInstanceId ) ;
const workflowRes = await startWorkFlow ( submitFormData . value ) ;
if ( ! workflowRes || ! workflowRes . data || ! workflowRes . data . taskId ) {
buttonLoading . value = false ;
throw new Error ( "工作流启动失败, 未能获取有效的任务ID" ) ;
}
console . log ( "[submitForm] 工作流启动成功, taskId:" , workflowRes . data . taskId ) ;
if ( submitVerifyRef . value ) {
buttonLoading . value = false ; / / o p e n D i a l o g 前 重 置 l o a d i n g
submitVerifyRef . value . openDialog ( String ( workflowRes . data . taskId ) ) ;
} else {
buttonLoading . value = false ;
throw new Error ( "提交流程组件不可用" ) ;
}
} else if ( currentTaskId . value && ! isCreatingWorkflow . value ) {
/ / 第 二 步 或 第 三 步 : 处 理 工 作 流 节 点
console . log ( "[submitForm] 处理工作流节点, taskId:" , currentTaskId . value ) ;
if ( submitVerifyRef . value ) {
buttonLoading . value = false ;
submitVerifyRef . value . openDialog ( String ( currentTaskId . value ) ) ;
} else {
buttonLoading . value = false ;
throw new Error ( "提交流程组件不可用" ) ;
}
} else {
buttonLoading . value = false ;
throw new Error ( "未知的提交流程状态或没有待办任务ID" ) ;
}
} catch ( error : any ) {
buttonLoading . value = false ;
buttonLoading . value = false ;
pendingActivityData . value = null ; / / 出 错 时 清 空 待 处 理 数 据
console . error ( '[submitForm] 提交失败:' , error ) ;
proxy ? . $modal . msgError ( error . message || "提交失败,请检查数据或联系管理员" ) ;
}
}
} else {
} else {
buttonLoading . value = false ;
proxy ? . $modal . msgError ( "表单校验失败,请检查输入项" ) ;
proxy ? . $modal . msgError ( "表单校验失败,请检查输入项" ) ;
}
}
} ) ;
} catch ( error ) {
} ;
/ / 启 动 工 作 流
const handleStartWorkFlow = async ( data : any ) => {
try {
submitFormData . value . businessId = lubeInstanceId ;
/ / 流 程 变 量
taskVariables . value = {
entity : data
} ;
submitFormData . value . variables = taskVariables . value ;
const resp = await startWorkFlow ( submitFormData . value ) ;
if ( submitVerifyRef . value ) {
buttonLoading . value = false ;
submitVerifyRef . value . openDialog ( resp . data . taskId ) ;
}
} finally {
buttonLoading . value = false ;
buttonLoading . value = false ;
console . error ( '[submitForm] 意外错误:' , error ) ;
proxy ? . $modal . msgError ( "表单提交过程中发生错误" ) ;
}
}
} ;
} ;
@ -455,9 +715,73 @@ const handleApprovalRecord = () => {
} ;
} ;
/ / 提 交 回 调
/ / 提 交 回 调
const submitCallback = async ( ) => {
const submitCallback = async ( /* success?: boolean, nextTaskId?: string | number | null */ ) => {
await getList ( ) ; / / 刷 新 列 表 获 取 最 新 节 点
/ / s u c c e s s 和 n e x t T a s k I d 参 数 在 此 被 注 释 掉 或 忽 略 ,
proxy ? . $modal . msgSuccess ( "操作成功" ) ;
/ / 因 为 s u b m i t V e r i f y . v u e 组 件 的 s u b m i t C a l l b a c k 事 件 没 有 传 递 这 些 参 数 ,
/ / 导 致 它 们 在 父 组 件 中 始 终 是 u n d e f i n e d 。
console . log ( '[submitCallback] Invoked.' ) ;
try {
if ( pendingActivityData . value ) {
/ / 当 s u b m i t C a l l b a c k 被 调 用 , 我 们 假 定 s u b m i t V e r i f y . v u e 中 的 工 作 流 步 骤 已 被 尝 试 。
/ / 现 在 , 我 们 尝 试 保 存 业 务 数 据 。
const activityRes = await addDmsBillsLubeInstanceActivity ( pendingActivityData . value ) ;
console . log ( "[submitCallback] Business data saved successfully:" , activityRes . data ) ;
/ / 根 据 已 暂 存 的 待 处 理 活 动 数 据 的 步 骤 顺 序 来 判 断 当 前 完 成 的 是 哪 个 步 骤
const stepOrderOfSavedData = pendingActivityData . value . processStepOrder ;
if ( stepOrderOfSavedData === 1 ) {
proxy ? . $modal . msgSuccess ( "工单创建数据已保存,流程已流转。" ) ;
} else if ( stepOrderOfSavedData === 2 ) {
proxy ? . $modal . msgSuccess ( "工单处理数据已保存,流程已流转。" ) ;
} else if ( stepOrderOfSavedData === 3 ) {
proxy ? . $modal . msgSuccess ( "工单完成数据已保存,工作流已结束。" ) ;
/ / 流 程 结 束 后 , c u r r e n t T a s k I d 应 该 在 l o a d D a t a 后 变 为 n u l l
} else {
/ / 这 是 一 个 通 用 回 退 , 理 论 上 不 应 发 生 , 因 为 步 骤 是 明 确 的 1 , 2 , 或 3
proxy ? . $modal . msgSuccess ( "业务数据已保存,操作已继续。" ) ;
}
/ / 注 意 : 实 际 的 下 一 个 任 务 I D ( c u r r e n t T a s k I d ) 将 由 后 续 的 l o a d D a t a ( ) 调 用 来 确 定 和 更 新 。
} else {
/ / 如 果 p e n d i n g A c t i v i t y D a t a . v a l u e 为 n u l l ,
/ / 这 可 能 意 味 着 s u b m i t F o r m 未 能 正 确 设 置 它 , 或 者 是 一 个 取 消 操 作 。
/ / s u b m i t V e r i f y . v u e 的 内 部 " 操 作 成 功 " 消 息 可 能 已 经 显 示 。
/ / 此 处 我 们 不 应 再 显 示 一 个 全 局 的 错 误 , 除 非 我 们 能 确 定 这 是 一 个 未 预 期 的 状 态 。
console . warn ( "[submitCallback] pendingActivityData was null upon callback. This might be normal if a cancel operation occurred or submitForm failed before calling workflow." ) ;
}
} catch ( error ) {
console . error ( '[submitCallback] Error saving business data:' , error ) ;
/ / 这 是 一 个 严 重 问 题 : 工 作 流 可 能 已 推 进 , 但 业 务 数 据 未 能 保 存 。
proxy ? . $modal . msgError ( "关键错误:业务数据保存失败!工作流可能已推进,请紧急核查数据一致性。" ) ;
} finally {
/ / 重 置 加 载 和 工 作 流 创 建 状 态
buttonLoading . value = false ;
/ / 一 旦 提 交 尝 试 发 生 ( 无 论 成 功 与 否 ) , 就 不 再 是 " 正 在 创 建 工 作 流 " 的 初 始 状 态 了 。
/ / i s C r e a t i n g W o r k f l o w 的 状 态 将 在 l o a d D a t a 完 成 后 , 根 据 实 际 的 活 动 列 表 长 度 被 重 新 评 估 。
/ / i s C r e a t i n g W o r k f l o w . v a l u e = f a l s e ; / / 暂 时 注 释 掉 , 让 l o a d D a t a 来 决 定
pendingActivityData . value = null ; / / 清 空 暂 存 的 业 务 数 据
/ / 重 新 加 载 数 据 以 反 映 工 作 流 的 最 新 状 态 和 更 新 U I
if ( isUpdate . value ) {
try {
console . log ( "[submitCallback] Reloading data to reflect current workflow state..." ) ;
await loadData ( ) ; / / l o a d D a t a 会 更 新 c u r r e n t T a s k I d , d m s B i l l s L u b e I n s t a n c e A c t i v i t y L i s t , 和 按 钮 状 态 等 。
console . log ( "[submitCallback] Data reloaded. Current Task ID is now:" , currentTaskId . value ) ;
} catch ( loadError ) {
console . error ( '[submitCallback] Failed to reload data post-submission attempt:' , loadError ) ;
proxy ? . $modal . msgError ( "数据刷新失败,请手动刷新页面以查看最新状态。" ) ;
}
}
}
} ;
/ / 取 消 回 调
const cancelCallback = ( ) => {
console . log ( '[cancelCallback] 用户取消了操作' ) ;
pendingActivityData . value = null ; / / 清 空 待 保 存 数 据
buttonLoading . value = false ;
} ;
} ;
< / script >
< / script >