ref : 重构令牌管理逻辑,,统一状态码识别
This commit is contained in:
@@ -1,15 +1,28 @@
|
|||||||
import { CACHE_SESSION_CRYPTO_API } from '@/constants/cache-keys-constants';
|
|
||||||
import { sessionGet } from '@/utils/cache-session-utils';
|
|
||||||
import { request } from '@/plugins/http-fetch';
|
import { request } from '@/plugins/http-fetch';
|
||||||
|
|
||||||
// 登录方法
|
/**
|
||||||
|
* 登录方法
|
||||||
|
* @param data 数据
|
||||||
|
* @returns 结果
|
||||||
|
*/
|
||||||
export function login(data: Record<string, string>) {
|
export function login(data: Record<string, string>) {
|
||||||
return request({
|
return request({
|
||||||
url: '/login',
|
url: '/auth/login',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: data,
|
data: data,
|
||||||
whithToken: false,
|
whithToken: false,
|
||||||
crypto: sessionGet(CACHE_SESSION_CRYPTO_API) !== 'false',
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出方法
|
||||||
|
* @returns object
|
||||||
|
*/
|
||||||
|
export function logout() {
|
||||||
|
return request({
|
||||||
|
url: '/auth/logout',
|
||||||
|
method: 'POST',
|
||||||
|
repeatSubmit: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,11 +33,24 @@ export function login(data: Record<string, string>) {
|
|||||||
*/
|
*/
|
||||||
export function register(data: Record<string, any>) {
|
export function register(data: Record<string, any>) {
|
||||||
return request({
|
return request({
|
||||||
url: '/register',
|
url: '/auth/register',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: data,
|
data: data,
|
||||||
whithToken: false,
|
whithToken: false,
|
||||||
crypto: sessionGet(CACHE_SESSION_CRYPTO_API) !== 'false',
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新登录令牌
|
||||||
|
* @param data 数据
|
||||||
|
* @returns 结果
|
||||||
|
*/
|
||||||
|
export function refreshToken(refreshToken: string) {
|
||||||
|
return request({
|
||||||
|
url: '/auth/refresh-token',
|
||||||
|
method: 'POST',
|
||||||
|
data: { refreshToken },
|
||||||
|
whithToken: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,16 +66,15 @@ export function getInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退出方法
|
* 获取路由
|
||||||
* @returns object
|
* @returns object
|
||||||
*/
|
*/
|
||||||
export function logout() {
|
export const getRouter = () => {
|
||||||
return request({
|
return request({
|
||||||
url: '/logout',
|
url: '/router',
|
||||||
method: 'POST',
|
method: 'GET',
|
||||||
repeatSubmit: false,
|
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取验证码
|
* 获取验证码
|
||||||
@@ -1,65 +1,5 @@
|
|||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { request } from '@/plugins/http-fetch';
|
import { request } from '@/plugins/http-fetch';
|
||||||
import { parseDateToStr } from '@/utils/date-utils';
|
|
||||||
import { NE_TYPE_LIST } from '@/constants/ne-constants';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询公告列表
|
|
||||||
* @param query 查询参数
|
|
||||||
* @returns object
|
|
||||||
*/
|
|
||||||
export async function listMain() {
|
|
||||||
const result = await request({
|
|
||||||
url: '/api/rest/systemManagement/v1/elementType/all/objectType/systemState',
|
|
||||||
method: 'GET',
|
|
||||||
timeout: 60_000,
|
|
||||||
});
|
|
||||||
// console.log(result);
|
|
||||||
let realData = result.data.data;
|
|
||||||
const mergedData = realData.map((obj: any) => {
|
|
||||||
// console.log(obj);
|
|
||||||
const [key, value] = Object.entries(obj)[0];
|
|
||||||
const ipAddress = (value as any).ipAddress;
|
|
||||||
const systemState = (value as any).systemState;
|
|
||||||
const serialNum = (value as any).serialNum;
|
|
||||||
const version = (value as any).version;
|
|
||||||
|
|
||||||
const errCode = systemState && systemState['errorCode'];
|
|
||||||
var time = new Date();
|
|
||||||
// console.log(key, value);
|
|
||||||
let mergedObj;
|
|
||||||
if (errCode === undefined && systemState) {
|
|
||||||
mergedObj = {
|
|
||||||
...systemState,
|
|
||||||
refresh: parseDateToStr(time),
|
|
||||||
ipAddress: ipAddress,
|
|
||||||
name: key.split('/').join('_'),
|
|
||||||
status: 'Normal',
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
mergedObj = {
|
|
||||||
version,
|
|
||||||
refresh: parseDateToStr(time),
|
|
||||||
ipAddress,
|
|
||||||
serialNum,
|
|
||||||
name: key.split('/').join('_'),
|
|
||||||
expiryDate: '-',
|
|
||||||
status: 'Abnormal',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return mergedObj;
|
|
||||||
});
|
|
||||||
//通过sort进行冒泡排序
|
|
||||||
mergedData.sort((a: any, b: any) => {
|
|
||||||
const typeA = NE_TYPE_LIST.indexOf(a.name.split('_')[0]);
|
|
||||||
const typeB = NE_TYPE_LIST.indexOf(b.name.split('_')[0]);
|
|
||||||
if (typeA === -1) return 1; // 如果不在特定顺序中,排到后面
|
|
||||||
if (typeB === -1) return -1; // 如果不在特定顺序中,排到后面
|
|
||||||
return typeA - typeB;
|
|
||||||
});
|
|
||||||
|
|
||||||
return mergedData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取服务器时间
|
* 获取服务器时间
|
||||||
|
|||||||
@@ -37,16 +37,3 @@ export function updateUserPassword(oldPassword: string, newPassword: string) {
|
|||||||
data: { oldPassword, newPassword },
|
data: { oldPassword, newPassword },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户强制重置密码
|
|
||||||
* @param password 密码
|
|
||||||
* @returns object
|
|
||||||
*/
|
|
||||||
export function updateUserPasswordForce(password: string) {
|
|
||||||
return request({
|
|
||||||
url: '/system/user/profile/password-force',
|
|
||||||
method: 'PUT',
|
|
||||||
data: { password },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import { request } from '@/plugins/http-fetch';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取路由
|
|
||||||
* @returns object
|
|
||||||
*/
|
|
||||||
export const getRouters = () => {
|
|
||||||
return request({
|
|
||||||
url: '/router',
|
|
||||||
method: 'GET',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -136,3 +136,16 @@ export function changeUserStatus(
|
|||||||
data: { userId, statusFlag },
|
data: { userId, statusFlag },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户强制重置密码
|
||||||
|
* @param password 密码
|
||||||
|
* @returns object
|
||||||
|
*/
|
||||||
|
export function updateUserPasswordForce(password: string) {
|
||||||
|
return request({
|
||||||
|
url: '/system/user/profile/password-force',
|
||||||
|
method: 'PUT',
|
||||||
|
data: { password },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { regExpPasswd, regExpUserName } from '@/utils/regular-utils';
|
|||||||
import { Form, message, Modal } from 'ant-design-vue';
|
import { Form, message, Modal } from 'ant-design-vue';
|
||||||
import useI18n from '@/hooks/useI18n';
|
import useI18n from '@/hooks/useI18n';
|
||||||
import useUserStore from '@/store/modules/user';
|
import useUserStore from '@/store/modules/user';
|
||||||
import { updateUserPasswordForce } from '@/api/profile';
|
import { updateUserPasswordForce } from '@/api/system/user';
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { getConfigKey } from '@/api/system/config';
|
import { getConfigKey } from '@/api/system/config';
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
/**响应-code加密数据 */
|
/**响应-code加密数据 */
|
||||||
export const RESULT_CODE_ENCRYPT = 2;
|
export const RESULT_CODE_ENCRYPT = 200999;
|
||||||
|
|
||||||
/**响应-msg加密数据 */
|
/**响应-msg加密数据 */
|
||||||
export const RESULT_MSG_ENCRYPT: Record<string, string> = {
|
export const RESULT_MSG_ENCRYPT: Record<string, string> = {
|
||||||
zh_CN: '加密!',
|
zh_CN: '加密!',
|
||||||
en_US: 'encrypt!',
|
en_US: 'Encrypt!',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**响应-code正常成功 */
|
/**响应-code正常成功 */
|
||||||
export const RESULT_CODE_SUCCESS = 1;
|
export const RESULT_CODE_SUCCESS = 200001;
|
||||||
|
|
||||||
/**响应-msg正常成功 */
|
/**响应-msg正常成功 */
|
||||||
export const RESULT_MSG_SUCCESS: Record<string, string> = {
|
export const RESULT_MSG_SUCCESS: Record<string, string> = {
|
||||||
@@ -17,7 +17,16 @@ export const RESULT_MSG_SUCCESS: Record<string, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**响应-code错误失败 */
|
/**响应-code错误失败 */
|
||||||
export const RESULT_CODE_ERROR = 0;
|
export const RESULT_CODE_ERROR = 400001;
|
||||||
|
|
||||||
|
/**响应-code错误异常 */
|
||||||
|
export const RESULT_CODE_EXCEPTION = 500001;
|
||||||
|
|
||||||
|
/**响应-服务器连接出错 */
|
||||||
|
export const RESULT_MSG_SERVER_ERROR: Record<string, string> = {
|
||||||
|
zh_CN: '服务器连接出错!',
|
||||||
|
en_US: 'Server Connection Error!',
|
||||||
|
};
|
||||||
|
|
||||||
/**响应-msg错误失败 */
|
/**响应-msg错误失败 */
|
||||||
export const RESULT_MSG_ERROR: Record<string, string> = {
|
export const RESULT_MSG_ERROR: Record<string, string> = {
|
||||||
@@ -37,18 +46,6 @@ export const RESULT_MSG_NOT_TYPE: Record<string, string> = {
|
|||||||
en_US: 'Unknown Response Data Type!',
|
en_US: 'Unknown Response Data Type!',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**响应-服务器连接出错 */
|
|
||||||
export const RESULT_MSG_SERVER_ERROR: Record<string, string> = {
|
|
||||||
zh_CN: '服务器连接出错!',
|
|
||||||
en_US: 'Server Connection Error!',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**响应-请求地址未找到 */
|
|
||||||
export const RESULT_MSG_URL_NOTFOUND: Record<string, string> = {
|
|
||||||
zh_CN: '请求地址未找到!',
|
|
||||||
en_US: 'Request Address Not Found!',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**响应-数据正在处理,请勿重复提交 */
|
/**响应-数据正在处理,请勿重复提交 */
|
||||||
export const RESULT_MSG_URL_RESUBMIT: Record<string, string> = {
|
export const RESULT_MSG_URL_RESUBMIT: Record<string, string> = {
|
||||||
zh_CN: '数据正在处理,请勿重复提交!',
|
zh_CN: '数据正在处理,请勿重复提交!',
|
||||||
|
|||||||
@@ -2,10 +2,13 @@
|
|||||||
export const TOKEN_RESPONSE_FIELD = 'accessToken';
|
export const TOKEN_RESPONSE_FIELD = 'accessToken';
|
||||||
|
|
||||||
/**令牌-请求头标识前缀 */
|
/**令牌-请求头标识前缀 */
|
||||||
export const TOKEN_KEY_PREFIX = 'Bearer ';
|
export const TOKEN_KEY_PREFIX = 'Bearer';
|
||||||
|
|
||||||
/**令牌-请求头标识 */
|
/**令牌-请求头标识 */
|
||||||
export const TOKEN_KEY = 'Authorization';
|
export const TOKEN_KEY = 'Authorization';
|
||||||
|
|
||||||
/**令牌-存放Cookie标识 */
|
/**令牌-访问令牌存放Cookie标识 */
|
||||||
export const TOKEN_COOKIE = 'AuthOMC';
|
export const TOKEN_ACCESS_COOKIE = 'omc_access';
|
||||||
|
|
||||||
|
/**令牌-刷新令牌存放Cookie标识 */
|
||||||
|
export const TOKEN_REFRESH_COOKIE = 'omc_refresh';
|
||||||
|
|||||||
@@ -1224,7 +1224,7 @@ export default {
|
|||||||
type:'网元类型',
|
type:'网元类型',
|
||||||
neId:'网元唯一标识',
|
neId:'网元唯一标识',
|
||||||
MML:'MML',
|
MML:'MML',
|
||||||
logTime:'log Time'
|
logTime:'记录时间'
|
||||||
},
|
},
|
||||||
forwarding:{
|
forwarding:{
|
||||||
alarmId:'告警唯一标识',
|
alarmId:'告警唯一标识',
|
||||||
|
|||||||
@@ -1,25 +1,45 @@
|
|||||||
import Cookies from 'js-cookie';
|
import Cookies from 'js-cookie';
|
||||||
import { TOKEN_COOKIE } from '@/constants/token-constants';
|
|
||||||
import { localRemove, localSet } from '@/utils/cache-local-utils';
|
|
||||||
import {
|
import {
|
||||||
CACHE_LOCAL_LOCK_PASSWD,
|
TOKEN_ACCESS_COOKIE,
|
||||||
CACHE_LOCAL_MASK,
|
TOKEN_REFRESH_COOKIE,
|
||||||
} from '@/constants/cache-keys-constants';
|
} from '@/constants/token-constants';
|
||||||
|
|
||||||
/**获取cookis中Token字符串 */
|
/**获取访问令牌 */
|
||||||
export function getToken(): string {
|
export function getAccessToken(): string {
|
||||||
return Cookies.get(TOKEN_COOKIE) || '';
|
return Cookies.get(TOKEN_ACCESS_COOKIE) || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**设置cookis中Token字符串 */
|
/**
|
||||||
export function setToken(token: string): void {
|
* 设置访问令牌
|
||||||
Cookies.set(TOKEN_COOKIE, token || '');
|
* @param token token字符串
|
||||||
localSet(CACHE_LOCAL_MASK, 'none');
|
* @param exp 过期时间(秒)
|
||||||
|
*/
|
||||||
|
export function setAccessToken(token: string, exp: number): void {
|
||||||
|
const expires = new Date(new Date().getTime() + exp * 1000);
|
||||||
|
Cookies.set(TOKEN_ACCESS_COOKIE, token, { expires });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**移除cookis中Token字符串,localStorage中锁屏字符串 */
|
/**移除访问令牌 */
|
||||||
export function removeToken(): void {
|
export function delAccessToken(): void {
|
||||||
Cookies.remove(TOKEN_COOKIE);
|
Cookies.remove(TOKEN_ACCESS_COOKIE);
|
||||||
localRemove(CACHE_LOCAL_MASK);
|
}
|
||||||
localRemove(CACHE_LOCAL_LOCK_PASSWD);
|
|
||||||
|
/**获取刷新令牌 */
|
||||||
|
export function getRefreshToken(): string {
|
||||||
|
return Cookies.get(TOKEN_REFRESH_COOKIE) || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置刷新令牌
|
||||||
|
* @param token token字符串
|
||||||
|
* @param exp 过期时间(秒)
|
||||||
|
*/
|
||||||
|
export function setRefreshToken(token: string, exp: number): void {
|
||||||
|
const expires = new Date(new Date().getTime() + exp * 1000);
|
||||||
|
Cookies.set(TOKEN_REFRESH_COOKIE, token, { expires });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**移除刷新令牌 */
|
||||||
|
export function delRefreshToken(): void {
|
||||||
|
Cookies.remove(TOKEN_REFRESH_COOKIE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
import { getToken, removeToken } from '@/plugins/auth-token';
|
import {
|
||||||
|
getAccessToken,
|
||||||
|
setAccessToken,
|
||||||
|
delAccessToken,
|
||||||
|
getRefreshToken,
|
||||||
|
setRefreshToken,
|
||||||
|
delRefreshToken,
|
||||||
|
} from '@/plugins/auth-token';
|
||||||
import {
|
import {
|
||||||
sessionGet,
|
sessionGet,
|
||||||
sessionGetJSON,
|
sessionGetJSON,
|
||||||
sessionSetJSON,
|
sessionSetJSON,
|
||||||
} from '@/utils/cache-session-utils';
|
} from '@/utils/cache-session-utils';
|
||||||
import { localGet } from '@/utils/cache-local-utils';
|
|
||||||
import { TOKEN_KEY, TOKEN_KEY_PREFIX } from '@/constants/token-constants';
|
import { TOKEN_KEY, TOKEN_KEY_PREFIX } from '@/constants/token-constants';
|
||||||
import {
|
import {
|
||||||
CACHE_LOCAL_I18N,
|
CACHE_LOCAL_I18N,
|
||||||
@@ -18,6 +24,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
RESULT_CODE_ENCRYPT,
|
RESULT_CODE_ENCRYPT,
|
||||||
RESULT_CODE_ERROR,
|
RESULT_CODE_ERROR,
|
||||||
|
RESULT_CODE_EXCEPTION,
|
||||||
RESULT_CODE_SUCCESS,
|
RESULT_CODE_SUCCESS,
|
||||||
RESULT_MSG_ENCRYPT,
|
RESULT_MSG_ENCRYPT,
|
||||||
RESULT_MSG_ERROR,
|
RESULT_MSG_ERROR,
|
||||||
@@ -25,10 +32,11 @@ import {
|
|||||||
RESULT_MSG_SERVER_ERROR,
|
RESULT_MSG_SERVER_ERROR,
|
||||||
RESULT_MSG_SUCCESS,
|
RESULT_MSG_SUCCESS,
|
||||||
RESULT_MSG_TIMEOUT,
|
RESULT_MSG_TIMEOUT,
|
||||||
RESULT_MSG_URL_NOTFOUND,
|
|
||||||
RESULT_MSG_URL_RESUBMIT,
|
RESULT_MSG_URL_RESUBMIT,
|
||||||
} from '@/constants/result-constants';
|
} from '@/constants/result-constants';
|
||||||
import { decryptAES, encryptAES } from '@/utils/encrypt-utils';
|
import { decryptAES, encryptAES } from '@/utils/encrypt-utils';
|
||||||
|
import { localGet } from '@/utils/cache-local-utils';
|
||||||
|
import { refreshToken } from '@/api/auth';
|
||||||
|
|
||||||
/**响应结果类型 */
|
/**响应结果类型 */
|
||||||
export type ResultType = {
|
export type ResultType = {
|
||||||
@@ -61,7 +69,7 @@ type OptionsType = {
|
|||||||
/**请求地址 */
|
/**请求地址 */
|
||||||
url: string;
|
url: string;
|
||||||
/**请求方法 */
|
/**请求方法 */
|
||||||
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
||||||
/**请求头 */
|
/**请求头 */
|
||||||
headers?: HeadersInit;
|
headers?: HeadersInit;
|
||||||
/**地址栏参数 */
|
/**地址栏参数 */
|
||||||
@@ -133,16 +141,21 @@ function beforeRequest(options: OptionsType): OptionsType | Promise<any> {
|
|||||||
Reflect.set(options.headers, 'Accept-Language', `${language};q=0.9`);
|
Reflect.set(options.headers, 'Accept-Language', `${language};q=0.9`);
|
||||||
|
|
||||||
// 是否需要设置 token
|
// 是否需要设置 token
|
||||||
const token = getToken();
|
const accessToken = getAccessToken();
|
||||||
if (options.whithToken && token) {
|
if (options.whithToken && accessToken) {
|
||||||
Reflect.set(options.headers, TOKEN_KEY, TOKEN_KEY_PREFIX + token);
|
Reflect.set(
|
||||||
|
options.headers,
|
||||||
|
TOKEN_KEY,
|
||||||
|
TOKEN_KEY_PREFIX + ' ' + accessToken
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否需要防止数据重复提交
|
// 是否需要防止数据重复提交
|
||||||
if (
|
if (
|
||||||
options.repeatSubmit &&
|
options.repeatSubmit &&
|
||||||
options.dataType === 'json' &&
|
options.dataType === 'json' &&
|
||||||
['post', 'put'].includes(options.method)
|
!(options.data instanceof FormData) &&
|
||||||
|
['POST', 'PUT'].includes(options.method)
|
||||||
) {
|
) {
|
||||||
const requestObj: RepeatSubmitType = {
|
const requestObj: RepeatSubmitType = {
|
||||||
url: options.url,
|
url: options.url,
|
||||||
@@ -212,13 +225,31 @@ function beforeRequest(options: OptionsType): OptionsType | Promise<any> {
|
|||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**请求后的拦截 */
|
/**响应前的拦截 */
|
||||||
function interceptorResponse(res: ResultType): ResultType | Promise<any> {
|
async function beforeResponse(
|
||||||
|
options: OptionsType,
|
||||||
|
res: ResultType
|
||||||
|
): Promise<any> {
|
||||||
// console.log('请求后的拦截', res);
|
// console.log('请求后的拦截', res);
|
||||||
|
|
||||||
// 登录失效时,移除授权令牌并重新刷新页面
|
// 登录失效时,移除授权令牌并重新刷新页面
|
||||||
if (res.code === 401) {
|
// 登录失效时,移除访问令牌并重新请求
|
||||||
removeToken();
|
if (res.code === 401001) {
|
||||||
|
const result = await refreshToken(getRefreshToken());
|
||||||
|
// 更新访问令牌和刷新令牌
|
||||||
|
if (result.code === RESULT_CODE_SUCCESS) {
|
||||||
|
setAccessToken(result.data.accessToken, result.data.refreshExpiresIn);
|
||||||
|
setRefreshToken(result.data.refreshToken, result.data.refreshExpiresIn);
|
||||||
|
return await request(options);
|
||||||
|
} else {
|
||||||
|
delAccessToken();
|
||||||
|
delRefreshToken();
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ([401002, 401003].includes(res.code)) {
|
||||||
|
delAccessToken();
|
||||||
|
delRefreshToken();
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,43 +302,45 @@ function interceptorResponse(res: ResultType): ResultType | Promise<any> {
|
|||||||
* @returns 返回 Promise<ResultType>
|
* @returns 返回 Promise<ResultType>
|
||||||
*/
|
*/
|
||||||
export async function request(options: OptionsType): Promise<ResultType> {
|
export async function request(options: OptionsType): Promise<ResultType> {
|
||||||
options = Object.assign({}, FATCH_OPTIONS, options);
|
let reqOptions = Object.assign({}, FATCH_OPTIONS, options);
|
||||||
let timeoutId: any = 0;
|
|
||||||
// 请求超时控制请求终止
|
// 请求超时控制请求终止
|
||||||
if (!options.signal) {
|
let timeoutId: any = null;
|
||||||
|
if (!reqOptions.signal) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const { signal } = controller;
|
reqOptions.signal = controller.signal;
|
||||||
options.signal = signal;
|
|
||||||
timeoutId = setTimeout(() => {
|
timeoutId = setTimeout(() => {
|
||||||
controller.abort(); // 终止请求
|
controller.abort(); // 终止请求
|
||||||
}, options.timeout);
|
}, reqOptions.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查请求拦截
|
// 检查请求拦截
|
||||||
const beforeReq = beforeRequest(options);
|
const beforeReq = beforeRequest(reqOptions);
|
||||||
if (beforeReq instanceof Promise) {
|
if (beforeReq instanceof Promise) {
|
||||||
return await beforeReq;
|
return await beforeReq;
|
||||||
}
|
}
|
||||||
options = beforeReq;
|
reqOptions = beforeReq;
|
||||||
|
|
||||||
// 判断用户传递的URL是否http或/开头
|
// 判断用户传递的URL是否http或/开头
|
||||||
if (!options.url.startsWith('http')) {
|
if (!reqOptions.url.startsWith('http')) {
|
||||||
const uri = options.url.startsWith('/') ? options.url : `/${options.url}`;
|
const uri = reqOptions.url.startsWith('/')
|
||||||
options.url = options.baseUrl + uri;
|
? reqOptions.url
|
||||||
|
: `/${reqOptions.url}`;
|
||||||
|
reqOptions.url = reqOptions.baseUrl + uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(options.url, options);
|
const res = await fetch(reqOptions.url, reqOptions);
|
||||||
// console.log('请求结果:', res);
|
// console.log('请求结果:', res);
|
||||||
|
if (res.status === 500) {
|
||||||
// 状态码拦截处理
|
return {
|
||||||
const reqNot = stateCode(res);
|
code: RESULT_CODE_EXCEPTION,
|
||||||
if (reqNot != false) {
|
msg: RESULT_MSG_SERVER_ERROR[language],
|
||||||
return reqNot;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据响应数据类型返回
|
// 根据响应数据类型返回
|
||||||
switch (options.responseType) {
|
switch (reqOptions.responseType) {
|
||||||
case 'text': // 文本数据
|
case 'text': // 文本数据
|
||||||
const str = await res.text();
|
const str = await res.text();
|
||||||
return {
|
return {
|
||||||
@@ -317,11 +350,7 @@ export async function request(options: OptionsType): Promise<ResultType> {
|
|||||||
case 'json': // json格式数据
|
case 'json': // json格式数据
|
||||||
const result = await res.json();
|
const result = await res.json();
|
||||||
// 请求后的拦截
|
// 请求后的拦截
|
||||||
const beforeRes = interceptorResponse(result);
|
return await beforeResponse(options, result);
|
||||||
if (beforeRes instanceof Promise) {
|
|
||||||
return await beforeRes;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
case 'blob': // 二进制数据则直接返回
|
case 'blob': // 二进制数据则直接返回
|
||||||
case 'arrayBuffer':
|
case 'arrayBuffer':
|
||||||
const contentType = res.headers.get('content-type') || '';
|
const contentType = res.headers.get('content-type') || '';
|
||||||
@@ -330,7 +359,7 @@ export async function request(options: OptionsType): Promise<ResultType> {
|
|||||||
return result as ResultType;
|
return result as ResultType;
|
||||||
}
|
}
|
||||||
const data =
|
const data =
|
||||||
options.responseType === 'blob'
|
reqOptions.responseType === 'blob'
|
||||||
? await res.blob()
|
? await res.blob()
|
||||||
: await res.arrayBuffer();
|
: await res.arrayBuffer();
|
||||||
return {
|
return {
|
||||||
@@ -356,41 +385,7 @@ export async function request(options: OptionsType): Promise<ResultType> {
|
|||||||
}
|
}
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timeoutId); // 请求成功,清除超时计时器
|
clearTimeout(timeoutId); // 清除超时计时器
|
||||||
|
timeoutId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断状态码处理结果信息(不可处理)
|
|
||||||
* @param res 请求结果
|
|
||||||
* @returns
|
|
||||||
*/
|
|
||||||
function stateCode(res: Response) {
|
|
||||||
// 网络异常
|
|
||||||
if (res.status === 500) {
|
|
||||||
return {
|
|
||||||
code: RESULT_CODE_ERROR,
|
|
||||||
msg: RESULT_MSG_SERVER_ERROR[language],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// 上传文件成功无内容返回
|
|
||||||
if (res.status === 204 || res.statusText === 'No Content') {
|
|
||||||
return {
|
|
||||||
code: RESULT_CODE_SUCCESS,
|
|
||||||
msg: RESULT_MSG_SUCCESS[language],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// 地址找不到
|
|
||||||
if (res.status === 404 || res.status === 405) {
|
|
||||||
return {
|
|
||||||
code: RESULT_CODE_ERROR,
|
|
||||||
msg: RESULT_MSG_URL_NOTFOUND[language],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// 身份授权
|
|
||||||
if (res.status === 401) {
|
|
||||||
removeToken();
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { sessionGet } from '@/utils/cache-session-utils';
|
import { sessionGet } from '@/utils/cache-session-utils';
|
||||||
import { getToken } from './auth-token';
|
import { getAccessToken } from './auth-token';
|
||||||
import { localGet } from '@/utils/cache-local-utils';
|
import { localGet } from '@/utils/cache-local-utils';
|
||||||
import { CACHE_LOCAL_I18N } from '@/constants/cache-keys-constants';
|
import { CACHE_LOCAL_I18N } from '@/constants/cache-keys-constants';
|
||||||
import { TOKEN_RESPONSE_FIELD } from '@/constants/token-constants';
|
import { TOKEN_RESPONSE_FIELD } from '@/constants/token-constants';
|
||||||
@@ -92,7 +92,7 @@ export class WS {
|
|||||||
// 地址栏参数
|
// 地址栏参数
|
||||||
let params = Object.assign({}, options.params, {
|
let params = Object.assign({}, options.params, {
|
||||||
// 设置 token
|
// 设置 token
|
||||||
[TOKEN_RESPONSE_FIELD]: getToken(),
|
[TOKEN_RESPONSE_FIELD]: getAccessToken(),
|
||||||
// 多语言
|
// 多语言
|
||||||
['language']: localGet(CACHE_LOCAL_I18N) || 'en_US',
|
['language']: localGet(CACHE_LOCAL_I18N) || 'en_US',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import NProgress from 'nprogress';
|
|||||||
import 'nprogress/nprogress.css';
|
import 'nprogress/nprogress.css';
|
||||||
import BasicLayout from '../layouts/BasicLayout.vue';
|
import BasicLayout from '../layouts/BasicLayout.vue';
|
||||||
import BlankLayout from '../layouts/BlankLayout.vue';
|
import BlankLayout from '../layouts/BlankLayout.vue';
|
||||||
import { getToken } from '@/plugins/auth-token';
|
import { getAccessToken } from '@/plugins/auth-token';
|
||||||
import { validHttp } from '@/utils/regular-utils';
|
import { validHttp } from '@/utils/regular-utils';
|
||||||
import useUserStore from '@/store/modules/user';
|
import useUserStore from '@/store/modules/user';
|
||||||
import useAppStore from '@/store/modules/app';
|
import useAppStore from '@/store/modules/app';
|
||||||
@@ -182,7 +182,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
next({ name: 'Index' });
|
next({ name: 'Index' });
|
||||||
}
|
}
|
||||||
|
|
||||||
let token = getToken();
|
let token = getAccessToken();
|
||||||
|
|
||||||
// 免用户登录认证
|
// 免用户登录认证
|
||||||
if (!appStore.loginAuth) {
|
if (!appStore.loginAuth) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
CACHE_SESSION_CRYPTO_API,
|
CACHE_SESSION_CRYPTO_API,
|
||||||
} from '@/constants/cache-keys-constants';
|
} from '@/constants/cache-keys-constants';
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { removeToken } from '@/plugins/auth-token';
|
import { delAccessToken, delRefreshToken } from '@/plugins/auth-token';
|
||||||
import { parseUrlPath } from '@/plugins/file-static-url';
|
import { parseUrlPath } from '@/plugins/file-static-url';
|
||||||
import { localGet, localSet } from '@/utils/cache-local-utils';
|
import { localGet, localSet } from '@/utils/cache-local-utils';
|
||||||
import { sessionSet } from '@/utils/cache-session-utils';
|
import { sessionSet } from '@/utils/cache-session-utils';
|
||||||
@@ -94,7 +94,8 @@ const useAppStore = defineStore('app', {
|
|||||||
this.bootloader = res.data.bootloader === 'true';
|
this.bootloader = res.data.bootloader === 'true';
|
||||||
// 引导时
|
// 引导时
|
||||||
if (this.bootloader) {
|
if (this.bootloader) {
|
||||||
removeToken();
|
delAccessToken();
|
||||||
|
delRefreshToken();
|
||||||
}
|
}
|
||||||
this.loginAuth = res.data.loginAuth !== 'false';
|
this.loginAuth = res.data.loginAuth !== 'false';
|
||||||
this.cryptoApi = res.data.cryptoApi !== 'false';
|
this.cryptoApi = res.data.cryptoApi !== 'false';
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const useNeInfoStore = defineStore('neinfo', {
|
|||||||
async fnNelist() {
|
async fnNelist() {
|
||||||
// 有数据不请求
|
// 有数据不请求
|
||||||
if (this.neList.length > 0) {
|
if (this.neList.length > 0) {
|
||||||
return { code: 1, data: this.neList, msg: 'success' };
|
return { code: RESULT_CODE_SUCCESS, data: this.neList, msg: 'success' };
|
||||||
}
|
}
|
||||||
const res = await listAllNeInfo({
|
const res = await listAllNeInfo({
|
||||||
bandStatus: false,
|
bandStatus: false,
|
||||||
@@ -79,7 +79,7 @@ const useNeInfoStore = defineStore('neinfo', {
|
|||||||
async fnNeTaskPerformance() {
|
async fnNeTaskPerformance() {
|
||||||
// 有数据不请求
|
// 有数据不请求
|
||||||
if (this.perMeasurementList.length > 0) {
|
if (this.perMeasurementList.length > 0) {
|
||||||
return { code: 1, data: this.perMeasurementList, msg: 'success' };
|
return { code: RESULT_CODE_SUCCESS, data: this.perMeasurementList, msg: 'success' };
|
||||||
}
|
}
|
||||||
const res = await getNePerformanceList();
|
const res = await getNePerformanceList();
|
||||||
if (res.code === RESULT_CODE_SUCCESS) {
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type {
|
|||||||
RouteMeta,
|
RouteMeta,
|
||||||
RouteRecordRaw,
|
RouteRecordRaw,
|
||||||
} from 'vue-router';
|
} from 'vue-router';
|
||||||
import { getRouters } from '@/api/router';
|
import { getRouter } from '@/api/auth';
|
||||||
import BasicLayout from '@/layouts/BasicLayout.vue';
|
import BasicLayout from '@/layouts/BasicLayout.vue';
|
||||||
import BlankLayout from '@/layouts/BlankLayout.vue';
|
import BlankLayout from '@/layouts/BlankLayout.vue';
|
||||||
import LinkLayout from '@/layouts/LinkLayout.vue';
|
import LinkLayout from '@/layouts/LinkLayout.vue';
|
||||||
@@ -46,7 +46,7 @@ const useRouterStore = defineStore('router', {
|
|||||||
* @returns 生成的路由菜单
|
* @returns 生成的路由菜单
|
||||||
*/
|
*/
|
||||||
async generateRoutes() {
|
async generateRoutes() {
|
||||||
const res = await getRouters();
|
const res = await getRouter();
|
||||||
if (res.code === RESULT_CODE_SUCCESS) {
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
const buildRoutes = buildRouters(res.data.concat());
|
const buildRoutes = buildRouters(res.data.concat());
|
||||||
this.buildRouterData = buildRoutes;
|
this.buildRouterData = buildRoutes;
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import defaultAvatar from '@/assets/images/default_avatar.png';
|
import defaultAvatar from '@/assets/images/default_avatar.png';
|
||||||
import useLayoutStore from './layout';
|
import useLayoutStore from './layout';
|
||||||
import { login, logout, getInfo } from '@/api/login';
|
import { login, logout, getInfo } from '@/api/auth';
|
||||||
import { setToken, removeToken } from '@/plugins/auth-token';
|
import {
|
||||||
|
delAccessToken,
|
||||||
|
delRefreshToken,
|
||||||
|
setAccessToken,
|
||||||
|
setRefreshToken,
|
||||||
|
} from '@/plugins/auth-token';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { TOKEN_RESPONSE_FIELD } from '@/constants/token-constants';
|
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { parseUrlPath } from '@/plugins/file-static-url';
|
import { parseUrlPath } from '@/plugins/file-static-url';
|
||||||
|
|
||||||
@@ -105,8 +109,8 @@ const useUserStore = defineStore('user', {
|
|||||||
async fnLogin(loginBody: Record<string, string>) {
|
async fnLogin(loginBody: Record<string, string>) {
|
||||||
const res = await login(loginBody);
|
const res = await login(loginBody);
|
||||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||||
const token = res.data[TOKEN_RESPONSE_FIELD];
|
setAccessToken(res.data.accessToken, res.data.refreshExpiresIn);
|
||||||
setToken(token);
|
setRefreshToken(res.data.refreshToken, res.data.refreshExpiresIn);
|
||||||
if (res.data?.forcePasswdChange) {
|
if (res.data?.forcePasswdChange) {
|
||||||
this.forcePasswdChange = true;
|
this.forcePasswdChange = true;
|
||||||
}
|
}
|
||||||
@@ -150,11 +154,6 @@ const useUserStore = defineStore('user', {
|
|||||||
this.forcePasswdChange = true;
|
this.forcePasswdChange = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 网络错误时退出登录状态
|
|
||||||
if (res.code === 0) {
|
|
||||||
removeToken();
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
// 退出系统
|
// 退出系统
|
||||||
@@ -166,7 +165,8 @@ const useUserStore = defineStore('user', {
|
|||||||
} finally {
|
} finally {
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.permissions = [];
|
this.permissions = [];
|
||||||
removeToken();
|
delAccessToken();
|
||||||
|
delRefreshToken();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ let tableColumns: ColumnsType = reactive([
|
|||||||
title: t('views.logManage.mml.logTime'),
|
title: t('views.logManage.mml.logTime'),
|
||||||
dataIndex: 'logTime',
|
dataIndex: 'logTime',
|
||||||
align: 'left',
|
align: 'left',
|
||||||
width: 150,
|
width: 200,
|
||||||
customRender(opt) {
|
customRender(opt) {
|
||||||
if (!opt.value) return '';
|
if (!opt.value) return '';
|
||||||
return parseDateToStr(opt.value);
|
return parseDateToStr(opt.value);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { message } from 'ant-design-vue/es';
|
|||||||
import { reactive, onMounted, computed, toRaw } from 'vue';
|
import { reactive, onMounted, computed, toRaw } from 'vue';
|
||||||
import useUserStore from '@/store/modules/user';
|
import useUserStore from '@/store/modules/user';
|
||||||
import useAppStore from '@/store/modules/app';
|
import useAppStore from '@/store/modules/app';
|
||||||
import { getCaptchaImage } from '@/api/login';
|
import { getCaptchaImage } from '@/api/auth';
|
||||||
import { useRouter, useRoute } from 'vue-router';
|
import { useRouter, useRoute } from 'vue-router';
|
||||||
import useI18n from '@/hooks/useI18n';
|
import useI18n from '@/hooks/useI18n';
|
||||||
import useLayoutStore from '@/store/modules/layout';
|
import useLayoutStore from '@/store/modules/layout';
|
||||||
@@ -75,21 +75,28 @@ function fnFinish() {
|
|||||||
function fnGetCaptcha() {
|
function fnGetCaptcha() {
|
||||||
if (state.captchaClick) return;
|
if (state.captchaClick) return;
|
||||||
state.captchaClick = true;
|
state.captchaClick = true;
|
||||||
getCaptchaImage().then(res => {
|
getCaptchaImage()
|
||||||
state.captchaClick = false;
|
.then(res => {
|
||||||
if (res.code != RESULT_CODE_SUCCESS) {
|
if (res.code !== RESULT_CODE_SUCCESS) {
|
||||||
message.warning(`${res.msg}`, 3);
|
message.warning({
|
||||||
return;
|
content: `${res.msg}`,
|
||||||
}
|
duration: 3,
|
||||||
state.captcha.enabled = Boolean(res.captchaEnabled);
|
});
|
||||||
if (state.captcha.enabled) {
|
return;
|
||||||
state.captcha.codeImg = res.img;
|
|
||||||
state.from.uuid = res.uuid;
|
|
||||||
if (res.text) {
|
|
||||||
state.from.code = res.text;
|
|
||||||
}
|
}
|
||||||
}
|
const { enabled, img, uuid } = res.data;
|
||||||
});
|
state.captcha.enabled = Boolean(enabled);
|
||||||
|
if (state.captcha.enabled) {
|
||||||
|
state.captcha.codeImg = img;
|
||||||
|
state.from.uuid = uuid;
|
||||||
|
}
|
||||||
|
if (res.data?.text) {
|
||||||
|
state.from.code = res.data.text;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
state.captchaClick = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否有背景地址
|
// 判断是否有背景地址
|
||||||
|
|||||||
@@ -910,6 +910,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
<!-- 状态历史框 -->
|
<!-- 状态历史框 -->
|
||||||
<HistoryModal
|
<HistoryModal
|
||||||
|
v-if="neTypeAndId.length > 1"
|
||||||
v-model:open="modalState.openByHistory"
|
v-model:open="modalState.openByHistory"
|
||||||
:title="t('views.neData.baseStation.history')"
|
:title="t('views.neData.baseStation.history')"
|
||||||
:ne-type="neTypeAndId[0]"
|
:ne-type="neTypeAndId[0]"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { GlobalFooter } from 'antdv-pro-layout';
|
import { GlobalFooter } from 'antdv-pro-layout';
|
||||||
import { Modal, message } from 'ant-design-vue/es';
|
import { Modal, message } from 'ant-design-vue/es';
|
||||||
import { computed, onMounted, reactive, toRaw } from 'vue';
|
import { computed, onMounted, reactive, toRaw } from 'vue';
|
||||||
import { register } from '@/api/login';
|
import { register } from '@/api/auth';
|
||||||
import { regExpPasswd, regExpUserName } from '@/utils/regular-utils';
|
import { regExpPasswd, regExpUserName } from '@/utils/regular-utils';
|
||||||
import { useRouter, useRoute } from 'vue-router';
|
import { useRouter, useRoute } from 'vue-router';
|
||||||
import useAppStore from '@/store/modules/app';
|
import useAppStore from '@/store/modules/app';
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { stepState, fnToStepName } from '../hooks/useStep';
|
import { stepState, fnToStepName } from '../hooks/useStep';
|
||||||
import { Modal } from 'ant-design-vue/es';
|
import { Modal } from 'ant-design-vue/es';
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { removeToken } from '@/plugins/auth-token';
|
import { delAccessToken, delRefreshToken } from '@/plugins/auth-token';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import useAppStore from '@/store/modules/app';
|
import useAppStore from '@/store/modules/app';
|
||||||
import useI18n from '@/hooks/useI18n';
|
import useI18n from '@/hooks/useI18n';
|
||||||
@@ -56,7 +56,8 @@ function fnGuideDone() {
|
|||||||
bootloaderDone()
|
bootloaderDone()
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS) {
|
if (res.code === RESULT_CODE_SUCCESS) {
|
||||||
removeToken();
|
delAccessToken();
|
||||||
|
delRefreshToken();
|
||||||
useAppStore().bootloader = false;
|
useAppStore().bootloader = false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,8 +2,7 @@
|
|||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
||||||
import { TOKEN_RESPONSE_FIELD } from '@/constants/token-constants';
|
import { getAccessToken, setAccessToken } from '@/plugins/auth-token';
|
||||||
import { getToken, setToken } from '@/plugins/auth-token';
|
|
||||||
import { bootloaderStart } from '@/api/system/quick-start/bootloader';
|
import { bootloaderStart } from '@/api/system/quick-start/bootloader';
|
||||||
import { fnToStepName } from '../hooks/useStep';
|
import { fnToStepName } from '../hooks/useStep';
|
||||||
import useI18n from '@/hooks/useI18n';
|
import useI18n from '@/hooks/useI18n';
|
||||||
@@ -19,11 +18,10 @@ function fnChangeLocale(e: any) {
|
|||||||
|
|
||||||
/**引导开始 */
|
/**引导开始 */
|
||||||
function fnGuideStart() {
|
function fnGuideStart() {
|
||||||
if (getToken()) return;
|
if (getAccessToken()) return;
|
||||||
bootloaderStart().then(res => {
|
bootloaderStart().then(res => {
|
||||||
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
if (res.code === RESULT_CODE_SUCCESS && res.data) {
|
||||||
const token = res.data[TOKEN_RESPONSE_FIELD];
|
setAccessToken(res.data.accessToken, res.data.refreshExpiresIn);
|
||||||
setToken(token);
|
|
||||||
} else {
|
} else {
|
||||||
router.push({ name: 'Login' });
|
router.push({ name: 'Login' });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user