diff --git a/src/pages/Setup/components/Layout/image/author.png b/src/pages/Setup/components/Layout/image/author.png new file mode 100644 index 0000000..2f55e55 Binary files /dev/null and b/src/pages/Setup/components/Layout/image/author.png differ diff --git a/src/pages/Setup/components/Layout/image/card.png b/src/pages/Setup/components/Layout/image/card.png new file mode 100644 index 0000000..9ebf61c Binary files /dev/null and b/src/pages/Setup/components/Layout/image/card.png differ diff --git a/src/pages/Setup/components/Layout/image/classics.png b/src/pages/Setup/components/Layout/image/classics.png new file mode 100644 index 0000000..fad6b18 Binary files /dev/null and b/src/pages/Setup/components/Layout/image/classics.png differ diff --git a/src/pages/Setup/components/Layout/image/hotArticle.png b/src/pages/Setup/components/Layout/image/hotArticle.png new file mode 100644 index 0000000..05714ad Binary files /dev/null and b/src/pages/Setup/components/Layout/image/hotArticle.png differ diff --git a/src/pages/Setup/components/Layout/image/newComments.png b/src/pages/Setup/components/Layout/image/newComments.png new file mode 100644 index 0000000..4876cbb Binary files /dev/null and b/src/pages/Setup/components/Layout/image/newComments.png differ diff --git a/src/pages/Setup/components/Layout/image/randomArticle.png b/src/pages/Setup/components/Layout/image/randomArticle.png new file mode 100644 index 0000000..a5558c6 Binary files /dev/null and b/src/pages/Setup/components/Layout/image/randomArticle.png differ diff --git a/src/pages/Setup/components/Layout/image/waterfall.png b/src/pages/Setup/components/Layout/image/waterfall.png new file mode 100644 index 0000000..35a80ef Binary files /dev/null and b/src/pages/Setup/components/Layout/image/waterfall.png differ diff --git a/src/pages/Setup/components/Layout/index.tsx b/src/pages/Setup/components/Layout/index.tsx index e69de29..533c63f 100644 --- a/src/pages/Setup/components/Layout/index.tsx +++ b/src/pages/Setup/components/Layout/index.tsx @@ -0,0 +1,136 @@ +import { useState, useEffect } from 'react'; +import { notification, Divider, Input, Alert, Button, Spin } from 'antd'; +import { PictureOutlined, LoadingOutlined } from '@ant-design/icons'; +import { editLayoutDataAPI, getLayoutDataAPI } from '@/api/System'; +import 'tailwindcss/tailwind.css'; + +interface Layout { + isArticleLayout: string; + rightSidebar: string[]; + swiperImage: string; + swiperText: string[]; +} + + +const list = [ + +] + +const LayoutPage = () => { + const [loading, setLoading] = useState(false); + const [tempSwiperText, setTempSwiperText] = useState(''); + const [layout, setLayout] = useState({ + isArticleLayout: 'classics', + rightSidebar: ['author', 'hotArticle', 'randomArticle', 'newComments'], + swiperImage: 'https://bu.dusays.com/2023/11/10/654e2cf6055b0.jpg', + swiperText: ['这是一段文本', '这是第二段文本'], + }); + + const onSidebar = (select: string) => { + setLayout((prevLayout) => { + const is = prevLayout.rightSidebar.includes(select); + const newRightSidebar = is + ? prevLayout.rightSidebar.filter((item) => item !== select) + : [...prevLayout.rightSidebar, select]; + + return { ...prevLayout, rightSidebar: newRightSidebar }; + }); + }; + + const getLayoutData = async () => { + setLoading(true); + const { data } = await getLayoutDataAPI(); + setLayout(data); + setTempSwiperText(data.swiperText.join('\n')); + setLoading(false); + }; + + // useEffect(() => { + // getLayoutData(); + // }, []); + + const editLayoutData = async () => { + setLoading(true); + const updatedLayout = { ...layout, swiperText: tempSwiperText.split('\n') }; + await editLayoutDataAPI(updatedLayout); + notification.success({ + message: '成功', + description: '🎉修改布局成功', + }); + setLoading(false); + }; + + // 动态渲染图片 + const getFile = (name: string) => { + return new URL(`./image/${name}.png`, import.meta.url).href + } + + return ( +
+ }> +

布局配置

+ + 首页背景图 +
+ setLayout({ ...layout, swiperImage: e.target.value })} + placeholder="请输入背景图地址" + prefix={} + /> + +
+ + 打字机文本 +
+ setTempSwiperText(e.target.value)} + autoSize={{ minRows: 2, maxRows: 4 }} + /> + +
+ + 侧边栏 +
+ {['author', 'hotArticle', 'randomArticle', 'newComments'].map((item) => ( +
onSidebar(item)} + > + + +

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

+
+ ))} +
+ + 文章布局 +
+ {['classics', 'card', 'waterfall'].map((item) => ( +
setLayout({ ...layout, isArticleLayout: item })} + > + +

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

+
+ ))} +
+ + +
+
+ ); +}; + +export default LayoutPage; diff --git a/src/pages/Setup/index.tsx b/src/pages/Setup/index.tsx index ab326a0..017c081 100644 --- a/src/pages/Setup/index.tsx +++ b/src/pages/Setup/index.tsx @@ -4,7 +4,7 @@ import Title from '@/components/Title'; import { BiGlobe, BiLayout, BiShieldQuarter, BiUser } from 'react-icons/bi'; import System from './components/System' import Web from './components/Web' -import Web from './components/Web' +import Layout from './components/Layout' import "./index.scss" interface Setup { @@ -51,7 +51,7 @@ const SetupPage = () => {
-
    +
      {list.map((item) => (
    • { ))}
    -
    +
    {active === "system" && } {active === "web" && } - {/* {active === "layout" && } - {active === "my" && } */} + {active === "layout" && } + {/* {active === "my" && } */}