diff --git a/src/pages/Footprint/index.tsx b/src/pages/Footprint/index.tsx index 986953e..8228af1 100644 --- a/src/pages/Footprint/index.tsx +++ b/src/pages/Footprint/index.tsx @@ -176,7 +176,7 @@ const FootprintPage = () => { const { data } = await axios.get('https://restapi.amap.com/v3/geocode/geo', { params: { address, - key: import.meta.env.VITE_GAODE_WEB_API // 替换为你的高德地图 API 密钥 + key: import.meta.env.VITE_GAODE_WEB_API } }); diff --git a/src/pages/Setup/components/Theme/index.tsx b/src/pages/Setup/components/Theme/index.tsx index ec5e56d..a01dd03 100644 --- a/src/pages/Setup/components/Theme/index.tsx +++ b/src/pages/Setup/components/Theme/index.tsx @@ -1,5 +1,5 @@ import { useState, useEffect } from 'react'; -import { notification, Divider, Input, Alert, Button, Spin } from 'antd'; +import { notification, Divider, Input, Alert, Button, Spin, Segmented, Form } from 'antd'; import { PictureOutlined, LoadingOutlined, CloudUploadOutlined } from '@ant-design/icons'; import { editConfigDataAPI, getConfigDataAPI } from '@/api/Project'; import { Theme } from '@/types/app/project'; @@ -7,18 +7,16 @@ import FileUpload from '@/components/FileUpload'; const ThemePage = () => { const [loading, setLoading] = useState(false); - const [isModalOpen, setIsModalOpen] = useState(false); - const [swiperText, setSwiperText] = useState(''); - const [social, setSocial] = useState(''); - const [cover, setCover] = useState(''); - const [recoArticle, setRecoArticle] = useState(''); const [theme, setTheme] = useState({} as Theme); + const [current, setCurrent] = useState("综合配置"); + + const [form] = Form.useForm(); const onSidebar = (value: string) => { const rightSidebar = JSON.parse(theme.right_sidebar || '[]'); const index = rightSidebar.indexOf(value); - index > -1 ? rightSidebar.splice(index, 1) : rightSidebar.push(value) + index > -1 ? rightSidebar.splice(index, 1) : rightSidebar.push(value); setTheme({ ...theme, right_sidebar: JSON.stringify(rightSidebar) }); }; @@ -26,13 +24,17 @@ const ThemePage = () => { setLoading(true); const { data } = await getConfigDataAPI("layout"); - setTheme(data); - setSwiperText(data.swiper_text ? JSON.parse(data.swiper_text).join('\n') : ''); - - setSocial(data.social); - setCover(data.covers ? JSON.parse(data.covers).join("\n") : ''); - setRecoArticle(data.reco_article ? JSON.parse(data.reco_article).join("\n") : ''); + + form.setFieldsValue({ + light_logo: data.light_logo, + dark_logo: data.dark_logo, + swiper_image: data.swiper_image, + swiper_text: data.swiper_text ? JSON.parse(data.swiper_text).join('\n') : '', + social: data.social, + covers: data.covers ? JSON.parse(data.covers).join("\n") : '', + reco_article: data.reco_article ? JSON.parse(data.reco_article).join("\n") : '', + }); setLoading(false); }; @@ -41,18 +43,19 @@ const ThemePage = () => { getLayoutData(); }, []); - const editLayoutData = async () => { + const editLayoutData = async (values: any) => { setLoading(true); const updatedLayout = { ...theme, - swiper_text: JSON.stringify(swiperText.split('\n')), - social, - covers: JSON.stringify(cover.split('\n')), - reco_article: JSON.stringify(recoArticle.split('\n')) + ...values, + swiper_text: JSON.stringify(values.swiper_text.split('\n')), + covers: JSON.stringify(values.covers.split('\n')), + reco_article: JSON.stringify(values.reco_article.split('\n')), }; await editConfigDataAPI("layout", updatedLayout); + notification.success({ message: '成功', description: '🎉 修改主题成功', @@ -61,143 +64,133 @@ const ThemePage = () => { setLoading(false); }; - // 动态渲染图片 const getFile = (name: string) => { - return new URL(`./image/${name}.png`, import.meta.url).href - } + return new URL(`./image/${name}.png`, import.meta.url).href; + }; - // 文件上传 const UploadBtn = () => ( setIsModalOpen(true)} /> - ) + ); return ( <> }>

主题配置

- + + size="large" + options={['综合配置', '说说配置']} + onChange={setCurrent} + className='md:ml-10 mb-4' + />
- 亮色主题 Logo -
- setTheme({ ...theme, light_logo: e.target.value })} - prefix={} - addonAfter={} - size='large' - placeholder="请输入亮色Logo地址" - className='customizeAntdInputAddonAfter' - /> - -
+ {current === "综合配置" && ( +
+ 亮色主题 Logo + + } + addonAfter={} + size='large' + placeholder="请输入亮色Logo地址" + /> + + - 暗色主题 Logo -
- setTheme({ ...theme, dark_logo: e.target.value })} - prefix={} - addonAfter={} - size='large' - placeholder="请输入暗色Logo地址" - className='customizeAntdInputAddonAfter' - /> - -
+ 暗色主题 Logo + + } + addonAfter={} + size='large' + placeholder="请输入暗色Logo地址" + /> + + - 首页背景图 -
- setTheme({ ...theme, swiper_image: e.target.value })} - prefix={} - addonAfter={} - size='large' - placeholder="请输入背景图地址" - className='customizeAntdInputAddonAfter' - /> - -
+ 首页背景图 + + } + addonAfter={} + size='large' + placeholder="请输入背景图地址" + /> + + - 打字机文本 -
- setSwiperText(e.target.value)} - autoSize={{ minRows: 2, maxRows: 4 }} - size='large' - placeholder="请输入打字机文本" - /> - -
+ 打字机文本 + + + + - 社交网站 -
- setSocial(e.target.value)} - autoSize={{ minRows: 2, maxRows: 4 }} - size='large' - placeholder="请输入社交网站" - /> - -
+ 社交网站 + + + + - 文章随机封面 -
- setCover(e.target.value)} - autoSize={{ minRows: 2, maxRows: 4 }} - size='large' - placeholder="请输入文章随机封面" - /> - -
+ 文章随机封面 + + + + - 作者推荐文章 -
- setRecoArticle(e.target.value)} - autoSize={{ minRows: 2, maxRows: 4 }} - size='large' - placeholder="请输入作者推荐文章ID" - /> - -
+ 作者推荐文章 + + + + - 侧边栏 -
-
- {['author', 'randomArticle', 'newComments', 'hotArticle'].map((item) => ( -
onSidebar(item)}> -

- {item === 'author' ? '作者信息模块' : item === 'hotArticle' ? '作者推荐模块' : item === 'randomArticle' ? '随机推荐模块' : '最新评论模块'} -

- - + 侧边栏 +
+
+ {['author', 'randomArticle', 'newComments', 'hotArticle'].map((item) => ( +
onSidebar(item)}> +

+ {item === 'author' ? '作者信息模块' : item === 'hotArticle' ? '作者推荐模块' : item === 'randomArticle' ? '随机推荐模块' : '最新评论模块'} +

+ +
+ ))}
- ))} -
-
+
- 文章布局 -
-
- {['classics', 'card', 'waterfall'].map((item) => ( -
setTheme({ ...theme, is_article_layout: item })} className={`item flex flex-col items-center p-4 m-4 border-2 rounded cursor-pointer ${theme.is_article_layout === item ? 'border-primary' : 'border-[#eee]'}`}> -

- {item === 'classics' ? '经典布局' : item === 'card' ? '卡片布局' : '瀑布流布局'} -

- - + 文章布局 +
+
+ {['classics', 'card', 'waterfall'].map((item) => ( +
setTheme({ ...theme, is_article_layout: item })} className={`item flex flex-col items-center p-4 m-4 border-2 rounded cursor-pointer ${theme.is_article_layout === item ? 'border-primary' : 'border-[#eee]'}`}> +

+ {item === 'classics' ? '经典布局' : item === 'card' ? '卡片布局' : '瀑布流布局'} +

+ +
+ ))}
- ))} -
-
+
- + + + )}
diff --git a/src/pages/Setup/index.tsx b/src/pages/Setup/index.tsx index e749cd1..e6d9d2a 100644 --- a/src/pages/Setup/index.tsx +++ b/src/pages/Setup/index.tsx @@ -39,7 +39,7 @@ const SetupPage = () => { title: "主题设置", description: "配置网站主题风格", icon: , - key: "layout" + key: "theme" }, { title: "个人设置", @@ -80,7 +80,7 @@ const SetupPage = () => {
{active === "system" && } {active === "web" && } - {active === "layout" && } + {active === "theme" && } {active === "my" && } {/* {active === "other" && } */}