perf: imporve axios logic

This commit is contained in:
Vben
2021-02-26 22:45:36 +08:00
parent 7c2f851692
commit a821d9a3a2
13 changed files with 77 additions and 74 deletions

View File

@@ -1,14 +1,12 @@
import { defHttp } from '/@/utils/http/axios';
import { GetAccountInfoModel } from './model/accountModel';
const { get } = defHttp;
enum Api {
ACCOUNT_INFO = '/account/getAccountInfo',
}
// Get personal center-basic settings
export function accountInfoApi() {
return defHttp.request<GetAccountInfoModel>({
url: Api.ACCOUNT_INFO,
method: 'GET',
});
}
export const accountInfoApi = () => get<GetAccountInfoModel>({ url: Api.ACCOUNT_INFO });

View File

@@ -1,5 +1,7 @@
import { defHttp } from '/@/utils/http/axios';
const { get } = defHttp;
enum Api {
// The address does not exist
Error = '/error',
@@ -8,9 +10,5 @@ enum Api {
/**
* @description: Trigger ajax error
*/
export function fireErrorApi() {
return defHttp.request({
url: Api.Error,
method: 'GET',
});
}
export const fireErrorApi = () => get({ url: Api.Error });

View File

@@ -1,5 +1,6 @@
import { defHttp } from '/@/utils/http/axios';
import { DemoOptionsGetResultModel } from './model/optionsModel';
const { get } = defHttp;
enum Api {
OPTIONS_LIST = '/select/getDemoOptions',
@@ -8,9 +9,4 @@ enum Api {
/**
* @description: Get sample options value
*/
export function optionsListApi() {
return defHttp.request<DemoOptionsGetResultModel>({
url: Api.OPTIONS_LIST,
method: 'GET',
});
}
export const optionsListApi = () => get<DemoOptionsGetResultModel>({ url: Api.OPTIONS_LIST });

View File

@@ -1,6 +1,8 @@
import { defHttp } from '/@/utils/http/axios';
import { DemoParams, DemoListGetResultModel } from './model/tableModel';
const { get } = defHttp;
enum Api {
DEMO_LIST = '/table/getDemoList',
}
@@ -8,13 +10,12 @@ enum Api {
/**
* @description: Get sample list value
*/
export function demoListApi(params: DemoParams) {
return defHttp.request<DemoListGetResultModel>({
export const demoListApi = (params: DemoParams) =>
get<DemoListGetResultModel>({
url: Api.DEMO_LIST,
method: 'GET',
params,
headers: {
ignoreCancelToken: true,
},
});
}

View File

@@ -1,7 +1,8 @@
import { defHttp } from '/@/utils/http/axios';
import { getMenuListByIdParams, getMenuListByIdParamsResultModel } from './model/menuModel';
const { get } = defHttp;
enum Api {
GetMenuListById = '/getMenuListById',
}
@@ -9,10 +10,7 @@ enum Api {
/**
* @description: Get user menu based on id
*/
export function getMenuListById(params: getMenuListByIdParams) {
return defHttp.request<getMenuListByIdParamsResultModel>({
url: Api.GetMenuListById,
method: 'GET',
params,
});
}
export const getMenuListById = (params: getMenuListByIdParams) => {
return get<getMenuListByIdParamsResultModel>({ url: Api.GetMenuListById, params });
};

View File

@@ -7,6 +7,7 @@ import {
} from './model/userModel';
import { ErrorMessageMode } from '/@/utils/http/axios/types';
const { post, get } = defHttp;
enum Api {
Login = '/login',
GetUserInfoById = '/getUserInfoById',
@@ -17,10 +18,9 @@ enum Api {
* @description: user login api
*/
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
return defHttp.request<LoginResultModel>(
return post<LoginResultModel>(
{
url: Api.Login,
method: 'POST',
params,
},
{
@@ -33,17 +33,15 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
* @description: getUserInfoById
*/
export function getUserInfoById(params: GetUserInfoByUserIdParams) {
return defHttp.request<GetUserInfoByUserIdModel>({
return get<GetUserInfoByUserIdModel>({
url: Api.GetUserInfoById,
method: 'GET',
params,
});
}
export function getPermCodeByUserId(params: GetUserInfoByUserIdParams) {
return defHttp.request<string[]>({
return get<string[]>({
url: Api.GetPermCodeByUserId,
method: 'GET',
params,
});
}