fix: 修复 MSW 接口和调试代码清理...

This commit is contained in:
zdl
2025-11-06 01:17:06 +08:00
parent ad933e9fb2
commit c5d6247f49
4 changed files with 27 additions and 23 deletions

View File

@@ -19,20 +19,6 @@ import { logger } from '../utils/logger';
* @param {'sm' | 'md'} props.size - 标签尺寸
*/
const SubscriptionBadge = ({ tier = 'pro', size = 'sm' }) => {
// 🔍 调试SubscriptionBadge 被渲染(强制输出)
console.error('🔴 [DEBUG] SubscriptionBadge 组件被渲染 - 这不应该出现max 会员)', {
tier,
size,
调用位置: new Error().stack
});
// 🔍 调试SubscriptionBadge 被渲染logger
logger.debug('SubscriptionBadge', '组件被渲染', {
tier,
size,
调用栈: new Error().stack
});
// PRO 和 MAX 配置
const config = {
pro: {

View File

@@ -31,11 +31,11 @@ export async function startMockServiceWorker() {
try {
await worker.start({
// 🎯 严格模式(关键配置)
// 🎯 警告模式(关键配置)
// 'bypass': 未定义 Mock 的请求自动转发到真实后端
// 'warn': 未定义的请求会显示警告(调试用)
// 'error': 未定义的请求会抛出错误(严格模式)✅ 当前使用 穿透模式 bypass
onUnhandledRequest: 'error',
// 'warn': 未定义的请求会显示警告(调试用)✅ 当前使用(允许 passthrough
// 'error': 未定义的请求会抛出错误(严格模式,不允许 passthrough
onUnhandledRequest: 'warn',
// 自定义 Service Worker URL如果需要
serviceWorker: {
@@ -48,11 +48,11 @@ export async function startMockServiceWorker() {
isStarted = true;
console.log(
'%c[MSW] Mock Service Worker 已启动 🎭 严格模式)',
'%c[MSW] Mock Service Worker 已启动 🎭 警告模式)',
'color: #4CAF50; font-weight: bold; font-size: 14px;'
);
console.log(
'%c严格模式:已定义 Mock → 返回假数据 | 未定义 Mock → 控制台报错 ❌',
'%c警告模式:已定义 Mock → 返回假数据 | 未定义 Mock → 显示警告 ⚠️ | 允许 passthrough',
'color: #FF9800; font-weight: bold; font-size: 12px;'
);
console.log(

View File

@@ -928,13 +928,16 @@ export function generateMockEvents(params = {}) {
const end = start + per_page;
const paginatedEvents = filteredEvents.slice(start, end);
const totalPages = Math.ceil(filteredEvents.length / per_page);
return {
events: paginatedEvents,
pagination: {
page: page,
per_page: per_page,
total: filteredEvents.length,
total_pages: Math.ceil(filteredEvents.length / per_page),
pages: totalPages, // ← 对齐后端字段名 (was: total_pages)
has_prev: page > 1, // ← 对齐后端:是否有上一页
has_next: page < totalPages // ← 对齐后端:是否有下一页
},
};
}

View File

@@ -13,7 +13,7 @@ export const eventHandlers = [
// ==================== 事件列表相关 ====================
// 获取事件列表
http.get('/api/events/', async ({ request }) => {
http.get('/api/events', async ({ request }) => {
await delay(500);
const url = new URL(request.url);
@@ -41,11 +41,26 @@ export const eventHandlers = [
});
} catch (error) {
console.error('[Mock] 获取事件列表失败:', error);
console.error('[Mock] Error details:', {
message: error.message,
stack: error.stack,
params: params
});
return HttpResponse.json(
{
success: false,
error: '获取事件列表失败',
data: { events: [], pagination: {} }
data: {
events: [],
pagination: {
page: 1,
per_page: 10,
total: 0,
pages: 0, // ← 对齐后端字段名
has_prev: false, // ← 对齐后端
has_next: false // ← 对齐后端
}
}
},
{ status: 500 }
);