From d27a29151efd3de5e89669be0ee6b92a35b0317a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Thu, 6 Feb 2025 18:18:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20alova.js=E6=9B=BF=E6=8D=A2axios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/api/panel/backup/index.ts | 12 ++-- web/src/api/panel/dashboard/index.ts | 30 ++++----- web/src/api/panel/monitor/index.ts | 11 ++-- web/src/main.ts | 4 +- web/src/views/backup/IndexView.vue | 6 +- web/src/views/backup/ListView.vue | 76 +++++++++------------- web/src/views/backup/types.ts | 6 -- web/src/views/dashboard/IndexView.vue | 83 ++++++++++++------------ web/src/views/dashboard/UpdateView.vue | 24 ++----- web/src/views/dashboard/types.ts | 49 -------------- web/src/views/monitor/IndexView.vue | 88 ++++++++------------------ web/src/views/monitor/types.ts | 37 ----------- web/src/views/task/CreateModal.vue | 35 +++++----- web/src/views/website/EditView.vue | 39 +++++------- web/src/views/website/IndexView.vue | 34 +++++----- 15 files changed, 186 insertions(+), 348 deletions(-) delete mode 100644 web/src/views/backup/types.ts delete mode 100644 web/src/views/monitor/types.ts diff --git a/web/src/api/panel/backup/index.ts b/web/src/api/panel/backup/index.ts index 33d05cbe..875a16f4 100644 --- a/web/src/api/panel/backup/index.ts +++ b/web/src/api/panel/backup/index.ts @@ -1,22 +1,22 @@ -import { request } from '@/utils' +import { http } from '@/utils' export default { // 获取备份列表 list: (type: string, page: number, limit: number): any => - request.get(`/backup/${type}`, { params: { page, limit } }), + http.Get(`/backup/${type}`, { params: { page, limit } }), // 创建备份 create: (type: string, target: string, path: string): any => - request.post(`/backup/${type}`, { target, path }), + http.Post(`/backup/${type}`, { target, path }), // 上传备份 upload: (type: string, formData: FormData): any => { - return request.post(`/backup/${type}/upload`, formData, { + return http.Post(`/backup/${type}/upload`, formData, { headers: { 'Content-Type': 'multipart/form-data' } }) }, // 删除备份 delete: (type: string, file: string): any => - request.delete(`/backup/${type}/delete`, { data: { file } }), + http.Delete(`/backup/${type}/delete`, { data: { file } }), // 恢复备份 restore: (type: string, file: string, target: string): any => - request.post(`/backup/${type}/restore`, { file, target }) + http.Post(`/backup/${type}/restore`, { file, target }) } diff --git a/web/src/api/panel/dashboard/index.ts b/web/src/api/panel/dashboard/index.ts index 173a3165..cae8bbd0 100644 --- a/web/src/api/panel/dashboard/index.ts +++ b/web/src/api/panel/dashboard/index.ts @@ -1,33 +1,25 @@ -import { http, request } from '@/utils' - -import type { RequestConfig } from '~/types/axios' +import { http } from '@/utils' export default { // 面板信息 - panel: (): Promise => fetch('/api/dashboard/panel'), - // 面板菜单 - menu: (): any => request.get('/dashboard/menu'), + panel: (): any => http.Get('/dashboard/panel'), // 首页应用 - homeApps: (): any => request.get('/dashboard/homeApps'), + homeApps: (): any => http.Get('/dashboard/homeApps'), // 实时信息 current: (nets: string[], disks: string[]): any => - request.post('/dashboard/current', { nets, disks }, { noNeedTip: true } as RequestConfig), + http.Post('/dashboard/current', { nets, disks }, { meta: { noAlert: true } }), // 系统信息 - systemInfo: (): any => request.get('/dashboard/systemInfo'), + systemInfo: (): any => http.Get('/dashboard/systemInfo'), // 统计信息 - countInfo: (): any => request.get('/dashboard/countInfo'), + countInfo: (): any => http.Get('/dashboard/countInfo'), // 已安装的数据库和PHP - installedDbAndPhp: (): any => request.get('/dashboard/installedDbAndPhp'), + installedDbAndPhp: (): any => http.Get('/dashboard/installedDbAndPhp'), // 检查更新 - checkUpdate: (): any => request.get('/dashboard/checkUpdate'), + checkUpdate: (): any => http.Get('/dashboard/checkUpdate'), // 更新日志 - updateInfo: (): any => request.get('/dashboard/updateInfo'), + updateInfo: (): any => http.Get('/dashboard/updateInfo'), // 更新面板 - update: (): any => request.post('/dashboard/update', null), + update: (): any => http.Post('/dashboard/update'), // 重启面板 - restart: (): any => request.post('/dashboard/restart') + restart: (): any => http.Post('/dashboard/restart') } - -export const panel = () => http.Get('/dashboard/panel') -export const current = (nets: string[], disks: string[]) => - http.Post('/dashboard/current', { nets, disks }, { meta: { noAlert: true } }) diff --git a/web/src/api/panel/monitor/index.ts b/web/src/api/panel/monitor/index.ts index 07a9e83d..c21c2fdd 100644 --- a/web/src/api/panel/monitor/index.ts +++ b/web/src/api/panel/monitor/index.ts @@ -1,14 +1,13 @@ -import { request } from '@/utils' +import { http } from '@/utils' export default { // 开关 - setting: (): any => request.get('/monitor/setting'), + setting: (): any => http.Get('/monitor/setting'), // 保存天数 updateSetting: (enabled: boolean, days: number): any => - request.post('/monitor/setting', { enabled, days }), + http.Post('/monitor/setting', { enabled, days }), // 清空监控记录 - clear: (): any => request.post('/monitor/clear'), + clear: (): any => http.Post('/monitor/clear'), // 监控记录 - list: (start: number, end: number): any => - request.get('/monitor/list', { params: { start, end } }) + list: (start: number, end: number): any => http.Get('/monitor/list', { params: { start, end } }) } diff --git a/web/src/main.ts b/web/src/main.ts index 7d7e6747..5bc4b4e4 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -13,7 +13,7 @@ import { setupNaiveDiscreteApi } from './utils' import { install as VueMonacoEditorPlugin } from '@guolao/vue-monaco-editor' -import { panel } from '@/api/panel/dashboard' +import dashboard from '@/api/panel/dashboard' import CronNaivePlugin from '@vue-js-cron/naive-ui' async function setupApp() { @@ -38,7 +38,7 @@ async function setupApp() { const setupPanel = async () => { const themeStore = useThemeStore() - useRequest(panel, { + useRequest(dashboard.panel, { initialData: { name: import.meta.env.VITE_APP_TITLE, locale: 'zh_CN' diff --git a/web/src/views/backup/IndexView.vue b/web/src/views/backup/IndexView.vue index e490c27f..fdde1845 100644 --- a/web/src/views/backup/IndexView.vue +++ b/web/src/views/backup/IndexView.vue @@ -15,10 +15,12 @@ const createModel = ref({ }) const handleCreate = () => { - backup.create(currentTab.value, createModel.value.target, createModel.value.path).then(() => { + useRequest( + backup.create(currentTab.value, createModel.value.target, createModel.value.path) + ).onSuccess(() => { createModal.value = false - window.$message.success('创建成功') window.$bus.emit('backup:refresh') + window.$message.success('创建成功') }) } diff --git a/web/src/views/backup/ListView.vue b/web/src/views/backup/ListView.vue index a2791eb2..b45d594f 100644 --- a/web/src/views/backup/ListView.vue +++ b/web/src/views/backup/ListView.vue @@ -1,11 +1,9 @@