From ff2b4d030efd09e1a74a6daa1dfe3ba2907936c9 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Tue, 22 Nov 2022 22:47:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/app_install.go | 2 +- backend/app/dto/app.go | 12 +- backend/app/repo/app_install.go | 5 +- backend/app/repo/common.go | 5 +- backend/app/service/app_install.go | 23 ++- backend/router/ro_app.go | 2 +- frontend/src/api/interface/app.ts | 5 + frontend/src/components/app-status/index.vue | 141 ++++++++++++++++++ frontend/src/lang/modules/zh.ts | 5 + frontend/src/layout/index.scss | 7 +- .../src/views/app-store/installed/index.vue | 30 ---- frontend/src/views/website/website/index.vue | 67 +++++---- 12 files changed, 230 insertions(+), 74 deletions(-) create mode 100644 frontend/src/components/app-status/index.vue diff --git a/backend/app/api/v1/app_install.go b/backend/app/api/v1/app_install.go index f2184c027..ab286213c 100644 --- a/backend/app/api/v1/app_install.go +++ b/backend/app/api/v1/app_install.go @@ -39,7 +39,7 @@ func (b *BaseApi) SearchAppInstalled(c *gin.Context) { } } -func (b *BaseApi) CheckAppInstalld(c *gin.Context) { +func (b *BaseApi) CheckAppInstalled(c *gin.Context) { key, ok := c.Params.Get("key") if !ok { helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, errors.New("error key in path")) diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index 1bbf77617..412571cb5 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -2,6 +2,7 @@ package dto import ( "encoding/json" + "time" "github.com/1Panel-dev/1Panel/backend/app/model" ) @@ -40,9 +41,14 @@ type AppInstallRequest struct { } type CheckInstalled struct { - IsExist bool `json:"isExist"` - Name string `json:"name"` - Version string `json:"version"` + IsExist bool `json:"isExist"` + Name string `json:"name"` + App string `json:"app"` + Version string `json:"version"` + Status string `json:"status"` + CreatedAt time.Time `json:"createdAt"` + LastBackupAt string `json:"lastBackupAt"` + AppInstallID uint `json:"appInstallId"` } type AppInstalled struct { diff --git a/backend/app/repo/app_install.go b/backend/app/repo/app_install.go index 2701ac166..73711770c 100644 --- a/backend/app/repo/app_install.go +++ b/backend/app/repo/app_install.go @@ -54,7 +54,10 @@ func (a AppInstallRepo) GetBy(opts ...DBOption) ([]model.AppInstall, error) { func (a AppInstallRepo) GetFirst(opts ...DBOption) (model.AppInstall, error) { var install model.AppInstall db := getDb(opts...).Model(&model.AppInstall{}) - err := db.Preload("App").Preload("Backups").First(&install).Error + err := db.Preload("App").Preload("Backups", func(db *gorm.DB) *gorm.DB { + db = db.Order("created_at desc") + return db + }).First(&install).Error return install, err } diff --git a/backend/app/repo/common.go b/backend/app/repo/common.go index 103afba34..aa3272d88 100644 --- a/backend/app/repo/common.go +++ b/backend/app/repo/common.go @@ -76,10 +76,9 @@ func getTx(ctx context.Context, opts ...DBOption) *gorm.DB { for _, opt := range opts { tx = opt(tx) } - } else { - return getDb(opts...) + return tx } - return tx + return getDb(opts...) } func getDb(opts ...DBOption) *gorm.DB { diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index e16d17cab..cde3c1832 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path" + "reflect" "strconv" "strings" @@ -38,15 +39,29 @@ func (a AppInstallService) Page(req dto.AppInstalledRequest) (int64, []dto.AppIn } func (a AppInstallService) CheckExist(key string) (*dto.CheckInstalled, error) { + res := &dto.CheckInstalled{ + IsExist: false, + } app, err := appRepo.GetFirst(appRepo.WithKey(key)) if err != nil { - return &dto.CheckInstalled{IsExist: false}, nil + return res, nil } appInstall, _ := appInstallRepo.GetFirst(appInstallRepo.WithAppId(app.ID)) - if appInstall.ID != 0 { - return &dto.CheckInstalled{Name: appInstall.Name, IsExist: true, Version: appInstall.Version}, nil + if reflect.DeepEqual(appInstall, model.AppInstall{}) { + return res, nil } - return &dto.CheckInstalled{IsExist: false}, nil + res.Name = appInstall.Name + res.App = app.Name + res.Version = appInstall.Version + res.CreatedAt = appInstall.CreatedAt + res.Status = appInstall.Status + res.AppInstallID = appInstall.ID + res.IsExist = true + if len(appInstall.Backups) > 0 { + res.LastBackupAt = appInstall.Backups[0].CreatedAt.Format("2006-01-02 15:04:05") + } + + return res, nil } func (a AppInstallService) Search(req dto.AppInstalledRequest) ([]dto.AppInstalled, error) { diff --git a/backend/router/ro_app.go b/backend/router/ro_app.go index b20ee65fe..e39b137d1 100644 --- a/backend/router/ro_app.go +++ b/backend/router/ro_app.go @@ -21,7 +21,7 @@ func (a *AppRouter) InitAppRouter(Router *gin.RouterGroup) { appRouter.GET("/detail/:appId/:version", baseApi.GetAppDetail) appRouter.POST("/install", baseApi.InstallApp) appRouter.GET("/installed/:appInstallId/versions", baseApi.GetUpdateVersions) - appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalld) + appRouter.GET("/installed/check/:key", baseApi.CheckAppInstalled) appRouter.POST("/installed", baseApi.SearchAppInstalled) appRouter.POST("/installed/op", baseApi.OperateInstalled) appRouter.POST("/installed/sync", baseApi.SyncInstalled) diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 9713ffb4f..d4876eadd 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -86,6 +86,11 @@ export namespace App { name: string; version: string; isExist: boolean; + app: string; + status: string; + createdAt: string; + lastBackupAt: string; + appInstallId: number; } export interface AppInstalledOp { diff --git a/frontend/src/components/app-status/index.vue b/frontend/src/components/app-status/index.vue new file mode 100644 index 000000000..8042cab75 --- /dev/null +++ b/frontend/src/components/app-status/index.vue @@ -0,0 +1,141 @@ + + + + diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 2ac589a94..fe2ce192f 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -687,8 +687,11 @@ export default { update: '升级', versioneSelect: '请选择版本', operatorHelper: '将对选中应用进行 {0} 操作,是否继续?', + checkInstalledWarn: '未检测到', + gotoInstalled: '去安装', }, website: { + website: '网站', primaryDomain: '主域名', otherDomains: '其他域名', type: '类型', @@ -747,5 +750,7 @@ export default { config: '配置', enableHTTPS: '启用HTTPS', aliasHelper: '代号是网站目录的文件夹名称', + lastBackupAt: '上次备份时间', + null: '无', }, }; diff --git a/frontend/src/layout/index.scss b/frontend/src/layout/index.scss index a858c3f4e..cc8f0f7e2 100644 --- a/frontend/src/layout/index.scss +++ b/frontend/src/layout/index.scss @@ -18,15 +18,16 @@ /* 防止切换出现横向滚动条 */ overflow-x: hidden; - background: #f0f2f5; + // background-color: #f0f2f5; + // background: #f0f2f5; .main-box { box-sizing: border-box; width: 100%; height: 100%; - padding: 15px; + padding: 5px; overflow: auto; overflow-x: hidden !important; - background-color: #ffffff; + // background-color: #f0f2f5; border-radius: 4px; // box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%); &::-webkit-scrollbar { diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 1f533cd14..457f82b2d 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -57,13 +57,6 @@ /> -

{{ $t('app.versioneSelect') }}

@@ -198,29 +191,6 @@ const onOperate = async (operation: string) => { }); }; -// const getMsg = (op: string) => { -// let tip = ''; -// switch (op) { -// case 'up': -// tip = i18n.global.t('app.up'); -// break; -// case 'down': -// tip = i18n.global.t('app.down'); -// break; -// case 'restart': -// tip = i18n.global.t('app.restart'); -// break; -// case 'delete': -// tip = i18n.global.t('app.deleteWarn'); -// break; -// case 'sync': -// tip = i18n.global.t('app.sync'); -// break; -// default: -// } -// return tip; -// }; - const buttons = [ { label: i18n.global.t('app.sync'), diff --git a/frontend/src/views/website/website/index.vue b/frontend/src/views/website/website/index.vue index 252430557..7f0f1f11a 100644 --- a/frontend/src/views/website/website/index.vue +++ b/frontend/src/views/website/website/index.vue @@ -1,33 +1,42 @@ + + + + + + + + + + + + + + + +