var e=(e,a,l)=>new Promise((r,d)=>{var o=e=>{try{u(l.next(e))}catch(a){d(a)}},s=e=>{try{u(l.throw(e))}catch(a){d(a)}},u=e=>e.done?r(e.value):Promise.resolve(e.value).then(o,s);u((l=l.apply(e,a)).next())});import{A as a,B as l,C as r,a5 as d,a6 as o,e as s,X as u,E as t}from"./vendor-element-DupX9wXy.js";import{d as n,ar as i,a8 as p}from"./index-BkDr3sJj.js";import{q as m,c as g,bM as c,r as v,a2 as h,S as b,D as _,v as f,E as q,M as V,u as y,t as w,L as U,aq as D,A as x,J as Q,h as P,X as R}from"./vendor-core-Di0OO4oJ.js";const j={class:"dialog-footer"},k=m({__name:"user-dialog",props:{visible:{type:Boolean},type:{},userData:{}},emits:["update:visible","submit"],setup(m,{emit:k}){const A=m,M=k,{width:N}=c(),C=n(),E=g(()=>{var e;const a=(null==(e=C.info)?void 0:e.roles)||[];return!(a.includes("R_ADMIN")||a.includes("R_SUPER"))&&N.value<768}),B=v([]),G=g({get:()=>A.visible,set:e=>M("update:visible",e)}),I=g(()=>A.type),S=v(),X=h({id:void 0,username:"",password:"",phone:"",qq:"",gender:"男",group_id:void 0}),$={username:[{required:!0,message:"请输入用户名",trigger:"blur"},{min:2,max:20,message:"长度在 2 到 20 个字符",trigger:"blur"}],phone:[{required:!1,message:"请输入手机号",trigger:"blur"},{pattern:/^1[3-9]\d{9}$/,message:"请输入正确的手机号格式",trigger:"blur"}],qq:[{pattern:/^[1-9][0-9]{4,10}$/,message:"请输入正确的QQ号码",trigger:"blur"}],gender:[{required:!0,message:"请选择性别",trigger:"blur"}],group_id:[{required:!0,message:"请选择权限组",trigger:"change"}]};b(()=>[A.visible,A.type,A.userData],([a])=>{a&&(e(null,null,function*(){try{const e=yield p({current:1,size:100});B.value=e.records||[]}catch(e){}}),(()=>{const e="edit"===A.type&&A.userData,a=A.userData;Object.assign(X,{id:e&&a?a.id:void 0,username:e&&a&&a.userName||"",password:"",phone:e&&a&&a.userPhone||"",qq:e&&a&&a.qq||"",gender:e&&a&&a.userGender||"男",group_id:e&&a&&a.group_id||void 0})})(),R(()=>{var e;null==(e=S.value)||e.clearValidate()}))},{immediate:!0});const z=()=>e(null,null,function*(){S.value&&(yield S.value.validate(a=>e(null,null,function*(){if(a)try{const e={id:X.id,userName:X.username,password:X.password,userPhone:X.phone,qq:X.qq,userGender:X.gender,group_id:X.group_id,role:["R_ADMIN"]};yield i(e),t.success("add"===I.value?"添加成功":"更新成功"),G.value=!1,M("submit")}catch(e){}})))});return(e,t)=>{const n=r,i=l,p=o,m=d,g=a,c=s,v=u;return f(),_(v,{modelValue:y(G),"onUpdate:modelValue":t[7]||(t[7]=e=>P(G)?G.value=e:null),title:"add"===y(I)?"添加用户":"编辑用户",width:y(E)?"90%":"30%","align-center":""},{footer:q(()=>[x("div",j,[V(c,{onClick:t[6]||(t[6]=e=>G.value=!1)},{default:q(()=>[...t[8]||(t[8]=[Q("取消",-1)])]),_:1}),V(c,{type:"primary",onClick:z},{default:q(()=>[...t[9]||(t[9]=[Q("提交",-1)])]),_:1})])]),default:q(()=>[V(g,{ref_key:"formRef",ref:S,model:y(X),rules:$,"label-width":y(E)?"auto":"80px","label-position":y(E)?"top":"right"},{default:q(()=>[V(i,{label:"用户名",prop:"username"},{default:q(()=>[V(n,{modelValue:y(X).username,"onUpdate:modelValue":t[0]||(t[0]=e=>y(X).username=e),placeholder:"请输入用户名"},null,8,["modelValue"])]),_:1}),V(i,{label:"密码",prop:"password"},{default:q(()=>[V(n,{modelValue:y(X).password,"onUpdate:modelValue":t[1]||(t[1]=e=>y(X).password=e),type:"password",placeholder:"add"===y(I)?"请输入密码":"留空不修改","show-password":""},null,8,["modelValue","placeholder"])]),_:1}),V(i,{label:"手机号",prop:"phone"},{default:q(()=>[V(n,{modelValue:y(X).phone,"onUpdate:modelValue":t[2]||(t[2]=e=>y(X).phone=e),placeholder:"请输入手机号"},null,8,["modelValue"])]),_:1}),V(i,{label:"QQ",prop:"qq"},{default:q(()=>[V(n,{modelValue:y(X).qq,"onUpdate:modelValue":t[3]||(t[3]=e=>y(X).qq=e),placeholder:"请输入QQ号码"},null,8,["modelValue"])]),_:1}),V(i,{label:"性别",prop:"gender"},{default:q(()=>[V(m,{modelValue:y(X).gender,"onUpdate:modelValue":t[4]||(t[4]=e=>y(X).gender=e)},{default:q(()=>[V(p,{label:"男",value:"男"}),V(p,{label:"女",value:"女"})]),_:1},8,["modelValue"])]),_:1}),V(i,{label:"权限组",prop:"group_id"},{default:q(()=>[V(m,{modelValue:y(X).group_id,"onUpdate:modelValue":t[5]||(t[5]=e=>y(X).group_id=e),placeholder:"请选择权限组"},{default:q(()=>[(f(!0),w(U,null,D(y(B),e=>(f(),_(p,{key:e.id,value:e.id,label:e.name},null,8,["value","label"]))),128))]),_:1},8,["modelValue"])]),_:1})]),_:1},8,["model","label-width","label-position"])]),_:1},8,["modelValue","title","width"])}}});export{k as _};
