完成一键登录和支付功能
This commit is contained in:
@@ -1,7 +1,32 @@
|
||||
const BASE_URL = '/api'
|
||||
// const BASE_URL = 'http://localhost:8084'
|
||||
// const BASE_URL = '/api'
|
||||
const BASE_URL = 'http://192.168.43.89:8084/api'
|
||||
|
||||
// 缓存相关常`量
|
||||
// OSS 静态资源基础地址
|
||||
export const OSS_BASE_URL = 'https://gymfuture.oss-cn-chengdu.aliyuncs.com'
|
||||
|
||||
/**
|
||||
* 获取 OSS 资源完整地址
|
||||
* @param {string} path - OSS 资源路径,如 '/static/images/camera.png'
|
||||
* @returns {string} 完整 OSS 地址
|
||||
*/
|
||||
export const getOssUrl = (path) => {
|
||||
if (!path) return ''
|
||||
if (path.startsWith('http://') || path.startsWith('https://')) {
|
||||
return path
|
||||
}
|
||||
return OSS_BASE_URL + path
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录会员ID
|
||||
* @returns {number|null} 会员ID,未登录返回null
|
||||
*/
|
||||
export const getMemberId = () => {
|
||||
const loginMember = uni.getStorageSync('loginMemberInfo')
|
||||
return loginMember?.id || loginMember?.memberId || null
|
||||
}
|
||||
|
||||
// 缓存相关常量
|
||||
const CACHE_PREFIX = 'API_CACHE_'
|
||||
const CACHE_EXPIRE_TIME = 5 * 60 * 1000 // 默认缓存时间5分钟
|
||||
|
||||
@@ -221,11 +246,11 @@ export const request = (options) => {
|
||||
console.log(`[API] 响应头:`, res.header)
|
||||
console.log(`[API] 响应数据:`, JSON.stringify(res.data, null, 2))
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
if (res.statusCode === 200 || res.statusCode === 204) {
|
||||
if (cache && cacheKey && res.data) {
|
||||
setCache(cacheKey, res.data, cacheTime)
|
||||
}
|
||||
resolve(res.data)
|
||||
resolve(res.data || {})
|
||||
} else if (res.statusCode === 401) {
|
||||
clearToken()
|
||||
uni.showToast({
|
||||
@@ -255,7 +280,9 @@ export const requestUtils = {
|
||||
getCache,
|
||||
setCache,
|
||||
clearCache,
|
||||
clearAllCache
|
||||
clearAllCache,
|
||||
OSS_BASE_URL,
|
||||
getOssUrl
|
||||
}
|
||||
|
||||
// 添加便捷方法
|
||||
|
||||
Reference in New Issue
Block a user