From bb9062f191aba431db6fe6c4cef7c8d65836c998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B4=9B=E5=B8=8C=E9=9B=85?= Date: Fri, 26 Apr 2024 17:25:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9api=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/example.ts | 12 --------- mock/excel.ts | 56 --------------------------------------- mock/table.ts | 31 ---------------------- src/api/menuManagement.ts | 28 -------------------- src/api/remote-search.ts | 17 ------------ src/api/roleManagement.ts | 39 +++++---------------------- src/api/router.ts | 2 +- src/api/user.ts | 24 ++++++++--------- src/api/userManagement.ts | 35 ++++-------------------- vite.config.ts | 20 +++++++------- 10 files changed, 35 insertions(+), 229 deletions(-) delete mode 100644 mock/example.ts delete mode 100644 mock/excel.ts delete mode 100644 mock/table.ts delete mode 100644 src/api/menuManagement.ts delete mode 100644 src/api/remote-search.ts diff --git a/mock/example.ts b/mock/example.ts deleted file mode 100644 index 4f04247..0000000 --- a/mock/example.ts +++ /dev/null @@ -1,12 +0,0 @@ -export default [ - { - url: '/getMapInfo', - method: 'get', - response: () => { - return { - code: 200, - title: 'mock请求测试' - } - } - } -] diff --git a/mock/excel.ts b/mock/excel.ts deleted file mode 100644 index c5ca37b..0000000 --- a/mock/excel.ts +++ /dev/null @@ -1,56 +0,0 @@ -import Mock from 'mockjs' - -const NameList: any = [] -const count = 100 - -for (let i = 0; i < count; i++) { - NameList.push( - Mock.mock({ - name: '@first' - }) - ) -} -NameList.push({ name: 'mock-Pan' }) - -export default [ - // username search - { - url: '/vue3-admin-plus/search/user', - method: 'get', - response: (config) => { - const { name } = config.query - const mockNameList = NameList.filter((item) => { - // @ts-ignore - const lowerCaseName = item.name.toLowerCase() - return !(name && !lowerCaseName.includes(name.toLowerCase())) - }) - return { - code: 20000, - data: { items: mockNameList } - } - } - }, - - // transaction list - { - url: '/vue3-admin-plus/transaction/list', - method: 'get', - response: () => { - return { - code: 20000, - data: { - total: 20, - 'items|20': [ - { - order_no: '@guid()', - timestamp: +Mock.Random.date('T'), - userName: '@name()', - price: '@float(1000, 15000, 0, 2)', - 'status|1': ['success', 'pending'] - } - ] - } - } - } - } -] diff --git a/mock/table.ts b/mock/table.ts deleted file mode 100644 index d5723e5..0000000 --- a/mock/table.ts +++ /dev/null @@ -1,31 +0,0 @@ -import Mock from 'mockjs' - -const data = Mock.mock({ - 'items|30': [ - { - id: '@id', - title: '@sentence(10, 20)', - 'status|1': ['published', 'draft', 'deleted'], - author: 'name', - display_time: '@datetime', - pageviews: '@integer(300, 5000)' - } - ] -}) - -export default [ - { - url: '/vue3-admin-template/table/list', - method: 'get', - response: () => { - const items = data.items - return { - code: 20000, - data: { - total: items.length, - items - } - } - } - } -] diff --git a/src/api/menuManagement.ts b/src/api/menuManagement.ts deleted file mode 100644 index e56bac5..0000000 --- a/src/api/menuManagement.ts +++ /dev/null @@ -1,28 +0,0 @@ -import request, { post } from '@/utils/request' - -export function getTree(data) { - return post('/menu/list', data) -} - -export function doAdd(data) { - return request({ - url: '/menu/create', - method: 'post', - data - }) -} -export function doUpdate(data) { - return request({ - url: '/menu/update', - method: 'post', - data - }) -} - -export function doDelete(data) { - return request({ - url: '/menu/destroy', - method: 'post', - data - }) -} diff --git a/src/api/remote-search.ts b/src/api/remote-search.ts deleted file mode 100644 index 457e9ae..0000000 --- a/src/api/remote-search.ts +++ /dev/null @@ -1,17 +0,0 @@ -import request from '@/utils/mock-axios-req' - -export function searchUser(name) { - return request({ - url: '/vue3-admin-plus/search/user', - method: 'get', - params: { name } - }) -} - -export function transactionList(query) { - return request({ - url: '/vue3-admin-plus/transaction/list', - method: 'get', - params: query - }) -} diff --git a/src/api/roleManagement.ts b/src/api/roleManagement.ts index 9a477f4..7e49f84 100644 --- a/src/api/roleManagement.ts +++ b/src/api/roleManagement.ts @@ -1,55 +1,30 @@ -import request from '@/utils/request' +import request, { post } from '@/utils/request' export function getList(data) { - return request({ - url: '/role/queryRoleByPage', - method: 'post', - data - }) + return post('/api/role/queryRoleByPage', data) } export function doAdd(data) { - return request({ - url: '/role/create', - method: 'post', - data - }) + return post('/api/role/create', data) } export function doUpdate(data) { - return request({ - url: '/role/update', - method: 'post', - data - }) + return post('/api/role/update', data) } export function doDelete(data) { - return request({ - url: '/role/destroy', - method: 'post', - data - }) + return post('/api/role/destroy', data) } /** * 获取角色列表 * @return {Promise>} */ export function getRoleList() { - return request({ - url: '/role/list', - method: 'post' - }) + return post('/api/role/list') } /** * 根据用户ID获取角色ID */ export function getRoleByUserId(userId) { - return request({ - url: '/userRole/getByUserId', - method: 'post', - data: { - userId - } - }) + return post('/api/userRole/getByUserId', { userId }) } diff --git a/src/api/router.ts b/src/api/router.ts index 9e66397..5b5c418 100644 --- a/src/api/router.ts +++ b/src/api/router.ts @@ -1,5 +1,5 @@ import { post } from '@/utils/request' export function getRouterList(data) { - return post('/menu/navigate', data) + return post('/api/menu/navigate', data) } diff --git a/src/api/user.ts b/src/api/user.ts index c6e055e..58c533e 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,5 +1,5 @@ //获取用户信息 -import request, { baseUrl, post } from '@/utils/request' +import request, { post } from '@/utils/request' export interface IUser { id: string @@ -23,29 +23,29 @@ export interface IUserRole { } export async function getMyInfo(): Promise { - return post('/user/myInfo') + return post('/api/user/myInfo') } export async function getMyRole(): Promise { - return post('/user/myRole') + return post('/api/user/myRole') } //登录 export async function login(data): Promise { - return post('/login', data) + return post('/api/login', data) } //退出登录 export async function logout(): Promise { - return post('/logout') + return post('/api/logout') } export async function getUser(idList): Promise { - return post('/user/get', { idList }) + return post('/api/user/get', { idList }) } export async function editUser(data: IUser) { - return post('/user/edit', data) + return post('/api/user/edit', data) } /** @@ -54,12 +54,12 @@ export async function editUser(data: IUser) { * @return {Promise} */ export function userSearching(keys) { - return post('/user/searching', { keys }) + return post('/api/user/searching', { keys }) } //修改密码 export function updatePassword(data: { id?; origin; target; session? }) { - return post('/user/updatePassword', data) + return post('/api/user/updatePassword', data) } //修改密码 @@ -67,17 +67,17 @@ export function setAvatar(id: string, avatar: Blob) { const form = new FormData() form.append('file', avatar, avatar instanceof File ? avatar.name : `${id}.jpg`) return request({ - url: `/user/avatar`, + url: `/api/user/avatar`, params: { id }, method: 'put', data: form - }) + }) as Promise } //修改密码 export function getAvatar(id: string): Promise { return request({ - url: `/user/avatar?id=${id}`, + url: `/api/user/avatar?id=${id}`, responseType: 'blob', headers: { 'Cache-Control': 'no-cache' diff --git a/src/api/userManagement.ts b/src/api/userManagement.ts index 34adc84..22c4b55 100644 --- a/src/api/userManagement.ts +++ b/src/api/userManagement.ts @@ -1,42 +1,17 @@ -import request from '@/utils/request' +import { post } from '@/utils/request' export function getList(data) { - return request({ - url: '/user/list', - method: 'post', - data - }) + return post('/api/user/list', data) } export function doEdit(data) { - return request({ - url: '/user/edit', - method: 'post', - data - }) + return post('/api/user/edit', data) } export function doCreate(data) { - return request({ - url: '/user/create', - method: 'post', - data - }) + return post('/api/user/create', data) } export function doDelete(data) { - return request({ - url: '/user/delete', - method: 'post', - data - }) -} - -// 查询学生信息 -export function getStudentInfoByStudentId(data) { - return request({ - url: '/user/getStudentInfoByStudentId', - method: 'post', - data - }) + return post('/api/user/delete', data) } diff --git a/vite.config.ts b/vite.config.ts index b2a9941..47b7f67 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -57,16 +57,16 @@ export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => { symbolId: 'icon-[dir]-[name]' }), //https://github.com/anncwb/vite-plugin-mock/blob/HEAD/README.zh_CN.md - viteMockServe({ - mockPath: 'mock', - localEnabled: command === 'serve', - prodEnabled: prodMock, - injectCode: ` - import { setupProdMockServer } from '../mock-prod-server'; - setupProdMockServer(); - `, - logger: true - } as ViteMockOptions), + // viteMockServe({ + // mockPath: 'mock', + // localEnabled: command === 'serve', + // prodEnabled: prodMock, + // injectCode: ` + // import { setupProdMockServer } from '../mock-prod-server'; + // setupProdMockServer(); + // `, + // logger: true + // } as ViteMockOptions), // VueSetupExtend(),using DefineOptions instant of it //https://github.com/antfu/unplugin-auto-import/blob/HEAD/src/types.ts Components({