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

+ 55 - 34
dashboard/src/components/article/AnthologyList.tsx

@@ -6,54 +6,75 @@ import type { IAnthologyListResponse } from "../api/Article";
 import AnthologyCard from "./AnthologyCard";
 import type { IAnthologyData } from "./AnthologyCard";
 
-interface IWidgetAnthologyList {
-  view: string;
-  id?: string;
+interface IWidget {
+  studioName?: string;
+  searchKey?: string;
 }
-const Widget = (prop: IWidgetAnthologyList) => {
+const Widget = ({ studioName, searchKey }: IWidget) => {
   const [tableData, setTableData] = useState<IAnthologyData[]>([]);
+  const [total, setTotal] = useState<number>();
+  const [currPage, setCurrPage] = useState<number>(1);
+  const pageSize = 20;
 
   useEffect(() => {
-    console.log("useEffect", prop);
-    if (typeof prop.id === "undefined") {
-      fetchData(prop.view);
-    } else {
-      fetchData(prop.view, prop.id);
+    const offset = (currPage - 1) * pageSize;
+    let url = `/v2/anthology?view=public&offset=${offset}&limit=${pageSize}`;
+    if (typeof studioName !== "undefined") {
+      url += `&studio=${studioName}`;
+    }
+    if (typeof searchKey === "string" && searchKey.length > 0) {
+      url += `&search=${searchKey}`;
     }
-  }, [prop]);
 
-  function fetchData(view: string, id?: string) {
-    let url = `/v2/anthology?view=${view}` + (id ? `&studio=${id}` : "");
     console.log("get-url", url);
-    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,
-          subTitle: item.subtitle,
-          summary: item.summary,
-          articles: item.article_list.map((al) => {
-            return {
-              key: al.article,
-              title: al.title,
-              level: parseInt(al.level),
-            };
-          }),
-          studio: item.studio,
-          created_at: item.created_at,
-          updated_at: item.updated_at,
-        };
-      });
-      setTableData(newTree);
+    get<IAnthologyListResponse>(url).then(function (json) {
+      if (json.ok) {
+        let newTree: IAnthologyData[] = json.data.rows.map((item) => {
+          return {
+            id: item.uid,
+            title: item.title,
+            subTitle: item.subtitle,
+            summary: item.summary,
+            articles: item.article_list.map((al) => {
+              return {
+                key: al.article,
+                title: al.title,
+                level: parseInt(al.level),
+              };
+            }),
+            studio: item.studio,
+            created_at: item.created_at,
+            updated_at: item.updated_at,
+          };
+        });
+        setTableData(newTree);
+        setTotal(json.data.count);
+      } else {
+        setTableData([]);
+        setTotal(0);
+      }
     });
-  }
+  }, [currPage, searchKey, studioName]);
 
   return (
     <List
       itemLayout="vertical"
       size="large"
       dataSource={tableData}
+      pagination={{
+        onChange: (page) => {
+          console.log(page);
+          setCurrPage(page);
+        },
+        showQuickJumper: true,
+        showSizeChanger: false,
+        pageSize: pageSize,
+        total: total,
+        position: "both",
+        showTotal: (total) => {
+          return `结果: ${total}`;
+        },
+      }}
       renderItem={(item) => (
         <List.Item>
           <AnthologyCard data={item} />

+ 52 - 45
dashboard/src/pages/library/anthology/list.tsx

@@ -1,4 +1,5 @@
-import { Space, Input } from "antd";
+import { useState } from "react";
+import { Input } from "antd";
 import { Layout, Affix, Col, Row } from "antd";
 
 import AnthologyList from "../../../components/article/AnthologyList";
@@ -8,52 +9,58 @@ const { Content, Header } = Layout;
 const { Search } = Input;
 
 const Widget = () => {
-	// TODO
-	const onSearch = (value: string) => console.log(value);
-	return (
-		<Layout>
-			<Header style={{ height: 200 }}>
-				<h2>composition</h2>
-				<p>
-					Make the Pāḷi easy to read <br />
-					solution of Pāḷi glossary For translating <br />
-					Pāḷi in Group Show the source reference in Pāḷi
-				</p>
-			</Header>
-			<Affix offsetTop={0}>
-				<Header style={{ backgroundColor: "gray", height: "3.5em" }}>
-					<Row style={{ paddingTop: "0.5em" }}>
-						<Col span="8" offset={8}>
-							<Search
-								placeholder="input search text"
-								onSearch={onSearch}
-								style={{ width: "100%" }}
-							/>
-						</Col>
-					</Row>
-				</Header>
-			</Affix>
+  // TODO
+  const [searchKey, setSearchKey] = useState<string>();
 
-			<Content>
-				<Row>
-					<Col flex="auto"></Col>
-					<Col flex="1260px">
-						<Row>
-							<Col span="18">
-								<AnthologyList view="public" />
-							</Col>
-							<Col span="6">
-								<AnthologStudioList />
-							</Col>
-						</Row>
-					</Col>
-					<Col flex="auto"></Col>
-				</Row>
+  return (
+    <Layout>
+      <Header style={{ height: 200, display: "none" }}>
+        <h2>composition</h2>
+        <p>
+          Make the Pāḷi easy to read <br />
+          solution of Pāḷi glossary For translating <br />
+          Pāḷi in Group Show the source reference in Pāḷi
+        </p>
+      </Header>
+      <Affix offsetTop={0}>
+        <div
+          style={{
+            backgroundColor: "rgba(100,100,100,0.3)",
+            backdropFilter: "blur(5px)",
+          }}
+        >
+          <Row style={{ paddingTop: "0.5em", paddingBottom: "0.5em" }}>
+            <Col span="8" offset={8}>
+              <Search
+                placeholder="标题搜索"
+                onSearch={(value: string) => {
+                  setSearchKey(value);
+                }}
+                style={{ width: "100%" }}
+              />
+            </Col>
+          </Row>
+        </div>
+      </Affix>
 
-				<Space></Space>
-			</Content>
-		</Layout>
-	);
+      <Content>
+        <Row>
+          <Col flex="auto"></Col>
+          <Col flex="1260px">
+            <Row>
+              <Col span="18">
+                <AnthologyList searchKey={searchKey} />
+              </Col>
+              <Col span="6">
+                <AnthologStudioList />
+              </Col>
+            </Row>
+          </Col>
+          <Col flex="auto"></Col>
+        </Row>
+      </Content>
+    </Layout>
+  );
 };
 
 export default Widget;

+ 1 - 1
dashboard/src/pages/library/blog/anthology.tsx

@@ -10,7 +10,7 @@ const Widget = () => {
   return (
     <>
       <BlogNav selectedKey="anthology" studio={studio ? studio : ""} />
-      <AnthologyList view="public_studio" id={studio ? studio : ""} />
+      <AnthologyList studioName={studio} />
     </>
   );
 };