2 lines
6.3 KiB
JavaScript
2 lines
6.3 KiB
JavaScript
import{u as G,G as H,r,j as e,T as Q,z as N,Q as U,B as c,I as E,U as W,V as X,M as y,N as Y,c as Z,J as ee,K as se,W as te,X as ae,s as _}from"./index-D2cxrzyv.js";import{l as re}from"./tenant-DSFtTF68.js";import{l as oe,d as ne,u as le,c as ie}from"./org-DMlC3mxP.js";import{u as ce}from"./useDict-BN4y0n-Y.js";import{P as de}from"./index-DICUnuN_.js";import{F as l}from"./index-KuslyOWx.js";import{T as P}from"./index-C8Xnkbw4.js";import{P as me}from"./index-Dv-9vGc2.js";import{C as k}from"./index-BFDbUxK1.js";import{F as ue}from"./Table-BLvbgkX9.js";import{I as v}from"./index-4zw5l6IX.js";import{R as pe,C as F}from"./row-C5EMotZ4.js";import"./useForm-CaItC8xb.js";import"./iconUtil-CAY5Il88.js";import"./index-COTHVrjr.js";import"./index-Iw46KAPi.js";import"./Pagination-lXX40XmA.js";const{Text:R}=Q;function ge(s){const n=new Map,d=[];s.forEach(a=>{n.set(a.id,{...a,children:[]})}),n.forEach(a=>{a.parentId&&n.has(a.parentId)?n.get(a.parentId).children.push(a):d.push(a)});const g=a=>{a.sort((m,x)=>(m.sortOrder||0)-(x.sortOrder||0)),a.forEach(m=>m.children&&g(m.children))};return g(d),d}function ke(){var O;const{t:s}=G(),{can:n}=H(),{items:d}=ce("sys_common_status"),[g,a]=r.useState(!1),[m,x]=r.useState(!1),[f,D]=r.useState([]),[b,M]=r.useState([]),[i,I]=r.useState(void 0),[V,u]=r.useState(!1),[w,T]=r.useState(null),[p]=l.useForm(),h=r.useMemo(()=>{const t=sessionStorage.getItem("userProfile");return t?JSON.parse(t).isPlatformAdmin&&localStorage.getItem("activeTenantId")==="0":!1},[]),C=r.useMemo(()=>Number(localStorage.getItem("activeTenantId")||0),[]),z=async()=>{if(!h){I(C);return}try{const o=(await re({current:1,size:100})).records||[];M(o),o.length>0&&i===void 0&&I(o[0].id)}catch{}},j=async()=>{if(i!==void 0){a(!0);try{const t=await oe(i);D(t||[])}finally{a(!1)}}};r.useEffect(()=>{z()},[]),r.useEffect(()=>{j()},[i]);const $=r.useMemo(()=>ge(f),[f]),L=r.useMemo(()=>f.map(t=>({label:t.orgName,value:t.id})),[f]),S=t=>{T(null),p.resetFields(),p.setFieldsValue({tenantId:i,parentId:t,status:1,sortOrder:0}),u(!0)},q=t=>{T(t),p.setFieldsValue(t),u(!0)},A=async t=>{await ne(t),_.success(s("common.success")),j()},B=async()=>{const t=await p.validateFields();x(!0);try{w?await le(w.id,t):await ie(t),_.success(s("common.success")),u(!1),j()}finally{x(!1)}},J=[{title:s("orgs.orgName"),dataIndex:"orgName",key:"orgName",render:t=>e.jsx(R,{strong:!0,children:t})},{title:s("orgs.orgCode"),dataIndex:"orgCode",key:"orgCode",width:150,render:t=>e.jsx(P,{className:"tabular-nums",children:t||"-"})},{title:s("orgs.sort"),dataIndex:"sortOrder",width:100,className:"tabular-nums"},{title:s("common.status"),dataIndex:"status",width:100,render:t=>{const o=d.find(K=>K.itemValue===String(t));return e.jsx(P,{color:t===1?"green":"red",children:o?o.itemLabel:s(t===1?"orgsExt.enabled":"orgsExt.disabled")})}},{title:s("common.action"),key:"action",width:180,render:(t,o)=>e.jsxs(N,{children:[n("sys:org:create")&&e.jsx(U,{title:s("orgs.addSub"),children:e.jsx(c,{type:"text",size:"small",icon:e.jsx(E,{"aria-hidden":"true"}),onClick:()=>S(o.id),"aria-label":s("orgs.addSub")})}),n("sys:org:update")&&e.jsx(c,{type:"text",size:"small",icon:e.jsx(W,{"aria-hidden":"true"}),onClick:()=>q(o),"aria-label":s("common.edit")}),n("sys:org:delete")&&e.jsx(me,{title:s("orgsExt.deleteConfirm",{name:o.orgName}),okText:s("common.confirm"),cancelText:s("common.cancel"),onConfirm:()=>A(o.id),children:e.jsx(c,{type:"text",size:"small",danger:!0,icon:e.jsx(X,{"aria-hidden":"true"}),"aria-label":s("common.delete")})})]})}];return e.jsxs("div",{className:"app-page",children:[e.jsx(de,{title:s("orgs.title"),subtitle:s("orgs.subtitle")}),e.jsx("div",{className:"app-page__page-actions",children:n("sys:org:create")&&e.jsx(c,{type:"primary",icon:e.jsx(E,{"aria-hidden":"true"}),onClick:()=>S(),children:s("common.create")})}),h&&e.jsx(k,{className:"app-page__filter-card",styles:{body:{padding:"16px"}},children:e.jsxs(N,{className:"app-page__toolbar",children:[e.jsx(R,{strong:!0,children:s("users.tenant")}),e.jsx(y,{style:{width:220},placeholder:s("orgs.selectTenant"),value:i,onChange:I,options:b.map(t=>({label:t.tenantName,value:t.id})),suffixIcon:e.jsx(Y,{"aria-hidden":"true"})}),e.jsx(c,{icon:e.jsx(Z,{"aria-hidden":"true"}),onClick:j,children:s("common.refresh")})]})}),e.jsx(k,{className:"app-page__content-card flex-1 flex flex-col overflow-hidden",styles:{body:{padding:0,flex:1,display:"flex",flexDirection:"column",overflow:"hidden"}},children:i!==void 0?e.jsx(ue,{rowKey:"id",columns:J,dataSource:$,loading:g,pagination:!1,size:"middle",scroll:{y:"calc(100vh - 350px)"},expandable:{defaultExpandAllRows:!0}}):e.jsx("div",{className:"py-20 flex justify-center",children:e.jsx(ee,{description:s("orgs.selectTenant")})})}),e.jsx(se,{title:e.jsxs(N,{children:[e.jsx(ae,{"aria-hidden":"true"}),e.jsx("span",{children:s(w?"orgs.drawerTitleEdit":"orgs.drawerTitleCreate")})]}),open:V,onClose:()=>u(!1),width:420,destroyOnClose:!0,footer:e.jsxs("div",{className:"app-page__drawer-footer",children:[e.jsx(c,{onClick:()=>u(!1),children:s("common.cancel")}),e.jsx(c,{type:"primary",loading:m,onClick:B,children:s("common.save")})]}),children:e.jsxs(l,{form:p,layout:"vertical",children:[e.jsx(l.Item,{label:s("users.tenant"),name:"tenantId",rules:[{required:!0}],hidden:!h,children:e.jsx(y,{disabled:!0,options:b.map(t=>({label:t.tenantName,value:t.id}))})}),!h&&e.jsx(l.Item,{label:s("users.tenant"),children:e.jsx(v,{value:((O=b.find(t=>t.id===C))==null?void 0:O.tenantName)||s("orgsExt.currentTenant"),disabled:!0})}),e.jsx(l.Item,{label:s("orgs.parentOrg"),name:"parentId",children:e.jsx(y,{placeholder:s("orgs.rootOrg"),allowClear:!0,showSearch:!0,optionFilterProp:"label",options:L})}),e.jsx(l.Item,{label:s("orgs.orgName"),name:"orgName",rules:[{required:!0,message:s("orgs.orgName")}],children:e.jsx(v,{placeholder:s("orgsExt.orgNamePlaceholder")})}),e.jsx(l.Item,{label:s("orgs.orgCode"),name:"orgCode",children:e.jsx(v,{placeholder:s("orgsExt.orgCodePlaceholder"),className:"tabular-nums"})}),e.jsxs(pe,{gutter:16,children:[e.jsx(F,{span:12,children:e.jsx(l.Item,{label:s("dicts.sort"),name:"sortOrder",initialValue:0,children:e.jsx(te,{style:{width:"100%"},min:0,className:"tabular-nums"})})}),e.jsx(F,{span:12,children:e.jsx(l.Item,{label:s("common.status"),name:"status",initialValue:1,children:e.jsx(y,{options:d.map(t=>({label:t.itemLabel,value:Number(t.itemValue)}))})})})]})]})})]})}export{ke as default};
|