|
|
|
@ -18,15 +18,16 @@ const loginFunc = (res, userInfo) => { |
|
|
|
// 用户授权登录
|
|
|
|
loginTiktok(params).then(res => { |
|
|
|
if (res.data.code === 200) { |
|
|
|
uni.setStorage({ |
|
|
|
uni.setStorageSync({ |
|
|
|
key: 'token', |
|
|
|
data: res.data.data.access_token, |
|
|
|
}); |
|
|
|
uni.setStorageSync({ |
|
|
|
key: 'userInfo', |
|
|
|
data: res.data.data.userInfo, |
|
|
|
}) |
|
|
|
this.userInfo = res.data.data.userInfo; |
|
|
|
uni.setStorage({ |
|
|
|
key: 'token', |
|
|
|
data: res.data.data.access_token |
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
uni.showToast({ |
|
|
|
title: res.data.msg, |
|
|
|
@ -125,35 +126,28 @@ const refreshToken = () => { |
|
|
|
service.interceptors.request.use( |
|
|
|
config => { |
|
|
|
const token = uni.getStorageSync('token'); |
|
|
|
// console.log('获取到的token',token)
|
|
|
|
if (token) { |
|
|
|
// 给请求头添加user-token
|
|
|
|
// console.log('进入携带token方法')
|
|
|
|
config.headers["TiktokAuthorization"] = token; |
|
|
|
// console.log('token放入headers',config.headers)
|
|
|
|
} |
|
|
|
config.headers['Content-Type'] = 'application/json' |
|
|
|
// config.method === 'post' ?
|
|
|
|
// config.data = qs.stringify({ ...config.data
|
|
|
|
// }) :
|
|
|
|
// config.params = { ...config.params
|
|
|
|
// };
|
|
|
|
return config; |
|
|
|
}, |
|
|
|
error => { |
|
|
|
// console.log(error); // for debug
|
|
|
|
return Promise.reject(error); |
|
|
|
} |
|
|
|
); |
|
|
|
|
|
|
|
//配置成功后的拦截器
|
|
|
|
service.interceptors.response.use(res => { |
|
|
|
if (res.data.code === 200) { |
|
|
|
return res |
|
|
|
// if (res.data.status == 200) {
|
|
|
|
// return res
|
|
|
|
// } else {
|
|
|
|
// return Promise.reject(res.data.msg);
|
|
|
|
// }
|
|
|
|
} else if (res.data.code === 401) { |
|
|
|
//登录过期,刷新token
|
|
|
|
refreshToken(); |
|
|
|
//return Promise.reject(res.data.msg);
|
|
|
|
}else{ |
|
|
|
return res; |
|
|
|
} |
|
|
|
}, error => { |
|
|
|
if(error.response.status === 401){ |
|
|
|
refreshToken() //刷新token并重置token
|
|
|
|
|