mirror of
https://github.com/LiuYuYang01/ThriveX-Blog.git
synced 2026-06-02 10:50:07 +08:00
更新 API 接口,修改获取网站配置的参数为名称,并在多个组件中调整数据解构方式,提升代码可读性和一致性。
This commit is contained in:
@@ -2,10 +2,11 @@ import Request from "@/utils/request";
|
||||
import { Config } from "@/types/app/config";
|
||||
|
||||
// 获取网站配置
|
||||
export const getWebConfigDataAPI = <T>(type: string) => Request<T>("GET", `/web_config/list/${type}`)
|
||||
export const getWebConfigDataAPI = <T>(name: string) => Request<T>("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<Config>("PATCH", `/web_config/json/name/${name}`, { data })
|
||||
|
||||
|
||||
// 获取高德地图配置
|
||||
export const getGaodeMapConfigDataAPI = () => Request("GET", `/env_config/gaode_map`)
|
||||
|
||||
@@ -12,7 +12,7 @@ import { getUserDataAPI } from '@/api/user'
|
||||
import { getRecordPagingAPI } from '@/api/record';
|
||||
|
||||
export async function GET() {
|
||||
const { data: web } = await getWebConfigDataAPI<Web>("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<Article[]> }
|
||||
const { data: record } = await getRecordPagingAPI({ pagination: { page: 1, size: 8 } }) || { data: {} as Paginate<Record[]> }
|
||||
|
||||
@@ -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>("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[] }
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ const LXGWWenKai = localFont({
|
||||
})
|
||||
|
||||
export default async function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) {
|
||||
const { data } = (await getWebConfigDataAPI<Web>("web")) || { data: {} as Web };
|
||||
const { data: { value: data } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } };
|
||||
|
||||
// 尊重开源,禁止删除此版权信息!!!
|
||||
console.log("🚀 欢迎使用 ThriveX 现代化博客管理系统")
|
||||
|
||||
@@ -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<Theme>("layout")) || { data: {} as Theme }
|
||||
const { data: { value: data } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } };
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -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<Record[]> }
|
||||
const { data: theme } = (await getWebConfigDataAPI<Theme>("layout")) || { data: {} as Theme }
|
||||
const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } };
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -17,7 +17,7 @@ interface CardProps {
|
||||
}
|
||||
|
||||
const Card = async ({ data }: CardProps) => {
|
||||
const { data: theme } = await getWebConfigDataAPI<Theme>("layout") || { data: {} as Theme }
|
||||
const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } };
|
||||
|
||||
const covers = JSON.parse(theme.covers || '[]')
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ interface ClassicsProps {
|
||||
}
|
||||
|
||||
const Classics = async ({ data }: ClassicsProps) => {
|
||||
const { data: theme } = await getWebConfigDataAPI<Theme>("layout") || { data: {} as Theme }
|
||||
const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } };
|
||||
|
||||
const covers = JSON.parse(theme.covers || '[]')
|
||||
|
||||
|
||||
@@ -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<Theme>("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条
|
||||
|
||||
@@ -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>("web")) || { data: {} as Web }
|
||||
const { data: { value: web } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } };
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -25,10 +25,10 @@ const Header = () => {
|
||||
|
||||
// 获取项目配置
|
||||
const getConfigData = async () => {
|
||||
const { data: web } = (await getWebConfigDataAPI<Web>("web")) || { data: {} as Web };
|
||||
const { data: { value: web } } = (await getWebConfigDataAPI<{ value: Web }>("web")) || { data: { value: {} as Web } };
|
||||
setWeb(web)
|
||||
|
||||
const { data: theme } = (await getWebConfigDataAPI<Theme>("layout")) || { data: {} as Theme };
|
||||
const { data: { value: theme } } = (await getWebConfigDataAPI<{ value: Theme }>("layout")) || { data: { value: {} as Theme } };
|
||||
setTheme(theme)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Theme>("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 } = {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Theme } from '@/types/app/config';
|
||||
import { Article } from '@/types/app/article';
|
||||
|
||||
const RandomArticle = async () => {
|
||||
const { data: theme } = await getWebConfigDataAPI<Theme>("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 : '[]')
|
||||
|
||||
@@ -7,7 +7,7 @@ import { getWebConfigDataAPI } from '@/api/config'
|
||||
import { Theme } from "@/types/app/config"
|
||||
|
||||
export default async () => {
|
||||
const { data: theme } = await getWebConfigDataAPI<Theme>("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 (
|
||||
|
||||
@@ -11,7 +11,8 @@ interface Props {
|
||||
}
|
||||
|
||||
export default async ({ src, isRipple = true, children }: Props) => {
|
||||
const { data } = await getWebConfigDataAPI<Theme>("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 = {
|
||||
|
||||
2
src/types/app/config.d.ts
vendored
2
src/types/app/config.d.ts
vendored
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user