ref : 重构令牌管理逻辑,,统一状态码识别

This commit is contained in:
TsMask
2025-04-27 17:23:33 +08:00
parent f76311cf1b
commit 2de9788373
23 changed files with 229 additions and 253 deletions

View File

@@ -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';
// 登录方法
/**
*
* @param data
* @returns
*/
export function login(data: Record<string, string>) {
return request({
url: '/login',
url: '/auth/login',
method: 'POST',
data: data,
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>) {
return request({
url: '/register',
url: '/auth/register',
method: 'POST',
data: data,
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
*/
export function logout() {
export const getRouter = () => {
return request({
url: '/logout',
method: 'POST',
repeatSubmit: false,
url: '/router',
method: 'GET',
});
}
};
/**
*

View File

@@ -1,65 +1,5 @@
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
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;
}
/**
* 获取服务器时间

View File

@@ -37,16 +37,3 @@ export function updateUserPassword(oldPassword: string, newPassword: string) {
data: { oldPassword, newPassword },
});
}
/**
* 用户强制重置密码
* @param password 密码
* @returns object
*/
export function updateUserPasswordForce(password: string) {
return request({
url: '/system/user/profile/password-force',
method: 'PUT',
data: { password },
});
}

View File

@@ -1,12 +0,0 @@
import { request } from '@/plugins/http-fetch';
/**
* 获取路由
* @returns object
*/
export const getRouters = () => {
return request({
url: '/router',
method: 'GET',
});
};

View File

@@ -136,3 +136,16 @@ export function changeUserStatus(
data: { userId, statusFlag },
});
}
/**
* 用户强制重置密码
* @param password 密码
* @returns object
*/
export function updateUserPasswordForce(password: string) {
return request({
url: '/system/user/profile/password-force',
method: 'PUT',
data: { password },
});
}