feat: 1.修改提示词模板的不用角色的操作权限。

2. 对接数据看板的数据。
3. 添加入口模块管理的页面。
This commit is contained in:
2025-11-21 17:16:07 +08:00
parent 3850d05bdd
commit dab0835605
13 changed files with 1877 additions and 297 deletions
+56 -21
View File
@@ -12,7 +12,7 @@ export type ApiResponse<T> = {
headers?: Record<string, string>;
};
export type QueryParams = Record<string, string | number | boolean | undefined>;
export type QueryParams = Record<string, string | number | boolean | undefined | number[] | string[]>;
// 获取 API 基础 URL (从配置文件导入)
// const API_BASE_URL = 'http://172.16.0.58:8008';
@@ -52,6 +52,12 @@ const AUTH_WHITELIST = [
'/oauth/userinfo'
];
// 错误容忍白名单 - 这些接口即使返回 401/403 也不触发强制登出
const ERROR_TOLERANT_WHITELIST = [
'/admin/statistics/top-error-points',
'/admin/statistics/top-risk-users'
];
/**
* 检查请求URL是否在白名单中
*/
@@ -60,6 +66,14 @@ function isInAuthWhitelist(url?: string): boolean {
return AUTH_WHITELIST.some(path => url.includes(path));
}
/**
* 检查请求URL是否在错误容忍白名单中
*/
function isInErrorTolerantWhitelist(url?: string): boolean {
if (!url) return false;
return ERROR_TOLERANT_WHITELIST.some(path => url.includes(path));
}
/**
* 请求拦截器 - 自动添加 Authorization 头
*/
@@ -104,10 +118,18 @@ axiosInstance.interceptors.response.use(
},
(error) => {
if (isAxiosError(error) && error.response?.status === 401) {
// 检查是否在错误容忍白名单中
const requestUrl = error.config?.url;
if (isInErrorTolerantWhitelist(requestUrl)) {
console.warn('⚠️ [容错白名单] 接口返回 401,但不触发强制登出:', requestUrl);
// 直接返回错误,不触发登出
return Promise.reject(error);
}
// Token 过期或无效
console.warn('⚠️ Token 已过期或无效,请重新登录');
console.warn('⚠️ 401 错误详情:', {
url: error.config?.url,
url: requestUrl,
status: error.response?.status,
statusText: error.response?.statusText,
data: error.response?.data,
@@ -208,7 +230,12 @@ function buildUrl(endpoint: string, params?: QueryParams): string {
if (params) {
Object.entries(params).forEach(([key, value]) => {
if (value !== undefined) {
url.searchParams.append(key, String(value));
// 处理数组参数:使用逗号分隔
if (Array.isArray(value)) {
url.searchParams.append(key, value.join(','));
} else {
url.searchParams.append(key, String(value));
}
}
});
}
@@ -292,16 +319,19 @@ export async function apiRequest<T>(
try {
// 构建 URL
const url = buildUrl(endpoint, params);
// 设置默认请求头
const headers = options.headers || {};
if (!headers['Content-Type'] && options.method !== 'GET') {
headers['Content-Type'] = 'application/json';
// 只有在 options.headers 存在时才处理,否则让拦截器处理
let headers = options.headers;
if (headers) {
// 设置默认请求头(仅当 headers 已存在时)
if (!headers['Content-Type'] && options.method !== 'GET') {
headers['Content-Type'] = 'application/json';
}
if (!headers['Accept']) {
headers['Accept'] = 'application/json';
}
}
if (!headers['Accept']) {
headers['Accept'] = 'application/json';
}
// 针对 PostgREST 的额外处理
if (endpoint.includes('evaluation_point_groups') && (options.method === 'POST' || options.method === 'PATCH')) {
// console.log('使用 PostgREST 特定配置处理请求');
@@ -315,10 +345,10 @@ export async function apiRequest<T>(
}
}
}
// console.log(`📦 axios-client.ts->请求URL: ${url}`);
// console.log(`axios-client.ts->发送 ${options.method || 'GET'} 请求到: ${url}`);
// 处理body参数,转换为data
if (options.body) {
// console.log(`axios-client.ts->请求体: \n${options.body}`);
@@ -327,20 +357,25 @@ export async function apiRequest<T>(
// console.log(`axios-client.ts->请求体: \n${typeof options.data === 'string' ? options.data : JSON.stringify(options.data)}`);
}
// 发送请求
// 构建请求配置
// 如果没有传入 headers,就不设置 headers,让拦截器自动添加
const config: AxiosRequestConfig = {
...options,
url,
headers,
// 确保使用默认超时时间
timeout: options.timeout || DEFAULT_TIMEOUT
};
// 🔍 调试:打印 Authorization 头
if (headers['Authorization']) {
// console.log('🔑 [apiRequest] 请求包含 Authorization 头:', headers['Authorization'].substring(0, 20) + '...');
} else {
console.warn('⚠️ [apiRequest] 请求缺少 Authorization 头!headers:', Object.keys(headers));
// 只有在 headers 存在时才设置
if (headers) {
config.headers = headers;
// 🔍 调试:打印 Authorization 头
if (headers['Authorization']) {
// console.log('🔑 [apiRequest] 请求包含 Authorization 头:', headers['Authorization'].substring(0, 20) + '...');
} else {
console.warn('⚠️ [apiRequest] 请求缺少 Authorization 头!headers:', Object.keys(headers));
}
}
// console.log(`📦 axios-client.ts->请求配置: \n${JSON.stringify(config)}`);