From dcd39da1fa461462924d542e81ecb51be85182ad Mon Sep 17 00:00:00 2001 From: MiAn Date: Sat, 28 Nov 2026 10:58:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=BA=AB=E4=BB=BD?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=BC=B9=E7=AA=97=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增身份选择组件,用户登录后未选择身份时弹出选择框 - 优化登录跳转逻辑,支持页面栈返回模式 - 修复跳转时参数处理的边界情况 - 新增服务配置缓存机制,减少重复请求 - 优化小程序跳转逻辑,增加防重复点击锁 - 修复订单页联系人信息初始化逻辑 --- tests/login_navigation.test.mjs | 140 ++++++++++++++++ yjyf-app/App.vue | 3 + yjyf-app/components/YjyfIdentityPicker.vue | 155 ++++++++++++++++++ yjyf-app/components/user/UserMineView.vue | 12 +- yjyf-app/pages/index/index.vue | 51 +----- yjyf-app/pages/login/login.vue | 76 +++++---- yjyf-app/pages/order/quick.vue | 16 +- yjyf-app/utils/api.js | 91 +++++++--- yjyf-app/utils/login-navigation.mjs | 115 +++++++++++++ yjyf-app/utils/request.js | 29 ++-- yjyf-master-app/App.vue | 1 + .../components/master/MasterHallView.vue | 10 +- .../components/master/MasterWorkbenchView.vue | 16 +- yjyf-master-app/pages/login/login.vue | 9 + yjyf-master-app/pages/master/apply.vue | 21 ++- yjyf-master-app/utils/api.js | 94 +++++++++-- yjyf-master-app/utils/request.js | 2 +- 17 files changed, 702 insertions(+), 139 deletions(-) create mode 100644 tests/login_navigation.test.mjs create mode 100644 yjyf-app/components/YjyfIdentityPicker.vue create mode 100644 yjyf-app/utils/login-navigation.mjs diff --git a/tests/login_navigation.test.mjs b/tests/login_navigation.test.mjs new file mode 100644 index 0000000..2afc403 --- /dev/null +++ b/tests/login_navigation.test.mjs @@ -0,0 +1,140 @@ +import assert from 'assert'; +import { + buildLoginUrl, + normalizeRoutePath, + parseLoginParams, + resolvePostLoginAction, + shouldPreservePageOnLogin +} from '../yjyf-app/utils/login-navigation.mjs'; + +assert.equal(normalizeRoutePath('/pages/order/quick?service_id=12#top'), 'pages/order/quick'); +assert.equal(shouldPreservePageOnLogin('pages/order/quick'), true); +assert.equal(shouldPreservePageOnLogin('/pages/order/quick?cat_id=3'), true); +assert.equal(shouldPreservePageOnLogin('pages/order/goods-template'), false); +assert.equal(shouldPreservePageOnLogin('pages/invoice/detail'), false); + +// 1. 构建与解析登录参数 +const quickLoginUrl = buildLoginUrl('/pages/order/quick?cat_id=2&service_id=10', { back: true }); +assert.equal( + quickLoginUrl, + '/pages/login/login?redirect=%2Fpages%2Forder%2Fquick%3Fcat_id%3D2%26service_id%3D10&back=1' +); + +const parsedQuick = parseLoginParams({ + redirect: encodeURIComponent('/pages/order/quick?cat_id=2&service_id=10'), + back: '1' +}); +assert.deepEqual(parsedQuick, { + redirectUrl: '/pages/order/quick?cat_id=2&service_id=10', + preferBack: true +}); + +// 兼容双层 encodeURIComponent 的场景 +const parsedDoubleEncoded = parseLoginParams({ + redirect: encodeURIComponent(encodeURIComponent('/pages/order/quick')), + back: '1' +}); +assert.deepEqual(parsedDoubleEncoded, { + redirectUrl: '/pages/order/quick', + preferBack: true +}); + +// 2. 下单到最后一步触发登录,返回时应直接 navigateBack 保留原页面与步骤状态 +assert.deepEqual( + resolvePostLoginAction({ + redirectUrl: '/pages/order/quick?cat_id=2&service_id=10', + preferBack: true, + pages: [{ route: 'pages/index/index' }, { route: 'pages/order/quick' }, { route: 'pages/login/login' }] + }), + { + type: 'navigateBack', + fallbackType: 'reLaunch', + fallbackUrl: '/pages/order/quick?cat_id=2&service_id=10' + } +); + +// 3. 若页面栈仅剩登录页(如 H5 刷新后),安全兜底回原目标 URL +assert.deepEqual( + resolvePostLoginAction({ + redirectUrl: '/pages/order/quick?cat_id=2', + preferBack: true, + pages: [{ route: 'pages/login/login' }] + }), + { + type: 'redirectTo', + url: '/pages/order/quick?cat_id=2', + fallbackType: 'reLaunch', + fallbackUrl: '/pages/order/quick?cat_id=2' + } +); + +// 4. 若栈上一页并非目标页(不匹配),避免误返回无关页面,走 redirectTo +assert.deepEqual( + resolvePostLoginAction({ + redirectUrl: '/pages/order/quick', + preferBack: true, + pages: [{ route: 'pages/service/detail' }, { route: 'pages/login/login' }] + }), + { + type: 'redirectTo', + url: '/pages/order/quick', + fallbackType: 'reLaunch', + fallbackUrl: '/pages/order/quick' + } +); + +// 5. 首页 / Tab 切页重定向保持 reLaunch 行为不变 +assert.deepEqual( + resolvePostLoginAction({ + redirectUrl: '/pages/index/index?tab=1&status=wait_pay', + preferBack: false, + pages: [{ route: 'pages/index/index' }, { route: 'pages/login/login' }] + }), + { + type: 'reLaunch', + url: '/pages/index/index?tab=1&status=wait_pay' + } +); + +// 6. 仅在 onLoad 拉数据的子页面维持 redirectTo 以触发重新加载 +assert.deepEqual( + resolvePostLoginAction({ + redirectUrl: '/pages/order/goods-template?cat_id=1', + preferBack: false, + pages: [{ route: 'pages/order/quick' }, { route: 'pages/order/goods-template' }, { route: 'pages/login/login' }] + }), + { + type: 'redirectTo', + url: '/pages/order/goods-template?cat_id=1', + fallbackType: 'reLaunch', + fallbackUrl: '/pages/order/goods-template?cat_id=1' + } +); + +// 7. 无 redirectUrl 时依据页面栈返回或回首页 +assert.deepEqual( + resolvePostLoginAction({ + redirectUrl: '', + preferBack: false, + pages: [{ route: 'pages/order/quick' }, { route: 'pages/login/login' }] + }), + { + type: 'navigateBack', + fallbackType: 'reLaunch', + fallbackUrl: '/pages/index/index' + } +); + +assert.deepEqual( + resolvePostLoginAction({ + redirectUrl: '', + preferBack: false, + pages: [{ route: 'pages/login/login' }] + }), + { + type: 'reLaunch', + url: '/pages/index/index' + } +); + +console.log('login navigation tests passed'); diff --git a/yjyf-app/App.vue b/yjyf-app/App.vue index f73aa2b..e1ceb16 100644 --- a/yjyf-app/App.vue +++ b/yjyf-app/App.vue @@ -1,9 +1,12 @@ + + diff --git a/yjyf-app/components/user/UserMineView.vue b/yjyf-app/components/user/UserMineView.vue index 420c27f..1e958d5 100644 --- a/yjyf-app/components/user/UserMineView.vue +++ b/yjyf-app/components/user/UserMineView.vue @@ -315,8 +315,16 @@ } } - function openMasterApp() { - api.openMasterMiniProgram('pages/master/apply'); + const openingMasterApp = ref(false); + + async function openMasterApp() { + if (openingMasterApp.value) return; + openingMasterApp.value = true; + try { + await api.openMasterMiniProgram('pages/master/hall'); + } finally { + setTimeout(() => { openingMasterApp.value = false; }, 600); + } } function logout() { diff --git a/yjyf-app/pages/index/index.vue b/yjyf-app/pages/index/index.vue index 621620c..0f6ac00 100644 --- a/yjyf-app/pages/index/index.vue +++ b/yjyf-app/pages/index/index.vue @@ -23,19 +23,7 @@ - - - 请选择用户类型 - 请选择您的使用身份,确认后不可自行修改 - - 个人用户家庭或个人使用 - - - 商家用户商家或企业使用 - - - - + @@ -48,13 +36,11 @@ import UserMineView from '@/components/user/UserMineView.vue'; import YjyfTabBar from '@/components/YjyfTabBar.vue'; import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue'; - import { isLogin, toLogin, getUser, setUser } from '@/utils/request.js'; - import api from '@/utils/api.js'; + import YjyfIdentityPicker from '@/components/YjyfIdentityPicker.vue'; + import { isLogin, toLogin, getUser } from '@/utils/request.js'; import { useShare } from '@/utils/share.js'; const showIdentityPicker = ref(false); - const identityChoice = ref(''); - const selectingIdentity = ref(false); const activeTab = ref(0); const initialOrderStatus = ref('all'); const visitedTabs = reactive({ 0: true, 1: false, 2: false, 3: false }); @@ -135,27 +121,6 @@ } }); - async function confirmIdentity() { - if (!identityChoice.value || selectingIdentity.value) return; - selectingIdentity.value = true; - try { - const res = await api.selectIdentity({ user_type: identityChoice.value }); - setUser(res.userinfo); - showIdentityPicker.value = false; - } catch (e) { - // A response can be lost after the selection has been saved. - try { - const current = await api.profile(); - if (current.identity_selected) { - setUser(current); - showIdentityPicker.value = false; - } - } catch (profileError) {} - } finally { - selectingIdentity.value = false; - } - } - onBackPress(() => showIdentityPicker.value); onShow(() => { @@ -175,16 +140,6 @@