From 78bc9e3c86cf88ed819813467144bf8a1260d56b Mon Sep 17 00:00:00 2001 From: cao123 Date: Mon, 7 Sep 2026 09:03:11 +0800 Subject: [PATCH] fix --- .../pages/live/registration/registration.ts | 18 +++---- miniprogram/pages/live/video/video.ts | 7 +-- miniprogram/utils/request.ts | 47 ++++++++++++------- project.private.config.json | 2 +- 4 files changed, 43 insertions(+), 31 deletions(-) diff --git a/miniprogram/pages/live/registration/registration.ts b/miniprogram/pages/live/registration/registration.ts index 09f7429..a2f0a4f 100644 --- a/miniprogram/pages/live/registration/registration.ts +++ b/miniprogram/pages/live/registration/registration.ts @@ -1,5 +1,5 @@ import UrlParamsHandler from "../../../utils/store"; -import { appversion, version } from "../../../env"; +import { version } from "../../../env"; import { request } from "../../../utils/request"; const defaultAvatarUrl = "https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0"; @@ -45,7 +45,7 @@ Page({ }; const data = await request({ options: { - url: `/app/video-watch/details?version=${version.details}&appVer=${appversion}`, + url: `/app/video-watch/details`, method: "GET", data: params, }, @@ -110,35 +110,35 @@ Page({ /** * 生命周期函数--监听页面初次渲染完成 */ - onReady() {}, + onReady() { }, /** * 生命周期函数--监听页面显示 */ - onShow() {}, + onShow() { }, /** * 生命周期函数--监听页面隐藏 */ - onHide() {}, + onHide() { }, /** * 生命周期函数--监听页面卸载 */ - onUnload() {}, + onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ - onPullDownRefresh() {}, + onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ - onReachBottom() {}, + onReachBottom() { }, /** * 用户点击右上角分享 */ - onShareAppMessage() {}, + onShareAppMessage() { }, }); \ No newline at end of file diff --git a/miniprogram/pages/live/video/video.ts b/miniprogram/pages/live/video/video.ts index 2c1f657..ff4e6f3 100644 --- a/miniprogram/pages/live/video/video.ts +++ b/miniprogram/pages/live/video/video.ts @@ -30,7 +30,7 @@ Page({ nodes: [] as any[], eveId: null, store: {}, - fileid: "5001834818839455549", + fileid: "", active: 0, canSubmit: false, safeBottom: 24, @@ -205,7 +205,7 @@ Page({ const detail = (e && e.detail) || e || {}; wx.showModal({ title: "播放出错", - content: String(detail.errMsg || detail.message || JSON.stringify(detail)), + content: String(detail.errMsg || detail.message || JSON.stringify(detail) + '请联系坐席'), showCancel: false, }); }, @@ -292,7 +292,7 @@ Page({ const targetData = code ? data.watch : data.data; - if (!targetData?.url) { + if (!targetData.extend?.fileid) { const stateParam = code ? -1 : 5; wx.reLaunch({ url: `/pages/live/registration/registration?content=${targetData?.content || ''}&state=${stateParam}`, @@ -304,6 +304,7 @@ Page({ dataList: targetData, eveId: targetData.eveId, nodes: htmlToWxNodes(targetData.content), + fileid: targetData.extend.fileid, }); this.syncResumeTime(); diff --git a/miniprogram/utils/request.ts b/miniprogram/utils/request.ts index 38bb459..6377a08 100644 --- a/miniprogram/utils/request.ts +++ b/miniprogram/utils/request.ts @@ -1,4 +1,5 @@ -import { BASE_URL } from "../env"; +import { BASE_URL, appId } from "../env"; +import { base64Encode } from "./crypto"; type RequestProps = { options: WechatMiniprogram.RequestOption; loadingTitle?: string; @@ -6,27 +7,23 @@ type RequestProps = { needLogin?: boolean; }; -// 生成设备指纹字符串 -const generateFingerprint = (): string => { - const info = wx.getSystemInfoSync(); - return [ - String(info.system), - String(info.platform), - String(info.SDKVersion), - String(info.screenWidth), - String(info.screenHeight), - ].join("&"); -}; - +// 每次请求动态生成 header,确保使用最新的 openId +const fingerprint = wx.getSystemInfoSync(); export const request = ( - { options, loadingTitle = "加载中", isLoading = true }: RequestProps + { options, loadingTitle = "加载中", isLoading = true, needLogin = true }: RequestProps ): Promise => { - + const app = getApp(); const header: any = { - "X-Fingerprint": generateFingerprint(), + "X-Fingerprint": fingerprint, }; - + if (needLogin) { + if (!app.checkLoginState()) { + return Promise.reject(new Error('请先登录')); + } + const openId = wx.getStorageSync("openId") || ""; + header.Authorization = `Basic ${base64Encode(`${openId}:${appId}`)}` + } return new Promise((resolve, reject) => { let showToast = false; @@ -47,13 +44,27 @@ export const request = ( if (!res.data.code || res.data.code === 200) { resolve(res.data as T); } else if (res.data.code === 401) { + // 保存当前页面路径,登录后跳转回来 + const pages = getCurrentPages(); + const currentPage = pages[pages.length - 1]; + if (currentPage) { + const route = `/${currentPage.route}`; + const options = currentPage.options || {}; + const query = Object.entries(options) + .filter(([, value]) => value !== undefined && value !== null) + .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value as string)}`) + .join("&"); + const fullPath = query ? `${route}?${query}` : route; + wx.setStorageSync("redirectPath", fullPath); + } wx.showModal({ title: "登录提示", content: "请先登录", confirmText: "去登录", success: (options) => { if (options.confirm) { - wx.navigateTo({ url: "/pages/login/login" }); + // 使用 redirectTo 替换当前页,登录页无返回按钮 + wx.redirectTo({ url: "/pages/login/login" }); } } }); diff --git a/project.private.config.json b/project.private.config.json index 14488ba..388130f 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -5,7 +5,7 @@ { "name": "pages/live/video/video", "pathName": "pages/live/video/video", - "query": "code=oyydS188FNmOVk89F_bm56bUwVK8", + "query": "code=2KnFxIm5GPLK7SLDhvoxdHTAZFrRAM34bi", "scene": null, "launchMode": "default" }