Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
+216
View File
@@ -0,0 +1,216 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>图像生成功能诊断测试</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
}
.test-section {
margin: 20px 0;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}
.test-section h3 {
margin-top: 0;
color: #333;
}
button {
padding: 10px 20px;
margin: 5px;
cursor: pointer;
background: #4caf50;
color: white;
border: none;
border-radius: 4px;
font-size: 14px;
}
button:hover {
background: #45a049;
}
.result {
margin-top: 10px;
padding: 10px;
background: #f5f5f5;
border-radius: 4px;
font-family: monospace;
white-space: pre-wrap;
}
.error {
color: red;
}
.success {
color: green;
}
</style>
</head>
<body>
<h1>图像生成功能诊断测试</h1>
<div class="test-section">
<h3>测试1: 检查后端连接</h3>
<button onclick="testBackendConnection()">测试后端连接</button>
<div id="backend-result" class="result"></div>
</div>
<div class="test-section">
<h3>测试2: 测试API调用</h3>
<button onclick="testApiCall()">测试创建图像任务</button>
<div id="api-result" class="result"></div>
</div>
<div class="test-section">
<h3>测试3: 检查认证状态</h3>
<button onclick="testAuth()">检查用户认证</button>
<div id="auth-result" class="result"></div>
</div>
<div class="test-section">
<h3>测试4: 获取任务列表</h3>
<button onclick="testGetTasks()">获取任务列表</button>
<div id="tasks-result" class="result"></div>
</div>
<script>
// 获取token(从localStorage或cookie)
function getToken() {
return localStorage.getItem('token') || '';
}
// 测试后端连接
async function testBackendConnection() {
const resultDiv = document.getElementById('backend-result');
resultDiv.innerHTML = '正在测试...';
try {
const response = await fetch('/api/status', {
method: 'GET',
headers: {
Authorization: 'Bearer ' + getToken(),
},
});
const data = await response.json();
resultDiv.innerHTML = `<span class="success">✓ 后端连接成功</span>\n${JSON.stringify(data, null, 2)}`;
} catch (error) {
resultDiv.innerHTML = `<span class="error">✗ 后端连接失败</span>\n${error.message}`;
}
}
// 测试API调用
async function testApiCall() {
const resultDiv = document.getElementById('api-result');
resultDiv.innerHTML = '正在测试...';
const requestData = {
prompt: '测试图片生成:一只可爱的小猫',
model: 'wanx2.2-t2i-flash',
n: 1,
size: '1024x1024',
quality: 'standard',
response_format: 'url',
};
console.log('发送请求:', requestData);
try {
const response = await fetch('/api/images/generations', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + getToken(),
},
body: JSON.stringify(requestData),
});
console.log('响应状态:', response.status);
const data = await response.json();
console.log('响应数据:', data);
if (response.ok) {
resultDiv.innerHTML = `<span class="success">✓ 任务创建成功</span>\n${JSON.stringify(data, null, 2)}`;
} else {
resultDiv.innerHTML = `<span class="error">✗ 任务创建失败</span>\nHTTP ${response.status}\n${JSON.stringify(data, null, 2)}`;
}
} catch (error) {
console.error('请求失败:', error);
resultDiv.innerHTML = `<span class="error">✗ 请求失败</span>\n${error.message}\n${error.stack}`;
}
}
// 测试认证
async function testAuth() {
const resultDiv = document.getElementById('auth-result');
const token = getToken();
if (!token) {
resultDiv.innerHTML =
'<span class="error">✗ 未找到token,请先登录</span>';
return;
}
resultDiv.innerHTML = '正在验证...';
try {
const response = await fetch('/api/user/self', {
method: 'GET',
headers: {
Authorization: 'Bearer ' + token,
},
});
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = `<span class="success">✓ 认证成功</span>\n用户: ${data.data?.username || 'N/A'}\nToken: ${token.substring(0, 20)}...`;
} else {
resultDiv.innerHTML = `<span class="error">✗ 认证失败</span>\n${JSON.stringify(data, null, 2)}`;
}
} catch (error) {
resultDiv.innerHTML = `<span class="error">✗ 请求失败</span>\n${error.message}`;
}
}
// 获取任务列表
async function testGetTasks() {
const resultDiv = document.getElementById('tasks-result');
resultDiv.innerHTML = '正在获取...';
try {
const response = await fetch(
'/api/images/tasks?page=1&page_size=20',
{
method: 'GET',
headers: {
Authorization: 'Bearer ' + getToken(),
},
},
);
const data = await response.json();
if (response.ok) {
const taskCount = data.data?.items?.length || 0;
resultDiv.innerHTML = `<span class="success">✓ 获取成功,共 ${taskCount} 个任务</span>\n${JSON.stringify(data, null, 2)}`;
} else {
resultDiv.innerHTML = `<span class="error">✗ 获取失败</span>\n${JSON.stringify(data, null, 2)}`;
}
} catch (error) {
resultDiv.innerHTML = `<span class="error">✗ 请求失败</span>\n${error.message}`;
}
}
// 页面加载时自动检测
window.onload = function () {
console.log('=== 诊断页面已加载 ===');
console.log('Token:', getToken() ? '已找到' : '未找到');
console.log('当前URL:', window.location.href);
};
</script>
</body>
</html>