restore: 恢复橙色逍遥梦UI版本(2ea2860)到主分支

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-09 00:17:03 +08:00
parent 267de7c780
commit 566aeaa3b7
228 changed files with 22076 additions and 11864 deletions

View File

@@ -1,7 +1,5 @@
/**
* 手机号强制认证 - 完全自包含逻辑模块
*
* check / ensurePhoneAuth 每次均请求后端 /peizhi/yhbdsjh 判断 need_auth
* 手机号强制认证:每次调用 check / ensurePhoneAuth 均请求后端 /peizhi/yhbdsjh
*/
const API_BASE = 'https://www.abas.asia/hqhd';
@@ -9,18 +7,29 @@ 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 buildHeaders(extra = {}) {
const token = wx.getStorageSync('token');
const header = { 'Content-Type': 'application/json', ...extra };
if (token) header['Authorization'] = 'Bearer ' + token;
try {
const { buildClubHeaders } = require('./club-context.js');
return buildClubHeaders(header);
} catch (e) {
const clubId = wx.getStorageSync('club_id') || 'xq';
header['X-Club-Id'] = clubId;
return header;
}
}
function innerRequest(url, data = {}) {
return new Promise((resolve, reject) => {
const token = wx.getStorageSync('token');
const header = { 'Content-Type': 'application/json' };
if (token) header['Authorization'] = 'Bearer ' + token;
wx.request({
url: API_BASE + url,
method: 'POST',
data,
header,
header: buildHeaders(),
success: (res) => resolve(res),
fail: (err) => reject(err),
});
@@ -43,7 +52,7 @@ function innerUpload(url, filePath, formData = {}, fileName = 'avatar') {
filePath,
name: fileName,
formData,
header: { Authorization: 'Bearer ' + token },
header: buildHeaders({ Authorization: 'Bearer ' + token }),
success: (res) => {
if (res.statusCode === 200) {
try {
@@ -92,10 +101,29 @@ function parseCheckResponse(res) {
return { ok: true, needAuth: !!needAuth };
}
/**
* 询问后端是否需要手机号认证
* @returns {Promise<boolean>} true=需要认证
*/
/** 根据当前主端/身份推断认证完成后回跳角色 */
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';
}
async function check() {
const token = wx.getStorageSync('token');
if (!token) return false;
@@ -110,9 +138,13 @@ async function check() {
}
}
function redirectToPhoneAuth(returnRole) {
if (returnRole) {
wx.setStorageSync(RETURN_ROLE_KEY, returnRole);
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);
}
if (!isOnPhoneAuthPage()) {
wx.reLaunch({ url: AUTH_PAGE });
@@ -120,26 +152,32 @@ function redirectToPhoneAuth(returnRole) {
}
/**
* 打手端等场景:向后端确认,未认证则跳转认证页
* @returns {Promise<boolean>} true=已通过或无需认证false=已跳转认证页
* 向后端确认是否需要手机号认证;需要则跳转认证页
* @returns {Promise<boolean>} true=无需认证或已满足false=已跳转认证页
*/
async function ensurePhoneAuth(options = {}) {
const { redirect = true, role = 'dashou' } = options;
const { redirect = true, role, returnPage } = options;
const token = wx.getStorageSync('token');
if (!token) return true;
const needAuth = await check();
if (!needAuth) return true;
if (redirect) redirectToPhoneAuth(role);
if (redirect) {
redirectToPhoneAuth(role || resolveReturnRole(), returnPage);
}
return false;
}
function getPhoneAuthReturnPage() {
const role = wx.getStorageSync(RETURN_ROLE_KEY) || '';
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();
wx.removeStorageSync(RETURN_ROLE_KEY);
if (role === 'dashou') return '/pages/accept-order/accept-order';
if (role === 'shangjia') return '/pages/merchant-orders/merchant-orders';
return '/pages/mine/mine';
return defaultReturnPage(role);
}
async function submit(phoneCode, avatarPath) {
@@ -166,4 +204,5 @@ module.exports = {
ensurePhoneAuth,
redirectToPhoneAuth,
getPhoneAuthReturnPage,
resolveReturnRole,
};