From 9d48e591afad02f1bc327263f1b984586f11dce3 Mon Sep 17 00:00:00 2001 From: ChengPlay <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 23 Apr 2025 15:44:59 +0800 Subject: [PATCH] fix(website): Add pinning feature for websites. (#8462) --- agent/app/dto/request/website.go | 3 +- agent/app/dto/response/website.go | 1 + agent/app/model/website.go | 2 + agent/app/service/website.go | 2 + agent/init/migration/migrate.go | 1 + agent/init/migration/migrations/init.go | 10 ++ frontend/src/api/interface/website.ts | 2 + frontend/src/lang/modules/en.ts | 2 + frontend/src/lang/modules/ja.ts | 2 + frontend/src/lang/modules/ko.ts | 2 + frontend/src/lang/modules/ms.ts | 2 + frontend/src/lang/modules/pt-br.ts | 2 + frontend/src/lang/modules/ru.ts | 2 + frontend/src/lang/modules/zh-Hant.ts | 2 + frontend/src/lang/modules/zh.ts | 2 + frontend/src/views/website/website/index.vue | 129 ++++++++++++++----- 16 files changed, 131 insertions(+), 35 deletions(-) diff --git a/agent/app/dto/request/website.go b/agent/app/dto/request/website.go index bb4ac4e80..35cb71882 100644 --- a/agent/app/dto/request/website.go +++ b/agent/app/dto/request/website.go @@ -7,7 +7,7 @@ import ( type WebsiteSearch struct { dto.PageInfo Name string `json:"name"` - OrderBy string `json:"orderBy" validate:"required,oneof=primary_domain type status createdAt expire_date created_at"` + OrderBy string `json:"orderBy" validate:"required,oneof=primary_domain type status createdAt expire_date created_at favorite"` Order string `json:"order" validate:"required,oneof=null ascending descending"` WebsiteGroupID uint `json:"websiteGroupId"` Type string `json:"type"` @@ -85,6 +85,7 @@ type WebsiteUpdate struct { WebsiteGroupID uint `json:"webSiteGroupID"` ExpireDate string `json:"expireDate"` IPV6 bool `json:"IPV6"` + Favorite bool `json:"favorite"` } type WebsiteDelete struct { diff --git a/agent/app/dto/response/website.go b/agent/app/dto/response/website.go index 449bd23d8..bfe63b8cc 100644 --- a/agent/app/dto/response/website.go +++ b/agent/app/dto/response/website.go @@ -35,6 +35,7 @@ type WebsiteRes struct { AppInstallID uint `json:"appInstallId"` ChildSites []string `json:"childSites"` RuntimeType string `json:"runtimeType"` + Favorite bool `json:"favorite"` } type WebsiteOption struct { diff --git a/agent/app/model/website.go b/agent/app/model/website.go index 729b8ad05..27426c40b 100644 --- a/agent/app/model/website.go +++ b/agent/app/model/website.go @@ -35,6 +35,8 @@ type Website struct { DbType string `json:"dbType"` DbID uint `json:"dbID"` + Favorite bool `json:"favorite"` + Domains []WebsiteDomain `json:"domains" gorm:"-:migration"` WebsiteSSL WebsiteSSL `json:"webSiteSSL" gorm:"-:migration"` } diff --git a/agent/app/service/website.go b/agent/app/service/website.go index e56b9961f..c4d5f447f 100644 --- a/agent/app/service/website.go +++ b/agent/app/service/website.go @@ -198,6 +198,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons SitePath: sitePath, AppInstallID: appInstallID, RuntimeType: runtimeType, + Favorite: web.Favorite, } sites, _ := websiteRepo.List(websiteRepo.WithParentID(web.ID)) @@ -529,6 +530,7 @@ func (w WebsiteService) UpdateWebsite(req request.WebsiteUpdate) error { website.WebsiteGroupID = req.WebsiteGroupID website.Remark = req.Remark website.IPV6 = req.IPV6 + website.Favorite = req.Favorite if req.ExpireDate != "" { expireDate, err := time.Parse(constant.DateLayout, req.ExpireDate) diff --git a/agent/init/migration/migrate.go b/agent/init/migration/migrate.go index 25517591b..6562f4a9f 100644 --- a/agent/init/migration/migrate.go +++ b/agent/init/migration/migrate.go @@ -31,6 +31,7 @@ func InitAgentDB() { migrations.AddLocalSSHSetting, migrations.AddAppIgnore, migrations.UpdateWebsiteSSL, + migrations.UpdateWebsite, }) if err := m.Migrate(); err != nil { global.LOG.Error(err) diff --git a/agent/init/migration/migrations/init.go b/agent/init/migration/migrations/init.go index f08fc6067..8686b1921 100644 --- a/agent/init/migration/migrations/init.go +++ b/agent/init/migration/migrations/init.go @@ -342,3 +342,13 @@ var UpdateWebsiteSSL = &gormigrate.Migration{ return nil }, } + +var UpdateWebsite = &gormigrate.Migration{ + ID: "20250424-update-website", + Migrate: func(tx *gorm.DB) error { + if err := tx.AutoMigrate(&model.Website{}); err != nil { + return err + } + return nil + }, +} diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index 94f9f5b5a..9f934d5b3 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -26,6 +26,7 @@ export namespace Website { childSites?: string[]; dbID: number; dbType: string; + favorite: boolean; } export interface WebsiteDTO extends Website { @@ -100,6 +101,7 @@ export namespace Website { webSiteGroupId: number; expireDate?: string; IPV6: boolean; + favorite: boolean; } export interface WebSiteOp { diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 0eda12433..179b3c1a3 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -2420,6 +2420,8 @@ const message = { cacheWarn: 'Please turn off the cache switch in the reverse proxy first', loadBalanceHelper: 'This section only creates load balancing rules, to use the rules please reverse proxy http(s)://', + favorite: 'Favorite', + cancelFavorite: 'Cancel Favorite', }, php: { short_open_tag: 'Short tag support', diff --git a/frontend/src/lang/modules/ja.ts b/frontend/src/lang/modules/ja.ts index 22489ecf2..ec79ba296 100644 --- a/frontend/src/lang/modules/ja.ts +++ b/frontend/src/lang/modules/ja.ts @@ -2327,6 +2327,8 @@ const message = { cacheWarn: 'まずリバースプロキシのキャッシュスイッチをオフにしてください', loadBalanceHelper: 'This section only creates load balancing rules, to use the rules please reverse proxy http(s)://', + favorite: 'お気に入り', + cancelFavorite: 'お気に入りを解除', }, php: { short_open_tag: '短いタグサポート', diff --git a/frontend/src/lang/modules/ko.ts b/frontend/src/lang/modules/ko.ts index 1f50fbec4..87c5ddb69 100644 --- a/frontend/src/lang/modules/ko.ts +++ b/frontend/src/lang/modules/ko.ts @@ -2288,6 +2288,8 @@ const message = { cacheWarn: '먼저 리버스 프록시의 캐시 스위치를 끄십시오', loadBalanceHelper: '여기서는 로드 밸런싱 규칙만 생성합니다. 규칙을 사용하려면 리버스 프록시 http(s)://<로드 밸런스 이름>을 사용하십시오', + favorite: '즐겨찾기', + cancelFavorite: '즐겨찾기 취소', }, php: { short_open_tag: '짧은 태그 지원', diff --git a/frontend/src/lang/modules/ms.ts b/frontend/src/lang/modules/ms.ts index bf01e88ac..a2e111bd8 100644 --- a/frontend/src/lang/modules/ms.ts +++ b/frontend/src/lang/modules/ms.ts @@ -2381,6 +2381,8 @@ const message = { cacheWarn: 'Sila matikan suis cache dalam pembalikan proksi terlebih dahulu', loadBalanceHelper: 'Di sini hanya mencipta peraturan keseimbangan beban, untuk menggunakan peraturan sila proksi terbalik http(s)://', + favorite: 'Kegemaran', + cancelFavorite: 'Batalkan Kegemaran', }, php: { short_open_tag: 'Sokongan tag pendek', diff --git a/frontend/src/lang/modules/pt-br.ts b/frontend/src/lang/modules/pt-br.ts index e4ed6f5b5..48cde115c 100644 --- a/frontend/src/lang/modules/pt-br.ts +++ b/frontend/src/lang/modules/pt-br.ts @@ -2377,6 +2377,8 @@ const message = { cacheWarn: 'Por favor, desligue o interruptor de cache no proxy reverso primeiro', loadBalanceHelper: 'Esta seção apenas cria regras de balanceamento de carga, para usar as regras, por favor, proxy reverso http(s)://', + favorite: 'Favorito', + cancelFavorite: 'Cancelar Favorito', }, php: { short_open_tag: 'Suporte para short tags', diff --git a/frontend/src/lang/modules/ru.ts b/frontend/src/lang/modules/ru.ts index c5105e99d..c2d9089e0 100644 --- a/frontend/src/lang/modules/ru.ts +++ b/frontend/src/lang/modules/ru.ts @@ -2378,6 +2378,8 @@ const message = { cacheWarn: 'Пожалуйста, сначала выключите кэш в обратном прокси', loadBalanceHelper: 'Здесь создаются только правила балансировки нагрузки, чтобы использовать правила, пожалуйста, используйте обратный прокси http(s)://<имя балансировки нагрузки>', + favorite: 'Избранное', + cancelFavorite: 'Отменить избранное', }, php: { short_open_tag: 'Поддержка коротких тегов', diff --git a/frontend/src/lang/modules/zh-Hant.ts b/frontend/src/lang/modules/zh-Hant.ts index 7ff523291..fc18ec478 100644 --- a/frontend/src/lang/modules/zh-Hant.ts +++ b/frontend/src/lang/modules/zh-Hant.ts @@ -2245,6 +2245,8 @@ const message = { runtimePortWarn: '當前運行環境沒有端口,無法代理', cacheWarn: '請先關閉反代中的緩存開關', loadBalanceHelper: '此處只是創建負載均衡規則,使用規則請反向代理 http(s)://<負載均衡名稱>', + favorite: '收藏', + cancelFavorite: '取消收藏', }, php: { short_open_tag: '短標簽支持', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 5b53716c7..71f6a2e47 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -2235,6 +2235,8 @@ const message = { runtimePortWarn: '当前运行环境没有端口,无法代理', cacheWarn: '请先关闭反代中的缓存开关', loadBalanceHelper: '此处只是创建负载均衡规则,使用规则请反向代理 http://<负载均衡名称>', + favorite: '收藏', + cancelFavorite: '取消收藏', }, php: { short_open_tag: '短标签支持', diff --git a/frontend/src/views/website/website/index.vue b/frontend/src/views/website/website/index.vue index 19bcdc9e9..32b5d856c 100644 --- a/frontend/src/views/website/website/index.vue +++ b/frontend/src/views/website/website/index.vue @@ -90,34 +90,71 @@ sortable show-overflow-tooltip > -