import{d as H,V as J,r as m,b as V,o as G,c as r,e as y,f as B,h as s,i as a,u,a2 as O,a0 as T,g as h,aC as Q,H as W,t as v,F as X,j as Y,k as Z,m as _,cJ as ee,cK as le,cL as se,cM as te,_ as oe}from"./index.0308b213.js";import{g as ne}from"./index.19ccf370.js";import{F as ae}from"./index.d8717905.js";import{c as A,g as ue}from"./el-tree.54e888c4.js";const ce={class:"role-edit"},re={style:{display:"flex","align-items":"flex-start"}},ie={class:"flex",style:{"margin-top":"3px"}},de=_(" \u5168\u9009 "),me=_(" \u5168\u4E0D\u9009 "),pe=_("\u4FDD\u5B58"),he=H({setup(_e){const{route:L,router:C}=J(),N=m(!0),b=m(),o=m(),i=m(null);let t=V({name:"",desc:"",permissions:[],agentids:[]});const w={name:[{required:!0,message:"\u8BF7\u8F93\u5165\u89D2\u8272\u540D\u79F0",trigger:["blur"]}]};let F=m([]);const z=e=>e==="M"||e==="C"?"\u83DC\u5355":e==="F"?"\u6743\u9650":"",x=()=>{ne({name:"",type:"",status:"",fields:"id,pid,name,type"}).then(e=>{F.value=e})};let D=V({list:[]});(()=>{ee().then(e=>{console.log("res",e),D.list=e.list})})();const S=()=>{var e;(e=b.value)==null||e.validate(l=>{!l||(i.value?K():q())})},M=e=>{var n;let l=(n=o==null?void 0:o.value)==null?void 0:n.getNode(e);console.log(l,l.isLeaf,"checkNode")},g=(e,l)=>{e.forEach(n=>{var d;console.log(n,n.name,"asss"),n.children&&n.children.length>0&&g(n.children,l),(d=o==null?void 0:o.value)==null||d.setChecked(n.id,l,!1)})},$=e=>{var n;const l=(n=o==null?void 0:o.value)==null?void 0:n.getNode(e).checked;console.log(e,l,"isChecked",e.children.length),l?e.children&&e.children.length>0&&g(e.children,!0):e.children&&e.children.length>0&&g(e.children,!1)},E=()=>{t.permissions=ue(o.value)},q=()=>{E(),le(t).then(e=>{console.log("res",e),setTimeout(()=>{C.back()},500)}).catch(e=>{console.log("err",e)})},K=()=>{E(),se({...t,id:i.value}).then(e=>{console.log("res",e),setTimeout(()=>{C.back()},500)}).catch(e=>{console.log("err",e)})},P=()=>{te({id:i.value}).then(e=>{var l;console.log("res",e),t.name=e.name,t.desc=e.desc,t.permissions=e.permissions,t.agentids=e.agentids,(l=o.value)==null||l.setCheckedKeys(e.auth_keys)}).catch(e=>{console.log("err",e)})},R=()=>{A(!0,o.value)},U=()=>{A(!1,o.value)};return G(()=>{const e=L.query;e.id?(i.value=e.id*1,x(),setTimeout(()=>{P()},1e3)):x()}),(e,l)=>{const n=r("el-page-header"),d=r("el-card"),p=r("el-form-item"),f=r("el-button"),I=r("el-checkbox"),j=r("el-checkbox-group");return y(),B("div",ce,[s(d,{shadow:"never"},{default:a(()=>[s(n,{content:i.value?"\u7F16\u8F91\u89D2\u8272":"\u65B0\u589E\u89D2\u8272",onBack:l[0]||(l[0]=c=>e.$router.back())},null,8,["content"])]),_:1}),s(d,{shadow:"never",class:"m-t-15"},{default:a(()=>[s(u(O),{ref_key:"formRef",ref:b,rules:w,class:"ls-form",model:u(t),"label-width":"150px",size:"small"},{default:a(()=>[s(p,{label:"\u540D\u79F0",prop:"name"},{default:a(()=>[s(u(T),{modelValue:u(t).name,"onUpdate:modelValue":l[1]||(l[1]=c=>u(t).name=c),placeholder:"\u8BF7\u8F93\u5165\u540D\u79F0"},null,8,["modelValue"])]),_:1}),s(p,{label:"\u5907\u6CE8",prop:"desc"},{default:a(()=>[s(u(T),{modelValue:u(t).desc,"onUpdate:modelValue":l[2]||(l[2]=c=>u(t).desc=c),placeholder:"\u8BF7\u8F93\u5165\u5907\u6CE8",type:"textarea",autosize:{minRows:4,maxRows:6}},null,8,["modelValue"])]),_:1}),s(p,{label:"\u6743\u9650",prop:"auth_keys"},{default:a(()=>[h("div",re,[h("div",ie,[s(f,{type:"primary",size:"small",onClick:l[3]||(l[3]=c=>R())},{default:a(()=>[de]),_:1}),s(f,{type:"primary",size:"small",onClick:l[4]||(l[4]=c=>U())},{default:a(()=>[me]),_:1})]),h("div",null,[s(u(Q),{ref_key:"treeRef",ref:o,data:u(F),onCheck:$,onCheckChange:M,"node-key":"id",props:{children:"children",label:"name"},"check-strictly":N.value,"show-checkbox":"","check-on-click-node":"","default-checked-keys":u(t).permissions},{default:a(({node:c,data:k})=>[h("text",{class:W(["permission-tree-text",[{permission:k.type==="F"}]])},v(k.name)+"["+v(z(k.type))+"] ",3)]),_:1},8,["data","check-strictly","default-checked-keys"])])])]),_:1}),s(p,{label:"\u5176\u4ED6\u4EE3\u7406\u5546\u5217\u8868"},{default:a(()=>[s(j,{modelValue:u(t).agentids,"onUpdate:modelValue":l[5]||(l[5]=c=>u(t).agentids=c),onChange:e.handleCheckedAgentChange},{default:a(()=>[(y(!0),B(X,null,Y(u(D).list,c=>(y(),Z(I,{label:c.id,key:c.id},{default:a(()=>[_(v(c.title),1)]),_:2},1032,["label"]))),128))]),_:1},8,["modelValue","onChange"])]),_:1})]),_:1},8,["model"])]),_:1}),s(ae,null,{default:a(()=>[s(f,{type:"primary",size:"small",onClick:S},{default:a(()=>[pe]),_:1})]),_:1})])}}});const Ce=oe(he,[["__scopeId","data-v-4cbf3a23"]]);export{Ce as default};
