|
@@ -4,8 +4,8 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
import Request from 'luch-request';
|
|
import Request from 'luch-request';
|
|
-import { refreshToken } from '@/api/auth';
|
|
|
|
-import { user } from '@/store/user'
|
|
|
|
|
|
+import { refreshToken } from '@/api/common';
|
|
|
|
+import { userStore } from '@/store/user'
|
|
|
|
|
|
const baseUrl = 'http://menduner.citupro.com:7878'
|
|
const baseUrl = 'http://menduner.citupro.com:7878'
|
|
const tenantId = '155'
|
|
const tenantId = '155'
|
|
@@ -68,11 +68,12 @@ const http = new Request({
|
|
*/
|
|
*/
|
|
http.interceptors.request.use(
|
|
http.interceptors.request.use(
|
|
(config) => {
|
|
(config) => {
|
|
- const useUserStore = user()
|
|
|
|
|
|
+ const useUserStore = userStore()
|
|
// 自定义处理【auth 授权】:必须登录的接口,则跳出 AuthModal 登录弹窗
|
|
// 自定义处理【auth 授权】:必须登录的接口,则跳出 AuthModal 登录弹窗
|
|
if (config.custom.auth && !useUserStore.isLogin) {
|
|
if (config.custom.auth && !useUserStore.isLogin) {
|
|
uni.showToast({
|
|
uni.showToast({
|
|
- title:'请先登录'
|
|
|
|
|
|
+ title:'请先登录',
|
|
|
|
+ icon: 'none'
|
|
})
|
|
})
|
|
uni.navigateTo({
|
|
uni.navigateTo({
|
|
url: '/pages/login/index'
|
|
url: '/pages/login/index'
|
|
@@ -116,8 +117,8 @@ http.interceptors.response.use(
|
|
(response) => {
|
|
(response) => {
|
|
// 约定:如果是 /auth/ 下的 URL 地址,并且返回了 accessToken 说明是登录相关的接口,则自动设置登陆令牌
|
|
// 约定:如果是 /auth/ 下的 URL 地址,并且返回了 accessToken 说明是登录相关的接口,则自动设置登陆令牌
|
|
if (response.config.url.indexOf('/system/auth/') >= 0 && response.data?.data?.accessToken) {
|
|
if (response.config.url.indexOf('/system/auth/') >= 0 && response.data?.data?.accessToken) {
|
|
- const userStore = user()
|
|
|
|
- userStore.setToken(response.data.data.accessToken, response.data.data.refreshToken);
|
|
|
|
|
|
+ const useUserStore = userStore()
|
|
|
|
+ useUserStore.setToken(response.data.data.accessToken, response.data.data.refreshToken);
|
|
}
|
|
}
|
|
|
|
|
|
// 自定处理【loading 加载中】:如果需要显示 loading,则关闭 loading
|
|
// 自定处理【loading 加载中】:如果需要显示 loading,则关闭 loading
|
|
@@ -154,8 +155,8 @@ http.interceptors.response.use(
|
|
return Promise.resolve(response.data);
|
|
return Promise.resolve(response.data);
|
|
},
|
|
},
|
|
(error) => {
|
|
(error) => {
|
|
- const userStore = user()
|
|
|
|
- const isLogin = userStore.isLogin;
|
|
|
|
|
|
+ const useUserStore = userStore()
|
|
|
|
+ const isLogin = useUserStore.isLogin;
|
|
let errorMessage = '网络请求出错';
|
|
let errorMessage = '网络请求出错';
|
|
if (error !== undefined) {
|
|
if (error !== undefined) {
|
|
switch (error.statusCode) {
|
|
switch (error.statusCode) {
|
|
@@ -278,10 +279,11 @@ const handleRefreshToken = async (config) => {
|
|
* 处理 401 未登录的错误
|
|
* 处理 401 未登录的错误
|
|
*/
|
|
*/
|
|
const handleAuthorized = () => {
|
|
const handleAuthorized = () => {
|
|
- const userStore = user()
|
|
|
|
- userStore.logout(true);
|
|
|
|
|
|
+ const useUserStore = userStore()
|
|
|
|
+ useUserStore.handleLogout(true);
|
|
uni.showToast({
|
|
uni.showToast({
|
|
- title:'请先登录'
|
|
|
|
|
|
+ title:'请先登录',
|
|
|
|
+ icon: 'none'
|
|
})
|
|
})
|
|
uni.navigateTo({
|
|
uni.navigateTo({
|
|
url: '/pages/login/index'
|
|
url: '/pages/login/index'
|
|
@@ -289,7 +291,7 @@ const handleAuthorized = () => {
|
|
// 登录超时
|
|
// 登录超时
|
|
return Promise.reject({
|
|
return Promise.reject({
|
|
code: 401,
|
|
code: 401,
|
|
- msg: userStore.isLogin ? '您的登陆已过期' : '请先登录'
|
|
|
|
|
|
+ msg: useUserStore.isLogin ? '您的登陆已过期' : '请先登录'
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|