import{d as J,O as j,l as I,v as k,k as T,o as B,c as D,a as v,b as M,u as l,t as F}from"./vue.1703796278973.js";import{aM as P,M as _,K as R,F as z,cD as U}from"./index.17037962789732.js";import"./index.1703796278973318.js";import"./index.170379627897318.js";import"./index.170379627897319.js";import"./index.170379627897315.js";import{u as $}from"./instance.17037962789732.js";import{u as q}from"./metadata.1703796278973.js";import{u as K}from"./product.17037962789738.js";import{s as L,_ as A}from"./product.17037962789737.js";import{m as G,a as H}from"./instance.1703796278973.js";import Q from"./BaseForm.17037962789732.js";import{_ as V}from"./_plugin-vue_export-helper.1703796278973.js";const W=(d,o,t,n)=>{if(!t)return t;const a=JSON.parse(t.metadata||"{}"),r=a[d]||[];return o.length>0?o.forEach(e=>{const i=r.findIndex(w=>w.id===e.id);i>-1?r[i]=e:r.push(e)}):console.warn("未触发物模型修改"),a[d]=r.sort((e,i)=>(i==null?void 0:i.sortsIndex)-(e==null?void 0:e.sortsIndex)),t.metadata=JSON.stringify(a),n==null||n(t.metadata),t},X=(d,o)=>{switch(d){case"product":return L(o);case"device":return G(o.id,JSON.parse(o.metadata||"{}"))}},fe=(d,o,t,n)=>{const a=JSON.parse(t.metadata||"{}"),r=a[d]||[];return a[d]=r.filter(e=>!o.map(i=>i.id).includes(e.id)),n==null||n("remove",o),t.metadata=JSON.stringify(a),t},Y=J({name:"Edit"}),Z=J({...Y,props:{type:{type:String,required:!0,default:"product"},tabs:{type:String}},emits:["refresh"],setup(d,{emit:o}){const t=d,n=j(),a=$(),r=K(),e=q(),i={properties:"属性",events:"事件",functions:"功能",tags:"标签"},w=()=>{e.set("edit",!1),e.set("item",{})},N=I(()=>e.model.action==="add"?"新增":"编辑"),y=k({model:{}});e.model.action==="edit"&&(y.model=P.cloneDeep(e.model.item));const h=T(),m=k({loading:!1,saveMetadata:g=>{var s;m.loading=!0,(s=h.value)==null||s.validateFields().then(async f=>{const S=e.model.type,u=t.type==="device"?a.detail:r.current,b=JSON.parse((u==null?void 0:u.metadata)||"{}")[S]||[];if(f.id&&e.model.action==="add"&&b.some(c=>c.id===f.id)){_.error("标识已存在"),m.loading=!1;return}const C=W(S,[f],u,c=>{if(t.type==="device"){const p=a.current;p.metadata=c,a.setCurrent(p)}else{const p=r.current||{};p.metadata=c,r.setCurrent(p)}o("refresh")}),x=await X(t.type,C);if(x.success)if(window.onTabSaveSuccess)x&&(window.onTabSaveSuccess(x),setTimeout(()=>window.close(),300));else{const{id:c}=n.params;(t==null?void 0:t.type)==="device"?a.refresh(c):r.getDetail(c),g?(await A(c)).success?(m.resetMetadata(),_.success({key:"metadata",content:"操作成功!"})):_.error("操作失败!"):_.success({key:"metadata",content:"操作成功!"}),e.set("edit",!1),e.set("item",{})}else _.error("操作失败!");m.loading=!1}),m.loading=!1},resetMetadata:async()=>{const{id:g}=n.params,s=await H(g);s.status===200&&(a.detail=(s==null?void 0:s.result)||[])}});return(g,s)=>{const f=R,S=z,u=U;return B(),D(u,{"mask-closable":!1,width:"25vw",visible:"",title:`${l(N)}-${i[l(e).model.type]}`,onClose:w,"destroy-on-close":"","z-index":1e3,placement:"right"},{extra:v(()=>[M(f,{loading:l(m).loading,type:"primary",onClick:s[0]||(s[0]=()=>l(m).saveMetadata())},{default:v(()=>[F("保存")]),_:1},8,["loading"])]),default:v(()=>[M(S,{ref_key:"formRef",ref:h,model:l(y).model,layout:"vertical"},{default:v(()=>[M(Q,{"model-type":l(e).model.type,type:d.type,value:l(y).model,"onUpdate:value":s[1]||(s[1]=O=>l(y).model=O)},null,8,["model-type","type","value"])]),_:1},8,["model"])]),_:1},8,["title"])}}});const E=V(Z,[["__scopeId","data-v-26e03c31"]]),_e=Object.freeze(Object.defineProperty({__proto__:null,default:E},Symbol.toStringTag,{value:"Module"}));export{E,X as a,_e as i,fe as r};