From 11d3f395caf7e2268630090eb34f4e5c114a96b7 Mon Sep 17 00:00:00 2001 From: Vben Date: Fri, 26 Feb 2021 23:30:22 +0800 Subject: [PATCH] fix: ensure to request the interface correctly --- src/api/demo/account.ts | 4 +--- src/api/demo/error.ts | 4 +--- src/api/demo/select.ts | 4 ++-- src/api/demo/table.ts | 4 +--- src/api/sys/menu.ts | 4 +--- src/api/sys/user.ts | 7 +++---- src/utils/http/axios/Axios.ts | 1 + types/config.d.ts | 2 +- 8 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/api/demo/account.ts b/src/api/demo/account.ts index a884fd0c410..54bed483b59 100644 --- a/src/api/demo/account.ts +++ b/src/api/demo/account.ts @@ -1,12 +1,10 @@ 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 const accountInfoApi = () => get({ url: Api.ACCOUNT_INFO }); +export const accountInfoApi = () => defHttp.get({ url: Api.ACCOUNT_INFO }); diff --git a/src/api/demo/error.ts b/src/api/demo/error.ts index 14d8e2ad1dd..3ce6072172b 100644 --- a/src/api/demo/error.ts +++ b/src/api/demo/error.ts @@ -1,7 +1,5 @@ import { defHttp } from '/@/utils/http/axios'; -const { get } = defHttp; - enum Api { // The address does not exist Error = '/error', @@ -11,4 +9,4 @@ enum Api { * @description: Trigger ajax error */ -export const fireErrorApi = () => get({ url: Api.Error }); +export const fireErrorApi = () => defHttp.get({ url: Api.Error }); diff --git a/src/api/demo/select.ts b/src/api/demo/select.ts index f27aeae24fa..30030aee499 100644 --- a/src/api/demo/select.ts +++ b/src/api/demo/select.ts @@ -1,6 +1,5 @@ import { defHttp } from '/@/utils/http/axios'; import { DemoOptionsGetResultModel } from './model/optionsModel'; -const { get } = defHttp; enum Api { OPTIONS_LIST = '/select/getDemoOptions', @@ -9,4 +8,5 @@ enum Api { /** * @description: Get sample options value */ -export const optionsListApi = () => get({ url: Api.OPTIONS_LIST }); +export const optionsListApi = () => + defHttp.get({ url: Api.OPTIONS_LIST }); diff --git a/src/api/demo/table.ts b/src/api/demo/table.ts index 4f1012e7eb3..6a5dcee7b81 100644 --- a/src/api/demo/table.ts +++ b/src/api/demo/table.ts @@ -1,8 +1,6 @@ import { defHttp } from '/@/utils/http/axios'; import { DemoParams, DemoListGetResultModel } from './model/tableModel'; -const { get } = defHttp; - enum Api { DEMO_LIST = '/table/getDemoList', } @@ -12,7 +10,7 @@ enum Api { */ export const demoListApi = (params: DemoParams) => - get({ + defHttp.get({ url: Api.DEMO_LIST, params, headers: { diff --git a/src/api/sys/menu.ts b/src/api/sys/menu.ts index b81f72d8e44..bf757455fc0 100644 --- a/src/api/sys/menu.ts +++ b/src/api/sys/menu.ts @@ -1,8 +1,6 @@ import { defHttp } from '/@/utils/http/axios'; import { getMenuListByIdParams, getMenuListByIdParamsResultModel } from './model/menuModel'; -const { get } = defHttp; - enum Api { GetMenuListById = '/getMenuListById', } @@ -12,5 +10,5 @@ enum Api { */ export const getMenuListById = (params: getMenuListByIdParams) => { - return get({ url: Api.GetMenuListById, params }); + return defHttp.get({ url: Api.GetMenuListById, params }); }; diff --git a/src/api/sys/user.ts b/src/api/sys/user.ts index f5b4b1e8f73..3a623158a6e 100644 --- a/src/api/sys/user.ts +++ b/src/api/sys/user.ts @@ -7,7 +7,6 @@ import { } from './model/userModel'; import { ErrorMessageMode } from '/@/utils/http/axios/types'; -const { post, get } = defHttp; enum Api { Login = '/login', GetUserInfoById = '/getUserInfoById', @@ -18,7 +17,7 @@ enum Api { * @description: user login api */ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') { - return post( + return defHttp.post( { url: Api.Login, params, @@ -33,14 +32,14 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') * @description: getUserInfoById */ export function getUserInfoById(params: GetUserInfoByUserIdParams) { - return get({ + return defHttp.get({ url: Api.GetUserInfoById, params, }); } export function getPermCodeByUserId(params: GetUserInfoByUserIdParams) { - return get({ + return defHttp.get({ url: Api.GetPermCodeByUserId, params, }); diff --git a/src/utils/http/axios/Axios.ts b/src/utils/http/axios/Axios.ts index 56cc126adfd..377e3e171f0 100644 --- a/src/utils/http/axios/Axios.ts +++ b/src/utils/http/axios/Axios.ts @@ -195,6 +195,7 @@ export class VAxios { } conf = this.supportFormData(conf); + return new Promise((resolve, reject) => { this.axiosInstance .request>(conf) diff --git a/types/config.d.ts b/types/config.d.ts index e0f43946e5e..a37d8ee6e1f 100644 --- a/types/config.d.ts +++ b/types/config.d.ts @@ -9,7 +9,7 @@ import { import { CacheTypeEnum } from '/@/enums/cacheEnum'; import type { LocaleType } from '/@/locales/types'; -import { ThemeMode } from '../../build/config/themeConfig'; +import { ThemeMode } from '../build/config/themeConfig'; export interface MenuSetting { bgColor: string;