From cc82642ba3f2ffd5a39ee351cfb63aa6da55afbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E7=A7=98=E4=BA=BA?= <3311118881@qq.com> Date: Fri, 11 Jul 2025 16:09:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20API=20=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=E7=BD=91=E7=AB=99?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=9A=84=E5=8F=82=E6=95=B0=E4=B8=BA=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8C=E5=B9=B6=E5=9C=A8=E5=A4=9A=E4=B8=AA=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E4=B8=AD=E8=B0=83=E6=95=B4=E6=95=B0=E6=8D=AE=E8=A7=A3?= =?UTF-8?q?=E6=9E=84=E6=96=B9=E5=BC=8F=EF=BC=8C=E6=8F=90=E5=8D=87=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/config.ts | 5 +++-- src/app/api/rss/route.ts | 2 +- src/app/friend/page.tsx | 2 +- src/app/layout.tsx | 2 +- src/app/page.tsx | 2 +- src/app/record/page.tsx | 2 +- src/components/ArticleLayout/Card/index.tsx | 2 +- src/components/ArticleLayout/Classics/index.tsx | 2 +- src/components/ArticleLayout/index.tsx | 2 +- src/components/Footer/index.tsx | 2 +- src/components/Header/index.tsx | 4 ++-- src/components/Sidebar/Author/index.tsx | 4 ++-- src/components/Sidebar/HotArticle/index.tsx | 2 +- src/components/Sidebar/index.tsx | 2 +- src/components/Slide/index.tsx | 3 ++- src/types/app/config.d.ts | 2 +- 16 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/api/config.ts b/src/api/config.ts index 8d48d32..354cb17 100755 --- a/src/api/config.ts +++ b/src/api/config.ts @@ -2,10 +2,11 @@ import Request from "@/utils/request"; import { Config } from "@/types/app/config"; // 获取网站配置 -export const getWebConfigDataAPI = (type: string) => Request("GET", `/web_config/list/${type}`) +export const getWebConfigDataAPI = (name: string) => Request("GET", `/web_config/name/${name}`) // 修改网站配置 -export const editWebConfigDataAPI = (type: string, data: object) => Request<{ [string: string]: string }>("PATCH", `/web_config/${type}`, { data }) +export const editWebConfigDataAPI = (name: string, data: object) => Request("PATCH", `/web_config/json/name/${name}`, { data }) + // 获取高德地图配置 export const getGaodeMapConfigDataAPI = () => Request("GET", `/env_config/gaode_map`) diff --git a/src/app/api/rss/route.ts b/src/app/api/rss/route.ts index 50dea9d..87ad895 100755 --- a/src/app/api/rss/route.ts +++ b/src/app/api/rss/route.ts @@ -12,7 +12,7 @@ import { getUserDataAPI } from '@/api/user' import { getRecordPagingAPI } from '@/api/record'; export async function GET() { - const { data: web } = await getWebConfigDataAPI("web") || { data: {} as Web } + const { data: { value: web } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } }; const { data: user } = await getUserDataAPI() || { data: {} as User } const { data: article } = await getArticlePagingAPI({ pagination: { page: 1, size: 8 } }) || { data: {} as Paginate } const { data: record } = await getRecordPagingAPI({ pagination: { page: 1, size: 8 } }) || { data: {} as Paginate } diff --git a/src/app/friend/page.tsx b/src/app/friend/page.tsx index 8f5ff67..8a9d675 100755 --- a/src/app/friend/page.tsx +++ b/src/app/friend/page.tsx @@ -22,7 +22,7 @@ export const metadata: Metadata = { export default async () => { const { data: user } = await getUserDataAPI() || { data: {} as User } - const { data: web } = await getWebConfigDataAPI("web") || { data: {} as Web } + const { data: { value: web } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } }; const { data: linkList } = await getWebListAPI() || { data: [] as WebLink[] } const { data: typeList } = await getWebTypeListAPI() || { data: [] as WebType[] } diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8fea2ae..a95ee82 100755 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -24,7 +24,7 @@ const LXGWWenKai = localFont({ }) export default async function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) { - const { data } = (await getWebConfigDataAPI("web")) || { data: {} as Web }; + const { data: { value: data } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } }; // 尊重开源,禁止删除此版权信息!!! console.log("🚀 欢迎使用 ThriveX 现代化博客管理系统") diff --git a/src/app/page.tsx b/src/app/page.tsx index 0f77cc8..b1a894f 100755 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -15,7 +15,7 @@ interface Props { export default async (props: Props) => { const searchParams = await props.searchParams; const page = searchParams.page || 1; - const { data } = (await getWebConfigDataAPI("layout")) || { data: {} as Theme } + const { data: { value: data } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; return ( <> diff --git a/src/app/record/page.tsx b/src/app/record/page.tsx index 02a19b0..7b8fed9 100755 --- a/src/app/record/page.tsx +++ b/src/app/record/page.tsx @@ -21,7 +21,7 @@ export default async (props: Props) => { const { data: user } = (await getUserDataAPI()) || { data: {} as User } const { data: record } = (await getRecordPagingAPI({ pagination: { page, size: 8 } })) || { data: {} as Paginate } - const { data: theme } = (await getWebConfigDataAPI("layout")) || { data: {} as Theme } + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; return ( <> diff --git a/src/components/ArticleLayout/Card/index.tsx b/src/components/ArticleLayout/Card/index.tsx index 65c432b..61e6593 100755 --- a/src/components/ArticleLayout/Card/index.tsx +++ b/src/components/ArticleLayout/Card/index.tsx @@ -17,7 +17,7 @@ interface CardProps { } const Card = async ({ data }: CardProps) => { - const { data: theme } = await getWebConfigDataAPI("layout") || { data: {} as Theme } + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; const covers = JSON.parse(theme.covers || '[]') diff --git a/src/components/ArticleLayout/Classics/index.tsx b/src/components/ArticleLayout/Classics/index.tsx index e3f13bd..1405bba 100755 --- a/src/components/ArticleLayout/Classics/index.tsx +++ b/src/components/ArticleLayout/Classics/index.tsx @@ -17,7 +17,7 @@ interface ClassicsProps { } const Classics = async ({ data }: ClassicsProps) => { - const { data: theme } = await getWebConfigDataAPI("layout") || { data: {} as Theme } + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; const covers = JSON.parse(theme.covers || '[]') diff --git a/src/components/ArticleLayout/index.tsx b/src/components/ArticleLayout/index.tsx index bdb13e8..207a321 100755 --- a/src/components/ArticleLayout/index.tsx +++ b/src/components/ArticleLayout/index.tsx @@ -14,7 +14,7 @@ import { getSwiperListAPI } from '@/api/swiper' export default async ({ page }: { page: number }) => { const { data: swiper } = await getSwiperListAPI() || { data: [] as SwiperType[] } - const { data: theme } = await getWebConfigDataAPI("layout") || { data: {} as Theme } + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; const sidebar: string[] = JSON.parse(theme?.right_sidebar || '[]') // 如果是瀑布流布局就显示28条数据,否则显示8条 diff --git a/src/components/Footer/index.tsx b/src/components/Footer/index.tsx index 1987bb3..c41b870 100755 --- a/src/components/Footer/index.tsx +++ b/src/components/Footer/index.tsx @@ -11,7 +11,7 @@ import ICP from './images/ICP.png'; export default async () => { const { data: user } = (await getUserDataAPI()) || { data: {} as User } - const { data: web } = (await getWebConfigDataAPI("web")) || { data: {} as Web } + const { data: { value: web } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } }; return ( <> diff --git a/src/components/Header/index.tsx b/src/components/Header/index.tsx index aa1744d..b1f9bd0 100755 --- a/src/components/Header/index.tsx +++ b/src/components/Header/index.tsx @@ -25,10 +25,10 @@ const Header = () => { // 获取项目配置 const getConfigData = async () => { - const { data: web } = (await getWebConfigDataAPI("web")) || { data: {} as Web }; + const { data: { value: web } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } }; setWeb(web) - const { data: theme } = (await getWebConfigDataAPI("layout")) || { data: {} as Theme }; + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; setTheme(theme) } diff --git a/src/components/Sidebar/Author/index.tsx b/src/components/Sidebar/Author/index.tsx index 3d3e129..dd0fbc2 100755 --- a/src/components/Sidebar/Author/index.tsx +++ b/src/components/Sidebar/Author/index.tsx @@ -16,9 +16,9 @@ import { Social, Theme } from '@/types/app/config'; const Author = async () => { const { data: user } = await getUserDataAPI() || { data: {} as User } - const { data: { social } } = await getWebConfigDataAPI("layout") || { data: {} as Theme } + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; - const socialList = JSON.parse(social || '[]')?.map((item: string) => JSON.parse(item)) + const socialList = theme?.social || [] // 图标列表 const images: { [string: string]: string } = { diff --git a/src/components/Sidebar/HotArticle/index.tsx b/src/components/Sidebar/HotArticle/index.tsx index b3fbd36..1f4f3bc 100755 --- a/src/components/Sidebar/HotArticle/index.tsx +++ b/src/components/Sidebar/HotArticle/index.tsx @@ -9,7 +9,7 @@ import { Theme } from '@/types/app/config'; import { Article } from '@/types/app/article'; const RandomArticle = async () => { - const { data: theme } = await getWebConfigDataAPI("layout") || { data: {} as Theme } + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; const { data: article } = await getArticleListAPI() || { data: [] as Article[] } const ids = JSON.parse(theme.reco_article ? theme.reco_article : '[]') diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index 9dc5550..e62ea05 100755 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -7,7 +7,7 @@ import { getWebConfigDataAPI } from '@/api/config' import { Theme } from "@/types/app/config" export default async () => { - const { data: theme } = await getWebConfigDataAPI("layout") || { data: {} as Theme } + const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; const sidebar: string[] = JSON.parse(theme?.right_sidebar || '[]') return ( diff --git a/src/components/Slide/index.tsx b/src/components/Slide/index.tsx index ee91907..be122f1 100755 --- a/src/components/Slide/index.tsx +++ b/src/components/Slide/index.tsx @@ -11,7 +11,8 @@ interface Props { } export default async ({ src, isRipple = true, children }: Props) => { - const { data } = await getWebConfigDataAPI("layout") || { data: {} as Theme } + const { data: { value: data } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } }; + const covers = JSON.parse(data.covers || '[]') const sty = { diff --git a/src/types/app/config.d.ts b/src/types/app/config.d.ts index b10894c..d58cad7 100755 --- a/src/types/app/config.d.ts +++ b/src/types/app/config.d.ts @@ -37,7 +37,7 @@ export interface Theme { swiper_image: string, swiper_text: string, reco_article: string, - social: string, + social: Social[], covers: string, record_name: string, record_info: string