feat:小程序修改

This commit is contained in:
dzc committed 2026-08-21 12:20:36 +08:00
1 parent 5f267c1e76
commit f4adf95e7a
8 files changed
+203 -69

No files matched your search

+2 -1
View File
@@ -63,7 +63,8 @@ const doSubmit = async () => {
uni.setStorageSync(tokenKey, {
accessToken: res.data.access_token,
refreshToken: res.data.refresh_token,
accessTokenExpiresIn: new Date(res.data.expires_in + Date.now()).toISOString(),
// OAuth expires_in 的单位是秒,Date.now() 的单位是毫秒,必须先乘 1000。
accessTokenExpiresIn: new Date(Date.now() + Number(res.data.expires_in) * 1000).toISOString(),
refreshTokenExpiresIn: "",
} as GlobalSetting.TokenStorage)
+15 -3
View File
@@ -82,6 +82,7 @@ import { isEmpty } from "radash"
import dayjs from "dayjs"
import { filePath } from "@@/utils/file"
import { getAppInfo } from "@@/utils/app"
import { normalizeTokenStorage } from "@@/utils/request"
import * as hooks from "@@/hooks"
import * as router from "@@/router"
import * as constant from "@@/constant"
@@ -136,7 +137,11 @@ const storage = {
// 保存token到存储
saveToken: (tokenData: any) => {
uni.setStorageSync(STORAGE_KEYS.TOKEN, tokenData)
// SSO 接口可能返回嵌套 token,统一落成请求层使用的扁平结构。
const normalizedToken = normalizeTokenStorage(tokenData)
if (!normalizedToken) return false
uni.setStorageSync(STORAGE_KEYS.TOKEN, normalizedToken)
return true
},
// 清除用户登录相关的存储
@@ -202,7 +207,11 @@ const login = {
const response = await userApi.authsh({ accountId, sessionId })
if (response.code == 0) {
storage.saveToken({ accessToken: response.data.accessToken })
if (!storage.saveToken(response.data)) {
uni.hideLoading()
uni.showToast({ title: "登录返回数据异常", icon: "none" })
return
}
uni.hideLoading()
uni.showToast({ title: "登录成功", icon: "none" })
@@ -226,7 +235,10 @@ const login = {
const res = await userApi.auth(token)
if (res.code == 0) {
storage.saveToken(res.data)
if (!storage.saveToken(res.data)) {
uni.showToast({ title: "登录返回数据异常", icon: "none" })
return
}
uni.hideLoading()
uni.showToast({ title: "登录成功", icon: "none" })
+30 -2
View File
@@ -27,6 +27,33 @@ import { filePath } from "@@/utils/file"
const show = ref(false)
function normalizeMallUrl(rawUrl: string) {
const matched = rawUrl.match(/^(https:\/\/(?:[a-z0-9-]+\.)*nbcb\.com\.cn)(\/[^?#]*)?(\?[^#]*)?(#.*)?$/i)
if (!matched) throw new Error("商城登录地址不合法")
const [, origin, rawPathname = "/", search = "", hash = ""] = matched
const queryItems = search.slice(1).split("&").filter(Boolean)
const queryKeys = queryItems.map((item) => decodeURIComponent(item.split("=")[0] || ""))
const hasToken = queryItems.some((item) => /^token=.+/i.test(item))
let pathname = rawPathname
// 宁波银行正常登录页是 /h5/thirdApp;部分环境会错误返回带 token 的根路径。
if (pathname === "/" && hasToken) {
pathname = "/h5/thirdApp"
}
console.log("[happyMall] 商城登录地址:", {
origin,
pathname,
queryKeys,
})
if (pathname === "/" || !hasToken) {
throw new Error("商城登录地址异常,请联系管理员")
}
return `${origin}${pathname}${search}${hash}`
}
onLoad(async () => {
const isLogin = await hooks.useCheckLogin()
if (isLogin) {
@@ -42,10 +69,11 @@ const thirdAppJump = async () => {
if (res.code == 0) {
show.value = false
if (!res.data) return uni.showToast({ title: "url错误", icon: "none" })
router.jump("/pages/root/web-view", { url: encodeURIComponent(res.data) }, 2)
const mallUrl = normalizeMallUrl(res.data)
router.jump("/pages/root/web-view", { url: encodeURIComponent(mallUrl) }, 2)
}
} catch (error: any) {
uni.showToast({ title: error, icon: "none" })
uni.showToast({ title: error?.message || String(error), icon: "none" })
} finally {
uni.hideLoading()
}