fix: 未登录一律回打手登录页;无商家身份禁止进入商家端

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQueandCursor committed 2026-07-27 04:48:24 +08:00
1 parent a44be49ac6
commit ada903de07
10 files changed
+118 -27

No files matched your search

+9
View File
@@ -2,6 +2,7 @@
const app = getApp()
import { createPage } from '../../utils/base-page.js';
import { buildClubHeaders } from '../../utils/club-context.js';
import { isFighterOnly, resolveFighterOnlyLaunchUrl } from '../../utils/fighter-only.js';
Page(createPage({
data: {
@@ -25,6 +26,10 @@ Page(createPage({
},
onLoad(options) {
if (isFighterOnly()) {
wx.reLaunch({ url: resolveFighterOnlyLaunchUrl() });
return;
}
this.setData({
ossImageUrl: app.globalData.ossImageUrl
})
@@ -32,6 +37,10 @@ Page(createPage({
},
onShow() {
if (isFighterOnly()) {
wx.reLaunch({ url: resolveFighterOnlyLaunchUrl() });
return;
}
this.registerNotificationComponent();
},
+20 -14
View File
@@ -18,7 +18,7 @@ import {
} from '../../utils/miniapp-icons.js'
import { getDefaultAvatarUrl } from '../../utils/avatar.js'
import { ensureRoleAgreement } from '../../utils/role-agreement-gate.js'
import { isFighterOnly, FIGHTER_ONLY_DEFAULT_INVITE, FIGHTER_HOME, shouldSkipAutoAuth, clearSkipAutoAuth } from '../../utils/fighter-only.js'
import { isFighterOnly, FIGHTER_ONLY_DEFAULT_INVITE, FIGHTER_HOME, shouldSkipAutoAuth, clearSkipAutoAuth, isShangjiaCertified } from '../../utils/fighter-only.js'
const PLATFORM_INVITE_CODE = FIGHTER_ONLY_DEFAULT_INVITE || '0000008VfJKPu4Spmcjt'
const app = getApp()
@@ -288,7 +288,7 @@ Page(createPage({
const isGuanshi = isRoleStatusActive(wx.getStorageSync('guanshistatus'));
const isZuzhang = isRoleStatusActive(wx.getStorageSync('zuzhangstatus'));
const isKaoheguan = isRoleStatusActive(wx.getStorageSync('kaoheguanstatus'));
const isShangjia = isRoleStatusActive(wx.getStorageSync('shangjiastatus'));
const isShangjia = isShangjiaCertified();
const subRoleCount = [isGuanshi, isZuzhang, isKaoheguan].filter(Boolean).length;
this.setData({
isDashou, isGuanshi, isZuzhang, isKaoheguan,
@@ -370,11 +370,10 @@ Page(createPage({
push('goToKefu', '在线客服', img.iconKefu);
push('goToComplaintCreate', '投诉反馈', img.iconComplaint || img.iconContact);
push('goToComplaintList', '投诉记录', img.iconComplaint || img.iconRecord);
// 龙先生:仅已开通商家时显示入口;未开通不展示
if (d.shangjiaCertified) {
// 仅 shangjiastatus===1 的商家老板显示;客服入口另算
if (isShangjiaCertified()) {
push('onTapShangjiaAuth', '进入商家端', img.iconShangjia);
}
// 仅已是商家客服时显示工作台,未入驻不展示「入驻」入口
if (isStaffMode()) {
push('onTapStaffAuth', '商家客服工作台', img.iconKefu || img.iconShangjia);
}
@@ -1272,17 +1271,22 @@ Page(createPage({
goToAuth(e) {
const type = e.currentTarget.dataset.type;
if (!type || !['dashou', 'shangjia', 'guanshi', 'zuzhang'].includes(type)) return;
// 纯打手端:禁止走商家认证页,未开通则直接提示
if (type === 'shangjia') {
if (isShangjiaCertified()) {
enterLockedRole('shangjia', getApp());
} else {
wx.showToast({ title: '未开通商家身份', icon: 'none' });
}
return;
}
const statusMap = {
dashou: 'dashoustatus',
shangjia: 'shangjiastatus',
guanshi: 'guanshistatus',
zuzhang: 'zuzhangstatus',
};
const statusKey = statusMap[type];
if (isRoleStatusActive(wx.getStorageSync(statusKey))) {
if (type === 'shangjia') {
enterLockedRole('shangjia', getApp());
}
return;
}
wx.navigateTo({ url: `/pages/verify/verify?type=${type}` });
@@ -1294,7 +1298,7 @@ Page(createPage({
if (isStaffMode()) {
enterLockedRole('shangjia', getApp());
} else {
wx.navigateTo({ url: '/pages/staff-join/staff-join' });
wx.showToast({ title: '未入驻商家客服', icon: 'none' });
}
return;
}
@@ -1306,19 +1310,21 @@ Page(createPage({
},
enterShangjiaCenter() {
if (!this.data.shangjiaCertified) {
wx.showToast({ title: '请联系客服开通商家', icon: 'none' });
if (!isShangjiaCertified()) {
this.setData({ shangjiaCertified: false, isShangjia: false });
wx.showToast({ title: '未开通商家身份', icon: 'none' });
return;
}
enterLockedRole('shangjia', getApp());
},
onTapShangjiaAuth() {
if (this.data.shangjiaCertified) {
if (isShangjiaCertified()) {
this.enterShangjiaCenter();
return;
}
wx.showToast({ title: '请联系客服开通商家', icon: 'none' });
this.setData({ shangjiaCertified: false, isShangjia: false });
wx.showToast({ title: '未开通商家身份', icon: 'none' });
},
goToReceiveOrder() { wx.switchTab({ url: '/pages/accept-order/accept-order' }) },
+19
View File
@@ -6,12 +6,22 @@ import { backfillUserProfileCache, getSessionToken } from '../../utils/role-tab-
import PopupService from '../../services/popupService.js';
import { createPage } from '../../utils/base-page.js';
import { fetchGonggaoLunbo, isGonggaoCacheValid, getCachedGonggaoLunbo } from '../../utils/display-config';
import { isFighterOnly, getLoginPageUrl, resolveFighterOnlyLaunchUrl } from '../../utils/fighter-only.js';
// 扫码场景参数名
const SCENE_PARAM = 'scene';
/** 点单商城轮播 page_key */
const ORDER_PAGE_KEY = 'order_pool';
function buildFighterRedirectUrl(options = {}) {
const q = [];
if (options.scene) q.push('scene=' + encodeURIComponent(options.scene));
if (options.inviteCode) q.push('inviteCode=' + encodeURIComponent(options.inviteCode));
if (options.registerType) q.push('registerType=' + encodeURIComponent(options.registerType));
const base = options.scene || options.inviteCode ? getLoginPageUrl() : resolveFighterOnlyLaunchUrl();
return q.length ? `${base}?${q.join('&')}` : base;
}
Page(createPage({
data: {
ossImageUrl: '',
@@ -38,6 +48,11 @@ Page(createPage({
shopId: null,
onLoad(options) {
// 纯打手端:点单商城不再使用;带扫码参数则转发到打手登录/注册页
if (isFighterOnly()) {
wx.reLaunch({ url: buildFighterRedirectUrl(options || {}) });
return;
}
// 解析二维码参数
if (options[SCENE_PARAM]) {
try {
@@ -80,6 +95,10 @@ Page(createPage({
},
onShow() {
if (isFighterOnly()) {
wx.reLaunch({ url: resolveFighterOnlyLaunchUrl() });
return;
}
backfillUserProfileCache(app);
if (this.data.ossImageUrl) {
this.setData({
+10
View File
@@ -21,6 +21,7 @@ import {
warmupPindaoConfig,
PINDAO_ICON_FALLBACK,
} from '../../utils/miniapp-icons.js';
import { isFighterOnly, getLoginPageUrl } from '../../utils/fighter-only.js';
Page(createPage({
data: {
@@ -47,6 +48,11 @@ Page(createPage({
},
onLoad() {
// 纯打手端:误入点单「我的」时立刻拉回打手登录页
if (isFighterOnly()) {
wx.reLaunch({ url: getLoginPageUrl() });
return;
}
this.initIconUrls();
this.loadUserData();
this.setBottomSafe();
@@ -54,6 +60,10 @@ Page(createPage({
},
onShow() {
if (isFighterOnly()) {
wx.reLaunch({ url: getLoginPageUrl() });
return;
}
ensurePhoneAuth({
redirect: true,
returnPage: '/pages/mine/mine',
+2 -2
View File
@@ -155,10 +155,10 @@ const BASE_METHODS = {
// ---------- 返回点单端(纯打手端禁用) ----------
switchToNormal() {
try {
const { isFighterOnly, FIGHTER_MINE } = require('./fighter-only.js');
const { isFighterOnly, getLoginPageUrl } = require('./fighter-only.js');
if (isFighterOnly()) {
wx.showToast({ title: '当前为打手端小程序', icon: 'none' });
wx.reLaunch({ url: FIGHTER_MINE });
wx.reLaunch({ url: getLoginPageUrl() });
return;
}
} catch (e) {}
+10
View File
@@ -53,3 +53,13 @@ export function resolveFighterOnlyLaunchUrl() {
}
return FIGHTER_MINE
}
/** 未登录 / 登录失效时的落地页(绝不再回点单端我的) */
export function getLoginPageUrl() {
return isFighterOnly() ? FIGHTER_MINE : '/pages/mine/mine'
}
/** 严格判断是否已开通商家老板身份 */
export function isShangjiaCertified() {
return Number(wx.getStorageSync('shangjiastatus')) === 1
}
+6 -1
View File
@@ -121,7 +121,12 @@ function resolveReturnRole() {
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';
try {
const { getLoginPageUrl } = require('./fighter-only.js');
return getLoginPageUrl();
} catch (e) {
return '/pages/fighter/fighter';
}
}
async function check() {
+8
View File
@@ -125,6 +125,14 @@ function finishEnterLockedRole(role, app) {
export function enterLockedRole(role, app) {
if (!VALID.includes(role) || role === 'normal') return false;
// 未开通商家/客服身份时,禁止进入商家端(纯打手端尤其重要)
if (role === 'shangjia') {
const isOwner = isRoleStatusActive(wx.getStorageSync('shangjiastatus'));
if (!isOwner && !isStaffMode()) {
wx.showToast({ title: '未开通商家身份', icon: 'none' });
return false;
}
}
if (role === 'dashou' || role === 'shangjia') {
ensurePhoneAuth({ redirect: true, role }).then((ok) => {
if (ok) finishEnterLockedRole(role, app);
+21 -2
View File
@@ -1,6 +1,25 @@
// utils/request.js
import { buildClubHeaders } from './club-context';
function getLoginFallbackUrl() {
try {
const { getLoginPageUrl } = require('./fighter-only.js');
return getLoginPageUrl();
} catch (e) {
return '/pages/fighter/fighter';
}
}
function goLoginPage() {
const url = getLoginFallbackUrl();
wx.reLaunch({
url,
fail: () => {
try { wx.redirectTo({ url }); } catch (e) {}
},
});
}
function request(options) {
const app = getApp();
const token = wx.getStorageSync('token');
@@ -41,7 +60,7 @@ function request(options) {
success: (modalRes) => {
if (modalRes.confirm) {
wx.removeStorageSync('token');
wx.switchTab({ url: '/pages/mine/mine' });
goLoginPage();
}
},
});
@@ -55,7 +74,7 @@ function request(options) {
success: (modalRes) => {
if (modalRes.confirm) {
wx.removeStorageSync('token');
wx.reLaunch({ url: '/pages/mine/mine' });
goLoginPage();
}
},
});
+13 -8
View File
@@ -142,17 +142,22 @@ export function syncProfileFields(data) {
});
}
/** 清除缓存:清空登录与身份;纯打手端回到打手「我的」,否则点单「我的」 */
/** 清除缓存:清空登录与身份;纯打手端回到打手登录页,否则点单「我的」 */
export function clearCacheAndEnterNormal(page) {
resetGuestSession(page, { skipPageReset: true });
let url = '/pages/mine/mine';
try {
const { isFighterOnly, FIGHTER_MINE } = require('./fighter-only.js');
if (isFighterOnly()) {
wx.reLaunch({ url: FIGHTER_MINE });
return;
}
} catch (e) {}
wx.reLaunch({ url: '/pages/mine/mine' });
const { getLoginPageUrl } = require('./fighter-only.js');
url = getLoginPageUrl();
} catch (e) {
url = '/pages/fighter/fighter';
}
wx.reLaunch({
url,
fail: () => {
try { wx.redirectTo({ url }); } catch (err) {}
},
});
}
/** 清除缓存并重置为点单端(不跳转,供当前已在点单端时使用) */