merge: 合并 origin/main(排行榜/手机号校验)并保留本地体验会员与UI改动

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-08 00:17:07 +08:00
3 changed files with 284 additions and 112 deletions

View File

@@ -1,5 +1,7 @@
/**
* 手机号强制认证:每次调用 check / ensurePhoneAuth 均请求后端 /peizhi/yhbdsjh
* 手机号强制认证 - 完全自包含逻辑模块
*
* check / ensurePhoneAuth 每次均请求后端 /peizhi/yhbdsjh 判断 need_auth
*/
const API_BASE = 'https://www.abas.asia/hqhd';
@@ -7,7 +9,6 @@ const AUTH_CHECK_URL = '/peizhi/yhbdsjh';
const AUTH_SUBMIT_URL = '/yonghu/xiugai';
const AUTH_PAGE = '/pages/phone-auth/phone-auth';
const RETURN_ROLE_KEY = 'phone_auth_return_role';
const RETURN_PAGE_KEY = 'phone_auth_return_page';
function innerRequest(url, data = {}) {
return new Promise((resolve, reject) => {
@@ -91,29 +92,10 @@ function parseCheckResponse(res) {
return { ok: true, needAuth: !!needAuth };
}
/** 根据当前主端/身份推断认证完成后回跳角色 */
function resolveReturnRole() {
const primary = wx.getStorageSync('primaryRole') || wx.getStorageSync('currentRole') || '';
if (primary === 'dashou' || primary === 'shangjia') return primary;
if (Number(wx.getStorageSync('shangjiastatus')) === 1) return 'shangjia';
if (Number(wx.getStorageSync('staffstatus')) === 1) return 'shangjia';
if (
Number(wx.getStorageSync('dashoustatus')) === 1
|| Number(wx.getStorageSync('guanshistatus')) === 1
|| Number(wx.getStorageSync('zuzhangstatus')) === 1
|| Number(wx.getStorageSync('kaoheguanstatus')) === 1
) {
return 'dashou';
}
return 'mine';
}
function defaultReturnPage(role) {
if (role === 'dashou') return '/pages/accept-order/accept-order';
if (role === 'shangjia') return '/pages/merchant-home/merchant-home';
return '/pages/mine/mine';
}
/**
* 询问后端是否需要手机号认证
* @returns {Promise<boolean>} true=需要认证
*/
async function check() {
const token = wx.getStorageSync('token');
if (!token) return false;
@@ -128,13 +110,9 @@ async function check() {
}
}
function redirectToPhoneAuth(returnRole, returnPage) {
const role = returnRole || resolveReturnRole();
wx.setStorageSync(RETURN_ROLE_KEY, role);
if (returnPage) {
wx.setStorageSync(RETURN_PAGE_KEY, returnPage);
} else {
wx.removeStorageSync(RETURN_PAGE_KEY);
function redirectToPhoneAuth(returnRole) {
if (returnRole) {
wx.setStorageSync(RETURN_ROLE_KEY, returnRole);
}
if (!isOnPhoneAuthPage()) {
wx.reLaunch({ url: AUTH_PAGE });
@@ -142,32 +120,26 @@ function redirectToPhoneAuth(returnRole, returnPage) {
}
/**
* 向后端确认是否需要手机号认证;需要则跳转认证页
* @returns {Promise<boolean>} true=无需认证或已满足false=已跳转认证页
* 打手端等场景:向后端确认,未认证则跳转认证页
* @returns {Promise<boolean>} true=已通过或无需认证false=已跳转认证页
*/
async function ensurePhoneAuth(options = {}) {
const { redirect = true, role, returnPage } = options;
const { redirect = true, role = 'dashou' } = options;
const token = wx.getStorageSync('token');
if (!token) return true;
const needAuth = await check();
if (!needAuth) return true;
if (redirect) {
redirectToPhoneAuth(role || resolveReturnRole(), returnPage);
}
if (redirect) redirectToPhoneAuth(role);
return false;
}
function getPhoneAuthReturnPage() {
const savedPage = wx.getStorageSync(RETURN_PAGE_KEY);
wx.removeStorageSync(RETURN_PAGE_KEY);
if (savedPage) {
wx.removeStorageSync(RETURN_ROLE_KEY);
return savedPage;
}
const role = wx.getStorageSync(RETURN_ROLE_KEY) || resolveReturnRole();
const role = wx.getStorageSync(RETURN_ROLE_KEY) || '';
wx.removeStorageSync(RETURN_ROLE_KEY);
return defaultReturnPage(role);
if (role === 'dashou') return '/pages/accept-order/accept-order';
if (role === 'shangjia') return '/pages/merchant-orders/merchant-orders';
return '/pages/mine/mine';
}
async function submit(phoneCode, avatarPath) {
@@ -194,5 +166,4 @@ module.exports = {
ensurePhoneAuth,
redirectToPhoneAuth,
getPhoneAuthReturnPage,
resolveReturnRole,
};

View File

@@ -1,6 +1,5 @@
/** 三端固定normal | dashou | shangjia认证后不可回退 */
import { isStaffMode } from './staff-api.js';
import { ensurePhoneAuth } from './phone-auth.js';
const VALID = ['normal', 'dashou', 'shangjia'];
@@ -56,9 +55,6 @@ export function getPrimaryRole(app) {
if (isRoleStatusActive(wx.getStorageSync('shangjiastatus'))) {
return 'shangjia';
}
if (isStaffMode()) {
return 'shangjia';
}
return 'normal';
}
@@ -89,7 +85,7 @@ export function clearPrimaryRole(app) {
export const PRIMARY_DEFAULT_PAGES = {
normal: '/pages/mine/mine',
dashou: '/pages/accept-order/accept-order',
shangjia: '/pages/merchant-home/merchant-home',
shangjia: '/pages/merchant-orders/merchant-orders',
};
/** 锁定主端并跳转到该端默认首页,同时建立 IM 长连接 */
@@ -111,8 +107,8 @@ function finishEnterLockedRole(role, app) {
export function enterLockedRole(role, app) {
if (!VALID.includes(role) || role === 'normal') return false;
if (role === 'dashou' || role === 'shangjia') {
ensurePhoneAuth({ redirect: true, role }).then((ok) => {
if (role === 'dashou') {
ensurePhoneAuth({ redirect: true, role: 'dashou' }).then((ok) => {
if (ok) finishEnterLockedRole(role, app);
});
return true;