import{R as $}from"./index-b671ca80.js";import{j as I}from"./index-a6ee13d3.js";import{q as B}from"./qs-c5b6dbf2.js";import{a as i}from"./element-plus-91d6d961.js";import{H as w,e as b,_ as M,a0 as U,i as q,ah as r,o as j,c as F,V as o,P as s,a as h,T as C,n as H,h as z}from"./@vue-6dabbe94.js";const G=h("span",null,"菜单权限",-1),J=h("span",null,"接口权限",-1),O={class:"dialog-footer"},Q=w({name:"systemAddRoleDialog"}),le=w({...Q,setup(W,{expose:D}){const{proxy:n}=z(),u=$(),c=b(),f=b(),e=M({row:null,isShowDialog:!1,treeCheckAll:!1,treeLoading:!1,defaultCheckedKeys:[],treeData:[],tableData:[],treeDefaultProps:{children:"children",label:"label"},treeSelArr:[],treeLength:0}),y=t=>{e.isShowDialog=!0,e.row=t},p=()=>{e.isShowDialog=!1},A=()=>{p()},S=t=>{let l=0;t.map(a=>{a.children&&(l+=a.children.length)}),e.treeLength=l+t.length},T=()=>{e.treeCheckAll?n.$refs.treeTable.setCheckedNodes(e.treeData):n.$refs.treeTable.setCheckedKeys([])},_=()=>{e.treeSelArr=[],e.treeSelArr=n.$refs.treeTable.getCheckedNodes(!1,!0),e.treeSelArr.length==e.treeLength?e.treeCheckAll=!0:e.treeCheckAll=!1},v=()=>{if(n.$refs.treeTable.getCheckedNodes(!1,!0).length<=0){i.warning("请选择元素");return}else console.log(n.$refs.treeTable.getCheckedNodes(!1,!0))},R=()=>{e.row&&e.row.id&&(e.defaultCheckedKeys=[],u.getRolePermissions(e.row.id).then(t=>{e.treeData=t.data.permissions,g(e.treeData),S(e.treeData),e.tableData=t.data.roleResources,_(),x()}))},x=()=>{H(()=>{console.log(">>>data len:"+e.tableData.length),e.tableData.forEach(t=>{t.roleId!=null&&f.value.toggleRowSelection(t,!0)})})},P=t=>{c.value=t};U(()=>{console.log("===>onUpdated"),R()}),q(()=>{console.log("===>onMounted")});const g=t=>{t.forEach(l=>{l.label=I.global.t(l.label),l.checked&&l.children==null&&e.defaultCheckedKeys.push(l.id),l.children&&l.children.length>0&&g(l.children)})},L=()=>{const t=new Array;e.treeSelArr.forEach(a=>{t.push(a.id)});const l=new Array;c.value&&c.value.length&&c.value.length>0&&c.value.forEach(a=>{l.push(a.resourcePath)}),u.saveRolePermissions(e.row.id,B.stringify({permissionIdList:t,resourcePathList:l},{arrayFormat:"repeat"})).then(()=>{i.success("保存成功"),p()}).catch(a=>{i.error(a.message)})};return D({openDialog:y,onSelect:v,onCheckAllChange:T}),(t,l)=>{const a=r("el-tree"),m=r("el-col"),d=r("el-table-column"),N=r("el-table"),V=r("el-row"),k=r("el-button"),E=r("el-dialog");return j(),F("div",null,[o(E,{title:"权限设置",fullscreen:"",modelValue:e.isShowDialog,"onUpdate:modelValue":l[0]||(l[0]=K=>e.isShowDialog=K),width:"769px"},{footer:s(()=>[h("span",O,[o(k,{onClick:A},{default:s(()=>[C("取 消")]),_:1}),o(k,{type:"primary",onClick:L},{default:s(()=>[C("保 存")]),_:1})])]),default:s(()=>[o(V,null,{default:s(()=>[o(m,{span:6},{default:s(()=>[G,o(a,{data:e.treeData,"show-checkbox":"","node-key":"id","default-expand-all":!0,ref:"treeTable",props:e.treeDefaultProps,"default-checked-keys":e.defaultCheckedKeys,onCheck:_},null,8,["data","props","default-checked-keys"])]),_:1}),o(m,{span:8},{default:s(()=>[J,o(N,{ref_key:"resourceTableRef",ref:f,data:e.tableData,style:{width:"100%"},onSelectionChange:P},{default:s(()=>[o(d,{type:"selection",width:"55"}),o(d,{property:"resourceName",label:"接口名称",width:"120"}),o(d,{property:"resourcePath",label:"权限标识","show-overflow-tooltip":""})]),_:1},8,["data"])]),_:1})]),_:1})]),_:1},8,["modelValue"])])}}});export{le as _};
