unis_crm/frontend1/dist/assets/index-D1S-tzz4.js

2 lines
5.1 KiB
JavaScript

import{u as O,r as a,j as e,B as Y,W as F,a3 as H,Y as b,b0 as W,a5 as J,bo as Z,T as q,Z as G,aT as Q,bd as U,b4 as V,s as v,be as X}from"./index-2nzO_M0d.js";import{P as ee}from"./index-Ds3G3GDW.js";import{R as se,C}from"./row-CR991LIl.js";import{C as T}from"./index-ESbS3nHt.js";import{I as te}from"./index-fAufRegR.js";import{F as re,b as ae}from"./Table-UD3nj3r6.js";import{T as y}from"./index-CASbXnpp.js";import"./useForm-CzLkm9RK.js";import"./index-z7YG9RTL.js";import"./Pagination-CRtRHhmu.js";const{Text:le}=q;function oe(t){if(!t.length)return[];const l=t.filter(r=>r.status!==0),m=new Map,n=[];l.forEach(r=>{m.set(r.permId,{...r,key:r.permId,children:[]})}),m.forEach(r=>{if(r.parentId&&r.parentId!==0){const i=m.get(r.parentId);i&&i.children.push(r)}else n.push(r)});const p=r=>{r.sort((i,h)=>(i.sortOrder||0)-(h.sortOrder||0)),r.forEach(i=>{var h;(h=i.children)!=null&&h.length&&p(i.children)})};return p(n),n}function k(t){return t.map(l=>{var m;return{key:l.permId,title:e.jsxs(b,{children:[e.jsx("span",{children:l.name}),l.permType==="button"?e.jsx(y,{color:"blue",style:{marginLeft:4},children:"Button"}):null]}),children:(m=l.children)!=null&&m.length?k(l.children):void 0}})}function xe(){const{t}=O(),[l,m]=a.useState([]),[n,p]=a.useState([]),[r,i]=a.useState(!1),[h,N]=a.useState(!1),[I,P]=a.useState(!1),[o,R]=a.useState(null),[S,f]=a.useState([]),[E,g]=a.useState([]),[x,_]=a.useState(""),M=a.useMemo(()=>{const s=sessionStorage.getItem("userProfile");return s?JSON.parse(s).isPlatformAdmin&&localStorage.getItem("activeTenantId")==="0":!1},[]),u=a.useMemo(()=>l.find(s=>s.roleId===o)||null,[l,o]),A=a.useMemo(()=>{if(!x)return l;const s=x.toLowerCase();return l.filter(c=>c.roleName.toLowerCase().includes(s)||c.roleCode.toLowerCase().includes(s))},[l,x]),L=a.useMemo(()=>k(oe(n)),[n]),z=async()=>{i(!0);try{const s=await Q();m(s||[])}finally{i(!1)}},B=async()=>{N(!0);try{const s=await U();p(s||[])}finally{N(!1)}},K=async s=>{try{const j=(await V(s)||[]).map(d=>Number(d)).filter(d=>!Number.isNaN(d)).filter(d=>!n.some(D=>D.parentId===d));f(j),g([])}catch{f([]),g([])}};a.useEffect(()=>{z(),B()},[]),a.useEffect(()=>{o&&n.length>0?K(o):(f([]),g([]))},[o,n]);const $=async()=>{if(!o){v.warning(t("rolePerm.selectRole"));return}P(!0);try{await X(o,Array.from(new Set([...S,...E]))),v.success(t("common.success"))}finally{P(!1)}};return e.jsxs("div",{className:"app-page",children:[e.jsx(ee,{title:t("rolePerm.title"),subtitle:t("rolePerm.subtitle")}),e.jsx("div",{className:"app-page__page-actions",children:e.jsx(Y,{type:"primary",icon:e.jsx(F,{"aria-hidden":"true"}),onClick:$,loading:I,disabled:!o||(u==null?void 0:u.roleCode)==="TENANT_ADMIN"&&!M,children:t(I?"common.loading":"common.save")})}),e.jsxs(se,{gutter:24,className:"app-page__split",style:{height:"calc(100vh - 180px)"},children:[e.jsx(C,{xs:24,lg:10,style:{height:"100%"},children:e.jsxs(T,{title:e.jsxs(b,{children:[e.jsx(W,{"aria-hidden":"true"}),e.jsx("span",{children:t("rolePerm.roleList")})]}),className:"app-page__panel-card full-height-card",children:[e.jsx("div",{className:"mb-4",children:e.jsx(te,{placeholder:t("rolePerm.searchRole"),prefix:e.jsx(H,{"aria-hidden":"true",className:"text-gray-400"}),value:x,onChange:s=>_(s.target.value),allowClear:!0,"aria-label":t("rolePerm.searchRole")})}),e.jsx("div",{style:{height:"calc(100% - 60px)",overflowY:"auto"},children:e.jsx(re,{rowKey:"roleId",size:"middle",loading:r,dataSource:A,rowSelection:{type:"radio",selectedRowKeys:o?[o]:[],onChange:s=>R(s[0])},onRow:s=>({onClick:()=>R(s.roleId),className:"cursor-pointer"}),pagination:{pageSize:10,showTotal:s=>t("common.total",{total:s})},columns:[{title:t("roles.roleName"),key:"role",render:(s,c)=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{style:{fontWeight:500},className:"truncate",children:c.roleName}),e.jsx("div",{style:{fontSize:12,color:"#8c8c8c"},className:"truncate tabular-nums",children:c.roleCode})]})},{title:t("common.status"),dataIndex:"status",width:80,render:s=>s===1?e.jsx(y,{color:"green",className:"m-0",children:"鍚敤"}):e.jsx(y,{className:"m-0",children:"绂佺敤"})}]})})]})}),e.jsx(C,{xs:24,lg:14,style:{height:"100%"},children:e.jsx(T,{title:e.jsxs(b,{children:[e.jsx(G,{"aria-hidden":"true"}),e.jsx("span",{children:t("rolePerm.permConfig")})]}),className:"app-page__panel-card full-height-card",extra:u?e.jsxs(y,{color:"blue",children:[t("rolePerm.currentRole"),": ",u.roleName]}):null,children:o?e.jsxs("div",{className:"role-permission-tree-container",style:{padding:"8px 0",height:"100%",overflowY:"auto"},children:[e.jsx(ae,{checkable:!0,selectable:!1,checkStrictly:!1,treeData:L,checkedKeys:S,onCheck:(s,c)=>{const w=Array.isArray(s)?s:s.checked,j=c.halfCheckedKeys||[];f(w.map(d=>Number(d))),g(j.map(d=>Number(d)))},defaultExpandAll:!0}),!n.length&&!h?e.jsx(J,{description:"鏆傛棤鏉冮檺鏁版嵁"}):null]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 bg-gray-50 rounded-lg border border-dashed border-gray-200",children:[e.jsx(Z,{style:{fontSize:40,color:"#bfbfbf",marginBottom:16},"aria-hidden":"true"}),e.jsx(le,{type:"secondary",children:t("rolePerm.selectRole")})]})})})]})]})}export{xe as default};