/* v40 (2026-09-18, P0-15 E): 手机端"忘记密码/账号找回"真流程
背景:原来 #show-forgot-password 只弹 alert('请联系在线客服重置密码'),用户无法自助。
现在接到后端 /account-service/*(一次性验证码写通知中心 + 自助重置,不依赖短信)。
设计:纯新增覆盖层,不改动原有登录/注册 DOM;用捕获阶段拦截旧 alert。 */
(function () {
'use strict';
if (window.__mobV40) return; window.__mobV40 = true;
var API = 'https://api-gateway.duoweiying.cn';
function el(id) { return document.getElementById(id); }
function build() {
if (el('v40Reset')) return;
var d = document.createElement('div');
d.id = 'v40Reset';
d.style.cssText = 'display:none;position:fixed;inset:0;z-index:40000;background:rgba(15,23,42,.55);' +
'align-items:center;justify-content:center;padding:20px;';
d.innerHTML =
'
' +
'
' +
' 账号找回 / 重置密码' +
' ' +
'
' +
'
支持手机号或用户名。验证码会下发到您的通知中心,10 分钟内有效。
' +
'
' +
'
手机号 / 用户名
' +
'
' +
'
' +
'
' +
' ' +
'
' +
'
' +
'
' +
'
' +
'
新密码(至少 6 位)
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
';
document.body.appendChild(d);
el('v40Close').onclick = function () { d.style.display = 'none'; };
el('v40Send').onclick = function () {
var acct = (el('v40Acct').value || '').trim();
if (!acct) { msg('请输入手机号或用户名'); return; }
msg('发送中…');
fetch(API + '/api/account-service/send-code', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ account: acct })
}).then(function (r) { return r.json(); }).then(function (j) {
if (j && j.success) {
el('v40Step2').style.display = 'block';
msg('📨 验证码已下发到您的通知中心,请到「我的 → 消息通知」查看(10 分钟内有效)');
} else {
msg('发送失败:' + ((j && (j.message || j.detail)) || '请稍后重试'));
}
}).catch(function () { msg('网络错误,请重试'); });
};
el('v40Do').onclick = function () {
var acct = (el('v40Acct').value || '').trim();
var code = (el('v40Code').value || '').trim();
var pwd = el('v40Pwd').value || '';
if (!code) { msg('请输入验证码'); return; }
if (pwd.length < 6) { msg('密码至少 6 位'); return; }
msg('重置中…');
fetch(API + '/api/account-service/reset-password', {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ account: acct, code: code, new_password: pwd })
}).then(function (r) { return r.json(); }).then(function (j) {
if (j && j.success) {
msg('✅ ' + (j.message || '密码已重置,请用新密码登录'));
setTimeout(function () { d.style.display = 'none'; }, 1800);
} else {
msg('重置失败:' + ((j && (j.message || j.detail)) || '验证码无效或已过期'));
}
}).catch(function () { msg('网络错误,请重试'); });
};
function msg(t) { var m = el('v40Msg'); if (m) m.textContent = t; }
}
function open() {
build();
var d = el('v40Reset');
if (d) d.style.display = 'flex';
}
/* 捕获阶段拦截旧的"请联系在线客服"alert */
document.addEventListener('click', function (ev) {
var t = ev.target;
if (t && (t.id === 'show-forgot-password')) {
ev.preventDefault();
ev.stopImmediatePropagation();
open();
}
}, true);
try {
build();
document.addEventListener('DOMContentLoaded', build);
setTimeout(build, 800);
setTimeout(build, 2500);
} catch (e) {}
console.log('[MobV40] 账号找回通道就绪');
})();