|
@@ -66,10 +66,21 @@ export const http = <T>(options: UniApp.RequestOptions) => {
|
|
|
...options,
|
|
|
// 响应成功
|
|
|
success(res) {
|
|
|
+ console.log('响应成功', res)
|
|
|
+
|
|
|
// 状态码 2xx, axios 就是这样设计的
|
|
|
if (res.statusCode >= 200 && res.statusCode < 300) {
|
|
|
// 2.1 提取核心数据 res.data
|
|
|
- resolve(res.data as Data<T>)
|
|
|
+ const data = res.data as Data<T>
|
|
|
+ if (data.code === 302) {
|
|
|
+ // 401错误 -> 清理用户信息,跳转到登录页
|
|
|
+ const memberStore = useMemberStore()
|
|
|
+ memberStore.clearProfile()
|
|
|
+ uni.navigateTo({ url: '/pages/login/login' })
|
|
|
+ reject(res)
|
|
|
+ } else {
|
|
|
+ resolve(res.data as Data<T>)
|
|
|
+ }
|
|
|
} else if (res.statusCode === 401) {
|
|
|
// 401错误 -> 清理用户信息,跳转到登录页
|
|
|
const memberStore = useMemberStore()
|