备份:修复前完整项目快照 2026-04-19

This commit is contained in:
root
2026-04-19 19:15:01 +08:00
parent 5266d7732b
commit d00f41a120
449 changed files with 89577 additions and 23251 deletions
+63
View File
@@ -0,0 +1,63 @@
import React, { useState, useEffect } from 'react';
import apiClient from '../utils/request';
const UserManagement: React.FC = () => {
console.log('UserManagement组件被渲染');
const [users, setUsers] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
// 从API获取用户数据
const fetchUsers = async () => {
console.log('开始获取用户列表...');
setLoading(true);
setError(null);
try {
console.log('发起API请求...');
const response = await apiClient.get('/api/users');
console.log('响应状态:', response.status);
console.log('API返回数据:', response.data);
if (response.data.success) {
setUsers(response.data.data || []);
console.log('用户列表更新成功:', response.data.data || []);
} else {
throw new Error('API返回失败: ' + (response.data.message || '未知错误'));
}
} catch (error) {
console.error('获取用户列表失败:', error);
setError(error instanceof Error ? error.message : '未知错误');
} finally {
setLoading(false);
}
};
useEffect(() => {
console.log('组件挂载,开始获取用户列表...');
fetchUsers();
}, []);
return (
<div style={{ padding: 24 }}>
<h1></h1>
<p>API调用是否正常</p>
<button onClick={fetchUsers} disabled={loading}>
{loading ? '加载中...' : '刷新用户列表'}
</button>
{error && (
<div style={{ marginTop: 10, color: 'red' }}>
: {error}
</div>
)}
<div style={{ marginTop: 20 }}>
<h2>API返回的数据:</h2>
<pre>{JSON.stringify(users, null, 2)}</pre>
</div>
<div style={{ marginTop: 20 }}>
<h2>:</h2>
<p>{loading ? '加载中...' : '加载完成'}</p>
</div>
</div>
);
};
export default UserManagement;