现在有的接口对接测试完成

This commit is contained in:
2026-07-25 19:19:36 +08:00
parent 8870136d1b
commit 817d85e117
59 changed files with 26623 additions and 1576 deletions
+29 -25
View File
@@ -18,22 +18,22 @@
var FORM_CONFIG = {
login: {
selector: '#login-password-form',
captchaScene: 'PC_SMS_LOGIN',
operationCode: 'password-login',
successUrl: 'profile.html'
},
'sms-login': {
selector: '#login-sms-form',
captchaScene: 'PC_SMS_LOGIN',
operationCode: 'sms-login',
successUrl: 'profile.html'
},
register: {
selector: '#register-form',
captchaScene: 'PC_REGISTER',
operationCode: 'register',
successUrl: 'login.html'
},
'password-reset': {
selector: '#password-reset-form',
captchaScene: 'PC_FORGOT_PASSWORD',
operationCode: 'forgot-password',
successUrl: 'login.html'
}
};
@@ -47,16 +47,19 @@
}
function buildLoginBody(values, hashFn) {
// 这里只组装登录 DTO 字段,grantType、tenantId、clientId 由 api-client 统一补齐。
// 这里只组装登录 DTO 字段,grantType、tenantId 由 api-client 统一补齐clientid 只走请求头
var hash = hashFn || hashPassword;
return {
var body = {
phone: values.phone,
password: hash(values.password)
};
if (values.validToken) body.validToken = values.validToken;
return body;
}
function buildSmsLoginBody(values) {
// 短信登录接口只需要页面字段,grantType、tenantId、clientId 由 api-client 统一补齐。
// 短信登录接口只需要页面字段,grantType、tenantId 由 api-client 统一补齐clientid 只走请求头
return {
phone: values.phone,
smsCode: values.smsCode
@@ -88,11 +91,11 @@
return root.GenealogyApi && root.GenealogyApi.defaultClient;
}
function getCaptchaScene(formType) {
// PC/H5 认证场景来自后台验证码配置,客户端 Key 为 web_pc
function getCaptchaOperation(formType) {
// PC 验证中心按业务动作解析服务端已激活的验证场景
var config = FORM_CONFIG[formType] || {};
return config.captchaScene || '';
return config.operationCode || '';
}
function getSuccessUrl(formType) {
@@ -101,16 +104,16 @@
return config.successUrl || '';
}
function getFormCaptchaScene(form, formType) {
// 场景码由当前脚本统一管理,避免散落在 HTML 属性中。
var sceneCode = getCaptchaScene(formType);
function getFormCaptchaOperation(form, formType) {
// 业务动作由当前脚本统一管理,避免散落在 HTML 属性中。
var operationCode = getCaptchaOperation(formType);
return sceneCode;
return operationCode;
}
async function ensureCaptcha(form, sceneCode, subject) {
// 未配置 PC/H5 验证场景时不调用验证中心,也不伪造 validToken。
if (!sceneCode) return true;
async function ensureCaptcha(form, operationCode, subject) {
// 未配置 PC 认证动作时不调用验证中心,也不伪造 validToken。
if (!operationCode) return true;
if (!root.CaptchaPages || !root.CaptchaPages.ensureToken) {
showMessage('验证码组件未加载,请刷新后重试');
@@ -118,7 +121,7 @@
}
return Boolean(await root.CaptchaPages.ensureToken(form, {
sceneCode: sceneCode,
operationCode: operationCode,
subject: subject
}));
}
@@ -310,6 +313,8 @@
return;
}
if (!validateBeforeSubmit('login', values)) return;
if (!await ensureCaptcha(form, getFormCaptchaOperation(form, 'login'), values.phone)) return;
values = readForm(form);
setBusy(button, true);
try {
await api.login(buildLoginBody(values));
@@ -364,26 +369,25 @@
}
async function sendCode(button) {
// 短信验证码场景由表单配置决定,不在按钮属性中重复声明。
// 短信验证码认证动作由表单配置决定,不在按钮属性中重复声明。
var api = getApi();
var form = button.closest('form');
var values = readForm(form);
var formType = getFormType(form);
var sceneCode = getFormCaptchaScene(form, formType);
var operationCode = getFormCaptchaOperation(form, formType);
if (!api) {
showMessage('接口初始化失败,请刷新后重试');
return;
}
if (!validateBeforeSendCode(values)) return;
if (!await ensureCaptcha(form, sceneCode, values.phone)) return;
if (!await ensureCaptcha(form, operationCode, values.phone)) return;
values = readForm(form);
setBusy(button, true);
try {
await api.sendSmsCode({
sceneCode: sceneCode,
await api.sendSmsCode(operationCode, {
phone: values.phone,
validToken: values.validToken || ''
});
@@ -473,8 +477,8 @@
buildPasswordResetBody: buildPasswordResetBody,
clearCaptchaToken: clearCaptchaToken,
startSmsCooldown: startSmsCooldown,
getCaptchaScene: getCaptchaScene,
getFormCaptchaScene: getFormCaptchaScene,
getCaptchaOperation: getCaptchaOperation,
getFormCaptchaOperation: getFormCaptchaOperation,
getSuccessUrl: getSuccessUrl,
validateAuthValues: validateAuthValues,
init: init