feat: 创建反代网站支持直接选择应用 (#6044)
Some checks failed
sync2gitee / repo-sync (push) Failing after -7m31s

This commit is contained in:
zhengkunwang 2024-08-06 17:30:30 +08:00 committed by GitHub
parent f2a2c7996f
commit 5cf174be84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 84 additions and 26 deletions

View file

@ -20,6 +20,7 @@ type IAppInstallRepo interface {
WithDetailIdNotIn(detailIds []uint) DBOption WithDetailIdNotIn(detailIds []uint) DBOption
WithAppId(appId uint) DBOption WithAppId(appId uint) DBOption
WithAppIdsIn(appIds []uint) DBOption WithAppIdsIn(appIds []uint) DBOption
WithAppIdsNotIn(appIds []uint) DBOption
WithStatus(status string) DBOption WithStatus(status string) DBOption
WithServiceName(serviceName string) DBOption WithServiceName(serviceName string) DBOption
WithContainerName(containerName 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 { func (a *AppInstallRepo) WithStatus(status string) DBOption {
return func(g *gorm.DB) *gorm.DB { return func(g *gorm.DB) *gorm.DB {
return g.Where("status = ?", status) return g.Where("status = ?", status)

View file

@ -89,6 +89,7 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo
if req.Name != "" { if req.Name != "" {
opts = append(opts, commonRepo.WithLikeName(req.Name)) opts = append(opts, commonRepo.WithLikeName(req.Name))
} }
if len(req.Tags) != 0 { if len(req.Tags) != 0 {
tags, err := tagRepo.GetByKeys(req.Tags) tags, err := tagRepo.GetByKeys(req.Tags)
if err != nil { if err != nil {
@ -202,18 +203,31 @@ func (a *AppInstallService) SearchForWebsite(req request.AppInstalledSearch) ([]
opts []repo.DBOption opts []repo.DBOption
) )
if req.Type != "" { if req.Type != "" {
apps, err := appRepo.GetBy(appRepo.WithType(req.Type)) if req.Type == "proxy" {
if err != nil { phpApps, _ := appRepo.GetBy(appRepo.WithType("php"))
return nil, err 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...) installs, err = appInstallRepo.ListBy(opts...)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -121,6 +121,7 @@ export namespace App {
icon: string; icon: string;
canUpdate: boolean; canUpdate: boolean;
path: string; path: string;
httpPort?: number;
app: App; app: App;
} }

View file

@ -316,17 +316,39 @@
</el-col> </el-col>
</el-row> </el-row>
<el-form-item v-if="website.type === 'proxy'" :label="$t('website.proxyAddress')" prop="proxyAddress"> <el-row :gutter="20" v-if="website.type === 'proxy'">
<el-input v-model="website.proxyAddress" :placeholder="$t('website.proxyHelper')"> <el-col :span="12">
<template #prepend> <el-form-item :label="$t('website.proxyAddress')" prop="proxyAddress">
<el-select v-model="website.proxyProtocol" class="pre-select"> <el-input v-model="website.proxyAddress" :placeholder="$t('website.proxyHelper')">
<el-option label="http" value="http://" /> <template #prepend>
<el-option label="https" value="https://" /> <el-select v-model="website.proxyProtocol" class="pre-select">
<el-option :label="$t('website.other')" value="" /> <el-option label="http" value="http://" />
<el-option label="https" value="https://" />
<el-option :label="$t('website.other')" value="" />
</el-select>
</template>
</el-input>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item :label="$t('app.app')">
<el-select
v-model="website.appInstallId"
class="p-w-200"
filterable
@change="changeInstall"
>
<el-option
v-for="(appInstall, index) in appInstalls"
:key="index"
:label="appInstall.name"
:value="appInstall.id"
></el-option>
</el-select> </el-select>
</template> </el-form-item>
</el-input> </el-col>
</el-form-item> </el-row>
<el-form-item :label="$t('website.remark')" prop="remark"> <el-form-item :label="$t('website.remark')" prop="remark">
<el-input type="textarea" :rows="3" clearable v-model="website.remark" /> <el-input type="textarea" :rows="3" clearable v-model="website.remark" />
</el-form-item> </el-form-item>
@ -479,6 +501,10 @@ const changeType = (type: string) => {
case 'runtime': case 'runtime':
getRuntimes(); getRuntimes();
break; break;
case 'proxy':
website.value.proxyAddress = '';
searchAppInstalled('proxy');
break;
default: default:
website.value.appInstallId = undefined; website.value.appInstallId = undefined;
break; break;
@ -487,15 +513,25 @@ const changeType = (type: string) => {
versionExist.value = true; versionExist.value = true;
}; };
const searchAppInstalled = () => { const searchAppInstalled = (appType: string) => {
GetAppInstalled({ type: 'website', unused: true, all: true, page: 1, pageSize: 100 }).then((res) => { GetAppInstalled({ type: appType, unused: true, all: true, page: 1, pageSize: 100 }).then((res) => {
appInstalls.value = res.data; 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; 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 = () => { const searchApp = () => {
SearchApp(appReq).then((res) => { SearchApp(appReq).then((res) => {
apps.value = res.data.items; apps.value = res.data.items;
@ -594,14 +630,14 @@ const acceptParams = async (installPath: string) => {
website.value.type = 'deployment'; website.value.type = 'deployment';
runtimeResource.value = 'appstore'; runtimeResource.value = 'appstore';
searchAppInstalled(); searchAppInstalled('website');
open.value = true; open.value = true;
}; };
const changeAppType = (type: string) => { const changeAppType = (type: string) => {
if (type === 'installed') { if (type === 'installed') {
searchAppInstalled(); searchAppInstalled('website');
} else { } else {
searchApp(); searchApp();
} }