From 08391ad53ea23cd6766d9e22e161dc16fc79f258 Mon Sep 17 00:00:00 2001 From: sea <45450994+warmthsea@users.noreply.github.com> Date: Wed, 7 Aug 2024 13:42:33 +0800 Subject: [PATCH] feat: api suffix (#4065) --- apps/web-antd/src/api/core/auth.ts | 4 ++-- apps/web-antd/src/api/core/menu.ts | 2 +- apps/web-antd/src/api/core/user.ts | 2 +- apps/web-antd/src/api/demos/status.ts | 4 ++-- apps/web-antd/src/router/access.ts | 4 ++-- apps/web-antd/src/store/auth.ts | 8 ++++---- .../src/views/demos/features/login-expired/index.vue | 4 ++-- apps/web-ele/src/api/core/auth.ts | 4 ++-- apps/web-ele/src/api/core/menu.ts | 2 +- apps/web-ele/src/api/core/user.ts | 2 +- apps/web-ele/src/router/access.ts | 4 ++-- apps/web-ele/src/store/auth.ts | 8 ++++---- apps/web-naive/src/api/core/auth.ts | 4 ++-- apps/web-naive/src/api/core/menu.ts | 2 +- apps/web-naive/src/api/core/user.ts | 2 +- apps/web-naive/src/router/access.ts | 4 ++-- apps/web-naive/src/store/auth.ts | 8 ++++---- docs/src/guide/essentials/server.md | 10 +++++----- 18 files changed, 39 insertions(+), 39 deletions(-) diff --git a/apps/web-antd/src/api/core/auth.ts b/apps/web-antd/src/api/core/auth.ts index 6950e3bf..548e9dc9 100644 --- a/apps/web-antd/src/api/core/auth.ts +++ b/apps/web-antd/src/api/core/auth.ts @@ -21,13 +21,13 @@ export namespace AuthApi { /** * 登录 */ -export async function login(data: AuthApi.LoginParams) { +export async function loginApi(data: AuthApi.LoginParams) { return requestClient.post('/auth/login', data); } /** * 获取用户权限码 */ -export async function getAccessCodes() { +export async function getAccessCodesApi() { return requestClient.get('/auth/codes'); } diff --git a/apps/web-antd/src/api/core/menu.ts b/apps/web-antd/src/api/core/menu.ts index 62c40f17..9ef60b11 100644 --- a/apps/web-antd/src/api/core/menu.ts +++ b/apps/web-antd/src/api/core/menu.ts @@ -5,6 +5,6 @@ import { requestClient } from '#/api/request'; /** * 获取用户所有菜单 */ -export async function getAllMenus() { +export async function getAllMenusApi() { return requestClient.get('/menu/all'); } diff --git a/apps/web-antd/src/api/core/user.ts b/apps/web-antd/src/api/core/user.ts index 34c14ea9..7e28ea84 100644 --- a/apps/web-antd/src/api/core/user.ts +++ b/apps/web-antd/src/api/core/user.ts @@ -5,6 +5,6 @@ import { requestClient } from '#/api/request'; /** * 获取用户信息 */ -export async function getUserInfo() { +export async function getUserInfoApi() { return requestClient.get('/user/info'); } diff --git a/apps/web-antd/src/api/demos/status.ts b/apps/web-antd/src/api/demos/status.ts index daa3d638..4a75fe7e 100644 --- a/apps/web-antd/src/api/demos/status.ts +++ b/apps/web-antd/src/api/demos/status.ts @@ -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 }; diff --git a/apps/web-antd/src/router/access.ts b/apps/web-antd/src/router/access.ts index 251db72f..3a48be23 100644 --- a/apps/web-antd/src/router/access.ts +++ b/apps/web-antd/src/router/access.ts @@ -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, diff --git a/apps/web-antd/src/store/auth.ts b/apps/web-antd/src/store/auth.ts index c731dea7..59a640ca 100644 --- a/apps/web-antd/src/store/auth.ts +++ b/apps/web-antd/src/store/auth.ts @@ -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; } diff --git a/apps/web-antd/src/views/demos/features/login-expired/index.vue b/apps/web-antd/src/views/demos/features/login-expired/index.vue index 7f381496..f6c72303 100644 --- a/apps/web-antd/src/views/demos/features/login-expired/index.vue +++ b/apps/web-antd/src/views/demos/features/login-expired/index.vue @@ -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 } }); } diff --git a/apps/web-ele/src/api/core/auth.ts b/apps/web-ele/src/api/core/auth.ts index 6950e3bf..548e9dc9 100644 --- a/apps/web-ele/src/api/core/auth.ts +++ b/apps/web-ele/src/api/core/auth.ts @@ -21,13 +21,13 @@ export namespace AuthApi { /** * 登录 */ -export async function login(data: AuthApi.LoginParams) { +export async function loginApi(data: AuthApi.LoginParams) { return requestClient.post('/auth/login', data); } /** * 获取用户权限码 */ -export async function getAccessCodes() { +export async function getAccessCodesApi() { return requestClient.get('/auth/codes'); } diff --git a/apps/web-ele/src/api/core/menu.ts b/apps/web-ele/src/api/core/menu.ts index 62c40f17..9ef60b11 100644 --- a/apps/web-ele/src/api/core/menu.ts +++ b/apps/web-ele/src/api/core/menu.ts @@ -5,6 +5,6 @@ import { requestClient } from '#/api/request'; /** * 获取用户所有菜单 */ -export async function getAllMenus() { +export async function getAllMenusApi() { return requestClient.get('/menu/all'); } diff --git a/apps/web-ele/src/api/core/user.ts b/apps/web-ele/src/api/core/user.ts index 34c14ea9..7e28ea84 100644 --- a/apps/web-ele/src/api/core/user.ts +++ b/apps/web-ele/src/api/core/user.ts @@ -5,6 +5,6 @@ import { requestClient } from '#/api/request'; /** * 获取用户信息 */ -export async function getUserInfo() { +export async function getUserInfoApi() { return requestClient.get('/user/info'); } diff --git a/apps/web-ele/src/router/access.ts b/apps/web-ele/src/router/access.ts index a123006f..2d07c892 100644 --- a/apps/web-ele/src/router/access.ts +++ b/apps/web-ele/src/router/access.ts @@ -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, diff --git a/apps/web-ele/src/store/auth.ts b/apps/web-ele/src/store/auth.ts index 0e711773..c2aeef5c 100644 --- a/apps/web-ele/src/store/auth.ts +++ b/apps/web-ele/src/store/auth.ts @@ -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; } diff --git a/apps/web-naive/src/api/core/auth.ts b/apps/web-naive/src/api/core/auth.ts index 6950e3bf..548e9dc9 100644 --- a/apps/web-naive/src/api/core/auth.ts +++ b/apps/web-naive/src/api/core/auth.ts @@ -21,13 +21,13 @@ export namespace AuthApi { /** * 登录 */ -export async function login(data: AuthApi.LoginParams) { +export async function loginApi(data: AuthApi.LoginParams) { return requestClient.post('/auth/login', data); } /** * 获取用户权限码 */ -export async function getAccessCodes() { +export async function getAccessCodesApi() { return requestClient.get('/auth/codes'); } diff --git a/apps/web-naive/src/api/core/menu.ts b/apps/web-naive/src/api/core/menu.ts index 62c40f17..9ef60b11 100644 --- a/apps/web-naive/src/api/core/menu.ts +++ b/apps/web-naive/src/api/core/menu.ts @@ -5,6 +5,6 @@ import { requestClient } from '#/api/request'; /** * 获取用户所有菜单 */ -export async function getAllMenus() { +export async function getAllMenusApi() { return requestClient.get('/menu/all'); } diff --git a/apps/web-naive/src/api/core/user.ts b/apps/web-naive/src/api/core/user.ts index 34c14ea9..7e28ea84 100644 --- a/apps/web-naive/src/api/core/user.ts +++ b/apps/web-naive/src/api/core/user.ts @@ -5,6 +5,6 @@ import { requestClient } from '#/api/request'; /** * 获取用户信息 */ -export async function getUserInfo() { +export async function getUserInfoApi() { return requestClient.get('/user/info'); } diff --git a/apps/web-naive/src/router/access.ts b/apps/web-naive/src/router/access.ts index 503a645c..dc90e891 100644 --- a/apps/web-naive/src/router/access.ts +++ b/apps/web-naive/src/router/access.ts @@ -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, diff --git a/apps/web-naive/src/store/auth.ts b/apps/web-naive/src/store/auth.ts index 9ad87257..bb0c7587 100644 --- a/apps/web-naive/src/store/auth.ts +++ b/apps/web-naive/src/store/auth.ts @@ -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; } diff --git a/docs/src/guide/essentials/server.md b/docs/src/guide/essentials/server.md index ab764f9c..5fe13967 100644 --- a/docs/src/guide/essentials/server.md +++ b/docs/src/guide/essentials/server.md @@ -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('/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('/user', user); } -export async function saveUser(user: UserInfo) { +export async function saveUserApi(user: UserInfo) { return requestClient.put('/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(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(`/user/${user.id}`, user); } ```