|
|
@@ -1,10 +1,97 @@
|
|
|
-import React from 'react';
|
|
|
+import React, { useState, useEffect } from 'react';
|
|
|
import { useAuth } from '../hooks/AuthProvider';
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
+import { userPreferenceClient } from '@/client/api';
|
|
|
+import { FontSizeType } from '@/server/modules/silver-users/user-preference.entity';
|
|
|
+import { App } from 'antd';
|
|
|
+
|
|
|
+const fontSizeOptions = [
|
|
|
+ { value: FontSizeType.SMALL, label: '小' },
|
|
|
+ { value: FontSizeType.MEDIUM, label: '中' },
|
|
|
+ { value: FontSizeType.LARGE, label: '大' },
|
|
|
+ { value: FontSizeType.EXTRA_LARGE, label: '超大' }
|
|
|
+];
|
|
|
|
|
|
const ProfilePage: React.FC = () => {
|
|
|
const { user, logout } = useAuth();
|
|
|
const navigate = useNavigate();
|
|
|
+ const { message } = App.useApp();
|
|
|
+ const [fontSize, setFontSize] = useState<FontSizeType>(FontSizeType.MEDIUM);
|
|
|
+ const [loading, setLoading] = useState(false);
|
|
|
+ const [preferenceId, setPreferenceId] = useState<number | null>(null);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (user) {
|
|
|
+ loadUserPreference();
|
|
|
+ }
|
|
|
+ }, [user]);
|
|
|
+
|
|
|
+ const loadUserPreference = async () => {
|
|
|
+ try {
|
|
|
+ const response = await (userPreferenceClient as any).$get({
|
|
|
+ query: { filters: JSON.stringify({ userId: user.id }) }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.status === 200) {
|
|
|
+ const data = await response.json();
|
|
|
+ if (data.data && data.data.length > 0) {
|
|
|
+ const preference = data.data[0];
|
|
|
+ setFontSize(preference.fontSize);
|
|
|
+ setPreferenceId(preference.id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载用户偏好设置失败:', error);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleFontSizeChange = async (size: FontSizeType) => {
|
|
|
+ if (!user) return;
|
|
|
+
|
|
|
+ setLoading(true);
|
|
|
+ try {
|
|
|
+ let response;
|
|
|
+
|
|
|
+ if (preferenceId) {
|
|
|
+ // 更新现有设置
|
|
|
+ response = await (userPreferenceClient as any)[preferenceId].$put({
|
|
|
+ json: { fontSize: size }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 创建新设置
|
|
|
+ response = await (userPreferenceClient as any).$post({
|
|
|
+ json: {
|
|
|
+ userId: user.id,
|
|
|
+ fontSize: size,
|
|
|
+ isDarkMode: 0
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (response.status === 200) {
|
|
|
+ const data = await response.json();
|
|
|
+ setFontSize(size);
|
|
|
+ setPreferenceId(data.id);
|
|
|
+ message.success('字体大小设置已更新');
|
|
|
+ updateDocumentFontSize(size);
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('更新字体大小失败:', error);
|
|
|
+ message.error('更新失败,请重试');
|
|
|
+ } finally {
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const updateDocumentFontSize = (size: FontSizeType) => {
|
|
|
+ const fontSizes: Record<FontSizeType, string> = {
|
|
|
+ [FontSizeType.SMALL]: '14px',
|
|
|
+ [FontSizeType.MEDIUM]: '16px',
|
|
|
+ [FontSizeType.LARGE]: '18px',
|
|
|
+ [FontSizeType.EXTRA_LARGE]: '20px'
|
|
|
+ };
|
|
|
+ document.documentElement.style.setProperty('--mobile-font-size', fontSizes[size]);
|
|
|
+ };
|
|
|
|
|
|
const handleLogout = () => {
|
|
|
logout();
|
|
|
@@ -42,6 +129,31 @@ const ProfilePage: React.FC = () => {
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
+ {/* 字体大小设置 */}
|
|
|
+ <div className="bg-white rounded-lg shadow p-6 mb-4">
|
|
|
+ <h3 className="text-lg font-semibold text-gray-900 mb-4">字体大小设置</h3>
|
|
|
+ <div className="space-y-2">
|
|
|
+ {fontSizeOptions.map((option) => (
|
|
|
+ <label
|
|
|
+ key={option.value}
|
|
|
+ className="flex items-center p-3 border rounded-lg cursor-pointer hover:bg-gray-50"
|
|
|
+ >
|
|
|
+ <input
|
|
|
+ type="radio"
|
|
|
+ name="fontSize"
|
|
|
+ value={option.value}
|
|
|
+ checked={fontSize === option.value}
|
|
|
+ onChange={() => handleFontSizeChange(option.value)}
|
|
|
+ disabled={loading}
|
|
|
+ className="mr-3"
|
|
|
+ />
|
|
|
+ <span className="text-gray-900">{option.label}</span>
|
|
|
+ <span className="ml-2 text-sm text-gray-600">示例文字</span>
|
|
|
+ </label>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
{/* 功能菜单 */}
|
|
|
<div className="bg-white rounded-lg shadow">
|
|
|
<div className="divide-y divide-gray-200">
|