Adapt to fatweb-api #29
@@ -11,36 +11,27 @@ const SIZE_ICON_MD = '24px'
|
|||||||
const SIZE_ICON_LG = '32px'
|
const SIZE_ICON_LG = '32px'
|
||||||
const SIZE_ICON_XL = '64px'
|
const SIZE_ICON_XL = '64px'
|
||||||
|
|
||||||
// Response Code
|
/**
|
||||||
const SYSTEM_OK = 20000
|
* Response code
|
||||||
const LOGIN_SUCCESS = 20010
|
*/
|
||||||
const LOGIN_USERNAME_PASSWORD_ERROR = 20011
|
const SYSTEM_OK = 10000
|
||||||
const OLD_PASSWORD_NOT_MATCH = 20012
|
const SYSTEM_LOGIN_SUCCESS = 10020
|
||||||
const LOGOUT_SUCCESS = 20015
|
const SYSTEM_PASSWORD_CHANGE_SUCCESS = 10021
|
||||||
const LOGOUT_FAILED = 20016
|
const SYSTEM_LOGOUT_SUCCESS = 10022
|
||||||
const TOKEN_IS_ILLEGAL = 20017
|
const SYSTEM_TOKEN_RENEW_SUCCESS = 10023
|
||||||
const TOKEN_HAS_EXPIRED = 20018
|
const SYSTEM_UNAUTHORIZED = 10030
|
||||||
const TOKEN_RENEW_SUCCESS = 20019
|
const SYSTEM_USERNAME_NOT_FOUND = 10031
|
||||||
const DATABASE_SELECT_OK = 20021
|
const SYSTEM_ACCESS_DENIED = 10032
|
||||||
const DATABASE_SAVE_OK = 20022
|
const SYSTEM_USER_DISABLE = 10033
|
||||||
const DATABASE_UPDATE_OK = 20023
|
const SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR = 10034
|
||||||
const DATABASE_DELETE_OK = 20024
|
const SYSTEM_OLD_PASSWORD_NOT_MATCH = 10035
|
||||||
const DATABASE_SELECT_ERROR = 20031
|
const SYSTEM_LOGOUT_FAILED = 10036
|
||||||
const DATABASE_SAVE_ERROR = 20032
|
const SYSTEM_TOKEN_ILLEGAL = 10037
|
||||||
const DATABASE_UPDATE_ERROR = 20033
|
const SYSTEM_TOKEN_HAS_EXPIRED = 10038
|
||||||
const DATABASE_DELETE_ERROR = 20034
|
const SYSTEM_REQUEST_ILLEGAL = 10040
|
||||||
const DATABASE_TIMEOUT_ERROR = 20035
|
const SYSTEM_ARGUMENT_NOT_VALID = 10041
|
||||||
const DATABASE_CONNECT_ERROR = 20036
|
const SYSTEM_ERROR = 10050
|
||||||
const DATABASE_DATA_TO_LONG = 20037
|
const SYSTEM_TIMEOUT = 10051
|
||||||
const DATABASE_DATA_VALIDATION_FAILED = 20038
|
|
||||||
const DATABASE_EXECUTE_ERROR = 20039
|
|
||||||
|
|
||||||
const UNAUTHORIZED = 30010
|
|
||||||
const ACCESS_DENIED = 30030
|
|
||||||
const USER_DISABLE = 30031
|
|
||||||
|
|
||||||
const SYSTEM_ERROR = 50001
|
|
||||||
const SYSTEM_TIMEOUT = 50002
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
PRODUCTION_NAME,
|
PRODUCTION_NAME,
|
||||||
@@ -56,30 +47,21 @@ export {
|
|||||||
SIZE_ICON_LG,
|
SIZE_ICON_LG,
|
||||||
SIZE_ICON_XL,
|
SIZE_ICON_XL,
|
||||||
SYSTEM_OK,
|
SYSTEM_OK,
|
||||||
LOGIN_SUCCESS,
|
SYSTEM_LOGIN_SUCCESS,
|
||||||
LOGIN_USERNAME_PASSWORD_ERROR,
|
SYSTEM_PASSWORD_CHANGE_SUCCESS,
|
||||||
OLD_PASSWORD_NOT_MATCH,
|
SYSTEM_LOGOUT_SUCCESS,
|
||||||
LOGOUT_SUCCESS,
|
SYSTEM_TOKEN_RENEW_SUCCESS,
|
||||||
LOGOUT_FAILED,
|
SYSTEM_UNAUTHORIZED,
|
||||||
TOKEN_IS_ILLEGAL,
|
SYSTEM_USERNAME_NOT_FOUND,
|
||||||
TOKEN_HAS_EXPIRED,
|
SYSTEM_ACCESS_DENIED,
|
||||||
TOKEN_RENEW_SUCCESS,
|
SYSTEM_USER_DISABLE,
|
||||||
DATABASE_SELECT_OK,
|
SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR,
|
||||||
DATABASE_SAVE_OK,
|
SYSTEM_OLD_PASSWORD_NOT_MATCH,
|
||||||
DATABASE_UPDATE_OK,
|
SYSTEM_LOGOUT_FAILED,
|
||||||
DATABASE_DELETE_OK,
|
SYSTEM_TOKEN_ILLEGAL,
|
||||||
DATABASE_SELECT_ERROR,
|
SYSTEM_TOKEN_HAS_EXPIRED,
|
||||||
DATABASE_SAVE_ERROR,
|
SYSTEM_REQUEST_ILLEGAL,
|
||||||
DATABASE_UPDATE_ERROR,
|
SYSTEM_ARGUMENT_NOT_VALID,
|
||||||
DATABASE_DELETE_ERROR,
|
|
||||||
DATABASE_TIMEOUT_ERROR,
|
|
||||||
DATABASE_CONNECT_ERROR,
|
|
||||||
DATABASE_DATA_TO_LONG,
|
|
||||||
DATABASE_DATA_VALIDATION_FAILED,
|
|
||||||
DATABASE_EXECUTE_ERROR,
|
|
||||||
UNAUTHORIZED,
|
|
||||||
ACCESS_DENIED,
|
|
||||||
USER_DISABLE,
|
|
||||||
SYSTEM_ERROR,
|
SYSTEM_ERROR,
|
||||||
SYSTEM_TIMEOUT
|
SYSTEM_TIMEOUT
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { login } from '@/utils/auth.ts'
|
import { login } from '@/utils/auth.ts'
|
||||||
import { LOGIN_SUCCESS, LOGIN_USERNAME_PASSWORD_ERROR } from '@/constants/Common.constants.ts'
|
import {
|
||||||
|
SYSTEM_LOGIN_SUCCESS,
|
||||||
|
SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR,
|
||||||
|
SYSTEM_USER_DISABLE,
|
||||||
|
SYSTEM_USERNAME_NOT_FOUND
|
||||||
|
} from '@/constants/Common.constants.ts'
|
||||||
import { setToken } from '@/utils/common.ts'
|
import { setToken } from '@/utils/common.ts'
|
||||||
import '@/assets/css/pages/login.scss'
|
import '@/assets/css/pages/login.scss'
|
||||||
|
|
||||||
@@ -15,14 +20,15 @@ const Login: React.FC = () => {
|
|||||||
const res = value.data
|
const res = value.data
|
||||||
const { code, data } = res
|
const { code, data } = res
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case LOGIN_SUCCESS:
|
case SYSTEM_LOGIN_SUCCESS:
|
||||||
setToken(data?.token ?? '')
|
setToken(data?.token ?? '')
|
||||||
void messageApi.success('登录成功')
|
void messageApi.success('登录成功')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
navigate('/')
|
navigate('/')
|
||||||
}, 1500)
|
}, 1500)
|
||||||
break
|
break
|
||||||
case LOGIN_USERNAME_PASSWORD_ERROR:
|
case SYSTEM_USERNAME_NOT_FOUND:
|
||||||
|
case SYSTEM_LOGIN_USERNAME_PASSWORD_ERROR:
|
||||||
void messageApi.error(
|
void messageApi.error(
|
||||||
<>
|
<>
|
||||||
<strong>用户名</strong>或<strong>密码</strong>错误,请重试
|
<strong>用户名</strong>或<strong>密码</strong>错误,请重试
|
||||||
@@ -30,6 +36,14 @@ const Login: React.FC = () => {
|
|||||||
)
|
)
|
||||||
setIsLoggingIn(false)
|
setIsLoggingIn(false)
|
||||||
break
|
break
|
||||||
|
case SYSTEM_USER_DISABLE:
|
||||||
|
void messageApi.error(
|
||||||
|
<>
|
||||||
|
该用户已被<strong>禁用</strong>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
setIsLoggingIn(false)
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
void messageApi.error(
|
void messageApi.error(
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ import axios, { type AxiosError, AxiosInstance, AxiosRequestConfig, AxiosRespons
|
|||||||
import jwtDecode, { JwtPayload } from 'jwt-decode'
|
import jwtDecode, { JwtPayload } from 'jwt-decode'
|
||||||
import { clearLocalStorage, getToken, setToken } from '@/utils/common'
|
import { clearLocalStorage, getToken, setToken } from '@/utils/common'
|
||||||
import {
|
import {
|
||||||
ACCESS_DENIED,
|
SYSTEM_ACCESS_DENIED,
|
||||||
DATABASE_DATA_TO_LONG,
|
SYSTEM_TOKEN_HAS_EXPIRED,
|
||||||
DATABASE_DATA_VALIDATION_FAILED,
|
SYSTEM_TOKEN_ILLEGAL,
|
||||||
DATABASE_EXECUTE_ERROR,
|
SYSTEM_TOKEN_RENEW_SUCCESS,
|
||||||
TOKEN_HAS_EXPIRED,
|
SYSTEM_UNAUTHORIZED
|
||||||
TOKEN_IS_ILLEGAL,
|
|
||||||
TOKEN_RENEW_SUCCESS,
|
|
||||||
UNAUTHORIZED
|
|
||||||
} from '@/constants/Common.constants'
|
} from '@/constants/Common.constants'
|
||||||
import { message } from 'antd'
|
import { message } from 'antd'
|
||||||
|
|
||||||
@@ -49,7 +46,7 @@ service.interceptors.request.use(
|
|||||||
})
|
})
|
||||||
.then((value: AxiosResponse<_Response<Token>>) => {
|
.then((value: AxiosResponse<_Response<Token>>) => {
|
||||||
const response = value.data
|
const response = value.data
|
||||||
if (response.code === TOKEN_RENEW_SUCCESS) {
|
if (response.code === SYSTEM_TOKEN_RENEW_SUCCESS) {
|
||||||
setToken(response.data?.token ?? '')
|
setToken(response.data?.token ?? '')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -68,9 +65,9 @@ service.interceptors.request.use(
|
|||||||
service.interceptors.response.use(
|
service.interceptors.response.use(
|
||||||
(response: AxiosResponse<_Response<never>>) => {
|
(response: AxiosResponse<_Response<never>>) => {
|
||||||
switch (response.data.code) {
|
switch (response.data.code) {
|
||||||
case UNAUTHORIZED:
|
case SYSTEM_UNAUTHORIZED:
|
||||||
case TOKEN_IS_ILLEGAL:
|
case SYSTEM_TOKEN_ILLEGAL:
|
||||||
case TOKEN_HAS_EXPIRED:
|
case SYSTEM_TOKEN_HAS_EXPIRED:
|
||||||
clearLocalStorage()
|
clearLocalStorage()
|
||||||
void message.error(
|
void message.error(
|
||||||
<>
|
<>
|
||||||
@@ -81,34 +78,13 @@ service.interceptors.response.use(
|
|||||||
location.reload()
|
location.reload()
|
||||||
}, 1500)
|
}, 1500)
|
||||||
throw response?.data
|
throw response?.data
|
||||||
case ACCESS_DENIED:
|
case SYSTEM_ACCESS_DENIED:
|
||||||
void message.error(
|
void message.error(
|
||||||
<>
|
<>
|
||||||
<strong>暂无权限操作</strong>
|
<strong>暂无权限操作</strong>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
throw response?.data
|
throw response?.data
|
||||||
case DATABASE_DATA_TO_LONG:
|
|
||||||
void message.error(
|
|
||||||
<>
|
|
||||||
<strong>数据过长</strong>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
throw response?.data
|
|
||||||
case DATABASE_DATA_VALIDATION_FAILED:
|
|
||||||
void message.error(
|
|
||||||
<>
|
|
||||||
<strong>数据验证失败</strong>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
throw response?.data
|
|
||||||
case DATABASE_EXECUTE_ERROR:
|
|
||||||
void message.error(
|
|
||||||
<>
|
|
||||||
<strong>数据库执行出错</strong>
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
throw response?.data
|
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { clearLocalStorage, getCaptcha, getLocalStorage, setLocalStorage } from './common'
|
import { clearLocalStorage, getCaptcha, getLocalStorage, setLocalStorage } from './common'
|
||||||
import { DATABASE_SELECT_OK, TOKEN_NAME } from '@/constants/Common.constants'
|
import { SYSTEM_OK, TOKEN_NAME } from '@/constants/Common.constants'
|
||||||
import request from '@/services'
|
import request from '@/services'
|
||||||
|
|
||||||
let captcha: Captcha
|
let captcha: Captcha
|
||||||
@@ -35,7 +35,7 @@ export async function requestUser(): Promise<User> {
|
|||||||
|
|
||||||
await request.get<User>('/user/info').then((value) => {
|
await request.get<User>('/user/info').then((value) => {
|
||||||
const response = value.data
|
const response = value.data
|
||||||
if (response.code === DATABASE_SELECT_OK) {
|
if (response.code === SYSTEM_OK) {
|
||||||
user = response.data
|
user = response.data
|
||||||
setLocalStorage('userInfo', JSON.stringify(user))
|
setLocalStorage('userInfo', JSON.stringify(user))
|
||||||
}
|
}
|
||||||
|
|||||||
1
src/vite-env.d.ts
vendored
1
src/vite-env.d.ts
vendored
@@ -17,6 +17,7 @@ type RouteHandle = {
|
|||||||
|
|
||||||
type _Response<T> = {
|
type _Response<T> = {
|
||||||
code: number
|
code: number
|
||||||
|
success: boolean
|
||||||
msg: string
|
msg: string
|
||||||
data: T | null
|
data: T | null
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user