From fedd2f6e8cec2a296d3d22fb7b9bcde8bcbee84f Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Thu, 16 Nov 2023 09:19:45 +0800 Subject: [PATCH] Optimize code --- src/pages/system/Group.tsx | 14 +++++++------- src/pages/system/User.tsx | 4 ++-- src/services/auth.tsx | 4 ++-- src/services/system.tsx | 14 ++++++++++---- src/services/user.tsx | 6 ------ src/utils/auth.ts | 10 +++++----- 6 files changed, 26 insertions(+), 26 deletions(-) delete mode 100644 src/services/user.tsx diff --git a/src/pages/system/Group.tsx b/src/pages/system/Group.tsx index c7546a9..fa47112 100644 --- a/src/pages/system/Group.tsx +++ b/src/pages/system/Group.tsx @@ -1,9 +1,9 @@ import React, { useEffect, useState } from 'react' -import FitFullScreen from '@/components/common/FitFullScreen.tsx' -import HideScrollbar from '@/components/common/HideScrollbar.tsx' -import FlexBox from '@/components/common/FlexBox.tsx' import Icon from '@ant-design/icons' -import Card from '@/components/common/Card.tsx' +import FitFullScreen from '@/components/common/FitFullScreen' +import HideScrollbar from '@/components/common/HideScrollbar' +import FlexBox from '@/components/common/FlexBox' +import Card from '@/components/common/Card' import { COLOR_ERROR_SECONDARY, COLOR_FONT_SECONDARY, @@ -13,8 +13,8 @@ import { DATABASE_INSERT_SUCCESS, DATABASE_SELECT_SUCCESS, DATABASE_UPDATE_SUCCESS -} from '@/constants/common.constants.ts' -import { getLocalTime } from '@/utils/common.tsx' +} from '@/constants/common.constants' +import { getLocalTime } from '@/utils/common' import { r_sys_group_add, r_sys_group_change_status, @@ -23,7 +23,7 @@ import { r_sys_group_get, r_sys_group_update, r_sys_role_get_list -} from '@/services/system.tsx' +} from '@/services/system' const Group: React.FC = () => { const [modal, contextHolder] = AntdModal.useModal() diff --git a/src/pages/system/User.tsx b/src/pages/system/User.tsx index 95d79f5..cf0215f 100644 --- a/src/pages/system/User.tsx +++ b/src/pages/system/User.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { r_getUserList } from '@/services/user' +import { r_sys_user } from '@/services/system' import { COLOR_BACKGROUND, DATABASE_SELECT_SUCCESS } from '@/constants/common.constants' import { ColumnsType } from 'antd/es/table/interface' @@ -32,7 +32,7 @@ const User: React.FC = () => { ] useEffect(() => { - r_getUserList().then((res) => { + r_sys_user().then((res) => { const data = res.data if (data.code === DATABASE_SELECT_SUCCESS) { data.data && setUserList(data.data) diff --git a/src/services/auth.tsx b/src/services/auth.tsx index 27ac85b..75a3246 100644 --- a/src/services/auth.tsx +++ b/src/services/auth.tsx @@ -1,10 +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) => +export const r_auth_login = (username: string, password: string) => request.post(URL_API_LOGIN, { username, password }) -export const r_logout = () => request.post(URL_API_LOGOUT) +export const r_auth_logout = () => request.post(URL_API_LOGOUT) diff --git a/src/services/system.tsx b/src/services/system.tsx index 16e662b..d499f8d 100644 --- a/src/services/system.tsx +++ b/src/services/system.tsx @@ -1,16 +1,19 @@ import React from 'react' import request from '@/services/index' import { - URL_API_SYS_LOG, + URL_API_SYS_USER_INFO, + URL_API_SYS_USER, URL_API_SYS_POWER_LIST, URL_API_SYS_ROLE, URL_API_SYS_ROLE_LIST, URL_API_SYS_GROUP, - URL_API_SYS_GROUP_LIST + URL_API_SYS_GROUP_LIST, + URL_API_SYS_LOG } from '@/constants/urls.constants' -export const r_sys_log_get = (param: SysLogGetParam) => - request.get>(URL_API_SYS_LOG, { ...param }) +export const r_sys_user_info = () => request.get(URL_API_SYS_USER_INFO) + +export const r_sys_user = () => request.get(URL_API_SYS_USER) export const r_sys_power_get_list = () => request.get(URL_API_SYS_POWER_LIST) @@ -51,3 +54,6 @@ export const r_sys_group_delete = (id: string) => request.delete(`${URL_API_SYS_ export const r_sys_group_delete_list = (ids: React.Key[]) => request.delete(URL_API_SYS_GROUP, { ids }) + +export const r_sys_log_get = (param: SysLogGetParam) => + request.get>(URL_API_SYS_LOG, { ...param }) diff --git a/src/services/user.tsx b/src/services/user.tsx deleted file mode 100644 index fc9a977..0000000 --- a/src/services/user.tsx +++ /dev/null @@ -1,6 +0,0 @@ -import request from '@/services' -import { URL_API_SYS_USER_INFO, URL_API_SYS_USER } from '@/constants/urls.constants' - -export const r_getInfo = () => request.get(URL_API_SYS_USER_INFO) - -export const r_getUserList = () => request.get(URL_API_SYS_USER) diff --git a/src/utils/auth.ts b/src/utils/auth.ts index a8bb4df..54761f9 100644 --- a/src/utils/auth.ts +++ b/src/utils/auth.ts @@ -1,6 +1,6 @@ import { getCaptcha, getLocalStorage, removeToken, setLocalStorage } from './common' -import { r_login, r_logout } from '@/services/auth' -import { r_getInfo } from '@/services/user' +import { r_auth_login, r_auth_logout } from '@/services/auth' +import { r_sys_user_info } from '@/services/system' import { STORAGE_TOKEN_KEY, STORAGE_USER_INFO_KEY, @@ -10,11 +10,11 @@ import { let captcha: Captcha export const login = async (username: string, password: string) => { - return await r_login(username, password) + return await r_auth_login(username, password) } export const logout = async () => { - return r_logout().finally(() => { + return r_auth_logout().finally(() => { removeToken() }) } @@ -37,7 +37,7 @@ export const getUserInfo = async (): Promise => { export const requestUserInfo = async () => { let user: UserWithPowerInfoVo | null - await r_getInfo().then((value) => { + await r_sys_user_info().then((value) => { const response = value.data if (response.code === DATABASE_SELECT_SUCCESS) { user = response.data