Skip to content

Commit

Permalink
Merge pull request #17 from suyuan32/refactor-interface
Browse files Browse the repository at this point in the history
Refactor: optimize interface
  • Loading branch information
suyuan32 authored Feb 9, 2023
2 parents 8dd09c6 + 490e575 commit a6d3a09
Show file tree
Hide file tree
Showing 79 changed files with 2,030 additions and 1,119 deletions.
4 changes: 2 additions & 2 deletions src/api/file/file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UploadApiResult } from '../sys/model/uploadModel';
import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode, UploadFileParams } from '/#/axios';
import { BaseDataResp, BaseIdReq, BaseListReq, BaseResp } from '../model/baseModel';
import { BaseDataResp, BaseIDReq, BaseListReq, BaseResp } from '../model/baseModel';
import { FileListResp, updateFileInfoReq } from './model/fileModel';

enum Api {
Expand Down Expand Up @@ -53,7 +53,7 @@ export const UpdateFileInfo = (params: updateFileInfoReq, mode: ErrorMessageMode
* author: Ryan Su
* @description: delete api
*/
export const deleteFile = (params: BaseIdReq, mode: ErrorMessageMode = 'modal') => {
export const deleteFile = (params: BaseIDReq, mode: ErrorMessageMode = 'modal') => {
return defHttp.delete<BaseResp>(
{ url: Api.UpdateFileInfo, params: params },
{
Expand Down
4 changes: 2 additions & 2 deletions src/api/model/baseModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export interface BaseResp {
msg: string;
}

export interface BaseIdReq {
export interface BaseIDReq {
id: number;
}

export interface BaseIdsReq {
export interface BaseIDsReq {
ids: number[];
}

Expand Down
49 changes: 38 additions & 11 deletions src/api/sys/api.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,71 @@
import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';
import { BaseDataResp, BaseIdReq, BaseListReq, BaseResp } from '/@/api/model/baseModel';
import { BaseDataResp, BaseListReq, BaseResp, BaseIDsReq, BaseIDReq } from '/@/api/model/baseModel';
import { ApiInfo, ApiListResp } from './model/apiModel';

enum Api {
CreateApi = '/sys-api/api/create',
UpdateApi = '/sys-api/api/update',
GetApiList = '/sys-api/api/list',
CreateOrUpdateApi = '/sys-api/api/create_or_update',
DeleteApi = '/sys-api/api/delete',
GetApiById = '/sys-api/api',
}

/**
* @description: Get api list
*/

export const getApiList = (params: BaseListReq) => {
return defHttp.post<BaseDataResp<ApiListResp>>({ url: Api.GetApiList, params });
export const getApiList = (params: BaseListReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseDataResp<ApiListResp>>(
{ url: Api.GetApiList, params },
{ errorMessageMode: mode },
);
};

/**
* @description: Create a new api
*/
export const createApi = (params: ApiInfo, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.CreateApi, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* author: ryan
* @description: create a new api
* @description: Update the api
*/
export const createOrUpdateApi = (params: ApiInfo, mode: ErrorMessageMode = 'modal') => {
export const updateApi = (params: ApiInfo, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.CreateOrUpdateApi, params: params },
{ url: Api.UpdateApi, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* author: Ryan Su
* @description: delete api
* @description: Delete apis
*/
export const deleteApi = (params: BaseIdReq, mode: ErrorMessageMode = 'modal') => {
export const deleteApi = (params: BaseIDsReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.DeleteApi, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* @description: Get api By ID
*/
export const getApiById = (params: BaseIDReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseDataResp<ApiInfo>>(
{ url: Api.GetApiById, params: params },
{
errorMessageMode: mode,
},
);
};
6 changes: 3 additions & 3 deletions src/api/sys/authority.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';
import { BaseDataResp, BaseIdReq, BaseResp } from '/@/api/model/baseModel';
import { BaseDataResp, BaseIDReq, BaseResp } from '/@/api/model/baseModel';
import { ApiListResp } from './model/apiModel';
import {
ApiAuthorityReq,
Expand Down Expand Up @@ -30,7 +30,7 @@ export const getApiList = (params: ApiListReq) => {
* @description: Get api authorization list
*/

export const getApiAuthority = (params: BaseIdReq) => {
export const getApiAuthority = (params: BaseIDReq) => {
return defHttp.post<BaseDataResp<ApiAuthorityResp>>({ url: Api.GetRoleApiList, params });
};

Expand Down Expand Up @@ -72,7 +72,7 @@ export const createOrUpdateMenuAuthority = (
* @description: get role's menu authorization ids
*/

export const getMenuAuthority = (params: BaseIdReq) => {
export const getMenuAuthority = (params: BaseIDReq) => {
return defHttp.post<BaseDataResp<MenuAuthorityInfo>>({
url: Api.GetRoleMenuList,
params,
Expand Down
48 changes: 27 additions & 21 deletions src/api/sys/department.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';
import { BaseDataResp, BaseListReq, BaseResp, BaseIdsReq, BaseIdReq } from '/@/api/model/baseModel';
import { BaseDataResp, BaseListReq, BaseResp, BaseIDsReq, BaseIDReq } from '/@/api/model/baseModel';
import { DepartmentInfo, DepartmentListResp } from './model/departmentModel';

enum Api {
CreateOrUpdateDepartment = '/sys-api/department/create_or_update',
CreateDepartment = '/sys-api/department/create',
UpdateDepartment = '/sys-api/department/update',
GetDepartmentList = '/sys-api/department/list',
DeleteDepartment = '/sys-api/department/delete',
BatchDeleteDepartment = '/sys-api/department/batch_delete',
SetDepartmentStatus = '/sys-api/department/status',
GetDepartmentById = '/sys-api/department',
}

/**
* @description: Get department list
*/

export const getDepartmentList = (params: BaseListReq) => {
return defHttp.post<BaseDataResp<DepartmentListResp>>({ url: Api.GetDepartmentList, params });
export const getDepartmentList = (params: BaseListReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseDataResp<DepartmentListResp>>(
{ url: Api.GetDepartmentList, params },
{ errorMessageMode: mode },
);
};

/**
* @description: create a new department
* @description: Create a new department
*/
export const createOrUpdateDepartment = (
params: DepartmentInfo,
mode: ErrorMessageMode = 'modal',
) => {
export const createDepartment = (params: DepartmentInfo, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.CreateOrUpdateDepartment, params: params },
{ url: Api.CreateDepartment, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* @description: delete department
* @description: Update the department
*/
export const deleteDepartment = (params: BaseIdReq, mode: ErrorMessageMode = 'modal') => {
export const updateDepartment = (params: DepartmentInfo, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.DeleteDepartment, params: params },
{ url: Api.UpdateDepartment, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* @description: batch delete departments
* @description: Delete departments
*/
export const batchDeleteDepartment = (params: BaseIdsReq, mode: ErrorMessageMode = 'modal') => {
export const deleteDepartment = (params: BaseIDsReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.BatchDeleteDepartment, params: params },
{ url: Api.DeleteDepartment, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* @description: set the department status
* @description: Get department By ID
*/
export const setDepartmentStatus = (id: string, status: number) =>
defHttp.post({ url: Api.SetDepartmentStatus, params: { id, status } });
export const getDepartmentById = (params: BaseIDReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseDataResp<DepartmentInfo>>(
{ url: Api.GetDepartmentById, params: params },
{
errorMessageMode: mode,
},
);
};
74 changes: 25 additions & 49 deletions src/api/sys/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,93 +1,69 @@
import { defHttp } from '/@/utils/http/axios';
import { ErrorMessageMode } from '/#/axios';
import { BaseDataResp, BaseIdReq, BaseListReq, BaseResp } from '/@/api/model/baseModel';
import {
DictionaryDetailInfo,
DictionaryDetailListResp,
DictionaryInfo,
DictionaryListResp,
} from './model/dictionaryModel';
import { BaseDataResp, BaseListReq, BaseResp, BaseIDsReq, BaseIDReq } from '/@/api/model/baseModel';
import { DictionaryInfo, DictionaryListResp } from './model/dictionaryModel';

enum Api {
GetDictionaryList = '/sys-api/dict/list',
CreateOrUpdateDictionary = '/sys-api/dict/create_or_update',
DeleteDictionary = '/sys-api/dict/delete',
GetDictionaryDetailList = '/sys-api/dict/detail/list',
CreateOrUpdateDictionaryDetail = '/sys-api/dict/detail/create_or_update',
DeleteDictionaryDetail = '/sys-api/dict/detail/delete',
CreateDictionary = '/sys-api/dictionary/create',
UpdateDictionary = '/sys-api/dictionary/update',
GetDictionaryList = '/sys-api/dictionary/list',
DeleteDictionary = '/sys-api/dictionary/delete',
GetDictionaryById = '/sys-api/dictionary',
}

/**
* @description: Get dictionary list
*/

export const getDictionaryList = (params: BaseListReq) => {
return defHttp.post<BaseDataResp<DictionaryListResp>>({ url: Api.GetDictionaryList, params });
export const getDictionaryList = (params: BaseListReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseDataResp<DictionaryListResp>>(
{ url: Api.GetDictionaryList, params },
{ errorMessageMode: mode },
);
};

/**
* author: ryan
* @description: create or update a new dictionary
* @description: Create a new dictionary
*/
export const createOrUpdateDictionary = (
params: DictionaryInfo,
mode: ErrorMessageMode = 'modal',
) => {
export const createDictionary = (params: DictionaryInfo, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.CreateOrUpdateDictionary, params: params },
{ url: Api.CreateDictionary, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* author: Ryan Su
* @description: delete a dictionary
* @description: Update the dictionary
*/
export const deleteDictionary = (params: BaseIdReq, mode: ErrorMessageMode = 'modal') => {
export const updateDictionary = (params: DictionaryInfo, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.DeleteDictionary, params: params },
{ url: Api.UpdateDictionary, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* @description: Get dictionary detail list
* @description: Delete dictionarys
*/

export const getDictionaryDetailList = (params: BaseListReq) => {
return defHttp.post<BaseDataResp<DictionaryDetailListResp>>({
url: Api.GetDictionaryDetailList,
params,
});
};

/**
* author: ryan
* @description: create a new dictionary detail
*/
export const createOrUpdateDictionaryDetail = (
params: DictionaryDetailInfo,
mode: ErrorMessageMode = 'modal',
) => {
export const deleteDictionary = (params: BaseIDsReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseResp>(
{ url: Api.CreateOrUpdateDictionaryDetail, params: params },
{ url: Api.DeleteDictionary, params: params },
{
errorMessageMode: mode,
},
);
};

/**
* author: Ryan Su
* @description: delete a dictionary detail
* @description: Get dictionary By ID
*/
export const deleteDictionaryDetail = (params: BaseIdReq, mode: ErrorMessageMode = 'modal') => {
return defHttp.post<BaseResp>(
{ url: Api.DeleteDictionaryDetail, params: params },
export const getDictionaryById = (params: BaseIDReq, mode: ErrorMessageMode = 'message') => {
return defHttp.post<BaseDataResp<DictionaryInfo>>(
{ url: Api.GetDictionaryById, params: params },
{
errorMessageMode: mode,
},
Expand Down
Loading

0 comments on commit a6d3a09

Please sign in to comment.