From 4d77345ce00621f25a14e7e8bda0ab0ad011d236 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Wed, 8 Feb 2023 16:21:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BA=94=E7=94=A8=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9D=83=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/dto/app.go | 1 + backend/app/dto/request/app.go | 7 ++++--- backend/app/model/app.go | 1 + backend/app/repo/app.go | 12 ++++++++++++ backend/app/service/app.go | 11 +++++++++-- backend/app/service/app_utils.go | 2 +- frontend/src/api/interface/app.ts | 1 + frontend/src/views/app-store/detail/params/index.vue | 1 + frontend/src/views/home/app/index.vue | 1 + 9 files changed, 31 insertions(+), 6 deletions(-) diff --git a/backend/app/dto/app.go b/backend/app/dto/app.go index 3f2278f00..654243566 100644 --- a/backend/app/dto/app.go +++ b/backend/app/dto/app.go @@ -47,6 +47,7 @@ type AppDefine struct { Required []string `json:"Required"` CrossVersionUpdate bool `json:"crossVersionUpdate"` Limit int `json:"limit"` + Recommend int `json:"recommend"` Website string `json:"website"` Github string `json:"github"` Document string `json:"document"` diff --git a/backend/app/dto/request/app.go b/backend/app/dto/request/app.go index 7ca73ca56..d962c5293 100644 --- a/backend/app/dto/request/app.go +++ b/backend/app/dto/request/app.go @@ -7,9 +7,10 @@ import ( type AppSearch struct { dto.PageInfo - Name string `json:"name"` - Tags []string `json:"tags"` - Type string `json:"type"` + Name string `json:"name"` + Tags []string `json:"tags"` + Type string `json:"type"` + Recommend bool `json:"recommend"` } type AppInstallCreate struct { diff --git a/backend/app/model/app.go b/backend/app/model/app.go index a8863cf32..4f408b1b8 100644 --- a/backend/app/model/app.go +++ b/backend/app/model/app.go @@ -14,6 +14,7 @@ type App struct { Website string `json:"website" gorm:"type:varchar(64);not null"` Github string `json:"github" gorm:"type:varchar(64);not null"` Document string `json:"document" gorm:"type:varchar(64);not null"` + Recommend int `json:"recommend" gorm:"type:Integer;not null"` Details []AppDetail `json:"-"` TagsKey []string `json:"-" gorm:"-"` AppTags []AppTag `json:"-" ` diff --git a/backend/app/repo/app.go b/backend/app/repo/app.go index 824fa0660..e1d997017 100644 --- a/backend/app/repo/app.go +++ b/backend/app/repo/app.go @@ -22,6 +22,18 @@ func (a AppRepo) WithType(typeStr string) DBOption { } } +func (a AppRepo) OrderByRecommend() DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Order("recommend asc") + } +} + +func (a AppRepo) GetRecommend() DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("recommend < 9999") + } +} + func (a AppRepo) Page(page, size int, opts ...DBOption) (int64, []model.App, error) { var apps []model.App db := getDb(opts...).Model(&model.App{}) diff --git a/backend/app/service/app.go b/backend/app/service/app.go index f0052ae2c..4ed534643 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -27,13 +27,16 @@ type AppService struct { func (a AppService) PageApp(req request.AppSearch) (interface{}, error) { var opts []repo.DBOption - opts = append(opts, commonRepo.WithOrderBy("name")) + opts = append(opts, appRepo.OrderByRecommend()) if req.Name != "" { opts = append(opts, commonRepo.WithLikeName(req.Name)) } if req.Type != "" { opts = append(opts, appRepo.WithType(req.Type)) } + if req.Recommend { + opts = append(opts, appRepo.GetRecommend()) + } if len(req.Tags) != 0 { tags, err := tagRepo.GetByKeys(req.Tags) if err != nil { @@ -51,7 +54,6 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) { for _, t := range appTags { appIds = append(appIds, t.AppId) } - opts = append(opts, commonRepo.WithIdsIn(appIds)) } var res response.AppRes @@ -377,6 +379,11 @@ func (a AppService) SyncAppList() error { iconStr := base64.StdEncoding.EncodeToString(icon) app.Icon = iconStr app.TagsKey = l.Tags + if l.Recommend > 0 { + app.Recommend = l.Recommend + } else { + app.Recommend = 9999 + } versions := l.Versions detailsMap := getAppDetails(app.Details, versions) diff --git a/backend/app/service/app_utils.go b/backend/app/service/app_utils.go index e0b1130c6..a1c923cf1 100644 --- a/backend/app/service/app_utils.go +++ b/backend/app/service/app_utils.go @@ -77,7 +77,7 @@ func createLink(ctx context.Context, app model.App, appInstall *model.AppInstall appInstall.Param = string(authByte) } } - if app.Type == "website" { + if app.Type == "website" || app.Type == "tool" { paramByte, err := json.Marshal(params) if err != nil { return err diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index f1ef7a898..2719f5c24 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -43,6 +43,7 @@ export namespace App { name?: string; tags?: string[]; type?: string; + recommend?: boolean; } export interface AppParams { diff --git a/frontend/src/views/app-store/detail/params/index.vue b/frontend/src/views/app-store/detail/params/index.vue index 8407bac14..63f53240e 100644 --- a/frontend/src/views/app-store/detail/params/index.vue +++ b/frontend/src/views/app-store/detail/params/index.vue @@ -6,6 +6,7 @@ v-if="p.type == 'text'" :type="p.type" @change="updateParam" + :disabled="p.disabled" >