From 586d9c062d2b084c86f4b9532ff849e86ae1a051 Mon Sep 17 00:00:00 2001 From: "34701892@qq.com" <34701892@qq.com> Date: Mon, 22 Dec 2025 11:17:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(utils):=20=E7=A7=BB=E9=99=A4=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=97=A5=E5=BF=97=E5=B9=B6=E4=BF=AE=E5=A4=8D=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=A0=8F=E9=AB=98=E5=BA=A6=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor(detail): 优化token处理和页面刷新逻辑 - 在新闻详情页添加phone参数处理逻辑 - 修改token过期判断条件 - 使用window.location替代uni.reLaunch进行页面刷新 --- src/pages/detail/indexNewsInfo.vue | 18 +++++++++++++----- src/utils/util.ts | 11 +++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/pages/detail/indexNewsInfo.vue b/src/pages/detail/indexNewsInfo.vue index be573cf..d4a9c43 100644 --- a/src/pages/detail/indexNewsInfo.vue +++ b/src/pages/detail/indexNewsInfo.vue @@ -125,16 +125,24 @@ onLoad(async (option: any) => { wxShare(); } } + if (option?.phone) { + uni.setStorageSync("token", option.phone); + // 去除链接中的phone字段 + let url = window.location.href; + url = url.replace(/phone=[^&]+&?/i, ""); + // 刷新本页面 + window.location.href = url; + window.location.reload(); + } + console.log("🚀 ~ Date.now():", Date.now()); // 打开页面时链接中带有time字段,表示上次分享的时间 let shareTime = option?.time || 0; // 现在的时间对比上次的分享时间,如果超过24小时,则刷新推荐栏目 - if (Date.now() - shareTime > 24 * 60 * 60 * 1000) { + if (uni.getStorageSync("token") && Date.now() - shareTime > 24 * 60 * 60 * 1000) { uni.removeStorageSync("token"); - // 刷新本页面 - uni.reLaunch({ - url: curPages[curPages.length - 1].route, - }); + // 1766373354519 + window.location.reload(); } }); diff --git a/src/utils/util.ts b/src/utils/util.ts index 95b68fa..1c67ea7 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -81,15 +81,10 @@ export const jumpUrl = (url) => { window.open(url, "_blank"); }; - export function getNavHeight() { const systemInfo = uni.getSystemInfoSync(); - console.log(systemInfo); const statusBarHeight = systemInfo.statusBarHeight; // 状态栏高度 - const navigationBarHeight = systemInfo.platform === 'android' ? statusBarHeight + 48 : statusBarHeight + 44; // 通常安卓底部有48px的导航栏,iOS是44px - console.log('状态栏高度:', statusBarHeight); - console.log('导航栏高度:', navigationBarHeight); + const navigationBarHeight = systemInfo.platform === "android" ? statusBarHeight + 48 : statusBarHeight + 44; // 通常安卓底部有48px的导航栏,iOS是44px - return statusBarHeight - -} \ No newline at end of file + return statusBarHeight; +}