|
|
@@ -15,12 +15,12 @@ import router from '@/router';
|
|
|
// 获取主站完整 URL(用于跨域跳转)
|
|
|
function getMainSiteUrl(path: string) {
|
|
|
if (import.meta.env.PROD) {
|
|
|
- return `https://passport.xiaoluwebsite.xyz${path}`;
|
|
|
+ return `https://index.xiaoluwebsite.xyz${path}`;
|
|
|
} else {
|
|
|
- // 本地开发:指向 www.xiaoluwebsite.xyz 加上当前运行的端口
|
|
|
- // 假设你启动 vite 后访问的是 http://www.xiaoluwebsite.xyz
|
|
|
+ // 本地开发:指向 index.xiaoluwebsite.xyz 加上当前运行的端口
|
|
|
+ // 假设你启动 vite 后访问的是 http://index.xiaoluwebsite.xyz
|
|
|
const devPort = window.location.port || import.meta.env.VITE_APP_PORT;
|
|
|
- return `https://passport.xiaoluwebsite.xyz:${devPort}${path}`;
|
|
|
+ return `https://index.xiaoluwebsite.xyz:${devPort}${path}`;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -57,9 +57,9 @@ service.interceptors.request.use(
|
|
|
// 是否需要加密
|
|
|
const isEncrypt = config.headers?.isEncrypt === 'true';
|
|
|
|
|
|
- // if (getToken() && !isToken) {
|
|
|
- // config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
- // }
|
|
|
+ if (getToken() && !isToken) {
|
|
|
+ config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
|
|
|
+ }
|
|
|
// get请求映射params参数
|
|
|
if (config.method === 'get' && config.params) {
|
|
|
let url = config.url + '?' + tansParams(config.params);
|
|
|
@@ -141,37 +141,62 @@ service.interceptors.response.use(
|
|
|
if (code === 401) {
|
|
|
if (!isRelogin.show) {
|
|
|
isRelogin.show = true;
|
|
|
- // ElMessageBox.confirm('登录状态已过期,请重新登录', '登录提示', {
|
|
|
- // confirmButtonText: '重新登录',
|
|
|
- // type: 'warning'
|
|
|
- // })
|
|
|
- // .then(() => {
|
|
|
- // isRelogin.show = false;
|
|
|
- // useUserStore()
|
|
|
- // .logout()
|
|
|
- // .then(() => {
|
|
|
- // if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
|
|
|
- // window.location.href = getMainSiteUrl('/login');
|
|
|
- // } else {
|
|
|
- // router.push('/login');
|
|
|
- // }
|
|
|
- // });
|
|
|
- // })
|
|
|
- // .catch(() => {
|
|
|
- // isRelogin.show = false;
|
|
|
- // });
|
|
|
- useUserStore()
|
|
|
- .logout()
|
|
|
+ ElMessageBox.confirm('登录状态已过期,请重新登录', '登录提示', {
|
|
|
+ confirmButtonText: '重新登录',
|
|
|
+ type: 'warning'
|
|
|
+ })
|
|
|
.then(() => {
|
|
|
isRelogin.show = false;
|
|
|
- if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
|
|
|
- window.location.href = getMainSiteUrl('/login');
|
|
|
- } else {
|
|
|
- router.push('/login');
|
|
|
- }
|
|
|
+ useUserStore()
|
|
|
+ .logout()
|
|
|
+ .then(() => {
|
|
|
+ if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
|
|
|
+ window.location.href = getMainSiteUrl('/login');
|
|
|
+ } else {
|
|
|
+ router.push('/login');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ isRelogin.show = false;
|
|
|
});
|
|
|
}
|
|
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
|
|
|
+
|
|
|
+ // prettier-ignore
|
|
|
+ // if (!isRelogin.show) {
|
|
|
+ // isRelogin.show = true;
|
|
|
+ // useUserStore().logout().then(() => {
|
|
|
+ // window.location.href = getMainSiteUrl('/index');
|
|
|
+ // });
|
|
|
+
|
|
|
+ // ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
+ // confirmButtonText: '重新登录',
|
|
|
+ // cancelButtonText: '取消',
|
|
|
+ // type: 'warning'
|
|
|
+ // }).then(() => {
|
|
|
+ // isRelogin.show = false;
|
|
|
+ // useUserStore().logout().then(() => {
|
|
|
+ // router.replace({
|
|
|
+ // path: '/login',
|
|
|
+ // query: {
|
|
|
+ // redirect: encodeURIComponent(router.currentRoute.value.fullPath || '/')
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // });
|
|
|
+ // }).catch(() => {
|
|
|
+ // isRelogin.show = false;
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+
|
|
|
+ // useUserStore().logout().then(() => {
|
|
|
+ // if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
|
|
|
+ // window.location.href = getMainSiteUrl('/login');
|
|
|
+ // }else{
|
|
|
+ // router.push('/login');
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
|
|
|
} else if (code === HttpStatus.SERVER_ERROR) {
|
|
|
ElMessage({ message: msg, type: 'error' });
|
|
|
// return Promise.reject(new Error(msg));
|