import{M as N,I as $,r as E,a9 as J,a5 as M,av as P,aw as A,aG as D,F as I,W as S}from"./index.17037962789732.js";import"./index.170379627897337.js";import"./index.170379627897315.js";import"./index.170379627897318.js";import"./index.170379627897319.js";import"./index.170379627897314.js";import"./index.170379627897327.js";import"./index.170379627897316.js";import"./index.170379627897317.js";import{b as u}from"./system.1703796278973.js";import{d as V,k as T,l as h,v as z,o as p,c as f,a as o,b as l,u as a,x as k,F as L,h as x,t as C,A as R}from"./vue.1703796278973.js";const re=r=>u.post("/relation/_query/",r),G=()=>u.get("/relation/types"),W=r=>u.post("/relation",r),Z=r=>u.patch("/relation",r),ie=r=>u.remove(`/relation/${r}`),H=r=>u.get("/relation/_validate",r),de=V({__name:"EditDialog",props:{visible:{type:Boolean},data:null},emits:["refresh","update:visible"],setup(r,{emit:m}){const c=r,_=T(!1),q=h(()=>c.data.id?"编辑":"新增"),w=()=>{var i;_.value=!0,(i=g.value)==null||i.validate().then(()=>e.submit()).then(t=>{t.status===200&&(N.success("操作成功"),m("refresh"),m("update:visible",!1))}).finally(()=>_.value=!1)},g=T(),e=z({data:c.data,rules:{checkRelation:async(i,t)=>{const d=new RegExp("^[0-9a-zA-Z_\\\\-]+$");return t?d.test(t)?e.rules.checkUnique():Promise.reject("标识只能由数字、字母、下划线、中划线组成"):Promise.reject("")},checkUnique:()=>{var i;if(!((i=c.data)!=null&&i.id||!e.data.relation||!e.data.objectType||!e.data.targetType))return new Promise(async(t,d)=>{const{result:s}=await H({relation:e.data.relation,objectType:e.data.objectType,targetType:e.data.targetType});s.passed?t(""):d(s.reason)})}},handleObjectTypeChange:()=>{e.data.targetType=void 0,e.rules.checkUnique()},objectList:[],getObjectList:()=>{G().then(i=>{e.objectList=i.result})},submit:()=>{var d;const i={...e.data,objectTypeName:e.objectList.find(s=>s.id===e.data.objectType).name,targetTypeName:(d=v.value.find(s=>s.id===e.data.targetType))==null?void 0:d.name};return(c.data.id?Z:W)(i)}}),v=h(()=>e.data.objectType==="device"?[{id:"user",name:"用户"}]:[]);return e.getObjectList(),(i,t)=>{const d=$,s=E,b=J,j=M,y=P,U=A,O=D,F=I,B=S;return p(),f(B,{visible:"",title:a(q),maskClosable:!1,width:"675px",onOk:w,onCancel:t[5]||(t[5]=n=>m("update:visible",!1)),confirmLoading:a(_),class:"edit-dialog-container"},{default:o(()=>[l(F,{ref_key:"formRef",ref:g,model:a(e).data,layout:"vertical"},{default:o(()=>[l(s,{label:"名称",name:"name",rules:[{required:!0,message:"请输入名称"},{max:64,message:"最多可输入64个字符"}]},{default:o(()=>[l(d,{value:a(e).data.name,"onUpdate:value":t[0]||(t[0]=n=>a(e).data.name=n),placeholder:"请输入名称"},null,8,["value"])]),_:1}),l(s,{name:"relation",label:"标识",rules:[{required:!0,message:"请输入标识"},{max:64,message:"最多可输入64个字符"},{validator:a(e).rules.checkRelation,trigger:"change"}]},{default:o(()=>[l(d,{value:a(e).data.relation,"onUpdate:value":t[1]||(t[1]=n=>a(e).data.relation=n),placeholder:"请输入标识",disabled:!!a(e).data.id},null,8,["value","disabled"])]),_:1},8,["rules"]),l(U,{gutter:24},{default:o(()=>[l(y,{span:12},{default:o(()=>[l(s,{name:"objectType",label:"关联方",rules:[{required:!0,message:"请选择关联方"}]},{default:o(()=>[l(j,{value:a(e).data.objectType,"onUpdate:value":t[2]||(t[2]=n=>a(e).data.objectType=n),disabled:!!a(e).data.id,onChange:a(e).handleObjectTypeChange,placeholder:"请选择关联方"},{default:o(()=>[(p(!0),k(L,null,x(a(e).objectList,n=>(p(),f(b,{value:n.id},{default:o(()=>[C(R(n.name),1)]),_:2},1032,["value"]))),256))]),_:1},8,["value","disabled","onChange"])]),_:1})]),_:1}),l(y,{span:12},{default:o(()=>[l(s,{name:"targetType",label:"被关联方",rules:[{required:!0,message:"请选择被关联方"}]},{default:o(()=>[l(j,{value:a(e).data.targetType,"onUpdate:value":t[3]||(t[3]=n=>a(e).data.targetType=n),disabled:!!a(e).data.id,onChange:a(e).rules.checkUnique,placeholder:"请选择被关联方"},{default:o(()=>[(p(!0),k(L,null,x(a(v),n=>(p(),f(b,{value:n.id},{default:o(()=>[C(R(n.name),1)]),_:2},1032,["value"]))),256))]),_:1},8,["value","disabled","onChange"])]),_:1})]),_:1})]),_:1}),l(s,{name:"description",label:"说明"},{default:o(()=>[l(O,{value:a(e).data.description,"onUpdate:value":t[4]||(t[4]=n=>a(e).data.description=n),placeholder:"请输入说明","show-count":"",maxlength:200},null,8,["value"])]),_:1})]),_:1},8,["model"])]),_:1},8,["title","confirmLoading"])}}});export{de as _,ie as d,re as g};
