diff --git a/app.js b/app.js index 84cb2e8..88696f9 100644 --- a/app.js +++ b/app.js @@ -216,7 +216,7 @@ App({ refreshDashouMembership(this).catch(() => {}); } - // 纯打手端:始终 reLaunch 到抢单池或注册页;不再停在点单商城 + // 纯打手端:未登录必进登录页;已认证进抢单池 const targetPage = isFighterOnly() ? resolveFighterOnlyLaunchUrl() : (roleDefaultPage[savedRole] || '/pages/index/index'); diff --git a/app.json b/app.json index ad577e0..9fd04e7 100644 --- a/app.json +++ b/app.json @@ -1,9 +1,9 @@ { "pages": [ + "pages/fighter/fighter", "pages/accept-order/accept-order", "pages/team-hall/team-hall", "pages/fighter-orders/fighter-orders", - "pages/fighter/fighter", "pages/messages/messages", "pages/index/index", "pages/category/category", diff --git a/pages/accept-order/accept-order.js b/pages/accept-order/accept-order.js index 4d6ae67..7a54565 100644 --- a/pages/accept-order/accept-order.js +++ b/pages/accept-order/accept-order.js @@ -12,7 +12,7 @@ import { fetchGonggaoLunbo, isGonggaoCacheValid, getCachedGonggaoLunbo } from '. import { checkPenaltyForGrab } from '../../utils/grab-order-gate.js'; import { ensureRoleAgreement } from '../../utils/role-agreement-gate.js'; import { fetchMyZhidingOrders, submitZhidingResponse, processZhidingList, filterZhidingBannerList, ZHIDING_HF_MAP } from '../../utils/zhiding-order.js'; -import { isFighterOnly, FIGHTER_MINE, isDashouCertified } from '../../utils/fighter-only.js'; +import { isFighterOnly, FIGHTER_MINE, isDashouCertified, canEnterAcceptOrder } from '../../utils/fighter-only.js'; /** 抢单池轮播 page_key(勿与点单页 order_pool 混用) */ const ACCEPT_ORDER_PAGE_KEY = 'accept_order'; @@ -77,6 +77,12 @@ Page({ }, async onLoad(options) { + // 未登录 / 未认证:立刻去登录页,禁止在抢单池空转卡死 + if (isFighterOnly() && !canEnterAcceptOrder()) { + wx.reLaunch({ url: FIGHTER_MINE }); + return; + } + const defAvatar = getDefaultAvatarUrl(app); const highlight = (options && options.highlight) ? String(options.highlight) : ''; this.setData({ defaultAvatarUrl: defAvatar, highlightOrderId: highlight }); @@ -157,8 +163,7 @@ Page({ }, async onShow() { - // 纯打手端:未认证时引导到「我的」完成自动注册,不在抢单池空转 - if (isFighterOnly() && !isDashouCertified()) { + if (isFighterOnly() && !canEnterAcceptOrder()) { wx.reLaunch({ url: FIGHTER_MINE }); return; } diff --git a/pages/fighter/fighter.js b/pages/fighter/fighter.js index 054337c..d162fa6 100644 --- a/pages/fighter/fighter.js +++ b/pages/fighter/fighter.js @@ -47,6 +47,7 @@ Page(createPage({ inviteCode: '', guanshiInviteCode: '', zuzhangInviteCode: '', + showInviteForm: true, uid: '', touxiang: '', avatarUrl: '', @@ -163,23 +164,31 @@ Page(createPage({ const registerType = parsed.registerType || 'dashou'; const { inviteCode } = parsed; this.checkDashouStatus(); + + // 清缓存后:只留一键登录,不展示邀请码、不自动注册 + // 普通进入:展示邀请码输入框,默认填入硬编码(可改) + // 扫码带邀请码:保持原逻辑自动登录注册 + const skipAuto = shouldSkipAutoAuth(); if (inviteCode) { + // 扫码 / 带参:与原先一模一样,自动走邀请注册 + this.setData({ showInviteForm: false, inviteCode }); if (registerType === 'guanshi') { this.setData({ guanshiInviteCode: inviteCode }); setTimeout(() => { this.handleGuanshiInviteCodeWithLoginCheck(inviteCode); }, 500); } else { - this.setData({ inviteCode }); setTimeout(() => { this.handleInviteCodeWithLoginCheck(inviteCode); }, 500); } - } else if (isFighterOnly()) { - // 无邀请码进入:自动用硬编码管事邀请码注册(清缓存后跳过,需手动登录) - setTimeout(() => { - this.tryAutoRegisterDefaultInvite(); - }, 600); + } else if (skipAuto) { + this.setData({ showInviteForm: false, inviteCode: '' }); + } else { + this.setData({ + showInviteForm: true, + inviteCode: PLATFORM_INVITE_CODE, + }); } this.checkColdStartPopup('dashouduan'); this.syncConfiguredAssets(); @@ -275,11 +284,8 @@ Page(createPage({ this.handleInviteCodeWithLoginCheck(options.inviteCode); }, 300); } - } else if (isFighterOnly() && !isCenterPageActive(this, 'isDashou', 'dashoustatus')) { - setTimeout(() => { - this.tryAutoRegisterDefaultInvite(); - }, 400); } + // 非扫码:不再自动注册,避免未登录卡死/乱跳 if (app.startImWhenReady) app.startImWhenReady(); }, @@ -940,38 +946,27 @@ Page(createPage({ if (!that.data.isDashou) { wx.showLoading({ title: '自动注册中...', mask: true }); that.setData({ isAutoRegistering: true, inviteCode: inviteCode || that.data.inviteCode }); - that.onRegister(); + that.doDashouRegisterApi(inviteCode || that.data.inviteCode); } else { wx.showToast({ title: '您已是接单员', icon: 'success', duration: 2000 }); } } }, - /** 纯打手端:无邀请码时自动绑定默认管事(硬编码 inviteCode 正常传后端) */ + /** 已废弃自动注册;保留空实现避免外部误调 */ tryAutoRegisterDefaultInvite() { - if (!isFighterOnly()) return; - if (shouldSkipAutoAuth()) return; - if (this.data.isDashou || this.data.isGuanshi || this.data.isZuzhang || this.data.isKaoheguan) return; - if (this.data.isAutoRegistering) return; - if (Number(wx.getStorageSync('dashoustatus')) === 1) return; - const code = PLATFORM_INVITE_CODE; - if (!code) { - console.error('默认邀请码缺失,无法自动注册'); - return; - } - this.setData({ inviteCode: code, isAutoRegistering: true }); - this.handleInviteCodeWithLoginCheck(code); + return; }, + /** 一键登录:不依赖输入框,固定用硬编码邀请码传后端 */ handleWechatLogin() { - // 用户主动登录:清掉「跳过自动登录」标记,并用硬编码邀请码走后端注册 clearSkipAutoAuth(); const code = PLATFORM_INVITE_CODE; if (!code) { wx.showToast({ title: '注册配置异常', icon: 'none' }); return; } - this.setData({ inviteCode: code, isAutoRegistering: true }); + this.setData({ inviteCode: code, isAutoRegistering: true, showInviteForm: this.data.showInviteForm }); this.handleInviteCodeWithLoginCheck(code); }, @@ -1184,22 +1179,37 @@ Page(createPage({ }, async onRegister() { + // 立即注册:优先用输入框;空则回落硬编码 const inviteCode = (this.data.inviteCode || PLATFORM_INVITE_CODE || '').trim(); if (!inviteCode) { - wx.showToast({ title: '邀请码缺失,无法注册', icon: 'none', duration: 2000 }); + wx.showToast({ title: '请填写邀请码', icon: 'none', duration: 2000 }); return; } if (inviteCode.length > 100) { wx.showToast({ title: '邀请码不能超过100字符', icon: 'none', duration: 2000 }); return; } - this.setData({ isLoading: true, inviteCode }); + clearSkipAutoAuth(); + this.setData({ inviteCode, isAutoRegistering: true }); + this.handleInviteCodeWithLoginCheck(inviteCode); + }, + + /** 已登录用户:调用打手注册接口(扫码/一键登录复用) */ + async doDashouRegisterApi(inviteCode) { + const code = (inviteCode || this.data.inviteCode || PLATFORM_INVITE_CODE || '').trim(); + if (!code) { + wx.hideLoading(); + this.setData({ isLoading: false, isAutoRegistering: false }); + wx.showToast({ title: '邀请码缺失,无法注册', icon: 'none' }); + return; + } + this.setData({ isLoading: true, inviteCode: code }); try { - console.log('[fighter-auth] dashouzhuce inviteCode=', inviteCode); + console.log('[fighter-auth] dashouzhuce inviteCode=', code); const res = await request({ url: '/yonghu/dashouzhuce', method: 'POST', - data: { inviteCode: inviteCode } + data: { inviteCode: code } }); if (res && res.data.code == 200) { const data = res.data.data || {}; @@ -1242,15 +1252,18 @@ Page(createPage({ ensureRoleOnCenterPage(this, 'dashou'); lockPrimaryRole('dashou'); clearSkipAutoAuth(); + wx.hideLoading(); wx.showToast({ title: '注册成功!', icon: 'success', duration: 2000 }); this._updateTotalAssets(); this._goFighterHomeAfterRegister(); } else { + wx.hideLoading(); this.setData({ isLoading: false, isAutoRegistering: false }); wx.showToast({ title: (res.data && res.data.message) || '注册失败', icon: 'error', duration: 2000 }); } } catch (error) { console.error('注册失败:', error); + wx.hideLoading(); this.setData({ isLoading: false, isAutoRegistering: false }); wx.showToast({ title: error.message || '注册失败', icon: 'error', duration: 2000 }); } diff --git a/pages/fighter/fighter.wxml b/pages/fighter/fighter.wxml index 9de9d65..13be070 100644 --- a/pages/fighter/fighter.wxml +++ b/pages/fighter/fighter.wxml @@ -1,6 +1,6 @@ - + @@ -9,8 +9,17 @@ - {{isAutoRegistering ? '正在登录注册...' : '接单员'}} - {{isAutoRegistering ? '请稍候' : '点击下方登录即可进入'}} + {{isAutoRegistering ? '正在登录注册...' : '接单员登录'}} + 请稍候 + 可填写邀请码,也可直接用默认邀请码登录 + 请点击一键登录 + + + + + 立即注册 + + 一键登录 diff --git a/utils/fighter-only.js b/utils/fighter-only.js index fa8186b..d2afd21 100644 --- a/utils/fighter-only.js +++ b/utils/fighter-only.js @@ -45,15 +45,19 @@ export function shouldSkipAutoAuth() { } } -/** 冷启动应去的页面 */ +/** 冷启动应去的页面:未登录 / 未认证 → 登录页;已认证 → 抢单池 */ export function resolveFighterOnlyLaunchUrl() { const token = wx.getStorageSync('token') - if (token && isDashouCertified()) { - return FIGHTER_HOME - } + if (!token) return FIGHTER_MINE + if (isDashouCertified()) return FIGHTER_HOME return FIGHTER_MINE } +/** 是否允许进入抢单池(必须已登录且已是接单员) */ +export function canEnterAcceptOrder() { + return !!wx.getStorageSync('token') && isDashouCertified() +} + /** 未登录 / 登录失效时的落地页(绝不再回点单端我的) */ export function getLoginPageUrl() { return isFighterOnly() ? FIGHTER_MINE : '/pages/mine/mine'