diff --git a/src/app/admin/page.tsx b/src/app/admin/page.tsx index a0fe34b..c3f25ec 100644 --- a/src/app/admin/page.tsx +++ b/src/app/admin/page.tsx @@ -5091,6 +5091,8 @@ const ThemeConfigComponent = ({ enableCache: true, cacheMinutes: 1440, // 默认1天(1440分钟) }); + const [loginBackgroundImages, setLoginBackgroundImages] = useState(['']); + const [registerBackgroundImages, setRegisterBackgroundImages] = useState(['']); useEffect(() => { if (config?.ThemeConfig) { @@ -5101,18 +5103,77 @@ const ThemeConfigComponent = ({ enableCache: config.ThemeConfig.enableCache !== false, cacheMinutes: config.ThemeConfig.cacheMinutes || 1440, }); + + // 解析背景图配置 + if (config.ThemeConfig.loginBackgroundImage) { + const urls = config.ThemeConfig.loginBackgroundImage + .split('\n') + .map((url) => url.trim()) + .filter((url) => url !== ''); + setLoginBackgroundImages(urls.length > 0 ? urls : ['']); + } else { + setLoginBackgroundImages(['']); + } + + if (config.ThemeConfig.registerBackgroundImage) { + const urls = config.ThemeConfig.registerBackgroundImage + .split('\n') + .map((url) => url.trim()) + .filter((url) => url !== ''); + setRegisterBackgroundImages(urls.length > 0 ? urls : ['']); + } else { + setRegisterBackgroundImages(['']); + } } }, [config]); const handleSave = async () => { await withLoading('saveThemeConfig', async () => { try { + // 验证登录背景图URL格式 + const validLoginUrls = loginBackgroundImages + .map((url) => url.trim()) + .filter((url) => url !== ''); + + for (const url of validLoginUrls) { + if (!url.startsWith('http://') && !url.startsWith('https://')) { + showAlert({ + type: 'error', + title: '格式错误', + message: `登录界面背景图URL格式错误:${url}\n每个URL必须以http://或https://开头`, + showConfirm: true, + }); + return; + } + } + + // 验证注册背景图URL格式 + const validRegisterUrls = registerBackgroundImages + .map((url) => url.trim()) + .filter((url) => url !== ''); + + for (const url of validRegisterUrls) { + if (!url.startsWith('http://') && !url.startsWith('https://')) { + showAlert({ + type: 'error', + title: '格式错误', + message: `注册界面背景图URL格式错误:${url}\n每个URL必须以http://或https://开头`, + showConfirm: true, + }); + return; + } + } + const response = await fetch('/api/admin/theme', { method: 'POST', headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify(themeSettings), + body: JSON.stringify({ + ...themeSettings, + loginBackgroundImage: validLoginUrls.join('\n'), + registerBackgroundImage: validRegisterUrls.join('\n'), + }), }); const data = await response.json(); @@ -5361,6 +5422,117 @@ const ThemeConfigComponent = ({

+ {/* 背景图配置 */} +
+

+ 背景图配置 +

+
+ {/* 登录界面背景图 */} +
+ +
+ {loginBackgroundImages.map((url, index) => ( +
+ { + const newImages = [...loginBackgroundImages]; + newImages[index] = e.target.value; + setLoginBackgroundImages(newImages); + }} + placeholder='请输入登录界面背景图URL (http:// 或 https://)' + className='flex-1 px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent font-mono text-sm' + /> + {loginBackgroundImages.length > 1 && ( + + )} +
+ ))} + +
+
+ + {/* 注册界面背景图 */} +
+ +
+ {registerBackgroundImages.map((url, index) => ( +
+ { + const newImages = [...registerBackgroundImages]; + newImages[index] = e.target.value; + setRegisterBackgroundImages(newImages); + }} + placeholder='请输入注册界面背景图URL (http:// 或 https://)' + className='flex-1 px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 focus:ring-2 focus:ring-blue-500 focus:border-transparent font-mono text-sm' + /> + {registerBackgroundImages.length > 1 && ( + + )} +
+ ))} + +
+
+
+

+ 配置登录和注册页面的背景图链接,留空则使用默认样式。支持配置多张图片,将随机展示其中一张 +

+
+ {/* 保存按钮 */}