diff --git a/src/config/request.tsx b/src/config/request.tsx index 64ed46e..07c3317 100644 --- a/src/config/request.tsx +++ b/src/config/request.tsx @@ -4,12 +4,13 @@ import { Spin } from "antd" import CreateAxiosInstance from "@/service/request" import type { IAxiosRequestConfig, IAxiosResponse, AxiosError } from "@/service/request" +import utils from "@/utils" const request = new CreateAxiosInstance({ baseURL: "", timeout: 10000, headers: { - token: "token" + token: utils.getToken() }, abort: false, load: false @@ -52,6 +53,11 @@ request.requestStart = (config: IAxiosRequestConfig) => { } requestNum += 1 } + if (config.headers!.token) { + config.headers!.token = utils.getToken() + } + + return config } request.requestEnd = (config: IAxiosRequestConfig) => { diff --git a/src/views/book/list/index.tsx b/src/views/book/list/index.tsx index 6e0e130..6595300 100644 --- a/src/views/book/list/index.tsx +++ b/src/views/book/list/index.tsx @@ -1,5 +1,5 @@ import { Table, Tag, Space, Pagination } from "antd" -import React, { useEffect, useState } from "react" +import React, { useEffect, useState, useCallback, Component } from "react" import type { PaginationProps } from "antd" import api from "@/api" import "./list.scss" @@ -10,11 +10,12 @@ const App = () => { const [list, setList] = useState([]) const [currentPage, setCurrentPage] = useState(1) const [numPerPage, setNumPerPage] = useState(10) - const [totalCount, setTotalCount] = useState(100) - const [pageSizeOptions] = useState(["10", "20", "50", "100"]) + const [totalCount, setTotalCount] = useState(10) + const pageSizeOptions = ["10", "20", "50", "100"] const [loading, setLoading] = useState(false) - const getBookList = (data) => { + const getBookList = data => { + console.log("getBookList currentPage:", currentPage) setLoading(true) api.book .getBookList(data) @@ -29,21 +30,28 @@ const App = () => { }) } + const resetCurrentPage = useCallback(num => setCurrentPage(num), [setCurrentPage]) + const onChange: PaginationProps["onChange"] = pageNumber => { console.log("Page: ", pageNumber) + getBookList({ currentPage: pageNumber, numPerPage }) setCurrentPage(pageNumber) } const onShowSizeChange = (current, size) => { - setCurrentPage(1) + resetCurrentPage(1) + getBookList({ currentPage: 1, numPerPage: size }) setNumPerPage(size) } useEffect(() => { - getBookList({ currentPage: currentPage, numPerPage: numPerPage }) - }, [currentPage]) + console.log("useEffect currentPage:", currentPage) + getBookList({ currentPage, numPerPage }) + }, []) + return (