Просмотр исходного кода

修改变量名 IAnthologyListApiResponse

visuddhinanda 3 лет назад
Родитель
Сommit
b470a035b9

+ 8 - 6
dashboard/src/components/api/Article.ts

@@ -6,8 +6,8 @@ export interface IArticleListApiResponse {
 	level: string;
 	children: number;
 }
-//'uid','title','subtitle','article_list','owner','lang','updated_at','created_at'
-export interface IAnthologyListApiResponse {
+
+export interface IAnthologyDataResponse {
 	uid: string;
 	title: string;
 	subtitle: string;
@@ -15,19 +15,21 @@ export interface IAnthologyListApiResponse {
 	article_list: IArticleListApiResponse[];
 	studio: IStudioApiResponse;
 	lang: string;
+	status: number;
+	childrenNumber: number;
 	created_at: string;
 	updated_at: string;
 }
-export interface IAnthologyListApiResponse2 {
+export interface IAnthologyResponse {
 	ok: boolean;
 	message: string;
-	data: IAnthologyListApiResponse;
+	data: IAnthologyDataResponse;
 }
-export interface IAnthologyListApiResponse3 {
+export interface IAnthologyListResponse {
 	ok: boolean;
 	message: string;
 	data: {
-		rows: IAnthologyListApiResponse[];
+		rows: IAnthologyDataResponse[];
 		count: number;
 	};
 }

+ 4 - 6
dashboard/src/components/article/AnthologyDetail.tsx

@@ -3,8 +3,8 @@ import { Typography } from "antd";
 
 import type { IAnthologyData } from "./AnthologyCard";
 import type {
-	IAnthologyListApiResponse,
-	IAnthologyListApiResponse2,
+	IAnthologyDataResponse,
+	IAnthologyResponse,
 } from "../api/Article";
 import TocTree from "./TocTree";
 import { get } from "../../request";
@@ -42,11 +42,9 @@ const Widget = (prop: IWidgetAnthologyDetail) => {
 	}, [prop.aid]);
 
 	function fetchData(id: string) {
-		get(`/v2/anthology/${id}`)
+		get<IAnthologyResponse>(`/v2/anthology/${id}`)
 			.then((response) => {
-				const json = response as unknown as IAnthologyListApiResponse2;
-
-				const item: IAnthologyListApiResponse = json.data;
+				const item: IAnthologyDataResponse = response.data;
 				let newTree: IAnthologyData = {
 					id: item.uid,
 					title: item.title,

+ 4 - 5
dashboard/src/components/article/AnthologyList.tsx

@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
 import { List } from "antd";
 import AnthologyCard from "./AnthologyCard";
 import type { IAnthologyData } from "./AnthologyCard";
-import type { IAnthologyListApiResponse3 } from "../api/Article";
+import type { IAnthologyListResponse } from "../api/Article";
 import { get } from "../../request";
 
 const defaultData: IAnthologyData[] = [];
@@ -25,10 +25,9 @@ const Widget = (prop: IWidgetAnthologyList) => {
 	function fetchData(view: string, id?: string) {
 		let url = `/v2/anthology?view=${view}` + (id ? `&studio=${id}` : "");
 		console.log("get-url", url);
-		get(url).then(function (myJson) {
-			console.log("ajex", myJson);
-			const json = myJson as unknown as IAnthologyListApiResponse3;
-			let newTree: IAnthologyData[] = json.data.rows.map((item) => {
+		get<IAnthologyListResponse>(url).then(function (response) {
+			console.log("ajex", response);
+			let newTree: IAnthologyData[] = response.data.rows.map((item) => {
 				return {
 					id: item.uid,
 					title: item.title,