-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e336e39
commit d0ed0e6
Showing
3 changed files
with
217 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,97 @@ | ||
import React, { useEffect, useState } from "react" | ||
import { InferGetServerSidePropsType, NextPageContext } from "next" | ||
import { Car } from "@dataswapjs/dataswapjs" | ||
import CarTabel from "@/components/table/car" | ||
import { getCar, getCarCount } from "../../../../shared/messagehub/get" | ||
import { ValueFields } from "@unipackage/utils" | ||
import { QueryParam } from "@/shared/messagehub/queryParams" | ||
import { TablePaginationConfig } from "antd" | ||
import { Input, Space } from "antd" | ||
import { onSearchBasic, handleTableChangeBasic } from "@/shared/table" | ||
const { Search } = Input | ||
|
||
export async function getServerSideProps(context: NextPageContext) { | ||
return { | ||
props: {}, | ||
} | ||
interface IProps { | ||
queryParam: QueryParam<Car> | ||
} | ||
|
||
export default function IndexPage({}: InferGetServerSidePropsType< | ||
typeof getServerSideProps | ||
>) { | ||
return <div>car</div> | ||
export default ({ queryParam }: IProps) => { | ||
const [dataList, setDataList] = useState<ValueFields<Car>[]>() | ||
const [loading, setLoading] = useState<boolean>(false) | ||
const [pagination, setPagination] = useState<TablePaginationConfig>({ | ||
current: queryParam?.queryFilter?.page, | ||
pageSize: queryParam?.queryFilter?.limit, | ||
}) | ||
const [search, setSearch] = useState<string>("") | ||
|
||
const currentQueryParams: QueryParam<Car> = { | ||
network: queryParam?.network, | ||
queryFilter: queryParam?.queryFilter && { | ||
...queryParam.queryFilter, | ||
page: pagination.current, | ||
limit: pagination.pageSize, | ||
}, | ||
} | ||
|
||
// get count when refresh page,do one time | ||
useEffect(() => { | ||
console.log("before getDataswapMessageCount", pagination) | ||
getCarCount(currentQueryParams).then((res) => { | ||
const totalRes = res.data | ||
setPagination({ | ||
...pagination, | ||
total: totalRes, | ||
}) | ||
}) | ||
}, [search]) | ||
|
||
// get count when use click page number,do multi times | ||
useEffect(() => { | ||
if (pagination.total) { | ||
console.log("before getDataswapMessage", pagination) | ||
setLoading(true) | ||
getCar(currentQueryParams).then((res) => { | ||
setDataList(res.data) | ||
setLoading(false) | ||
}) | ||
} | ||
}, [JSON.stringify(pagination), search]) | ||
|
||
const handleTableChange = (_pagination: TablePaginationConfig) => { | ||
handleTableChangeBasic({ | ||
newPagination: _pagination, | ||
oldPagination: pagination, | ||
setDataList, | ||
setPagination, | ||
}) | ||
} | ||
|
||
const onSearch = (_search: string) => { | ||
onSearchBasic({ | ||
newSearch: _search, | ||
oldSearch: search, | ||
setSearch, | ||
setDataList, | ||
}) | ||
} | ||
|
||
return ( | ||
<> | ||
<div style={{ display: "flex", justifyContent: "flex-end" }}> | ||
<Space direction="vertical"> | ||
<Search | ||
placeholder="search:Height/From/To/Method" | ||
onSearch={onSearch} | ||
style={{ width: 300 }} | ||
/> | ||
</Space> | ||
</div> | ||
{dataList && ( | ||
<CarTabel | ||
data={dataList} | ||
pagination={pagination ? pagination : {}} | ||
loading={loading} | ||
onChange={handleTableChange} | ||
/> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { useEffect, useState } from "react" | ||
import { DatasetRequirement } from "@dataswapjs/dataswapjs" | ||
import DatasetRequirementTabel from "@/components/table/dataset/requirement" | ||
import { | ||
getDatasetRequirement, | ||
getDatasetRequirementCount, | ||
} from "../../../../shared/messagehub/get" | ||
import { ValueFields } from "@unipackage/utils" | ||
import { defaultTableQueryParams } from "../../../../config/params" | ||
import { Input, Space } from "antd" | ||
import { TablePaginationConfig } from "antd" | ||
import { onSearchBasic, handleTableChangeBasic } from "@/shared/table" | ||
import { QueryParam } from "@/shared/messagehub/queryParams" | ||
const { Search } = Input | ||
|
||
interface IProps { | ||
queryParam: QueryParam<DatasetRequirement> | ||
} | ||
|
||
export default ({ queryParam }: IProps) => { | ||
const [dataLis, setDataList] = useState<ValueFields<DatasetRequirement>[]>() | ||
const [loading, setLoading] = useState<boolean>(false) | ||
const [pagination, setPagination] = useState<TablePaginationConfig>({ | ||
current: defaultTableQueryParams.page, | ||
pageSize: defaultTableQueryParams.limit, | ||
}) | ||
const [search, setSearch] = useState<string>("") | ||
|
||
const currentQueryParams: QueryParam<DatasetRequirement> = { | ||
network: queryParam?.network, | ||
queryFilter: { | ||
page: pagination.current, | ||
limit: pagination.pageSize, | ||
}, | ||
} | ||
|
||
// get count when refresh page,do one time | ||
useEffect(() => { | ||
console.log("before getDatasetRequirementCount", pagination) | ||
getDatasetRequirementCount(currentQueryParams).then((res) => { | ||
const totalRes = res.data | ||
setPagination({ | ||
...pagination, | ||
total: totalRes, | ||
}) | ||
}) | ||
}, [search]) | ||
|
||
useEffect(() => { | ||
setLoading(true) | ||
console.log("before getDatasetRequirement", currentQueryParams) | ||
getDatasetRequirement(currentQueryParams).then((res) => { | ||
const datasetOveriew = res.data | ||
setDataList(datasetOveriew) | ||
setLoading(false) | ||
}) | ||
}, [JSON.stringify(pagination), search]) | ||
|
||
const handleTableChange = (_pagination: TablePaginationConfig) => { | ||
handleTableChangeBasic({ | ||
newPagination: _pagination, | ||
oldPagination: pagination, | ||
setPagination, | ||
setDataList, | ||
}) | ||
} | ||
|
||
const onSearch = (_search: string) => { | ||
onSearchBasic({ | ||
newSearch: _search, | ||
oldSearch: search, | ||
setSearch, | ||
setDataList, | ||
}) | ||
} | ||
|
||
return ( | ||
<> | ||
<div style={{ display: "flex", justifyContent: "flex-end" }}> | ||
<Space direction="vertical"> | ||
<Search | ||
placeholder="search:Height/Name/Submitter/accessMethod" | ||
onSearch={onSearch} | ||
style={{ width: 300 }} | ||
/> | ||
</Space> | ||
</div> | ||
|
||
{dataLis && ( | ||
<DatasetRequirementTabel | ||
data={dataLis} | ||
pagination={pagination ? pagination : {}} | ||
loading={loading} | ||
onChange={handleTableChange} | ||
/> | ||
)} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters