import{q as L,c as B,a as p,b as l,w as n,y as G,k as H,r as o,x as J,h as m,f as K,o as U,e as d,t as w,F as O,z as P,E as b,A as Q,j as W}from"./index-jnsG7DVq.js";import{b as c}from"./index-DD1Ebu5S.js";const X={class:"content-card"},Y={class:"card-title"},ae={__name:"UserManage",setup(Z){const x=m([]),y=m(!1),f=m(!1),V=m(!1),u=m(null),v=m(null),s=K({username:"",password:"",realname:"",role:""}),h=W(()=>({username:s.role==="sales"?[]:[{required:!0,message:"请输入用户名",trigger:"blur"}],password:s.role==="sales"?[]:[{required:!0,message:"请输入密码",trigger:"blur"}],realname:[{required:!0,message:"请输入姓名",trigger:"blur"}],role:[{required:!0,message:"请选择角色",trigger:"change"}]}));function z(){v.value&&v.value.clearValidate(["username","password"])}const E=a=>({admin:"管理员",sales:"销售",rd:"研发"})[a]||a,M=a=>({admin:"danger",sales:"warning",rd:""})[a]||"info";async function g(){y.value=!0;try{const a=await c.getUsers();x.value=a.data}finally{y.value=!1}}function D(a){u.value=(a==null?void 0:a.id)||null,s.username=(a==null?void 0:a.username)||"",s.password="",s.realname=(a==null?void 0:a.realname)||"",s.role=(a==null?void 0:a.role)||"",f.value=!0}async function N(){var e;if(await((e=v.value)==null?void 0:e.validate().catch(()=>!1))){V.value=!0;try{if(u.value){const r={realname:s.realname,role:s.role};s.password&&(r.password=s.password),await c.updateUser(u.value,r),b.success("更新成功")}else await c.createUser(s),b.success("创建成功");f.value=!1,g()}finally{V.value=!1}}}async function R(a){await c.updateUser(a.id,{status:a.status===1?0:1}),b.success("状态已更新"),g()}async function S(a){await Q.confirm(`确定删除用户 "${a.realname}" 吗？`,"确认删除",{type:"warning"}),await c.deleteUser(a.id),b.success("删除成功"),g()}return L(g),(a,e)=>{const r=o("el-button"),i=o("el-table-column"),$=o("el-tag"),A=o("el-table"),k=o("el-option"),F=o("el-select"),_=o("el-form-item"),C=o("el-input"),I=o("el-form"),T=o("el-dialog"),j=J("loading");return U(),B("div",null,[e[13]||(e[13]=p("div",{class:"page-header"},[p("h1",null,"账号管理"),p("p",null,"管理系统用户账号，分配角色权限")],-1)),p("div",X,[p("div",Y,[e[8]||(e[8]=p("span",null,"用户列表",-1)),l(r,{type:"primary",onClick:e[0]||(e[0]=t=>D())},{default:n(()=>[...e[7]||(e[7]=[d("+ 新增用户",-1)])]),_:1})]),G((U(),H(A,{data:x.value,stripe:""},{default:n(()=>[l(i,{prop:"id",label:"ID",width:"60"}),l(i,{prop:"username",label:"用户名",width:"120"}),l(i,{prop:"realname",label:"姓名",width:"120"}),l(i,{prop:"role",label:"角色",width:"100"},{default:n(({row:t})=>[l($,{type:M(t.role),effect:"dark",round:""},{default:n(()=>[d(w(E(t.role)),1)]),_:2},1032,["type"])]),_:1}),l(i,{prop:"status",label:"状态",width:"80"},{default:n(({row:t})=>[l($,{type:t.status===1?"success":"danger",effect:"dark",round:""},{default:n(()=>[d(w(t.status===1?"启用":"禁用"),1)]),_:2},1032,["type"])]),_:1}),l(i,{prop:"created_at",label:"创建时间",width:"180"}),l(i,{label:"操作","min-width":"200"},{default:n(({row:t})=>[l(r,{size:"small",onClick:q=>D(t)},{default:n(()=>[...e[9]||(e[9]=[d("编辑",-1)])]),_:1},8,["onClick"]),l(r,{size:"small",type:t.status===1?"warning":"success",onClick:q=>R(t)},{default:n(()=>[d(w(t.status===1?"禁用":"启用"),1)]),_:2},1032,["type","onClick"]),l(r,{size:"small",type:"danger",onClick:q=>S(t)},{default:n(()=>[...e[10]||(e[10]=[d("删除",-1)])]),_:1},8,["onClick"])]),_:1})]),_:1},8,["data"])),[[j,y.value]])]),l(T,{modelValue:f.value,"onUpdate:modelValue":e[6]||(e[6]=t=>f.value=t),title:u.value?"编辑用户":"新增用户",width:"460px","destroy-on-close":""},{footer:n(()=>[l(r,{onClick:e[5]||(e[5]=t=>f.value=!1)},{default:n(()=>[...e[11]||(e[11]=[d("取消",-1)])]),_:1}),l(r,{type:"primary",loading:V.value,onClick:N},{default:n(()=>[...e[12]||(e[12]=[d("保存",-1)])]),_:1},8,["loading"])]),default:n(()=>[l(I,{model:s,rules:h.value,ref_key:"formRef",ref:v,"label-width":"80px"},{default:n(()=>[l(_,{label:"角色",prop:"role"},{default:n(()=>[l(F,{modelValue:s.role,"onUpdate:modelValue":e[1]||(e[1]=t=>s.role=t),placeholder:"选择角色",style:{width:"100%"},onChange:z},{default:n(()=>[l(k,{label:"管理员",value:"admin"}),l(k,{label:"销售",value:"sales"}),l(k,{label:"研发",value:"rd"})]),_:1},8,["modelValue"])]),_:1}),l(_,{label:"姓名",prop:"realname"},{default:n(()=>[l(C,{modelValue:s.realname,"onUpdate:modelValue":e[2]||(e[2]=t=>s.realname=t),placeholder:"真实姓名"},null,8,["modelValue"])]),_:1}),s.role!=="sales"?(U(),B(O,{key:0},[l(_,{label:"用户名",prop:"username"},{default:n(()=>[l(C,{modelValue:s.username,"onUpdate:modelValue":e[3]||(e[3]=t=>s.username=t),disabled:!!u.value,placeholder:"登录用户名"},null,8,["modelValue","disabled"])]),_:1}),l(_,{label:"密码",prop:u.value?"":"password"},{default:n(()=>[l(C,{modelValue:s.password,"onUpdate:modelValue":e[4]||(e[4]=t=>s.password=t),type:"password","show-password":"",placeholder:u.value?"留空则不修改":"请输入密码"},null,8,["modelValue","placeholder"])]),_:1},8,["prop"])],64)):P("",!0)]),_:1},8,["model","rules"])]),_:1},8,["modelValue","title"])])}}};export{ae as default};
