|
|
|
@ -21,7 +21,8 @@ const httpInterceptor = {
|
|
|
|
|
}
|
|
|
|
|
// 4. 添加 token 请求头标识
|
|
|
|
|
const memberStore = useMemberStore()
|
|
|
|
|
const token = memberStore.profile?.token
|
|
|
|
|
const token = memberStore.profile
|
|
|
|
|
console.log(memberStore.profile, 'memberStore')
|
|
|
|
|
if (token) {
|
|
|
|
|
options.header.Authorization = 'Bearer ' + token // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
|
|
}
|
|
|
|
@ -59,6 +60,8 @@ export const http = <T>(options: UniApp.RequestOptions) => {
|
|
|
|
|
})
|
|
|
|
|
// 1. 返回 Promise 对象
|
|
|
|
|
return new Promise<Data<T>>((resolve, reject) => {
|
|
|
|
|
console.log(options, 'options请求数据')
|
|
|
|
|
|
|
|
|
|
uni.request({
|
|
|
|
|
...options,
|
|
|
|
|
// 响应成功
|
|
|
|
@ -88,11 +91,11 @@ export const http = <T>(options: UniApp.RequestOptions) => {
|
|
|
|
|
title: '请求错误',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
})
|
|
|
|
|
const memberStore = useMemberStore()
|
|
|
|
|
memberStore.clearProfile()
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
uni.navigateTo({ url: '/pages/login/OneClickLogin/OneClickLogin' })
|
|
|
|
|
}, 1000)
|
|
|
|
|
// const memberStore = useMemberStore()
|
|
|
|
|
// memberStore.clearProfile()
|
|
|
|
|
// setTimeout(() => {
|
|
|
|
|
// uni.navigateTo({ url: '/pages/login/OneClickLogin/OneClickLogin' })
|
|
|
|
|
// }, 1000)
|
|
|
|
|
reject(resList)
|
|
|
|
|
} else {
|
|
|
|
|
console.log('500请求错误', res.data)
|
|
|
|
@ -111,9 +114,9 @@ export const http = <T>(options: UniApp.RequestOptions) => {
|
|
|
|
|
title: (res.data as Data<T>).msg || '请求错误',
|
|
|
|
|
icon: 'error',
|
|
|
|
|
})
|
|
|
|
|
const memberStore = useMemberStore()
|
|
|
|
|
memberStore.clearProfile()
|
|
|
|
|
uni.navigateTo({ url: '/pages/login/OneClickLogin/OneClickLogin' })
|
|
|
|
|
// const memberStore = useMemberStore()
|
|
|
|
|
// memberStore.clearProfile()
|
|
|
|
|
// uni.navigateTo({ url: '/pages/login/OneClickLogin/OneClickLogin' })
|
|
|
|
|
reject(res)
|
|
|
|
|
} else {
|
|
|
|
|
console.log('500请求错误', res.data)
|
|
|
|
|