diff --git a/src/api/base.ts b/src/api/base.ts index 0508e87..b345cf1 100644 --- a/src/api/base.ts +++ b/src/api/base.ts @@ -4,8 +4,13 @@ const base = { api_v1_url: 'https://api.locyanfrp.cn', api_v2_url: 'https://api-v2.locyanfrp.cn/api/v2', buildResponse: (res: any, useDataPath: boolean = true) => { - const message = res.data?.data?.message ?? res.data?.data?.msg ?? res.data?.message ?? res.data?.msg ?? '未指定或请求失败' - const data = useDataPath ? res.data?.data : res.data ?? {} + const message = + res.data?.data?.message ?? + res.data?.data?.msg ?? + res.data?.message ?? + res.data?.msg ?? + '未指定或请求失败' + const data = (useDataPath ? res.data?.data : res.data) ?? {} return { status: res.status as number, message: message, diff --git a/src/utils/logger.ts b/src/utils/logger.ts index fea4651..cef5c87 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,40 +1,28 @@ const style = { - info: { - levelColor: 'color: #00cc00;' - }, - warn: { - levelColor: 'color: #ff9933;' - }, - error: { - levelColor: 'color: red;' - }, - reset: 'color: none; background: none;' + info: { + levelColor: 'color: #00cc00;' + }, + warn: { + levelColor: 'color: #ff9933;' + }, + error: { + levelColor: 'color: red;' + }, + reset: 'color: none; background: none;' } const logger = { - info: (m: any) => { - console.log( - `[%cINFO%c] ${m}`, - style.info.levelColor, - style.reset - ) - }, - warn: (m: any, clevel = true) => { - const fn = (clevel) ? console.warn : console.log - fn( - `[%cWARN%c] ${m}`, - style.warn.levelColor, - style.reset - ) - }, - error: (m: any, clevel = true) => { - const fn = (clevel) ? console.error : console.log - fn( - `[%cERROR%c] ${m}`, - style.error.levelColor, - style.reset - ) - }, + info: (m: any) => { + console.log(`[%cINFO%c] ${m}`, style.info.levelColor, style.reset) + }, + warn: (m: any, clevel = true) => { + const fn = clevel ? console.warn : console.log + fn(`[%cWARN%c] ${m}`, style.warn.levelColor, style.reset) + }, + error: (m: any, clevel = true) => { + const fn = clevel ? console.error : console.log + fn(`[%cERROR%c] ${m}`, style.error.levelColor, style.reset) + } } export default logger diff --git a/src/utils/request.js b/src/utils/request.js index 355e867..736ad9c 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -23,10 +23,7 @@ const instance = axios.create({ timeout: 80000 }) -const tokenDomains = [ - 'api.locyanfrp.cn', - 'api-v2.locyanfrp.cn' -] +const tokenDomains = ['api.locyanfrp.cn', 'api-v2.locyanfrp.cn'] // post请求的时候,我们需要加上一个请求头,所以可以在这里进行一个默认的设置,即设置post的请求头为 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'