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