diff --git a/src/components/common/sidebar/SidebarFooter.tsx b/src/components/common/sidebar/SidebarFooter.tsx index c7fec43..a142249 100644 --- a/src/components/common/sidebar/SidebarFooter.tsx +++ b/src/components/common/sidebar/SidebarFooter.tsx @@ -1,9 +1,9 @@ import React from 'react' import Icon from '@ant-design/icons' -import { getLoginStatus, getNickName, logout } from '@/utils/auth' -import { getRedirectUrl } from '@/utils/common' import { notification } from 'antd' -import { COLOR_ERROR } from '@/constants/common.constants.ts' +import { getLoginStatus, getNickname, logout } from '@/utils/auth' +import { getRedirectUrl } from '@/utils/common' +import { COLOR_ERROR } from '@/constants/common.constants' const SidebarFooter: React.FC = () => { const matches = useMatches() @@ -11,7 +11,7 @@ const SidebarFooter: React.FC = () => { const location = useLocation() const navigate = useNavigate() const [exiting, setExiting] = useState(false) - const [nickName, setNickName] = useState('') + const [nickname, setNickname] = useState('') const handleClickAvatar = () => { if (getLoginStatus()) { @@ -42,8 +42,8 @@ const SidebarFooter: React.FC = () => { useEffect(() => { if (getLoginStatus()) { - void getNickName().then((nickName) => { - setNickName(nickName) + void getNickname().then((nickname) => { + setNickname(nickname) }) } }, [loginStatus]) @@ -60,7 +60,7 @@ const SidebarFooter: React.FC = () => {
- + + + + } + > + +
diff --git a/src/pages/UserFramework.tsx b/src/pages/UserFramework.tsx index 76c7dd8..63bffc2 100644 --- a/src/pages/UserFramework.tsx +++ b/src/pages/UserFramework.tsx @@ -5,7 +5,8 @@ import FitFullScreen from '@/components/common/FitFullScreen' import Sidebar from '@/components/common/sidebar' import SidebarItemList from '@/components/common/sidebar/SidebarItemList' import SidebarItem from '@/components/common/sidebar/SidebarItem' -import { hasPathPermission } from '@/utils/auth.ts' +import { hasPathPermission } from '@/utils/auth' +import LoadingMask from '@/components/common/LoadingMask' const ToolsFramework: React.FC = () => { return ( @@ -42,7 +43,15 @@ const ToolsFramework: React.FC = () => {
- + + + + } + > + +
diff --git a/src/pages/system/User.tsx b/src/pages/system/User.tsx index 4e446cd..95d79f5 100644 --- a/src/pages/system/User.tsx +++ b/src/pages/system/User.tsx @@ -1,7 +1,50 @@ import React from 'react' +import { r_getUserList } from '@/services/user' +import { COLOR_BACKGROUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants' +import { ColumnsType } from 'antd/es/table/interface' const User: React.FC = () => { - return <> + const [userList, setUserList] = useState([]) + + const tableColumns: ColumnsType = [ + { + dataIndex: 'id', + title: 'ID' + }, + { + dataIndex: ['userInfo', 'avatar'], + title: '头像', + render: (value) => ( + } + style={{ background: COLOR_BACKGROUND }} + /> + ) + }, + { + dataIndex: 'username', + title: '用户名' + }, + { + dataIndex: ['userInfo', 'nickname'], + title: '昵称' + } + ] + + useEffect(() => { + r_getUserList().then((res) => { + const data = res.data + if (data.code === DATABASE_SELECT_SUCCESS) { + data.data && setUserList(data.data) + } + }) + }, []) + + return ( + <> + + + ) } export default User diff --git a/src/services/auth.tsx b/src/services/auth.tsx new file mode 100644 index 0000000..27ac85b --- /dev/null +++ b/src/services/auth.tsx @@ -0,0 +1,10 @@ +import request from '@/services' +import { URL_API_LOGIN, URL_API_LOGOUT } from '@/constants/urls.constants' + +export const r_login = (username: string, password: string) => + request.post(URL_API_LOGIN, { + username, + password + }) + +export const r_logout = () => request.post(URL_API_LOGOUT) diff --git a/src/services/user.tsx b/src/services/user.tsx new file mode 100644 index 0000000..96bbe1c --- /dev/null +++ b/src/services/user.tsx @@ -0,0 +1,6 @@ +import request from '@/services' +import { URL_API_USER_INFO, URL_API_USER_LIST } from '@/constants/urls.constants' + +export const r_getInfo = () => request.get(URL_API_USER_INFO) + +export const r_getUserList = () => request.get(URL_API_USER_LIST) diff --git a/src/utils/auth.ts b/src/utils/auth.ts index e335ce5..a8bb4df 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -1,23 +1,20 @@ import { getCaptcha, getLocalStorage, removeToken, setLocalStorage } from './common' -import request from '@/services' +import { r_login, r_logout } from '@/services/auth' +import { r_getInfo } from '@/services/user' import { STORAGE_TOKEN_KEY, STORAGE_USER_INFO_KEY, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants' -import { URL_API_LOGIN, URL_API_LOGOUT, URL_API_USER_INFO } from '@/constants/urls.constants' let captcha: Captcha export const login = async (username: string, password: string) => { - return await request.post(URL_API_LOGIN, { - username, - password - }) + return await r_login(username, password) } export const logout = async () => { - return request.post(URL_API_LOGOUT).finally(() => { + return r_logout().finally(() => { removeToken() }) } @@ -40,7 +37,7 @@ export const getUserInfo = async (): Promise => { export const requestUserInfo = async () => { let user: UserWithPowerInfoVo | null - await request.get(URL_API_USER_INFO).then((value) => { + await r_getInfo().then((value) => { const response = value.data if (response.code === DATABASE_SELECT_SUCCESS) { user = response.data @@ -56,10 +53,10 @@ export const requestUserInfo = async () => { }) } -export const getNickName = async () => { +export const getNickname = async () => { const user = await getUserInfo() - return user.userInfo.nickName + return user.userInfo.nickname } export const getUsername = async () => {