import{N as B,_ as R}from"./add-BQ5j9vop.js";import{_ as S,f as V,a as F,b as L,c as j}from"./search-CYpszvI_.js";import{d as O,S as Q,W,a as Y,o as Z,e as l,w as n,h as o,U as i,f as b,Y as N,V as P,B as d,g as f,N as G,Z as H,a0 as J,E as p,Q as K,R as X}from"./index-DSCno0m2.js";import{N as h}from"./Space-Dex4J4Il.js";import{N as ee,a as C}from"./FormItem-CHgZe7qM.js";import"./get-slot-Bk_rJcZu.js";const ae={class:"permission-management"},te=O({name:"system_permission",__name:"index",setup(le){const m=Q(),v=P({keyword:""}),y=i(!1),g=i(!1),r=i(!1),u=i(!1),_=i(null),w=i([]),U=b(()=>u.value?"编辑权限":"新增权限"),I=b(()=>{const e=v.keyword.trim().toLowerCase();return e?w.value.filter(a=>`${a.code} ${a.name}`.toLowerCase().includes(e)):w.value}),E=[{label:"接口权限(API)",value:"API"},{label:"菜单权限(MENU)",value:"MENU"}],t=P({id:null,code:"",name:"",type:"API"}),D={code:[{required:!0,message:"请输入权限编码",trigger:"blur"}],name:[{required:!0,message:"请输入权限名称",trigger:"blur"}],type:[{required:!0,message:"请选择权限类型",trigger:"change"}]},M=b(()=>[{title:"ID",key:"id",width:90},{title:"权限编码",key:"code",width:240},{title:"权限名称",key:"name",width:220},{title:"权限类型",key:"type",width:120,render:e=>p(K,{size:"small",bordered:!1,type:e.type==="MENU"?"warning":"info"},{default:()=>e.type})},{title:"操作",key:"actions",width:180,render:e=>p(h,{size:8},{default:()=>[p(d,{size:"small",onClick:()=>z(e)},{default:()=>"编辑"}),p(d,{size:"small",type:"error",onClick:()=>$(e)},{default:()=>"删除"})]})}]);async function c(){y.value=!0;try{const e=await V();w.value=e.data||[]}catch(e){m.error("加载权限失败"),console.error(e)}finally{y.value=!1}}function x(){t.id=null,t.code="",t.name="",t.type="API"}function T(){x(),u.value=!1,r.value=!0}function z(e){x(),u.value=!0,t.id=e.id,t.code=e.code,t.name=e.name,t.type=e.type,r.value=!0}async function A(){if(_.value)try{await _.value.validate(),g.value=!0;const e={code:t.code.trim(),name:t.name.trim(),type:t.type};u.value&&t.id?await F(t.id,e):await L(e),m.success(u.value?"权限已更新":"权限已创建"),r.value=!1,await c()}catch(e){console.error(e)}finally{g.value=!1}}async function $(e){const a=window.$dialog;a&&a.warning({title:"删除确认",content:`确定删除权限“${e.name}”吗？`,positiveText:"删除",negativeText:"取消",async onPositiveClick(){try{await j(e.id),m.success("权限已删除"),await c()}catch(k){m.error("删除权限失败"),console.error(k)}}})}return W(()=>{c()}),(e,a)=>{const k=S,q=R;return Z(),Y("div",ae,[l(o(G),{title:"权限管理",bordered:!1,size:"small"},{"header-extra":n(()=>[l(o(h),null,{default:n(()=>[l(o(N),{value:v.keyword,"onUpdate:value":a[0]||(a[0]=s=>v.keyword=s),placeholder:"搜索权限编码或名称",clearable:"",style:{width:"240px"}},null,8,["value"]),l(o(d),{onClick:c},{icon:n(()=>[l(k)]),default:n(()=>[a[6]||(a[6]=f(" 搜索 ",-1))]),_:1}),l(o(d),{type:"primary",onClick:T},{icon:n(()=>[l(q)]),default:n(()=>[a[7]||(a[7]=f(" 新增权限 ",-1))]),_:1})]),_:1})]),default:n(()=>[l(o(B),{columns:M.value,data:I.value,loading:y.value,pagination:!1},null,8,["columns","data","loading"])]),_:1}),l(o(J),{show:r.value,"onUpdate:show":a[5]||(a[5]=s=>r.value=s),preset:"card",title:U.value,style:{width:"520px"}},{footer:n(()=>[l(o(h),{justify:"end"},{default:n(()=>[l(o(d),{onClick:a[4]||(a[4]=s=>r.value=!1)},{default:n(()=>[...a[8]||(a[8]=[f("取消",-1)])]),_:1}),l(o(d),{type:"primary",loading:g.value,onClick:A},{default:n(()=>[...a[9]||(a[9]=[f("保存",-1)])]),_:1},8,["loading"])]),_:1})]),default:n(()=>[l(o(ee),{ref_key:"formRef",ref:_,model:t,rules:D,"label-placement":"left","label-width":90},{default:n(()=>[l(o(C),{label:"权限编码",path:"code"},{default:n(()=>[l(o(N),{value:t.code,"onUpdate:value":a[1]||(a[1]=s=>t.code=s),placeholder:"例如 sys:user:read"},null,8,["value"])]),_:1}),l(o(C),{label:"权限名称",path:"name"},{default:n(()=>[l(o(N),{value:t.name,"onUpdate:value":a[2]||(a[2]=s=>t.name=s),placeholder:"请输入权限名称"},null,8,["value"])]),_:1}),l(o(C),{label:"权限类型",path:"type"},{default:n(()=>[l(o(H),{value:t.type,"onUpdate:value":a[3]||(a[3]=s=>t.type=s),options:E,placeholder:"请选择类型"},null,8,["value"])]),_:1})]),_:1},8,["model"])]),_:1},8,["show","title"])])}}}),ue=X(te,[["__scopeId","data-v-30999ee4"]]);export{ue as default};
