console.log('=== 模型列表接口测试 ==='); // 获取 CSRF token(如果需要) function getCsrfToken() { const meta = document.querySelector('meta[name="csrf-token"]'); return meta ? meta.content : ''; } // 测试获取模型列表 async function testGetModels() { try { console.log('发送请求获取模型列表...'); const response = await fetch('/watershed/model/list?page=1&size=10', { method: 'GET', credentials: 'include', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem('token') || '' } }); console.log('响应状态:', response.status, response.statusText); if (response.ok) { const data = await response.json(); console.log('响应数据:', JSON.stringify(data, null, 2)); if (data.code === 200 && data.rows) { console.log('成功获取到模型列表'); console.log('模型数量:', data.rows.length); if (data.rows.length > 0) { const firstModel = data.rows[0]; console.log('第一个模型的所有字段:', Object.keys(firstModel)); if (firstModel.created_at) { console.log('✅ created_at 字段存在:', firstModel.created_at); } else if (firstModel.createTime) { console.log('✅ createTime 字段存在:', firstModel.createTime); } else { console.log('❌ 未找到创建时间字段'); } } } else { console.log('❌ 请求失败:', data.msg); } } else { console.log('❌ 请求失败:', response.status); } } catch (error) { console.error('❌ 请求异常:', error); } } // 获取当前用户信息 async function testUserInfo() { try { console.log('\n=== 获取当前用户信息 ==='); const response = await fetch('/getInfo', { method: 'GET', credentials: 'include', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' } }); const data = await response.json(); console.log('用户信息:', JSON.stringify(data, null, 2)); } catch (error) { console.error('获取用户信息失败:', error); } } // 执行测试 console.log('=== 开始测试 ==='); // 检查是否已登录 if (!localStorage.getItem('token')) { console.log('⚠️ 未检测到登录 token,请先登录'); // 尝试获取用户信息(可能会重定向到登录页) testUserInfo(); } else { console.log('✅ 已检测到登录 token'); testGetModels(); testUserInfo(); }