Skip to content

Commit

Permalink
feat: alova.js替换axios
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Feb 5, 2025
1 parent 4632cf7 commit 645e6d6
Show file tree
Hide file tree
Showing 17 changed files with 99 additions and 152 deletions.
6 changes: 3 additions & 3 deletions web/src/api/apps/gitea/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { request } from '@/utils'
import { http } from '@/utils'

export default {
// 获取配置
config: (): any => request.get('/apps/gitea/config'),
config: (): any => http.Get('/apps/gitea/config'),
// 保存配置
saveConfig: (config: string): any => request.post('/apps/gitea/config', { config })
saveConfig: (config: string): any => http.Post('/apps/gitea/config', { config })
}
11 changes: 5 additions & 6 deletions web/src/api/apps/memcached/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { http } from '@/utils'

// 负载状态
export const getLoad = () => http.Get('/apps/memcached/load')
// 获取配置
export const getConfig = () => http.Get('/apps/memcached/config')
// 保存配置
export const updateConfig = (config: string) => http.Post('/apps/memcached/config', { config })
export default {
getLoad: (): any => http.Get('/apps/memcached/load'),
getConfig: (): any => http.Get('/apps/memcached/config'),
updateConfig: (config: string): any => http.Post('/apps/memcached/config', { config })
}
18 changes: 9 additions & 9 deletions web/src/api/panel/systemctl/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { request } from '@/utils'
import { http } from '@/utils'

export default {
// 服务状态
status: (service: string): any => request.get('/systemctl/status', { params: { service } }),
status: (service: string): any => http.Get('/systemctl/status', { params: { service } }),
// 是否启用服务
isEnabled: (service: string): any => request.get('/systemctl/isEnabled', { params: { service } }),
isEnabled: (service: string): any => http.Get('/systemctl/isEnabled', { params: { service } }),
// 启用服务
enable: (service: string): any => request.post('/systemctl/enable', { service }),
enable: (service: string): any => http.Post('/systemctl/enable', { service }),
// 禁用服务
disable: (service: string): any => request.post('/systemctl/disable', { service }),
disable: (service: string): any => http.Post('/systemctl/disable', { service }),
// 重启服务
restart: (service: string): any => request.post('/systemctl/restart', { service }),
restart: (service: string): any => http.Post('/systemctl/restart', { service }),
// 重载服务
reload: (service: string): any => request.post('/systemctl/reload', { service }),
reload: (service: string): any => http.Post('/systemctl/reload', { service }),
// 启动服务
start: (service: string): any => request.post('/systemctl/start', { service }),
start: (service: string): any => http.Post('/systemctl/start', { service }),
// 停止服务
stop: (service: string): any => request.post('/systemctl/stop', { service })
stop: (service: string): any => http.Post('/systemctl/stop', { service })
}
37 changes: 18 additions & 19 deletions web/src/views/apps/docker/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,38 @@ const statusStr = computed(() => {
})
const getStatus = async () => {
await systemctl.status('docker').then((res: any) => {
status.value = res.data
})
status.value = await systemctl.status('docker')
}
const getIsEnabled = async () => {
await systemctl.isEnabled('docker').then((res: any) => {
isEnabled.value = res.data
})
isEnabled.value = await systemctl.isEnabled('docker')
}
const handleSaveConfig = async () => {
useRequest(() => docker.updateConfig(config.value)).onSuccess(() => {
useRequest(docker.updateConfig(config.value)).onSuccess(() => {
window.$message.success('保存成功')
})
}
const handleStart = async () => {
await systemctl.start('docker')
window.$message.success('启动成功')
await getStatus()
const handleStart = () => {
useRequest(systemctl.start('docker')).onSuccess(() => {
window.$message.success('启动成功')
getStatus()
})
}
const handleStop = async () => {
await systemctl.stop('docker')
window.$message.success('停止成功')
await getStatus()
const handleStop = () => {
useRequest(systemctl.stop('docker')).onSuccess(() => {
window.$message.success('停止成功')
getStatus()
})
}
const handleRestart = async () => {
await systemctl.restart('docker')
window.$message.success('重启成功')
await getStatus()
const handleRestart = () => {
useRequest(systemctl.restart('docker')).onSuccess(() => {
window.$message.success('重启成功')
getStatus()
})
}
const handleIsEnabled = async () => {
Expand Down
37 changes: 18 additions & 19 deletions web/src/views/apps/fail2ban/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,11 @@ const { loading, data, page, total, pageSize, pageCount, refresh } = usePaginati
)
const getStatus = async () => {
await systemctl.status('fail2ban').then((res: any) => {
status.value = res.data
})
status.value = await systemctl.status('fail2ban')
}
const getIsEnabled = async () => {
await systemctl.isEnabled('fail2ban').then((res: any) => {
isEnabled.value = res.data
})
isEnabled.value = await systemctl.isEnabled('fail2ban')
}
const handleStart = async () => {
Expand Down Expand Up @@ -241,17 +237,19 @@ const handleReload = async () => {
await getStatus()
}
const handleAddJail = async () => {
await fail2ban.add(addJailModel.value)
await refresh()
window.$message.success('添加成功')
addJailModal.value = false
const handleAddJail = () => {
useRequest(fail2ban.add(addJailModel.value)).onSuccess(() => {
refresh()
window.$message.success('添加成功')
addJailModal.value = false
})
}
const handleDeleteJail = async (name: string) => {
await fail2ban.delete(name)
await refresh()
window.$message.success('删除成功')
const handleDeleteJail = (name: string) => {
useRequest(fail2ban.delete(name)).onSuccess(() => {
refresh()
window.$message.success('删除成功')
})
}
const getJailInfo = async (name: string) => {
Expand All @@ -261,10 +259,11 @@ const getJailInfo = async (name: string) => {
jailBanedList.value = data.baned_list
}
const handleUnBan = async (name: string, ip: string) => {
await fail2ban.unban(name, ip)
window.$message.success('解封成功')
await getJailInfo(name)
const handleUnBan = (name: string, ip: string) => {
useRequest(fail2ban.unban(name, ip)).onSuccess(() => {
window.$message.success('解封成功')
getJailInfo(name)
})
}
onMounted(() => {
Expand Down
25 changes: 10 additions & 15 deletions web/src/views/apps/frp/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,26 @@ const statusStr = computed(() => {
})
const getStatus = async () => {
await systemctl.status('frps').then((res: any) => {
status.value.frps = res.data
})
await systemctl.status('frpc').then((res: any) => {
status.value.frpc = res.data
})
status.value.frps = await systemctl.status('frps')
status.value.frpc = await systemctl.status('frpc')
}
const getIsEnabled = async () => {
await systemctl.isEnabled('frps').then((res: any) => {
isEnabled.value.frps = res.data
})
await systemctl.isEnabled('frpc').then((res: any) => {
isEnabled.value.frpc = res.data
})
isEnabled.value.frps = await systemctl.isEnabled('frps')
isEnabled.value.frpc = await systemctl.isEnabled('frpc')
}
const getConfig = async () => {
config.value.frps = await frp.config('frps')
config.value.frpc = await frp.config('frpc')
}
const handleSaveConfig = async (service: string) => {
await frp.saveConfig(service, config.value[service as keyof typeof config.value])
window.$message.success('保存成功')
const handleSaveConfig = (service: string) => {
useRequest(frp.saveConfig(service, config.value[service as keyof typeof config.value])).onSuccess(
() => {
window.$message.success('保存成功')
}
)
}
const handleStart = async (name: string) => {
Expand Down
19 changes: 7 additions & 12 deletions web/src/views/apps/gitea/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,21 @@ const statusStr = computed(() => {
})
const getStatus = async () => {
await systemctl.status('gitea').then((res: any) => {
status.value = res.data
})
status.value = await systemctl.status('gitea')
}
const getIsEnabled = async () => {
await systemctl.isEnabled('gitea').then((res: any) => {
isEnabled.value = res.data
})
isEnabled.value = await systemctl.isEnabled('gitea')
}
const getConfig = async () => {
gitea.config().then((res: any) => {
config.value = res.data
})
config.value = await gitea.config()
}
const handleSaveConfig = async () => {
await gitea.saveConfig(config.value)
window.$message.success('保存成功')
const handleSaveConfig = () => {
useRequest(gitea.saveConfig(config.value)).onSuccess(() => {
window.$message.success('保存成功')
})
}
const handleStart = async () => {
Expand Down
18 changes: 7 additions & 11 deletions web/src/views/apps/memcached/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defineOptions({
import Editor from '@guolao/vue-monaco-editor'
import { NButton, NDataTable, NPopconfirm } from 'naive-ui'
import { getConfig, getLoad, updateConfig } from '@/api/apps/memcached'
import memcached from '@/api/apps/memcached'
import systemctl from '@/api/panel/systemctl'
const currentTab = ref('status')
Expand Down Expand Up @@ -36,30 +36,26 @@ const loadColumns: any = [
}
]
const { data: load }: { data: any } = useRequest(getLoad, {
const { data: load } = useRequest(memcached.getLoad, {
initialData: []
})
const getStatus = async () => {
await systemctl.status('memcached').then((res: any) => {
status.value = res.data
})
status.value = await systemctl.status('memcached')
}
const getIsEnabled = async () => {
await systemctl.isEnabled('memcached').then((res: any) => {
isEnabled.value = res.data
})
isEnabled.value = await systemctl.isEnabled('memcached')
}
const { data: config }: { data: any } = useRequest(getConfig, {
const { data: config } = useRequest(memcached.getConfig, {
initialData: {
config: ''
}
})
const handleSaveConfig = async () => {
useRequest(() => updateConfig(config.value)).onSuccess(() => {
const handleSaveConfig = () => {
useRequest(memcached.updateConfig(config.value)).onSuccess(() => {
window.$message.success('保存成功')
})
}
Expand Down
12 changes: 4 additions & 8 deletions web/src/views/apps/mysql/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,12 @@ const getLoad = async () => {
return data
}
const getIsEnabled = async () => {
await systemctl.isEnabled('mysqld').then((res: any) => {
isEnabled.value = res.data
})
const getStatus = async () => {
status.value = await systemctl.status('mysqld')
}
const getStatus = async () => {
await systemctl.status('mysqld').then((res: any) => {
status.value = res.data
})
const getIsEnabled = async () => {
isEnabled.value = await systemctl.isEnabled('mysqld')
}
const getRootPassword = async () => {
Expand Down
8 changes: 2 additions & 6 deletions web/src/views/apps/nginx/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@ const getLoad = async () => {
}
const getStatus = async () => {
await systemctl.status('nginx').then((res: any) => {
status.value = res.data
})
status.value = await systemctl.status('nginx')
}
const getIsEnabled = async () => {
await systemctl.isEnabled('nginx').then((res: any) => {
isEnabled.value = res.data
})
isEnabled.value = await systemctl.isEnabled('nginx')
}
const getErrorLog = async () => {
Expand Down
8 changes: 2 additions & 6 deletions web/src/views/apps/php/PhpView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,11 @@ const getExtensions = async () => {
}
const getStatus = async () => {
await systemctl.status(`php-fpm-${version.value}`).then((res: any) => {
status.value = res.data
})
status.value = await systemctl.status(`php-fpm-${version.value}`)
}
const getIsEnabled = async () => {
await systemctl.isEnabled(`php-fpm-${version.value}`).then((res: any) => {
isEnabled.value = res.data
})
isEnabled.value = await systemctl.isEnabled(`php-fpm-${version.value}`)
}
const getErrorLog = async () => {
Expand Down
8 changes: 2 additions & 6 deletions web/src/views/apps/podman/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ const statusStr = computed(() => {
})
const getStatus = async () => {
await systemctl.status('podman').then((res: any) => {
status.value = res.data
})
status.value = await systemctl.status('podman')
}
const getIsEnabled = async () => {
await systemctl.isEnabled('podman').then((res: any) => {
isEnabled.value = res.data
})
isEnabled.value = await systemctl.isEnabled('podman')
}
const getConfig = async () => {
Expand Down
12 changes: 4 additions & 8 deletions web/src/views/apps/postgresql/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,12 @@ const getLoad = async () => {
return data
}
const getIsEnabled = async () => {
await systemctl.isEnabled('postgresql').then((res: any) => {
isEnabled.value = res.data
})
const getStatus = async () => {
status.value = await systemctl.status('postgresql')
}
const getStatus = async () => {
await systemctl.status('postgresql').then((res: any) => {
status.value = res.data
})
const getIsEnabled = async () => {
isEnabled.value = await systemctl.isEnabled('postgresql')
}
const getLog = async () => {
Expand Down
Loading

0 comments on commit 645e6d6

Please sign in to comment.