From e83bc0b675bc037836f55dc3b87b1fd1b9f13f02 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Tue, 31 Jan 2023 15:22:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A7=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=85=A8=E5=B1=80=20loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/auth.go | 5 + backend/app/api/v1/setting.go | 10 + backend/constant/errs.go | 1 + backend/cron/job/monitor.go | 8 +- backend/init/router/router.go | 1 + backend/middleware/loading.go | 24 +++ backend/router/ro_setting.go | 1 + backend/utils/ssh/ssh.go | 2 +- frontend/src/api/index.ts | 9 + frontend/src/api/modules/setting.ts | 3 + frontend/src/components/app-layout/index.vue | 47 ++++- frontend/src/enums/http-enum.ts | 1 + frontend/src/lang/modules/en.ts | 7 +- frontend/src/lang/modules/zh.ts | 7 +- frontend/src/store/index.ts | 9 + frontend/src/store/interface/index.ts | 2 + frontend/src/views/cronjob/operate/index.vue | 3 + frontend/src/views/host/monitor/index.vue | 20 +- .../views/setting/backup-account/index.vue | 184 +++++++++--------- frontend/src/views/setting/safe/index.vue | 2 - frontend/src/views/setting/snapshot/index.vue | 6 +- 21 files changed, 237 insertions(+), 115 deletions(-) create mode 100644 backend/middleware/loading.go diff --git a/backend/app/api/v1/auth.go b/backend/app/api/v1/auth.go index 319557b9c..c6eb55840 100644 --- a/backend/app/api/v1/auth.go +++ b/backend/app/api/v1/auth.go @@ -137,6 +137,11 @@ func (b *BaseApi) SafeEntrance(c *gin.Context) { helper.SuccessWithData(c, nil) } +// @Tags Auth +// @Summary Check is First login +// @Description 判断是否为首次登录 +// @Success 200 +// @Router /auth/status [get] func (b *BaseApi) CheckIsFirstLogin(c *gin.Context) { helper.SuccessWithData(c, authService.CheckIsFirst()) } diff --git a/backend/app/api/v1/setting.go b/backend/app/api/v1/setting.go index 7bc5ff8c9..ff0ac9913 100644 --- a/backend/app/api/v1/setting.go +++ b/backend/app/api/v1/setting.go @@ -28,6 +28,16 @@ func (b *BaseApi) GetSettingInfo(c *gin.Context) { helper.SuccessWithData(c, setting) } +// @Tags System Setting +// @Summary Load system available status +// @Description 获取系统可用状态 +// @Success 200 +// @Security ApiKeyAuth +// @Router /settings/search/available [get] +func (b *BaseApi) GetSystemAvailable(c *gin.Context) { + helper.SuccessWithData(c, nil) +} + // @Tags System Setting // @Summary Update system setting // @Description 更新系统配置 diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 98d597d3c..4bccaafe7 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -13,6 +13,7 @@ const ( CodeErrNotFound = 404 CodePasswordExpired = 405 CodeAuth = 406 + CodeGlobalLoading = 407 CodeErrInternalServer = 500 CodeErrHeader = 406 ) diff --git a/backend/cron/job/monitor.go b/backend/cron/job/monitor.go index 3802b732f..60c77fb2c 100644 --- a/backend/cron/job/monitor.go +++ b/backend/cron/job/monitor.go @@ -43,7 +43,7 @@ func (m *monitor) Run() { itemModel.Memory = memoryInfo.UsedPercent if err := global.DB.Create(&itemModel).Error; err != nil { - global.LOG.Debug("create monitor base failed, err: %v", err) + global.LOG.Debugf("Insert basic monitoring data failed, err: %v", err) } ioStat, _ := disk.IOCounters() @@ -77,7 +77,7 @@ func (m *monitor) Run() { itemIO.Time = writeTime } if err := global.DB.Create(&itemIO).Error; err != nil { - global.LOG.Debug("create monitor io failed, err: %v", err) + global.LOG.Debugf("Insert io monitoring data failed, err: %v", err) } } @@ -96,7 +96,7 @@ func (m *monitor) Run() { itemNet.Up = float64(v.BytesSent-aheadData.BytesSent) / 1024 / stime itemNet.Down = float64(v.BytesRecv-aheadData.BytesRecv) / 1024 / stime if err := global.DB.Create(&itemNet).Error; err != nil { - global.LOG.Debug("create monitor network failed, err: %v", err) + global.LOG.Debugf("Insert network monitoring data failed, err: %v", err) } } netStatAll, _ := net.IOCounters(false) @@ -114,7 +114,7 @@ func (m *monitor) Run() { itemNet.Up = float64(netStatAll[0].BytesSent-aheadData.BytesSent) / 1024 / stime itemNet.Down = float64(netStatAll[0].BytesRecv-aheadData.BytesRecv) / 1024 / stime if err := global.DB.Create(&itemNet).Error; err != nil { - global.LOG.Debug("create monitor network all failed, err: %v", err) + global.LOG.Debugf("Insert network all monitoring data failed, err: %v", err) } } diff --git a/backend/init/router/router.go b/backend/init/router/router.go index 841521fb4..883e4e1cb 100644 --- a/backend/init/router/router.go +++ b/backend/init/router/router.go @@ -67,6 +67,7 @@ func Routers() *gin.Engine { } PrivateGroup := Router.Group("/api/v1") + PrivateGroup.Use(middleware.GlobalLoading()) //PrivateGroup.Use(middleware.SafetyAuth()) { systemRouter.InitBaseRouter(PrivateGroup) diff --git a/backend/middleware/loading.go b/backend/middleware/loading.go new file mode 100644 index 000000000..4de81b10a --- /dev/null +++ b/backend/middleware/loading.go @@ -0,0 +1,24 @@ +package middleware + +import ( + "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" + "github.com/1Panel-dev/1Panel/backend/app/repo" + "github.com/1Panel-dev/1Panel/backend/constant" + "github.com/gin-gonic/gin" +) + +func GlobalLoading() gin.HandlerFunc { + return func(c *gin.Context) { + settingRepo := repo.NewISettingRepo() + upgradeSetting, err := settingRepo.Get(settingRepo.WithByKey("SystemVersion")) + if err != nil { + helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err) + return + } + if upgradeSetting.Value == constant.StatusWaiting { + helper.ErrorWithDetail(c, constant.CodeGlobalLoading, "Upgrading", err) + return + } + c.Next() + } +} diff --git a/backend/router/ro_setting.go b/backend/router/ro_setting.go index a7a18bc2d..36047dbcf 100644 --- a/backend/router/ro_setting.go +++ b/backend/router/ro_setting.go @@ -16,6 +16,7 @@ func (s *SettingRouter) InitSettingRouter(Router *gin.RouterGroup) { baseApi := v1.ApiGroupApp.BaseApi { settingRouter.POST("/search", baseApi.GetSettingInfo) + settingRouter.GET("/search/available", baseApi.GetSystemAvailable) settingRouter.POST("/expired/handle", baseApi.HandlePasswordExpired) settingRouter.POST("/update", baseApi.UpdateSetting) settingRouter.POST("/port/update", baseApi.UpdatePort) diff --git a/backend/utils/ssh/ssh.go b/backend/utils/ssh/ssh.go index aa2058dfb..b33b76a5d 100644 --- a/backend/utils/ssh/ssh.go +++ b/backend/utils/ssh/ssh.go @@ -74,7 +74,7 @@ func (c *ConnInfo) Run(shell string) (string, error) { func (c *ConnInfo) Close() { if err := c.Client.Close(); err != nil { - global.LOG.Error("close ssh client failed, err: %v", err) + global.LOG.Errorf("close ssh client failed, err: %v", err) } } diff --git a/frontend/src/api/index.ts b/frontend/src/api/index.ts index 018999351..477e9f95a 100644 --- a/frontend/src/api/index.ts +++ b/frontend/src/api/index.ts @@ -58,6 +58,15 @@ class RequestHttp { router.push({ name: 'Expired' }); return data; } + if (data.code == ResultEnum.ERRGLOBALLOADDING) { + globalStore.setGlobalLoading(true); + globalStore.setLoadingText(data.message); + return; + } else { + if (globalStore.isLoading) { + globalStore.setGlobalLoading(false); + } + } if (data.code == ResultEnum.ERRAUTH) { return data; } diff --git a/frontend/src/api/modules/setting.ts b/frontend/src/api/modules/setting.ts index c72ef8e6a..fd64d7dfb 100644 --- a/frontend/src/api/modules/setting.ts +++ b/frontend/src/api/modules/setting.ts @@ -5,6 +5,9 @@ import { Setting } from '../interface/setting'; export const getSettingInfo = () => { return http.post(`/settings/search`); }; +export const getSystemAvailable = () => { + return http.get(`/settings/search/available`); +}; export const updateSetting = (param: Setting.SettingUpdate) => { return http.post(`/settings/update`, param); diff --git a/frontend/src/components/app-layout/index.vue b/frontend/src/components/app-layout/index.vue index 70084aa1e..72aa4204e 100644 --- a/frontend/src/components/app-layout/index.vue +++ b/frontend/src/components/app-layout/index.vue @@ -1,5 +1,5 @@