var e=Object.defineProperty,a=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,t=Object.prototype.propertyIsEnumerable,r=(a,l,t)=>l in a?e(a,l,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[l]=t;import{P as s,Q as n,e as u,X as o,E as c}from"./vendor-element-DupX9wXy.js";import{m as i,I as d,a7 as h}from"./index-CeAbLubS.js";import{q as v,bs as p,r as f,c as m,S as y,D as k,v as g,E as b,M as _,u as x,A as C,t as O,K as j,J as V,h as w,X as K}from"./vendor-core-Di0OO4oJ.js";const M={style:{display:"flex","align-items":"center"}},P={key:0},A={key:1},D=v({__name:"role-permission-dialog",props:{modelValue:{type:Boolean,default:!1},roleData:{default:void 0}},emits:["update:modelValue","success"],setup(e,{emit:v}){const D=e,E=v,{menuList:S}=p(i()),$=f(),J=f(!0),L=f(!1),I=m({get:()=>D.modelValue,set:e=>E("update:modelValue",e)}),N=m(()=>{const e=s=>{var n,u;const o=((e,s)=>{for(var n in s||(s={}))l.call(s,n)&&r(e,n,s[n]);if(a)for(var n of a(s))t.call(s,n)&&r(e,n,s[n]);return e})({},s);if(null==(u=null==(n=s.meta)?void 0:n.authList)?void 0:u.length){const e=s.meta.authList.map(e=>({id:`${s.id}_${e.authMark}`,name:`${s.name}_${e.authMark}`,label:e.title,authMark:e.authMark,isAuth:!0,checked:e.checked||!1}));o.children=o.children?[...o.children,...e]:e}return o.children&&(o.children=o.children.map(e)),o};return S.value.map(e)}),X={children:"children",label:e=>{var a;return d(null==(a=e.meta)?void 0:a.title)||e.label||""}},q=e=>{let a=[];for(const l of e)l.name&&a.push(l.name),l.children&&l.children.length&&(a=a.concat(q(l.children)));return a};y(()=>D.modelValue,e=>{const a=D.roleData;e&&a&&K(()=>{if(!$.value)return;let e=[];if("*"===a.rules)e=q(N.value);else if(a.rules)try{const l=JSON.parse(a.rules);Array.isArray(l)&&(e=l,e.includes("*")&&(e=q(N.value)))}catch(l){"string"==typeof a.rules&&(e=a.rules.split(","))}$.value.setCheckedKeys(e)})});const B=()=>{var e;I.value=!1,null==(e=$.value)||e.setCheckedKeys([])},Q=()=>{return e=null,a=null,l=function*(){if(!$.value||!D.roleData)return;const e=$.value.getCheckedKeys(!1),a=JSON.stringify(e);try{yield h({id:D.roleData.id,rules:a}),c.success("权限保存成功"),E("success"),B()}catch(l){}},new Promise((t,r)=>{var s=e=>{try{u(l.next(e))}catch(a){r(a)}},n=e=>{try{u(l.throw(e))}catch(a){r(a)}},u=e=>e.done?t(e.value):Promise.resolve(e.value).then(s,n);u((l=l.apply(e,a)).next())});var e,a,l},R=()=>{const e=$.value;if(!e)return;const a=e.store.nodesMap;Object.values(a).forEach(e=>{e.expanded=!J.value}),J.value=!J.value},U=()=>{const e=$.value;if(e){if(L.value)e.setCheckedKeys([]);else{const a=z(N.value);e.setCheckedKeys(a)}L.value=!L.value}},z=e=>{const a=[],l=e=>{e.forEach(e=>{var t;e.name&&a.push(e.name),(null==(t=e.children)?void 0:t.length)&&l(e.children)})};return l(e),a},F=()=>{const e=$.value;if(!e)return;const a=e.getCheckedKeys(),l=z(N.value);L.value=a.length===l.length&&l.length>0};return(e,a)=>{const l=n,t=s,r=u,c=o;return g(),k(c,{modelValue:x(I),"onUpdate:modelValue":a[0]||(a[0]=e=>w(I)?I.value=e:null),title:"菜单权限",width:"520px","align-center":"",class:"el-dialog-border",onClose:B},{footer:b(()=>[_(r,{onClick:R},{default:b(()=>[V(j(x(J)?"全部收起":"全部展开"),1)]),_:1}),_(r,{onClick:U,style:{"margin-left":"8px"}},{default:b(()=>[V(j(x(L)?"取消全选":"全部选择"),1)]),_:1}),_(r,{type:"primary",onClick:Q},{default:b(()=>[...a[1]||(a[1]=[V("保存",-1)])]),_:1})]),default:b(()=>[_(t,{height:"70vh"},{default:b(()=>[_(l,{ref_key:"treeRef",ref:$,data:x(N),"show-checkbox":"","node-key":"name","default-expand-all":x(J),"default-checked-keys":[1,2,3],props:X,onCheck:F},{default:b(({data:e})=>[C("div",M,[e.isAuth?(g(),O("span",P,j(e.label),1)):(g(),O("span",A,j(X.label(e)),1))])]),_:1},8,["data","default-expand-all"])]),_:1})]),_:1},8,["modelValue"])}}});export{D as _};
