import{t as P,g as G,a as H,r as K,b as Q}from"./role-gbXRIS2k.js";import{a as X,r as o,e as i,o as b,c as C,f as n,h as d,i as f,F as T,I as B,J as I,m as k,y as R,k as Y,B as Z,v as ee}from"./index-C1_1_QXk.js";const ae={class:"app-container"},te={style:{margin:"20px",display:"flex","justify-content":"flex-end"}},le=Z({name:"Role"}),re=Object.assign(le,{setup(oe){const{proxy:c}=ee(),y=X(),m=o([]),E=o([]),h=o([]),L=o([]),V=o([]);o([]),o([]);const v=o(!1);o(0);const w=o([]),t=o({name:"",radio:""});let _="";P().then(a=>{w.value=[...a.data.map(e=>({tag:e.tag,label:e.code,id:e.id}))]});function U(){if(v.value=!0,c.$route.query.row){const a=JSON.parse(c.$route.query.row);_=a.id,t.value.name=a.name,t.value.radio=a.code}G(t.value).then(a=>{m.value=a.data.menuList,E.value=a.data.buttonList,v.value=!1,M()})}function M(){m.value.forEach(a=>{a.children.forEach(e=>{e.buttonList=[],E.value.forEach(l=>{e.id==l.menuId&&e.buttonList.push(l)})})}),S("")}async function S(a){let e={code:a,id:_};const{data:l}=await H(e);L.value=l.menuArray,h.value=l.buttonArray,L.value.forEach(r=>{m.value.forEach(u=>{r.menuId==u.id&&(c.$refs.selectTable.toggleRowSelection(u,!0),u.children.forEach(p=>{c.$refs.selectTable.toggleRowSelection(p,!1)}))})}),L.value.forEach(r=>{m.value.forEach(u=>{u.children.forEach(p=>{r.menuId==p.id&&c.$refs.selectTable.toggleRowSelection(p,!0)})})}),h.value.forEach(r=>{E.value.forEach(u=>{r.id==u.id&&(u.checked=!0)})})}function N(a){c.$refs.selectTable.clearSelection(),m.value.forEach(e=>{e.children.forEach(l=>{l.buttonList.forEach(r=>{r.checked=!1})})}),S(a.target._value)}function q(a){V.value=a}function j(){h.value=[],m.value.forEach(a=>{a.children.forEach(e=>{e.buttonList.forEach(l=>{l.checked&&h.value.push(l)})})})}async function A(){if(!t.value.name){c.$modal.msgWarning("请输入名称");return}if(!t.value.radio){c.$modal.msgWarning("请选择标签");return}let a={name:t.value.name,code:t.value.radio,menuList:V.value,actionList:h.value};w.value.map(e=>{e.label==t.value.radio&&(a.tag=e.tag)}),_&&(a.id=_),_?K(a).then(e=>{c.$modal.msgSuccess(e.code),y.back()}):Q(a).then(e=>{c.$modal.msgSuccess(e.code),y.back()})}async function F(){y.back()}return U(),(a,e)=>{const l=i("el-input"),r=i("el-form-item"),u=i("el-radio"),p=i("el-radio-group"),J=i("el-form"),x=i("el-table-column"),O=i("el-checkbox"),W=i("el-table"),$=i("el-button");return b(),C("div",ae,[n(J,{"label-width":"70px"},{default:d(()=>[n(r,{label:"名称",prop:"name"},{default:d(()=>[n(l,{modelValue:f(t).name,"onUpdate:modelValue":e[0]||(e[0]=s=>f(t).name=s),placeholder:"请输入名称",clearable:"",style:{width:"240px"},maxlength:"10"},null,8,["modelValue"])]),_:1}),n(r,{label:"标签"},{default:d(()=>[n(p,{modelValue:f(t).radio,"onUpdate:modelValue":e[1]||(e[1]=s=>f(t).radio=s),size:"small",onInput:N},{default:d(()=>[(b(!0),C(T,null,B(f(w),(s,g)=>(b(),I(u,{key:g,label:s.label,border:""},{default:d(()=>[k(R(s.tag),1)]),_:2},1032,["label"]))),128))]),_:1},8,["modelValue"])]),_:1})]),_:1}),n(W,{data:f(m),"row-key":s=>s.id,"default-expand-all":"",ref:"selectTable","tree-props":{children:"children"},onSelectionChange:q},{default:d(()=>[n(x,{type:"selection","reserve-selection":"true",width:"55"}),n(x,{prop:"title",label:"模块栏"}),n(x,{label:"操作栏"},{default:d(s=>[(b(!0),C(T,null,B(s.row.buttonList,(g,z)=>(b(),I(O,{key:z,modelValue:g.checked,"onUpdate:modelValue":D=>g.checked=D,onChange:j},{default:d(()=>[k(R(g.title),1)]),_:2},1032,["modelValue","onUpdate:modelValue"]))),128))]),_:1})]),_:1},8,["data","row-key"]),Y("div",te,[n($,{type:"primary",loading:f(v),onClick:A},{default:d(()=>[k("提交")]),_:1},8,["loading"]),n($,{loading:f(v),onClick:F},{default:d(()=>[k("取消")]),_:1},8,["loading"])])])}}});export{re as default};
