| 1 |
- import{t as H,R as te,K as pe,E as N}from"./index.DxJKo3PQ.js";import{U as ue,A as me,a as _e,b as oe,D as ce}from"./api.CPPHJzir.js";import{a as fe,r as K,w as Q,_ as L,t as ge,aj as c,J as D,o as v,K as l,S as t,b as q,P as b,c as j,a9 as F,R,M as O,Q as ye,u as W}from"./vue.D1BjjNmv.js";import{_ as ve}from"./_plugin-vue_export-helper.DlAUqK2U.js";function we(){return H({url:"/api/system/device/category/",method:"get"})}function be(){return H({url:"/api/system/app_user/?user_type=3",method:"get"})}function Ve(G){return H({url:"/api/system/approval/workflow_step/?workflow_id="+G,method:"get"})}const ke={class:"workflow-steps"},qe={class:"workflow-step"},he={class:"step-title"},xe={class:"step-roles"},$e={style:{"text-align":"center",margin:"16px 0"}},Ue={class:"workflow-step"},Se=fe({__name:"index",props:{visible:{type:Boolean},editData:{},mode:{}},emits:["update:visible","success"],setup(G,{emit:le}){const g=G,X=le,T=K(g.visible);Q(()=>g.visible,r=>T.value=r),Q(T,r=>X("update:visible",r));const J=L([]);be().then(r=>{const e=r.data||[];J.splice(0,J.length,...e)}).catch(r=>{console.error("请求失败:",r)});const M=L([]);we().then(r=>{const e=r.data||[];console.log("获取到的data值:",e),M.splice(0,M.length,...e)}).catch(r=>{console.error("请求失败:",r)});const ae=()=>({name:"",passType:"",leaderId:null}),E=()=>({roles:[ae()]}),o=L({name:"",scene:"",workflow_type:"0",description:"",is_active:!0,condition:{min_days:1,max_days:null,roles:[],equipment:[],borrow_types:[],team_type:[]},steps:[E()]}),P=L({name:[{required:!0,message:"请输入流程名称",trigger:"blur"}],workflow_type:[{required:!0,message:"请选择流程类型",trigger:"change"}],description:[{required:!0,message:"请输入流程描述",trigger:"blur"}],is_active:[{required:!0,message:"请输选择是否启用",trigger:"blur"}],"condition.min_days":[{required:!0,message:"请输入最少借用天数",trigger:"change"}],"condition.max_days":[{required:!1,validator:(r,e,m)=>{const i=o.condition.min_days;return e==null||e===void 0||e===""?m():typeof e=="number"&&typeof i=="number"&&e<i?m(new Error("最多借用天数不能小于最少借用天数")):m()},trigger:"change"}],"condition.roles":[{required:!0,message:"请选择用户角色",trigger:"change"}],"condition.equipment":[{required:!1,message:"请选择设备标签",trigger:"change"}],"condition.borrow_types":[{required:!0,message:"请选择借用类型",trigger:"change"}],"condition.team_type":[{required:!0,message:"请选择借用方式",trigger:"change"}]}),Y=K();function Z(){o.steps.forEach((r,e)=>{r.roles.forEach((m,i)=>{P[`steps.${e}.roles.${i}.name`]=[{required:!0,message:"请选择角色",trigger:"change"}],P[`steps.${e}.roles.${i}.passType`]=[{required:!0,message:"请选择通过条件",trigger:"change"}]})})}const I=K([]);Q(()=>g.editData,async r=>{var e,m,i,f,y,h;if(console.log("编辑时获取到的值val:",r),r){const p=JSON.parse(JSON.stringify(r));o.name=p.name||"",o.scene=p.scene||"",o.workflow_type=String(p.workflow_type??"0"),o.description=p.description||"",o.is_active=p.is_active??!0;const x=p.trigger_conditions||{};o.condition={min_days:(m=(e=p.duration_rules)==null?void 0:e[0])==null?void 0:m.min_days,max_days:(f=(i=p.duration_rules)==null?void 0:i[0])==null?void 0:f.max_days,roles:x.user_types||[],equipment:Array.isArray(x.equipment_categories)?x.equipment_categories[0]:"",borrow_types:Array.isArray((h=(y=p.duration_rules)==null?void 0:y[0])==null?void 0:h.borrow_types)?p.duration_rules[0].borrow_types.map(u=>String(u)):[],team_type:Array.isArray(x.team_type)?x.team_type.map(u=>String(u)):[]};const U=await Ve(p.id);if(console.log("workflowSteps",U),U&&U.data){const u=U.data.sort((d,C)=>(d.step_order||0)-(C.step_order||0));I.value=u.map(d=>d.id),o.steps=u.map(d=>({roles:[{name:d.step_name||"",passType:String(d.step_type??"1"),leaderId:d.app_approvers&&d.app_approvers.length>0?Array.isArray(d.app_approvers)?d.app_approvers[0]:d.app_approvers:d.app_approver_names&&d.app_approver_names.length>0?d.app_approver_names[0]:null}]}))}else I.value=[],o.steps=[E()];Z()}else I.value=[],o.name="",o.scene="",o.workflow_type="0",o.description="",o.is_active=!0,o.condition={min_days:1,max_days:null,roles:[],equipment:[],borrow_types:[],team_type:[]},o.steps=[E()];Z(),await ge()},{immediate:!0});function se(){if(o.steps.length>=5){N.warning("最多只能添加 5 个审批步骤");return}o.steps.push(E())}function re(r){o.steps.length>1&&o.steps.splice(r,1)}function ne(r,e){o.steps[r].roles.length>1&&o.steps[r].roles.splice(e,1)}function ee(){T.value=!1}const ie={管理员:1,指导老师:2};async function de(){var i,f,y,h,p,x,U,u,d,C,A;try{await((i=Y.value)==null?void 0:i.validate())}catch(n){console.warn("表单验证失败:",n);return}const r=!!g.editData,e={name:o.name,workflow_type:o.workflow_type,description:o.description,is_active:typeof o.is_active=="boolean"?o.is_active:!0,trigger_conditions:{min_days:((f=o.condition)==null?void 0:f.min_days)??0,max_days:((y=o.condition)==null?void 0:y.max_days)??null,equipment_categories:(h=o.condition)!=null&&h.equipment?[o.condition.equipment]:[],borrow_types:(x=(p=o.condition)==null?void 0:p.borrow_types)!=null&&x.length?o.condition.borrow_types:[],team_type:(u=(U=o.condition)==null?void 0:U.team_type)!=null&&u.length?o.condition.team_type:[],user_types:(C=(d=o.condition)==null?void 0:d.roles)!=null&&C.length?o.condition.roles:[],require_approval:!0}};let m="";if(r){m=g.editData.id;const n=await ue(Number(m),e);if(console.log("流程更新结果:",n),!n||n.code!==2e3){N.error((n==null?void 0:n.msg)||"编辑流程失败");return}}else{const n=await me(e);if(m=(A=n==null?void 0:n.data)==null?void 0:A.id,!m){N.error("新增未能获取流程 ID");return}}for(let n=0;n<o.steps.length;n++){const V=o.steps[n],S=n+1,B=V.roles.map(a=>a.name).filter(Boolean),z=V.roles.map(a=>a.passType).filter(Boolean),s=V.roles.map(a=>a.leaderId).filter(a=>!!a).map(a=>typeof a=="string"&&a.includes(",")?a.split(",").map(_=>parseInt(_.trim())).filter(_=>!isNaN(_)):typeof a=="number"?[a]:[parseInt(String(a))].filter(_=>!isNaN(_))).flat(),k=z[0]||"1",$=B.map(a=>ie[a]).filter(Boolean),w={step_name:B.join(",")||`审批步骤${S}`,step_order:S,step_type:k,description:`由${B.join(",")}进行审批`,approvers:[1],app_approvers:s.length>0?s:[],approver_roles:$,approver_depts:[],approval_conditions:{required_fields:[],value_ranges:{}},timeout_hours:24,timeout_action:"auto_reject",is_active:!0};if(console.log(`步骤 ${S} payload`,w),r){const a=I.value[n];if(a){const _=await _e(a,w);if(!_||_.code!==2e3){N.error(`更新步骤${S}失败: ${(_==null?void 0:_.msg)||"未知错误"}`);return}}else{w.workflow=m;const _=await oe(w);if(!_||_.code!==2e3){N.error(`创建步骤${S}失败: ${(_==null?void 0:_.msg)||"未知错误"}`);return}}}else{w.workflow=m;const a=await oe(w);if(!a||a.code!==2e3){N.error(`创建步骤${S}失败: ${(a==null?void 0:a.msg)||"未知错误"}`);return}}}if(r&&I.value.length>o.steps.length)for(let n=o.steps.length;n<I.value.length;n++){const V=I.value[n];try{await ce(V)}catch(S){console.warn(`删除步骤失败 (ID: ${V}):`,S)}}N.success("保存成功"),X("success"),T.value=!1}return(r,e)=>{const m=c("el-input"),i=c("el-form-item"),f=c("el-col"),y=c("el-option"),h=c("el-select"),p=c("el-row"),x=c("el-divider"),U=c("el-input-number"),u=c("el-checkbox"),d=c("el-checkbox-group"),C=c("el-card"),A=c("el-icon"),n=c("el-button"),V=c("el-radio"),S=c("el-radio-group"),B=c("el-form"),z=c("el-dialog");return v(),D(z,{title:r.editData?g.mode==="view"?"查看":"编辑":"新建审批流程",modelValue:T.value,"onUpdate:modelValue":e[10]||(e[10]=s=>T.value=s),width:"900px",onClose:ee},{footer:l(()=>[t(n,{onClick:ee},{default:l(()=>e[27]||(e[27]=[b("关闭")])),_:1}),g.mode!=="view"?(v(),D(n,{key:0,type:"primary",onClick:de},{default:l(()=>e[28]||(e[28]=[b("提交")])),_:1})):O("",!0)]),default:l(()=>[t(B,{model:o,"label-width":"110px",rules:P,ref_key:"formRef",ref:Y,disabled:g.mode==="view"},{default:l(()=>[t(p,{gutter:20},{default:l(()=>[t(f,{span:12},{default:l(()=>[t(i,{label:"流程名称",prop:"name"},{default:l(()=>[t(m,{modelValue:o.name,"onUpdate:modelValue":e[0]||(e[0]=s=>o.name=s),placeholder:"请输入"},null,8,["modelValue"])]),_:1})]),_:1}),t(f,{span:12},{default:l(()=>[t(i,{label:"流程类型",prop:"workflow_type"},{default:l(()=>[t(h,{modelValue:o.workflow_type,"onUpdate:modelValue":e[1]||(e[1]=s=>o.workflow_type=s),placeholder:"请选择流程类型",disabled:g.mode==="view"},{default:l(()=>[t(y,{label:"设备借用申请",value:"0"})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1})]),_:1}),t(p,{gutter:20},{default:l(()=>[t(f,{span:12},{default:l(()=>[t(i,{label:"流程描述",prop:"description"},{default:l(()=>[t(m,{modelValue:o.description,"onUpdate:modelValue":e[2]||(e[2]=s=>o.description=s),type:"textarea",rows:2,placeholder:"请输入流程描述",disabled:g.mode==="view"},null,8,["modelValue","disabled"])]),_:1})]),_:1}),t(f,{span:12},{default:l(()=>[t(i,{label:"是否启用",prop:"is_active"},{default:l(()=>[t(h,{modelValue:o.is_active,"onUpdate:modelValue":e[3]||(e[3]=s=>o.is_active=s),placeholder:"请选择启用还是禁用",disabled:g.mode==="view"},{default:l(()=>[t(y,{label:"启用",value:!0}),t(y,{label:"禁用",value:!1})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1})]),_:1}),t(x,null,{default:l(()=>e[11]||(e[11]=[b("条件选择")])),_:1}),t(p,{gutter:20},{default:l(()=>[t(f,{span:8},{default:l(()=>[t(i,{label:"最少借用天数",prop:"condition.min_days"},{default:l(()=>[t(U,{modelValue:o.condition.min_days,"onUpdate:modelValue":e[4]||(e[4]=s=>o.condition.min_days=s),min:0,"controls-position":"right",style:{width:"100px"}},null,8,["modelValue"]),e[12]||(e[12]=q("span",{style:{"margin-left":"8px"}},"天",-1))]),_:1})]),_:1}),t(f,{span:8},{default:l(()=>[t(i,{label:"最多借用天数",prop:"condition.max_days"},{default:l(()=>[t(U,{modelValue:o.condition.max_days,"onUpdate:modelValue":e[5]||(e[5]=s=>o.condition.max_days=s),min:1,"controls-position":"right",style:{width:"100px"}},null,8,["modelValue"]),e[13]||(e[13]=q("span",{style:{"margin-left":"8px"}},"天",-1))]),_:1})]),_:1}),t(f,{span:8},{default:l(()=>[t(i,{label:"用户角色",prop:"condition.roles"},{default:l(()=>[t(d,{modelValue:o.condition.roles,"onUpdate:modelValue":e[6]||(e[6]=s=>o.condition.roles=s)},{default:l(()=>[t(u,{label:"教师",value:"teacher"}),t(u,{label:"学生",value:"student"}),t(u,{label:"非本院师生",value:"external"})]),_:1},8,["modelValue"])]),_:1})]),_:1}),t(f,{span:8},{default:l(()=>[t(i,{label:"设备标签",prop:"condition.equipment"},{default:l(()=>[t(h,{modelValue:o.condition.equipment,"onUpdate:modelValue":e[7]||(e[7]=s=>o.condition.equipment=s),placeholder:"请选择"},{default:l(()=>[(v(!0),j(R,null,F(M,(s,k)=>(v(),D(y,{key:k,label:s.name,value:s.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1})]),_:1}),t(f,{span:8},{default:l(()=>[t(i,{label:"借用类型",prop:"condition.borrow_types"},{default:l(()=>[t(d,{modelValue:o.condition.borrow_types,"onUpdate:modelValue":e[8]||(e[8]=s=>o.condition.borrow_types=s),disabled:g.mode==="view"},{default:l(()=>[t(u,{label:"0"},{default:l(()=>e[14]||(e[14]=[b("常规借用")])),_:1}),t(u,{label:"1"},{default:l(()=>e[15]||(e[15]=[b("课堂借用")])),_:1}),t(u,{label:"2"},{default:l(()=>e[16]||(e[16]=[b("特殊借用")])),_:1})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1}),t(f,{span:8},{default:l(()=>[t(i,{label:"借用方式",prop:"condition.team_type"},{default:l(()=>[t(d,{modelValue:o.condition.team_type,"onUpdate:modelValue":e[9]||(e[9]=s=>o.condition.team_type=s),disabled:g.mode==="view"},{default:l(()=>[t(u,{label:"0"},{default:l(()=>e[17]||(e[17]=[b("个人借用")])),_:1}),t(u,{label:"1"},{default:l(()=>e[18]||(e[18]=[b("团队借用")])),_:1})]),_:1},8,["modelValue","disabled"])]),_:1})]),_:1})]),_:1}),t(x,null,{default:l(()=>e[19]||(e[19]=[b("流程配置")])),_:1}),q("div",ke,[q("div",qe,[t(C,{shadow:"never",class:"step-card borrower"},{default:l(()=>e[20]||(e[20]=[q("div",{class:"step-title"},"借用人",-1)])),_:1}),e[21]||(e[21]=q("div",{class:"step-line"},null,-1))]),(v(!0),j(R,null,F(o.steps,(s,k)=>(v(),j("div",{class:"workflow-step",key:k},[t(C,{shadow:"never",class:"step-card"},{default:l(()=>[q("div",he,[b(" 审批步骤"+ye(k+1)+" ",1),o.steps.length>1&&k!==0?(v(),D(n,{key:0,type:"danger",size:"small",onClick:$=>re(k),style:{"margin-left":"10px"}},{default:l(()=>[t(A,null,{default:l(()=>[t(W(te))]),_:1}),e[22]||(e[22]=b(" 删除步骤 "))]),_:2},1032,["onClick"])):O("",!0)]),q("div",xe,[(v(!0),j(R,null,F(s.roles,($,w)=>(v(),j("div",{key:w,class:"role-row",style:{position:"relative",padding:"0 20px"}},[t(i,{label:"角色","label-position":"left","label-width":"100px",prop:`steps.${k}.roles.${w}.name`,rules:[{required:!0,message:"请选择角色",trigger:"change"}]},{default:l(()=>[t(h,{modelValue:$.name,"onUpdate:modelValue":a=>$.name=a,placeholder:"请选择角色",style:{width:"300px"}},{default:l(()=>[t(y,{label:"老师",value:"老师"}),t(y,{label:"管理员",value:"管理员"}),t(y,{label:"学院领导",value:"学院领导"})]),_:2},1032,["modelValue","onUpdate:modelValue"])]),_:2},1032,["prop"]),$.name==="学院领导审批"||$.name==="学院领导"?(v(),D(i,{key:0,label:"领导姓名","label-position":"left","label-width":"100px",prop:`steps.${k}.roles.${w}.leaderId`,rules:[{required:!0,message:"请选择领导姓名",trigger:"change"}]},{default:l(()=>[t(h,{modelValue:$.leaderId,"onUpdate:modelValue":a=>$.leaderId=a,placeholder:"请选择领导姓名",style:{width:"300px"}},{default:l(()=>[(v(!0),j(R,null,F(J,a=>(v(),D(y,{key:a.id,label:a.name,value:a.id},null,8,["label","value"]))),128))]),_:2},1032,["modelValue","onUpdate:modelValue"])]),_:2},1032,["prop"])):O("",!0),t(i,{label:"通过条件","label-position":"left",prop:`steps.${k}.roles.${w}.passType`,rules:[{required:!0,message:"请选择通过条件",trigger:"change"}]},{default:l(()=>[t(S,{modelValue:$.passType,"onUpdate:modelValue":a=>$.passType=a},{default:l(()=>[t(V,{label:"1名通过即可",value:"1"}),t(V,{label:"所有人员通过",value:"2"}),t(V,{label:"部门负责人审批",value:"3"}),t(V,{label:"角色审批",value:"4"}),t(V,{label:"自动审批",value:"5"})]),_:2},1032,["modelValue","onUpdate:modelValue"])]),_:2},1032,["prop"]),s.roles.length>1&&w!==0?(v(),D(n,{key:1,type:"danger",size:"small",onClick:a=>ne(k,w),style:{position:"absolute",right:"0",top:"0"}},{default:l(()=>[t(A,null,{default:l(()=>[t(W(te))]),_:1}),e[23]||(e[23]=b(" 删除角色 "))]),_:2},1032,["onClick"])):O("",!0)]))),128))])]),_:2},1024),e[24]||(e[24]=q("div",{class:"step-line"},null,-1))]))),128)),q("div",$e,[g.mode!=="view"?(v(),D(n,{key:0,type:"primary",onClick:se,disabled:o.steps.length>=5},{default:l(()=>[t(A,null,{default:l(()=>[t(W(pe))]),_:1}),e[25]||(e[25]=b(" 添加审批步骤 "))]),_:1},8,["disabled"])):O("",!0)]),q("div",Ue,[t(C,{shadow:"never",class:"step-card done"},{default:l(()=>e[26]||(e[26]=[q("div",{class:"step-title"},"审批完成",-1)])),_:1})])])]),_:1},8,["model","rules","disabled"])]),_:1},8,["title","modelValue"])}}}),Te=ve(Se,[["__scopeId","data-v-86317d4c"]]);export{Te as default};
|