Files
JayuCloud/docs/product/Frontend/assets/AccountSettingsView-dV-lWHMq.js
T

2 lines
10 KiB
JavaScript

import{c as e,I as re,d as le,o as ie,b as ce,e as m,f as n,r as f,i as s,B as de,Q as ue,M as j,j as D,s as F,Y as fe,as as ve,at as pe,au as he,av as me,t as y,O as ge,m as be,aw as _e,R as we,F as Ce,p as Pe,q as ye,l as B,A as ke,D as R,u as Se,G as Ie}from"./index-bPsB4P3d.js";import{u as g}from"./user-BRXmSDmz.js";import{L as k}from"./LockOutlined-CTRDfVcq.js";var Oe={icon:{tag:"svg",attrs:{viewBox:"64 64 896 896",focusable:"false"},children:[{tag:"path",attrs:{d:"M877.1 238.7L770.6 132.3c-13-13-30.4-20.3-48.8-20.3s-35.8 7.2-48.8 20.3L558.3 246.8c-13 13-20.3 30.5-20.3 48.9 0 18.5 7.2 35.8 20.3 48.9l89.6 89.7a405.46 405.46 0 01-86.4 127.3c-36.7 36.9-79.6 66-127.2 86.6l-89.6-89.7c-13-13-30.4-20.3-48.8-20.3a68.2 68.2 0 00-48.8 20.3L132.3 673c-13 13-20.3 30.5-20.3 48.9 0 18.5 7.2 35.8 20.3 48.9l106.4 106.4c22.2 22.2 52.8 34.9 84.2 34.9 6.5 0 12.8-.5 19.2-1.6 132.4-21.8 263.8-92.3 369.9-198.3C818 606 888.4 474.6 910.4 342.1c6.3-37.6-6.3-76.3-33.3-103.4zm-37.6 91.5c-19.5 117.9-82.9 235.5-178.4 331s-213 158.9-330.9 178.4c-14.8 2.5-30-2.5-40.8-13.2L184.9 721.9 295.7 611l119.8 120 .9.9 21.6-8a481.29 481.29 0 00285.7-285.8l8-21.6-120.8-120.7 110.8-110.9 104.5 104.5c10.8 10.8 15.8 26 13.3 40.8z"}}]},name:"phone",theme:"outlined"};function z(v){for(var i=1;i<arguments.length;i++){var r=arguments[i]!=null?Object(arguments[i]):{},p=Object.keys(r);typeof Object.getOwnPropertySymbols=="function"&&(p=p.concat(Object.getOwnPropertySymbols(r).filter(function(b){return Object.getOwnPropertyDescriptor(r,b).enumerable}))),p.forEach(function(b){xe(v,b,r[b])})}return v}function xe(v,i,r){return i in v?Object.defineProperty(v,i,{value:r,enumerable:!0,configurable:!0,writable:!0}):v[i]=r,v}var S=function(i,r){var p=z({},i,r.attrs);return e(re,z({},p,{icon:Oe}),null)};S.displayName="PhoneOutlined";S.inheritAttrs=!1;const Le={class:"mobile-container"},Ve={class:"header"},Ae={class:"account-settings"},Ue=le({__name:"AccountSettingsView",setup(v){const i=Se(),r=f({id:0,nickname:"",account:"",avatar:"",type:0,status:0,createTime:"",updateTime:""}),p=f(!1),b=f(!1),w=f(!1),O=f(!1),c=R({phone:"",verificationCode:""}),C=f(!1),x=f(!1),d=R({newPhone:"",verificationCode:""}),P=f(!1),L=f(!1),l=R({verificationCode:"",password:"",confirmPassword:""}),u=f(0),$=f([{key:"changePhone",title:"修改手机号",icon:S,bgColor:"#e6f7ff"},{key:"changePassword",title:"修改密码",icon:k,bgColor:"#f6ffed"},{key:"deactivateAccount",title:"注销账号",icon:k,bgColor:"#fff1f0"}]),N=()=>{const a=[];b.value?a.push({key:"changePhone",title:"修改手机号",icon:S,bgColor:"#e6f7ff"}):a.push({key:"bindPhone",title:"绑定手机号",icon:S,bgColor:"#e6f7ff"}),p.value?a.push({key:"changePassword",title:"修改密码",icon:k,bgColor:"#f6ffed"}):a.push({key:"setPassword",title:"设置密码",icon:k,bgColor:"#fff7e6"}),a.push({key:"deactivateAccount",title:"注销账号",icon:k,bgColor:"#fff1f0"}),$.value=a},V=async()=>{try{const a=await g.getUserInfo();r.value=a,b.value=!!r.value.phone,p.value=localStorage.getItem("needSetPassword")!=="true",N()}catch(a){console.error("获取用户信息失败:",a),s.error("获取用户信息失败")}},E=()=>{i.back()},q=a=>{switch(a){case"bindPhone":w.value=!0;break;case"changePhone":C.value=!0;break;case"setPassword":G();break;case"changePassword":P.value=!0;break;case"deactivateAccount":oe();break}},G=()=>{i.push("/settings/password")},Q=async()=>{if(!c.phone){s.error("请输入手机号");return}if(!/^1[3-9]\d{9}$/.test(c.phone)){s.error("手机号格式不正确");return}try{await g.sendVerificationCode({phone:c.phone}),s.success("验证码发送成功"),A()}catch(o){console.error("发送验证码失败:",o),s.error("发送验证码失败")}},Y=async()=>{if(!d.newPhone){s.error("请输入新手机号");return}if(!/^1[3-9]\d{9}$/.test(d.newPhone)){s.error("手机号格式不正确");return}try{await g.sendVerificationCode({phone:d.newPhone}),s.success("验证码发送成功"),A()}catch(o){console.error("发送验证码失败:",o),s.error("发送验证码失败")}},H=async()=>{if(!r.value.phone){s.error("请先绑定手机号");return}if(!/^1[3-9]\d{9}$/.test(r.value.phone)){s.error("手机号格式不正确");return}try{await g.sendVerificationCode({phone:r.value.phone}),s.success("验证码发送成功"),A()}catch(o){console.error("发送验证码失败:",o),s.error("发送验证码失败")}},A=()=>{u.value=60;const a=setInterval(()=>{u.value--,u.value<=0&&clearInterval(a)},1e3)},J=async()=>{if(!c.phone||!c.verificationCode){s.error("请填写完整信息");return}O.value=!0;try{await g.bindPhone({phone:c.phone,verificationCode:c.verificationCode}),s.success("手机号绑定成功"),w.value=!1,await V()}catch(a){console.error("绑定手机号失败:",a),s.error(a.message||"绑定手机号失败")}finally{O.value=!1}},W=()=>{w.value=!1,c.phone="",c.verificationCode=""},X=async()=>{if(!d.newPhone||!d.verificationCode){s.error("请填写完整信息");return}x.value=!0;try{await g.updatePhone({oldPhone:r.value.phone,newPhone:d.newPhone,verificationCode:d.verificationCode}),s.success("手机号修改成功"),C.value=!1,await V()}catch(a){console.error("修改手机号失败:",a),s.error(a.message||"修改手机号失败")}finally{x.value=!1}},Z=()=>{C.value=!1,d.newPhone="",d.verificationCode=""},K=async()=>{if(!l.verificationCode||!l.password||!l.confirmPassword){s.error("请填写完整信息");return}if(l.password!==l.confirmPassword){s.error("两次输入的密码不一致");return}L.value=!0;try{await g.updatePassword({password:l.password,verificationCode:l.verificationCode}),s.success("密码修改成功"),P.value=!1,localStorage.removeItem("needSetPassword"),p.value=!0}catch(a){console.error("修改密码失败:",a),s.error(a.message||"修改密码失败")}finally{L.value=!1}},ee=()=>{P.value=!1,l.verificationCode="",l.password="",l.confirmPassword=""},oe=async()=>{j.confirm({title:"确认注销账号",content:"注销账号后,您的所有数据将被删除且无法恢复。确定要注销账号吗?",okText:"确认注销",okType:"danger",cancelText:"取消",onOk:async()=>{try{await g.deactivateAccount(),s.success("账号注销成功")}catch(a){console.error("注销账号失败:",a),s.error("注销账号失败")}finally{localStorage.removeItem("accessToken"),localStorage.removeItem("refreshToken"),localStorage.removeItem("userInfo"),localStorage.removeItem("adminAccessToken"),localStorage.removeItem("adminRefreshToken"),localStorage.removeItem("adminUserInfo"),localStorage.removeItem("needSetPassword"),localStorage.removeItem("userPermissions"),sessionStorage.removeItem("accessToken"),sessionStorage.removeItem("adminAccessToken"),i.push("/")}}})};return ie(()=>{V()}),(a,o)=>{const I=de,ae=he,ne=pe,te=ve,se=ue,_=ye,h=Pe,U=Ce,T=j,M=ke;return D(),ce("div",Le,[m("header",Ve,[e(I,{class:"back-btn",type:"text",onClick:E},{default:n(()=>[e(F(fe),{style:{fontSize:"20px"}})]),_:1}),o[10]||(o[10]=m("h1",null,"账号设置",-1)),o[11]||(o[11]=m("div",{class:"empty"},null,-1))]),m("div",Ae,[e(se,{bordered:!1,class:"settings-card"},{default:n(()=>[e(te,{"data-source":$.value,split:!1},{renderItem:n(({item:t})=>[e(ne,{class:"setting-item",onClick:Te=>q(t.key)},{actions:n(()=>[e(F(we))]),default:n(()=>[e(ae,null,me({avatar:n(()=>[m("div",{class:"setting-icon",style:ge({backgroundColor:t.bgColor})},[(D(),be(_e(t.icon)))],4)]),title:n(()=>[m("span",null,y(t.title),1)]),_:2},[t.desc?{name:"description",fn:n(()=>[m("span",null,y(t.desc),1)]),key:"0"}:void 0]),1024)]),_:2},1032,["onClick"])]),_:1},8,["data-source"])]),_:1})]),e(T,{visible:w.value,"onUpdate:visible":o[2]||(o[2]=t=>w.value=t),title:"绑定手机号",onOk:J,onCancel:W,confirmLoading:O.value},{default:n(()=>[e(U,{layout:"vertical"},{default:n(()=>[e(h,{label:"手机号",name:"phone"},{default:n(()=>[e(_,{value:c.phone,"onUpdate:value":o[0]||(o[0]=t=>c.phone=t),placeholder:"请输入手机号",disabled:!!r.value.phone},null,8,["value","disabled"])]),_:1}),e(h,{label:"验证码",name:"verificationCode"},{default:n(()=>[e(_,{value:c.verificationCode,"onUpdate:value":o[1]||(o[1]=t=>c.verificationCode=t),placeholder:"请输入验证码"},{suffix:n(()=>[e(I,{type:"link",disabled:u.value>0||!c.phone,onClick:Q},{default:n(()=>[B(y(u.value>0?`${u.value}秒后重发`:"发送验证码"),1)]),_:1},8,["disabled"])]),_:1},8,["value"])]),_:1})]),_:1})]),_:1},8,["visible","confirmLoading"]),e(T,{visible:C.value,"onUpdate:visible":o[5]||(o[5]=t=>C.value=t),title:"修改手机号",onOk:X,onCancel:Z,confirmLoading:x.value},{default:n(()=>[e(U,{layout:"vertical"},{default:n(()=>[e(h,{label:"旧手机号"},{default:n(()=>[e(_,{value:r.value.phone,disabled:""},null,8,["value"])]),_:1}),e(h,{label:"新手机号",name:"newPhone"},{default:n(()=>[e(_,{value:d.newPhone,"onUpdate:value":o[3]||(o[3]=t=>d.newPhone=t),placeholder:"请输入新手机号"},null,8,["value"])]),_:1}),e(h,{label:"验证码",name:"verificationCode"},{default:n(()=>[e(_,{value:d.verificationCode,"onUpdate:value":o[4]||(o[4]=t=>d.verificationCode=t),placeholder:"请输入验证码"},{suffix:n(()=>[e(I,{type:"link",disabled:u.value>0||!d.newPhone,onClick:Y},{default:n(()=>[B(y(u.value>0?`${u.value}秒后重发`:"发送验证码"),1)]),_:1},8,["disabled"])]),_:1},8,["value"])]),_:1})]),_:1})]),_:1},8,["visible","confirmLoading"]),e(T,{visible:P.value,"onUpdate:visible":o[9]||(o[9]=t=>P.value=t),title:"修改密码",onOk:K,onCancel:ee,confirmLoading:L.value},{default:n(()=>[e(U,{layout:"vertical"},{default:n(()=>[e(h,{label:"手机号"},{default:n(()=>[e(_,{value:r.value.phone,disabled:""},null,8,["value"])]),_:1}),e(h,{label:"验证码",name:"verificationCode"},{default:n(()=>[e(_,{value:l.verificationCode,"onUpdate:value":o[6]||(o[6]=t=>l.verificationCode=t),placeholder:"请输入验证码"},{suffix:n(()=>[e(I,{type:"link",disabled:u.value>0,onClick:H},{default:n(()=>[B(y(u.value>0?`${u.value}秒后重发`:"发送验证码"),1)]),_:1},8,["disabled"])]),_:1},8,["value"])]),_:1}),e(h,{label:"新密码",name:"password"},{default:n(()=>[e(M,{value:l.password,"onUpdate:value":o[7]||(o[7]=t=>l.password=t),placeholder:"请输入新密码"},null,8,["value"]),o[12]||(o[12]=m("div",{class:"password-tip"}," 密码长度至少8位,包含字母和数字 ",-1))]),_:1}),e(h,{label:"确认密码",name:"confirmPassword"},{default:n(()=>[e(M,{value:l.confirmPassword,"onUpdate:value":o[8]||(o[8]=t=>l.confirmPassword=t),placeholder:"请再次输入新密码"},null,8,["value"])]),_:1})]),_:1})]),_:1},8,["visible","confirmLoading"])])}}}),Me=Ie(Ue,[["__scopeId","data-v-5b38bf5f"]]);export{Me as default};