import{p as j,r,A as ee,t as te,F as p,j as e,B as C,h as se,I as _,a as ae,b as oe,ci as re,g as x,v as F,M as ne}from"./index-CKIL6d0V.js";import{R as D}from"./PlusCircleOutlined-C3dgw0Zs.js";import{F as le}from"./Table-BaVi_066.js";import{D as ie}from"./index-BzG6U_Bx.js";import{T as ce}from"./index-C-LPyJas.js";import{R as de}from"./DeleteOutlined-BHDTCKcb.js";import"./iconUtil-Co5gbObL.js";const he=j.div`
  height: 100%;
  .roleList {
    height: 100%;
    padding: 16px;
    display: flex;
    flex-direction: column;
    .topBarAddBtn {
      height: 40px;
      .add_btn {
        margin-right: 40px;
        border-radius: 10px;
      }
    }
    .bottomList {
      flex: 1;
      box-sizing: border-box;
      overflow: hidden;
      .role_table {
        overflow: hidden;
        height: 100%;
      }
    }
  }
`,pe=j.div`
  min-height: 100px;
  height: 100%;
  padding: 16px 0;
`,xe=j.div`
  // 自定义样式
  .ysh_basicinfo_p {
    height: 40px;
    font-size: 16px;
    line-height: 40px;
    margin-bottom: 10px;
    padding-left: 20px;
  }
  .ysh_p {
    height: 60px;
    font-size: 16px;
    padding-top: 20px;
    padding-left: 20px;
    text-align: center;
    .ysh_basicinfo_btn {
      width: 100px;
    }
  }
`,me=r.memo(()=>{const{message:n,modal:z}=ee.useApp(),{token:{colorBgContainer:N,borderRadius:M,colorPrimaryText:T}}=te.useToken(),[m,w]=r.useState([]),[I,v]=r.useState([]),[S,u]=r.useState({}),[E,g]=r.useState([]),[B,f]=r.useState(0),[L,b]=r.useState(!1),[$,y]=r.useState(0),[O,d]=r.useState(!1),[R,A]=r.useState("添加"),[P,k]=r.useState(!1),[h]=p.useForm(),V=[{title:"序 号",dataIndex:"id",width:"80px",align:"center",key:"id",render:(s,t,a)=>e.jsx(e.Fragment,{children:a+1})},{title:"角 色",dataIndex:"name",key:"name",align:"center",render:s=>e.jsx(e.Fragment,{children:s})},{title:"描 述",dataIndex:"remark",key:"remark",align:"center",render:s=>e.jsx(e.Fragment,{children:s})},{title:"操 作",align:"center",key:"handle",render:(s,t)=>e.jsx(e.Fragment,{children:e.jsxs(ae,{size:"large",style:{color:T},children:[e.jsxs("span",{style:{cursor:"pointer"},onClick:()=>H("编 辑",t),children:[e.jsx(oe,{}),"  编 辑"]}),e.jsxs("span",{style:{cursor:"pointer"},onClick:()=>{z.confirm({title:"温馨提示",content:"确定删除吗?",onOk(){Z(t.id)}})},children:[e.jsx(de,{}),"  删 除"]}),e.jsxs("span",{style:{cursor:"pointer"},onClick:()=>q(s),children:[e.jsx(re,{}),"  菜 单 管 理"]})]})})}];r.useEffect(()=>{(async()=>{try{const{data:t,total:a}=await x("/api/Role/All",{pageSize:9999,pageIndex:1});g(t),f(a)}catch(t){console.log(t)}})()},[]);const q=async s=>{u(s),k(!0);const t=[];try{const{code:a,data:o,msg:l}=await x("/api/Role/GetMenu",{RoleIdId:s.id});a===200?(n.success(l,3),v(o),o.forEach(i=>{i.state.checked?(t.push(i.id),i.nodes&&i.nodes.forEach(c=>{c.state.checked&&t.push(c.id)})):i.nodes&&i.nodes.forEach(c=>{c.state.checked&&t.push(c.id)})}),w(t)):n.warning(l)}catch(a){n.error(a)}},G=()=>{k(!1)},J=(s,t)=>{if(t.node.parent){let o=Array.from(new Set([...s.checked,t.node.parent]));s.checked=o}else{let o=[...s.checked];t.checkedNodes.forEach(l=>{l.parent===t.node.id&&(o.push(t.node.id),s.checked=Array.from(new Set(o)))})}w(s)},Q=async()=>{const s=m.checked?m.checked:[],t={RoleId:S.id};try{const{code:a,msg:o}=await F("/api/Role/SetRoleMenu",s,t);a===200?(n.success(o,3),k(!1)):n.warning(o)}catch(a){n.error(a)}},U=s=>{A(s),d(!0),y(0),u({})},H=(s,t)=>{A(s),d(!0),u(t),y(t.id),h.setFieldsValue({name:t.name,remark:t.remark})},W=()=>{h.submit()},X=async s=>{R!=="添 加"&&(s.id=$),b(!0);try{const{code:t,msg:a}=await F("/api/Role/AddOrUpdate",s);if(t===200){n.success(a);const{data:o,total:l}=await x("/api/Role/All",{pageSize:9999,pageIndex:1});g(o),f(l)}else n.info(a);d(!1)}catch(t){n.error(t,3)}b(!1)},Y=()=>{d(!1)},Z=async s=>{try{const{code:t,msg:a}=await ne(`/api/Role/Del/${s}`);if(t===200){n.success(a);const{data:o,total:l}=await x("/api/Role/All",{pageSize:9999,pageIndex:1});g(o),f(l)}else n.warning(a)}catch(t){console.log(t)}},K=()=>{h.resetFields(),y(null)};return e.jsxs(he,{children:[e.jsxs("div",{className:"roleList",style:{backgroundColor:N,borderRadius:M},children:[e.jsx("div",{className:"topBarAddBtn",children:e.jsxs(C,{type:"primary",onClick:()=>U("添 加"),children:[e.jsx(D,{}),"添加角色"]})}),e.jsx("div",{className:"bottomList",children:e.jsx(le,{columns:V,rowKey:s=>s.id,dataSource:E,sticky:!0,size:"small",loading:L,pagination:{total:B,defaultPageSize:50,showSizeChanger:!0,showQuickJumper:!0,showTotal:s=>`共 ${s} 条`}})})]}),e.jsx(se,{text:e.jsxs("span",{style:{fontSize:"24px"},children:[e.jsx(D,{})," ",R]}),width:618,open:O,onOk:W,onCancel:Y,afterClose:K,destroyOnClose:!0,children:e.jsx(pe,{children:e.jsxs(p,{form:h,layout:"inline",onFinish:X,children:[e.jsx(p.Item,{label:"角色名 : ",name:"name",style:{width:"45%"},rules:[{required:!0,message:"请输入角色名"}],children:e.jsx(_,{className:"ysh_antd_input",placeholder:"请输入角色名"})}),e.jsx(p.Item,{label:"描 述 : ",name:"remark",style:{width:"45%"},children:e.jsx(_,{className:"ysh_antd_input",placeholder:"请输入描述"})})]})})}),e.jsx(ie,{title:`${S.name} ~ 菜单设置`,placement:"right",open:P,onClose:G,children:e.jsxs(xe,{children:[I.length>0&&e.jsx(ce,{className:"ysh_antd_tree",checkable:!0,checkStrictly:!0,checkedKeys:m,onCheck:J,treeData:I,defaultExpandAll:!0,fieldNames:{title:"menuname",key:"id",children:"nodes"}}),e.jsx("p",{className:"ysh_p",children:e.jsx(C,{onClick:Q,children:"提 交"})})]})})]})});me.displayName="SystemRole";export{me as default};
