备份:PWA配置前的完整版本
包含所有最新开发的功能和修复,作为PWA正确配置前的备份点。
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import apiClient from '../utils/request';
|
||||
import { useLanguageStore } from '../store/languageStore';
|
||||
|
||||
const UserManagement: React.FC = () => {
|
||||
const { t, currentLanguage } = useLanguageStore();
|
||||
const [users, setUsers] = useState<any[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// 从API获取用户数据
|
||||
const fetchUsers = async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
@@ -15,11 +16,11 @@ const UserManagement: React.FC = () => {
|
||||
if (response.data.success) {
|
||||
setUsers(response.data.data || []);
|
||||
} else {
|
||||
throw new Error('API返回失败: ' + (response.data.message || '未知错误'));
|
||||
throw new Error(t('userManagement.apiFailed') + (response.data.message || t('userManagement.unknownError')));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户列表失败:', error);
|
||||
setError(error instanceof Error ? error.message : '未知错误');
|
||||
setError(error instanceof Error ? error.message : t('userManagement.unknownError'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -31,23 +32,23 @@ const UserManagement: React.FC = () => {
|
||||
|
||||
return (
|
||||
<div style={{ padding: 24 }}>
|
||||
<h1>用户管理</h1>
|
||||
<p>这是一个测试页面,用于检查API调用是否正常。</p>
|
||||
<h1>{t('userManagement.title')}</h1>
|
||||
<p>{t('userManagement.testPage')}</p>
|
||||
<button onClick={fetchUsers} disabled={loading}>
|
||||
{loading ? '加载中...' : '刷新用户列表'}
|
||||
{loading ? t('common.loading') : t('userManagement.refreshList')}
|
||||
</button>
|
||||
{error && (
|
||||
<div style={{ marginTop: 10, color: 'red' }}>
|
||||
错误: {error}
|
||||
{t('userManagement.errorPrefix')}{error}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<h2>API返回的数据:</h2>
|
||||
<h2>{t('userManagement.apiResult')}</h2>
|
||||
<pre>{JSON.stringify(users, null, 2)}</pre>
|
||||
</div>
|
||||
<div style={{ marginTop: 20 }}>
|
||||
<h2>加载状态:</h2>
|
||||
<p>{loading ? '加载中...' : '加载完成'}</p>
|
||||
<h2>{t('userManagement.loadStatus')}</h2>
|
||||
<p>{loading ? t('common.loading') : t('userManagement.loadComplete')}</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user