Files
wecom_it_smart_desk/frontend-agent/dist.bak/assets/Settings-0Zjw48iD.js
T

2 lines
8.6 KiB
JavaScript
Raw Normal View History

import{d as z,o as N,b as d,c,f as t,t as O,e as M,g as n,w as i,u as C,l as I,Z as K,h as T,p as L,G as Z,n as j,r as _,s as A,E as g,i as u,m as D,F as q,k as H,$ as J,B as Q}from"./index-B1u3nieA.js";import{a as V}from"./index-ChNUjLLo.js";import{u as W}from"./agent-WRYR5BAs.js";import"./conversation-C4tqOoff.js";async function X(){return await V.post("/auth/otp-bind")}async function Y(p){const y={otp_code:p};return await V.post("/auth/otp-verify",y)}async function ee(){return await V.get("/auth/otp-status")}async function te(p){const y={otp_code:p};return await V.post("/auth/otp-unbind",y)}const se={class:"otp-bind-panel"},ne={class:"bind-title"},oe={key:0,class:"bind-subtitle"},ae={key:0,class:"bind-loading"},le={key:1,class:"bind-content"},ie={class:"qr-section"},re={class:"qr-wrapper"},de=["src"],ce={key:1,class:"qr-placeholder"},ue={class:"secret-section"},pe={class:"secret-display"},fe={class:"secret-text"},_e={class:"verify-section"},ve={class:"bind-actions"},me=z({__name:"OtpBindPanel",props:{userId:{},name:{}},emits:["bind-success","cancel"],setup(p,{emit:y}){const r=p,P=y,b=_(),v=_(!0),m=_(!1),x=_(""),w=_(""),f=_(""),s=_(!1),e=A({otpCode:""}),h={otpCode:[{required:!0,message:"请输入 6 位验证码",trigger:"blur"},{len:6,message:"验证码为 6 位数字",trigger:"blur"},{pattern:/^\d{6}$/,message:"验证码只能包含数字",trigger:"blur"}]};N(async()=>{await $()});async function $(){v.value=!0,f.value="";try{const a=await X();w.value=a.secret,x.value=a.qr_code_base64}catch(a){const o=a instanceof Error?a.message:"获取绑定信息失败";console.error("[OtpBindPanel] 获取绑定信息失败:",a),f.value=o}finally{v.value=!1}}async function B(){if(w.value)try{await navigator.clipboard.writeText(w.value),s.value=!0,g.success("密钥已复制到剪贴板"),setTimeout(()=>{s.value=!1},2e3)}catch{const a=document.createElement("textarea");a.value=w.value,a.style.position="fixed",a.style.opacity="0",document.body.appendChild(a),a.select();try{document.execCommand("copy"),s.value=!0,g.success("密钥已复制到剪贴板"),setTimeout(()=>{s.value=!1},2e3)}catch{g.error("复制失败,请手动复制密钥")}document.body.removeChild(a)}}async function k(){var o;if(await((o=b.value)==null?void 0:o.validate().catch(()=>!1))){m.value=!0,f.value="";try{const l=await Y(e.otpCode.trim());l.verified?(g.success("OTP 绑定成功"),P("bind-success",l.token||"",l.user_id||r.userId,l.name||r.name,l.role||"")):(f.value="验证码错误,请重新输入",e.otpCode="")}catch(l){const S=l instanceof Error?l.message:"验证失败,请重试";console.error("[OtpBindPanel] 验证失败:",l),f.value=S}finally{m.value=!1}}}return(a,o)=>{const l=u("el-icon"),S=u("el-button"),F=u("el-input"),R=u("el-form-item"),U=u("el-form"),G=u("el-alert");return d(),c("div",se,[t("div",ne,[o[2]||(o[2]=t("h2",null,"🔐 首次登录 — 绑定 OTP 二次验证",-1)),p.name?(d(),c("p",oe,"欢迎,"+O(p.name),1)):M("",!0)]),v.value?(d(),c("div",ae,[n(l,{class:"is-loading"},{default:i(()=>[n(C(I))]),_:1}),o[3]||(o[3]=t("p",null,"正在生成密钥...",-1))])):(d(),c("div",le,[t("div",ie,[t("div",re,[x.value?(d(),c("img",{key:0,src:"data:image/png;base64,"+x.value,alt:"OTP 二维码",class:"qr-image"},null,8,de)):(d(),c("div",ce,[n(l,{size:48},{default:i(()=>[n(C(K))]),_:1}),o[4]||(o[4]=t("p",null,"二维码加载失败",-1))]))]),o[5]||(o[5]=t("p",{class:"qr-hint"},"请使用 Google Authenticator 或 Microsoft Authenticator 扫码",-1))]),o[6]||(o[6]=t("div",{class:"divider-line"},[t("span",null,"或手动输入密钥")],-1)),t("div",ue,[t("div",pe,[t("code",fe,O(w.value),1),n(S,{size:"small",type:s.value?"success":"default",class:"copy-btn",onClick:B},{default:i(()=>[T(O(s.value?"✅ 已复制":"📋 复制"),1)]),_:1},8,["type"])])]),t("div",_e,[n(U,{ref_key:"formRef",ref:b,model:e,rules:h,"label-position":"top",onSubmit:L(k,["prevent"])},{default:i(()=>[n(R,{label:"验证码",prop:"otpCode"},{default:i(()=>[n(F,{modelValue:e.otpCode,"onUpdate:modelValue":o[0]||(o[0]=E=>e.otpCode=E),placeholder:"请输入 6 位验证码",size:"large",maxl