From 5cf174be84a5ed54901fa64d45e426cca6987f36 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:30:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=9B=E5=BB=BA=E5=8F=8D=E4=BB=A3?= =?UTF-8?q?=E7=BD=91=E7=AB=99=E6=94=AF=E6=8C=81=E7=9B=B4=E6=8E=A5=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=BA=94=E7=94=A8=20(#6044)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent/app/repo/app_install.go | 7 ++ agent/app/service/app_install.go | 36 ++++++---- frontend/src/api/interface/app.ts | 1 + .../views/website/website/create/index.vue | 66 ++++++++++++++----- 4 files changed, 84 insertions(+), 26 deletions(-) diff --git a/agent/app/repo/app_install.go b/agent/app/repo/app_install.go index 7176e6a7f..1b3c3ae68 100644 --- a/agent/app/repo/app_install.go +++ b/agent/app/repo/app_install.go @@ -20,6 +20,7 @@ type IAppInstallRepo interface { WithDetailIdNotIn(detailIds []uint) DBOption WithAppId(appId uint) DBOption WithAppIdsIn(appIds []uint) DBOption + WithAppIdsNotIn(appIds []uint) DBOption WithStatus(status string) DBOption WithServiceName(serviceName string) DBOption WithContainerName(containerName string) DBOption @@ -72,6 +73,12 @@ func (a *AppInstallRepo) WithAppIdsIn(appIds []uint) DBOption { } } +func (a *AppInstallRepo) WithAppIdsNotIn(appIds []uint) DBOption { + return func(g *gorm.DB) *gorm.DB { + return g.Where("app_id not in (?)", appIds) + } +} + func (a *AppInstallRepo) WithStatus(status string) DBOption { return func(g *gorm.DB) *gorm.DB { return g.Where("status = ?", status) diff --git a/agent/app/service/app_install.go b/agent/app/service/app_install.go index b45f06697..c12da544d 100644 --- a/agent/app/service/app_install.go +++ b/agent/app/service/app_install.go @@ -89,6 +89,7 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo if req.Name != "" { opts = append(opts, commonRepo.WithLikeName(req.Name)) } + if len(req.Tags) != 0 { tags, err := tagRepo.GetByKeys(req.Tags) if err != nil { @@ -202,18 +203,31 @@ func (a *AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([] opts []repo.DBOption ) if req.Type != "" { - apps, err := appRepo.GetBy(appRepo.WithType(req.Type)) - if err != nil { - return nil, err + if req.Type == "proxy" { + phpApps, _ := appRepo.GetBy(appRepo.WithType("php")) + var ids []uint + for _, app := range phpApps { + ids = append(ids, app.ID) + } + runtimeApps, _ := appRepo.GetBy(appRepo.WithType("runtime")) + for _, app := range runtimeApps { + ids = append(ids, app.ID) + } + opts = append(opts, appInstallRepo.WithAppIdsNotIn(ids)) + } else { + apps, err := appRepo.GetBy(appRepo.WithType(req.Type)) + if err != nil { + return nil, err + } + var ids []uint + for _, app := range apps { + ids = append(ids, app.ID) + } + if req.Unused { + opts = append(opts, appInstallRepo.WithIdNotInWebsite()) + } + opts = append(opts, appInstallRepo.WithAppIdsIn(ids)) } - var ids []uint - for _, app := range apps { - ids = append(ids, app.ID) - } - if req.Unused { - opts = append(opts, appInstallRepo.WithIdNotInWebsite()) - } - opts = append(opts, appInstallRepo.WithAppIdsIn(ids)) installs, err = appInstallRepo.ListBy(opts...) if err != nil { return nil, err diff --git a/frontend/src/api/interface/app.ts b/frontend/src/api/interface/app.ts index 2c353ce9d..0ec91eaf7 100644 --- a/frontend/src/api/interface/app.ts +++ b/frontend/src/api/interface/app.ts @@ -121,6 +121,7 @@ export namespace App { icon: string; canUpdate: boolean; path: string; + httpPort?: number; app: App; } diff --git a/frontend/src/views/website/website/create/index.vue b/frontend/src/views/website/website/create/index.vue index d7a9a4fec..5e9098d2b 100644 --- a/frontend/src/views/website/website/create/index.vue +++ b/frontend/src/views/website/website/create/index.vue @@ -316,17 +316,39 @@ - - - - - + + + + @@ -479,6 +501,10 @@ const changeType = (type: string) => { case 'runtime': getRuntimes(); break; + case 'proxy': + website.value.proxyAddress = ''; + searchAppInstalled('proxy'); + break; default: website.value.appInstallId = undefined; break; @@ -487,15 +513,25 @@ const changeType = (type: string) => { versionExist.value = true; }; -const searchAppInstalled = () => { - GetAppInstalled({ type: 'website', unused: true, all: true, page: 1, pageSize: 100 }).then((res) => { +const searchAppInstalled = (appType: string) => { + GetAppInstalled({ type: appType, unused: true, all: true, page: 1, pageSize: 100 }).then((res) => { appInstalls.value = res.data; - if (res.data && res.data.length > 0) { + website.value.appInstallId = undefined; + if (appType == 'website' && res.data && res.data.length > 0) { website.value.appInstallId = res.data[0].id; } }); }; +const changeInstall = () => { + appInstalls.value.forEach((app) => { + if (app.id === website.value.appInstallId) { + website.value.proxyProtocol = 'http://'; + website.value.proxyAddress = '127.0.0.1:' + app.httpPort; + } + }); +}; + const searchApp = () => { SearchApp(appReq).then((res) => { apps.value = res.data.items; @@ -594,14 +630,14 @@ const acceptParams = async (installPath: string) => { website.value.type = 'deployment'; runtimeResource.value = 'appstore'; - searchAppInstalled(); + searchAppInstalled('website'); open.value = true; }; const changeAppType = (type: string) => { if (type === 'installed') { - searchAppInstalled(); + searchAppInstalled('website'); } else { searchApp(); }