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

+7 -10
View File
@@ -1,11 +1,13 @@
import storageConstant from "../constant/storage-constant"
import { jump } from "../router/index"
import { isDevEnv } from "../utils/app"
export const useToken = () => {
const tokenKey = storageConstant.TOKEN
const tokenStorage = uni.getStorageSync(tokenKey)
return tokenStorage?.access_token ? `Bearer ${tokenStorage.access_token}` : ""
// 登录与刷新接口历史上存在两种字段格式,上传等原生请求也必须读取同一个有效 token。
const rawToken = tokenStorage?.accessToken ?? tokenStorage?.access_token
const tokenValue = typeof rawToken === "string" ? rawToken : rawToken?.tokenValue
return tokenValue ? `Bearer ${tokenValue}` : ""
}
export const useDefaultHeader = () => {
@@ -18,17 +20,12 @@ export const useDefaultHeader = () => {
}
export const useStaticCheckLogin = () => {
const tokenKey = storageConstant.TOKEN
const tokenStorage = uni.getStorageSync(tokenKey)
if (tokenStorage) return true
return false
// 不能只判断缓存对象存在,刷新失败留下的空对象不代表已登录。
return Boolean(useToken())
}
export const useCheckLogin = async (): Promise<boolean> => {
const tokenKey = storageConstant.TOKEN
const tokenStorage = uni.getStorageSync(tokenKey)
if (tokenStorage) return true
if (useToken()) return true
uni.showModal({
title: "提示",
content: "您还未登录,请先登录",