feat: api suffix (#4065)

This commit is contained in:
sea 2024-08-07 13:42:33 +08:00 committed by GitHub
parent d9ba9917ff
commit 08391ad53e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 39 additions and 39 deletions

View File

@ -21,13 +21,13 @@ export namespace AuthApi {
/**
*
*/
export async function login(data: AuthApi.LoginParams) {
export async function loginApi(data: AuthApi.LoginParams) {
return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
}
/**
*
*/
export async function getAccessCodes() {
export async function getAccessCodesApi() {
return requestClient.get<string[]>('/auth/codes');
}

View File

@ -5,6 +5,6 @@ import { requestClient } from '#/api/request';
/**
*
*/
export async function getAllMenus() {
export async function getAllMenusApi() {
return requestClient.get<RouteRecordStringComponent[]>('/menu/all');
}

View File

@ -5,6 +5,6 @@ import { requestClient } from '#/api/request';
/**
*
*/
export async function getUserInfo() {
export async function getUserInfoApi() {
return requestClient.get<UserInfo>('/user/info');
}

View File

@ -3,8 +3,8 @@ import { requestClient } from '#/api/request';
/**
*
*/
async function getMockStatus(status: string) {
async function getMockStatusApi(status: string) {
return requestClient.get('/status', { params: { status } });
}
export { getMockStatus };
export { getMockStatusApi };

View File

@ -8,7 +8,7 @@ import { preferences } from '@vben/preferences';
import { message } from 'ant-design-vue';
import { getAllMenus } from '#/api';
import { getAllMenusApi } from '#/api';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
@ -29,7 +29,7 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
content: `${$t('common.loadingMenu')}...`,
duration: 1.5,
});
return await getAllMenus();
return await getAllMenusApi();
},
// 可以指定没有权限跳转403页面
forbiddenComponent,

View File

@ -10,7 +10,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
import { notification } from 'ant-design-vue';
import { defineStore } from 'pinia';
import { getAccessCodes, getUserInfo, login } from '#/api';
import { getAccessCodesApi, getUserInfoApi, loginApi } from '#/api';
import { $t } from '#/locales';
export const useAuthStore = defineStore('auth', () => {
@ -33,7 +33,7 @@ export const useAuthStore = defineStore('auth', () => {
let userInfo: null | UserInfo = null;
try {
loginLoading.value = true;
const { accessToken, refreshToken } = await login(params);
const { accessToken, refreshToken } = await loginApi(params);
// 如果成功获取到 accessToken
if (accessToken) {
@ -44,7 +44,7 @@ export const useAuthStore = defineStore('auth', () => {
// 获取用户信息并存储到 accessStore 中
const [fetchUserInfoResult, accessCodes] = await Promise.all([
fetchUserInfo(),
getAccessCodes(),
getAccessCodesApi(),
]);
userInfo = fetchUserInfoResult;
@ -92,7 +92,7 @@ export const useAuthStore = defineStore('auth', () => {
async function fetchUserInfo() {
let userInfo: null | UserInfo = null;
userInfo = await getUserInfo();
userInfo = await getUserInfoApi();
userStore.setUserInfo(userInfo);
return userInfo;
}

View File

@ -5,13 +5,13 @@ import { preferences, updatePreferences } from '@vben/preferences';
import { Button } from 'ant-design-vue';
import { getMockStatus } from '#/api';
import { getMockStatusApi } from '#/api';
async function handleClick(type: LoginExpiredModeType) {
const loginExpiredMode = preferences.app.loginExpiredMode;
updatePreferences({ app: { loginExpiredMode: type } });
await getMockStatus('401');
await getMockStatusApi('401');
updatePreferences({ app: { loginExpiredMode } });
}
</script>

View File

@ -21,13 +21,13 @@ export namespace AuthApi {
/**
*
*/
export async function login(data: AuthApi.LoginParams) {
export async function loginApi(data: AuthApi.LoginParams) {
return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
}
/**
*
*/
export async function getAccessCodes() {
export async function getAccessCodesApi() {
return requestClient.get<string[]>('/auth/codes');
}

View File

@ -5,6 +5,6 @@ import { requestClient } from '#/api/request';
/**
*
*/
export async function getAllMenus() {
export async function getAllMenusApi() {
return requestClient.get<RouteRecordStringComponent[]>('/menu/all');
}

View File

@ -5,6 +5,6 @@ import { requestClient } from '#/api/request';
/**
*
*/
export async function getUserInfo() {
export async function getUserInfoApi() {
return requestClient.get<UserInfo>('/user/info');
}

View File

@ -8,7 +8,7 @@ import { preferences } from '@vben/preferences';
import { ElMessage } from 'element-plus';
import { getAllMenus } from '#/api';
import { getAllMenusApi } from '#/api';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
@ -29,7 +29,7 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
duration: 1500,
message: `${$t('common.loadingMenu')}...`,
});
return await getAllMenus();
return await getAllMenusApi();
},
// 可以指定没有权限跳转403页面
forbiddenComponent,

View File

@ -10,7 +10,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
import { ElNotification } from 'element-plus';
import { defineStore } from 'pinia';
import { getAccessCodes, getUserInfo, login } from '#/api';
import { getAccessCodesApi, getUserInfoApi, loginApi } from '#/api';
import { $t } from '#/locales';
export const useAuthStore = defineStore('auth', () => {
@ -33,7 +33,7 @@ export const useAuthStore = defineStore('auth', () => {
let userInfo: null | UserInfo = null;
try {
loginLoading.value = true;
const { accessToken, refreshToken } = await login(params);
const { accessToken, refreshToken } = await loginApi(params);
// 如果成功获取到 accessToken
if (accessToken) {
@ -44,7 +44,7 @@ export const useAuthStore = defineStore('auth', () => {
// 获取用户信息并存储到 accessStore 中
const [fetchUserInfoResult, accessCodes] = await Promise.all([
fetchUserInfo(),
getAccessCodes(),
getAccessCodesApi(),
]);
userInfo = fetchUserInfoResult;
@ -92,7 +92,7 @@ export const useAuthStore = defineStore('auth', () => {
async function fetchUserInfo() {
let userInfo: null | UserInfo = null;
userInfo = await getUserInfo();
userInfo = await getUserInfoApi();
userStore.setUserInfo(userInfo);
return userInfo;
}

View File

@ -21,13 +21,13 @@ export namespace AuthApi {
/**
*
*/
export async function login(data: AuthApi.LoginParams) {
export async function loginApi(data: AuthApi.LoginParams) {
return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
}
/**
*
*/
export async function getAccessCodes() {
export async function getAccessCodesApi() {
return requestClient.get<string[]>('/auth/codes');
}

View File

@ -5,6 +5,6 @@ import { requestClient } from '#/api/request';
/**
*
*/
export async function getAllMenus() {
export async function getAllMenusApi() {
return requestClient.get<RouteRecordStringComponent[]>('/menu/all');
}

View File

@ -5,6 +5,6 @@ import { requestClient } from '#/api/request';
/**
*
*/
export async function getUserInfo() {
export async function getUserInfoApi() {
return requestClient.get<UserInfo>('/user/info');
}

View File

@ -6,7 +6,7 @@ import type {
import { generateAccessible } from '@vben/access';
import { preferences } from '@vben/preferences';
import { getAllMenus } from '#/api';
import { getAllMenusApi } from '#/api';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
import { message } from '#/naive';
@ -27,7 +27,7 @@ async function generateAccess(options: GenerateMenuAndRoutesOptions) {
message.loading(`${$t('common.loadingMenu')}...`, {
duration: 1.5,
});
return await getAllMenus();
return await getAllMenusApi();
},
// 可以指定没有权限跳转403页面
forbiddenComponent,

View File

@ -9,7 +9,7 @@ import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
import { defineStore } from 'pinia';
import { getAccessCodes, getUserInfo, login } from '#/api';
import { getAccessCodesApi, getUserInfoApi, loginApi } from '#/api';
import { $t } from '#/locales';
import { notification } from '#/naive';
@ -33,7 +33,7 @@ export const useAuthStore = defineStore('auth', () => {
let userInfo: null | UserInfo = null;
try {
loginLoading.value = true;
const { accessToken, refreshToken } = await login(params);
const { accessToken, refreshToken } = await loginApi(params);
// 如果成功获取到 accessToken
if (accessToken) {
@ -44,7 +44,7 @@ export const useAuthStore = defineStore('auth', () => {
// 获取用户信息并存储到 accessStore 中
const [fetchUserInfoResult, accessCodes] = await Promise.all([
fetchUserInfo(),
getAccessCodes(),
getAccessCodesApi(),
]);
userInfo = fetchUserInfoResult;
@ -92,7 +92,7 @@ export const useAuthStore = defineStore('auth', () => {
async function fetchUserInfo() {
let userInfo: null | UserInfo = null;
userInfo = await getUserInfo();
userInfo = await getUserInfoApi();
userStore.setUserInfo(userInfo);
return userInfo;
}

View File

@ -117,7 +117,7 @@ VITE_GLOB_API_URL=https://mock-napi.vben.pro/api
```ts
import { requestClient } from '#/api/request';
export async function getUserInfo() {
export async function getUserInfoApi() {
return requestClient.get<UserInfo>('/user/info');
}
```
@ -127,15 +127,15 @@ export async function getUserInfo() {
```ts
import { requestClient } from '#/api/request';
export async function saveUser(user: UserInfo) {
export async function saveUserApi(user: UserInfo) {
return requestClient.post<UserInfo>('/user', user);
}
export async function saveUser(user: UserInfo) {
export async function saveUserApi(user: UserInfo) {
return requestClient.put<UserInfo>('/user', user);
}
export async function saveUser(user: UserInfo) {
export async function saveUserApi(user: UserInfo) {
const url = user.id ? `/user/${user.id}` : '/user/';
return requestClient.request<UserInfo>(url, {
data: user,
@ -150,7 +150,7 @@ export async function saveUser(user: UserInfo) {
```ts
import { requestClient } from '#/api/request';
export async function deleteUser(user: UserInfo) {
export async function deleteUserApi(user: UserInfo) {
return requestClient.delete<boolean>(`/user/${user.id}`, user);
}
```