diff --git a/src/pages/Article/index.tsx b/src/pages/Article/index.tsx index 9011460..0a8b96c 100644 --- a/src/pages/Article/index.tsx +++ b/src/pages/Article/index.tsx @@ -27,10 +27,8 @@ const ArticlePage = () => { const getArticleList = async () => { setLoading(true); - const { data } = await getArticleListAPI(); setArticleList(data as Article[]); - setLoading(false); }; diff --git a/src/pages/Create/index.tsx b/src/pages/Create/index.tsx index f1cc20f..6526e14 100644 --- a/src/pages/Create/index.tsx +++ b/src/pages/Create/index.tsx @@ -53,8 +53,6 @@ const CreatePage = () => { // 保存文章 const saveBtn = () => { - console.log(content, 333); - if (content.trim().length >= 1) { // 将文章内容持久化存储到本地 localStorage.setItem('article_content', content) diff --git a/src/pages/User/index.tsx b/src/pages/User/index.tsx index 44ba79f..782c46b 100644 --- a/src/pages/User/index.tsx +++ b/src/pages/User/index.tsx @@ -1,10 +1,10 @@ import { useState, useEffect } from 'react'; -import { Table, Button, Tag, notification, Card, Popconfirm, Form, Input, Select, Avatar, Drawer } from 'antd'; +import { Table, Button, Tag, notification, Card, Popconfirm, Form, Input, Select, Avatar, Drawer, DatePicker } from 'antd'; import { getUserDataAPI, getUserListAPI, delUserDataAPI, addUserDataAPI, editUserDataAPI } from '@/api/User'; import { getRoleListAPI } from '@/api/Role' -import type { User } from '@/types/app/user'; +import type { FilterForm, FilterUser, User } from '@/types/app/user'; import { Role } from '@/types/app/role'; import { titleSty } from '@/styles/sty'; @@ -17,13 +17,10 @@ const UserPage = () => { const [userList, setUserList] = useState([]); const [roleList, setRoleList] = useState([]); - + const [user, setUser] = useState({} as User) const [drawerVisible, setDrawerVisible] = useState(false); - const [user, setUser] = useState({} as User) - - const [filterForm] = Form.useForm(); - const [userForm] = Form.useForm(); + const { RangePicker } = DatePicker; const columns = [ { @@ -105,6 +102,8 @@ const UserPage = () => { }, ]; + const [userForm] = Form.useForm(); + const getUserList = async () => { setLoading(true); const { data } = await getUserListAPI(); @@ -122,20 +121,6 @@ const UserPage = () => { getRoleList() }, []); - const onSubmit = async () => { - userForm.validateFields().then(async (values: User) => { - if (user.id) { - await editUserDataAPI({ ...values, ...user, roleId: values.role }); - notification.success({ message: '🎉 编辑用户成功' }); - } else { - await addUserDataAPI({ ...values, roleId: values.role, createTime: new Date().getTime().toString() }); - notification.success({ message: '🎉 创建用户成功' }); - } - setDrawerVisible(false); - getUserList(); - }) - }; - const delUserData = async (id: number) => { setLoading(true); await delUserDataAPI(id); @@ -157,6 +142,34 @@ const UserPage = () => { userForm.resetFields() } + const onSubmit = async () => { + userForm.validateFields().then(async (values: User) => { + if (user.id) { + await editUserDataAPI({ ...values, ...user, roleId: values.role }); + notification.success({ message: '🎉 编辑用户成功' }); + } else { + await addUserDataAPI({ ...values, roleId: values.role, createTime: new Date().getTime().toString() }); + notification.success({ message: '🎉 创建用户成功' }); + } + setDrawerVisible(false); + getUserList(); + }) + }; + + const [filterForm] = Form.useForm(); + + const onFilterSubmit = async (values: FilterForm) => { + const query: FilterUser = { + key: values.name, + roleId: values.role, + startDate: values.createTime && values.createTime[0].valueOf() + '', + endDate: values.createTime && values.createTime[1].valueOf() + '' + } + + const { data } = await getUserListAPI({ query }); + setUserList(data as User[]); + } + return ( <> @@ -164,20 +177,19 @@ const UserPage = () => { -
- - + + + - - ({ label: item.name, value: item.id }))} placeholder="请选择角色" /> + + + + + diff --git a/src/types/app/user.d.ts b/src/types/app/user.d.ts index 44a2376..520d589 100644 --- a/src/types/app/user.d.ts +++ b/src/types/app/user.d.ts @@ -25,4 +25,16 @@ export interface EditUser { username: string, oldPassword: string, newPassword: string +} + + +export interface FilterForm { + name?: string, + role?: number, + createTime: Date[] +} + +export interface FilterUser extends FilterData { + name?: string, + roleId?: number, } \ No newline at end of file diff --git a/src/utils/request.ts b/src/utils/request.ts index 2251db8..501f032 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -3,8 +3,8 @@ import { Modal, notification } from "antd"; import { useUserStore } from "@/stores"; // 配置项目API域名 -export const baseURL = "http://localhost:9003/api"; -// export const baseURL = "https://api.liuyuyang.net/api"; +// export const baseURL = "http://localhost:9003/api"; +export const baseURL = "https://api.liuyuyang.net/api"; // 创建 axios 实例 export const instance = axios.create({