import{d as G,u as J,r as i,H as O,e as b,i as M,o as k,w as r,g as c,x as I,h as l,k as m,t as p,p as h,z as x,U as Q,s as Z,f as T,F as ee,v as ae,I as te,j as ne,W as se,P as le,D as v,X as V,B as oe,Y as ie,_ as re}from"./index-5k_MqT6o.js";import{u as ce,C as ue,a as de}from"./index-BHx7dntQ.js";const pe={class:"page-container"},he={class:"page-left"},fe={class:"role-list"},me=["onClick"],ve={class:"page-right"},_e={class:"page-right-title"},ge={class:"menu-permission"},ke={class:"permission-title"},Ce={class:"permission-actions"},ye=G({__name:"index",setup(be){const{t}=J(),E=i(),[N,{setValues:z,setFormModel:w,getValues:B}]=ce({colSpan:24,schema:[{label:"角色名称",prop:"name",type:"input",required:!0},{label:"头像",prop:"avatar",type:"input",slotName:"avatar"},{prop:"desc",label:"描述",type:"input",props:{type:"textarea"}},{prop:"id",label:"ID",type:"input",hidden:!0}]}),u=i(),C=i([]),L=i([]),R=i([]),F={children:"children",label:"name"},_=i(t("新增")),y=i(""),o=i(0),$=i([]);function A(e){z("avatar",e)}function f(e){v.roleList({name:y.value}).then(a=>{$.value=a.list||[],a.list.length&&(_.value=t("编辑"),e||(o.value=a.list[0].id),D())})}function D(){v.roleInfo({id:o.value}).then(e=>{w({name:e.name,desc:e.desc,id:e.id,avatar:e.avatar}),K(),V(()=>{[...e.menu].forEach(a=>{V(()=>{u.value?.setChecked(a,!0,!1)})})})})}function P(e){e.id!==o.value&&(o.value=e.id,_.value=t("编辑"))}function S(){_.value=t("新增"),o.value=0,w({name:"",desc:"",id:""}),R.value=[],V(()=>{u.value?.setCheckedKeys([])})}function U(){v.menuList({}).then(e=>{C.value=e.list||[];const a=(n=[])=>n.map(s=>{const g={...s,name:`${t(s.name)}  -  ${s.type===2?t("按钮"):t("菜单")}`};return Array.isArray(s.children)&&(g.children=a(s.children)),g});L.value=a(C.value)})}function q(){u.value?.setCheckedKeys(j())}function K(){u.value?.setCheckedKeys([])}function H(e,a){R.value=u.value?.getCheckedKeys()}function j(){const e=[];function a(n){n.forEach(s=>{e.push(s.id),s.children&&s.children.length&&a(s.children)})}return a(C.value),e}function W(){let e=u.value?.getHalfCheckedKeys()||[],a=u.value?.getCheckedKeys()||[];return[].concat(e,a)}function X(){const e=B(),a=W();if(!e.name){oe.warning(t("请输入角色名称"));return}const n={...e,menu_id:a};console.log(n),console.log(B(),306),v.roleUpdate(n).then(()=>{f(!!n.id)})}function Y(){ie.confirm(t("确认删除角色?"),t("提示"),{confirmButtonText:t("确定"),cancelButtonText:t("取消"),type:"warning"}).then(()=>{v.roleDelete({id:o.value}).then(()=>{f(!1)})})}return O(o,e=>{e&&D()}),f(!1),U(),(e,a)=>{const n=b("el-button"),s=b("el-icon"),g=b("el-input");return k(),M(le,{bgColor:"none"},{default:r(()=>[c("div",pe,[c("div",he,[I(l(n,{class:"add-btn",icon:"Plus",size:"large",style:{border:"1px dashed #316be1",color:"#316be1"},onClick:S},{default:r(()=>[m(p(h(t)("新增角色")),1)]),_:1},512),[[x,e.$perm(10)]]),l(g,{modelValue:y.value,"onUpdate:modelValue":a[0]||(a[0]=d=>y.value=d),class:"search-input",clearable:"",placeholder:e.$t("搜索角色名称"),onClear:f,onKeyup:Q(f,["enter"])},{append:r(()=>[l(s,{onClick:f},{default:r(()=>[l(h(Z))]),_:1})]),_:1},8,["modelValue","placeholder"]),c("div",fe,[(k(!0),T(ee,null,ae($.value,d=>(k(),T("div",{key:d.id,class:te([{active:o.value===d.id},"role-item"]),onClick:Ie=>P(d)},p(d.name),11,me))),128))])]),c("div",ve,[c("div",_e,[m(p(_.value)+" ",1),c("span",null,[o.value?I((k(),M(n,{key:0,type:"danger",onClick:Y},{default:r(()=>[m(p(e.$t("删除")),1)]),_:1},512)),[[x,e.$perm(20)]]):ne("",!0),I(l(n,{type:"primary",onClick:X},{default:r(()=>[m(p(e.$t("保存")),1)]),_:1},512),[[x,e.$perm(10)]])])]),l(h(ue),{ref_key:"formRef",ref:E,onRegister:h(N)},{avatar:r(({model:d})=>[l(de,{"default-img-url":d.avatar,onChange:A},null,8,["default-img-url"])]),_:1},8,["onRegister"]),c("div",ge,[c("div",ke,p(h(t)("菜单权限")),1),c("div",Ce,[l(n,{link:"",size:"small",type:"primary",onClick:q},{default:r(()=>[m(p(h(t)("全选")),1)]),_:1}),l(n,{link:"",size:"small",type:"danger",onClick:K},{default:r(()=>[m(p(h(t)("全不选")),1)]),_:1})]),l(h(se),{ref_key:"treeRef",ref:u,"check-strictly":!1,data:L.value,props:F,class:"permission-tree","node-key":"id","show-checkbox":"",onCheckChange:H},null,8,["data"])])])])]),_:1})}}}),we=re(ye,[["__scopeId","data-v-175230a7"]]);export{we as default};
