diff --git a/backend/app/dto/website.go b/backend/app/dto/website.go index 2a9375021..c3e842172 100644 --- a/backend/app/dto/website.go +++ b/backend/app/dto/website.go @@ -60,8 +60,9 @@ type WebSiteGroupCreate struct { } type WebSiteGroupUpdate struct { - ID uint `json:"id"` - Name string `json:"name"` + ID uint `json:"id"` + Name string `json:"name"` + Default bool `json:"default"` } type WebSiteDomainCreate struct { diff --git a/backend/app/repo/website_group.go b/backend/app/repo/website_group.go index 946d3f70b..0b05083ac 100644 --- a/backend/app/repo/website_group.go +++ b/backend/app/repo/website_group.go @@ -2,6 +2,7 @@ package repo import ( "github.com/1Panel-dev/1Panel/backend/app/model" + "github.com/1Panel-dev/1Panel/backend/global" "gorm.io/gorm/clause" ) @@ -13,14 +14,14 @@ func (w WebSiteGroupRepo) Page(page, size int, opts ...DBOption) (int64, []model db := getDb(opts...).Model(&model.WebSiteGroup{}) count := int64(0) db = db.Count(&count) - err := db.Debug().Limit(size).Offset(size * (page - 1)).Find(&groups).Error + err := db.Limit(size).Offset(size * (page - 1)).Order("`default` desc").Find(&groups).Error return count, groups, err } func (w WebSiteGroupRepo) GetBy(opts ...DBOption) ([]model.WebSiteGroup, error) { var groups []model.WebSiteGroup db := getDb(opts...).Model(&model.WebSiteGroup{}) - if err := db.Find(&groups).Error; err != nil { + if err := db.Order("`default` desc").Find(&groups).Error; err != nil { return groups, err } return groups, nil @@ -37,3 +38,7 @@ func (w WebSiteGroupRepo) Save(app *model.WebSiteGroup) error { func (w WebSiteGroupRepo) DeleteBy(opts ...DBOption) error { return getDb(opts...).Delete(&model.WebSiteGroup{}).Error } + +func (w WebSiteGroupRepo) CancelDefault() error { + return global.DB.Model(&model.WebSiteGroup{}).Where("`default` = 1").Updates(map[string]interface{}{"default": 0}).Error +} diff --git a/backend/app/service/website_group.go b/backend/app/service/website_group.go index 4ab56f319..93cdde93c 100644 --- a/backend/app/service/website_group.go +++ b/backend/app/service/website_group.go @@ -19,12 +19,26 @@ func (w WebsiteGroupService) GetGroups() ([]model.WebSiteGroup, error) { } func (w WebsiteGroupService) UpdateGroup(update dto.WebSiteGroupUpdate) error { - return websiteGroupRepo.Save(&model.WebSiteGroup{ - BaseModel: model.BaseModel{ - ID: update.ID, - }, - Name: update.Name, - }) + + if update.Default { + if err := websiteGroupRepo.CancelDefault(); err != nil { + return err + } + return websiteGroupRepo.Save(&model.WebSiteGroup{ + BaseModel: model.BaseModel{ + ID: update.ID, + }, + Name: update.Name, + Default: true, + }) + } else { + return websiteGroupRepo.Save(&model.WebSiteGroup{ + BaseModel: model.BaseModel{ + ID: update.ID, + }, + Name: update.Name, + }) + } } func (w WebsiteGroupService) DeleteGroup(id uint) error { diff --git a/frontend/src/api/interface/website.ts b/frontend/src/api/interface/website.ts index a3a961e34..cdd5c0fea 100644 --- a/frontend/src/api/interface/website.ts +++ b/frontend/src/api/interface/website.ts @@ -70,6 +70,7 @@ export namespace WebSite { export interface GroupOp { name: string; id?: number; + default: boolean; } export interface Domain { diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index b2d00b9bd..23d74be7e 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -763,6 +763,8 @@ export default { nginxPer: '性能调整', neverExpire: '永不过期', protocol: '协议', + setDefault: '设为默认', + default: '默认', }, nginx: { serverNamesHashBucketSizeHelper: '服务器名字的hash表大小', diff --git a/frontend/src/views/website/website/group/index.vue b/frontend/src/views/website/website/group/index.vue index e2cf7d443..567162479 100644 --- a/frontend/src/views/website/website/group/index.vue +++ b/frontend/src/views/website/website/group/index.vue @@ -6,18 +6,38 @@ @@ -39,13 +59,13 @@ interface groupData { let open = ref(false); let data = ref([]); - const handleClose = () => { open.value = false; data.value = []; }; const search = () => { + data.value = []; ListGroups().then((res) => { for (const d of res.data) { const g = { @@ -59,18 +79,24 @@ const search = () => { }); }; -const saveGroup = (create: groupData) => { +const saveGroup = (create: groupData, isDefault: boolean) => { const group = { name: create.name, id: create.id, + default: create.default, }; + if (isDefault) { + group.default = isDefault; + } if (create.id == 0) { CreateGroup(group).then(() => { ElMessage.success(i18n.global.t('commons.msg.createSuccess')); + search(); }); } else { UpdateGroup(group).then(() => { ElMessage.success(i18n.global.t('commons.msg.updateSuccess')); + search(); }); } }; @@ -103,5 +129,17 @@ const deleteGroup = (index: number) => { } }; +const editGroup = (index: number) => { + data.value[index].edit = true; +}; + +const cancelEdit = (index: number) => { + if (data.value[index].id == 0) { + data.value.splice(index, 1); + } else { + data.value[index].edit = false; + } +}; + defineExpose({ acceptParams }); diff --git a/go.mod b/go.mod index 9a1ff7b09..40cb63512 100644 --- a/go.mod +++ b/go.mod @@ -66,6 +66,7 @@ require ( github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect + github.com/cloudflare/cloudflare-go v0.49.0 // indirect github.com/containerd/cgroups v1.0.3 // indirect github.com/containerd/containerd v1.6.8 // indirect github.com/containerd/continuity v0.3.0 // indirect @@ -93,8 +94,11 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/flatbuffers v1.12.1 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/securecookie v1.1.1 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/go-retryablehttp v0.7.1 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/jinzhu/inflection v1.0.0 // indirect diff --git a/go.sum b/go.sum index afb93465a..a012daf9c 100644 --- a/go.sum +++ b/go.sum @@ -145,6 +145,8 @@ github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2u github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28 h1:LdXxtjzvZYhhUaonAaAKArG3pyC67kGL3YY+6hGG8G4= github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudflare/cloudflare-go v0.49.0 h1:KqJYk/YQ5ZhmyYz1oa4kGDskfF1gVuZfqesaJ/XDLto= +github.com/cloudflare/cloudflare-go v0.49.0/go.mod h1:h0QgcIZ3qEXwFiwfBO8sQxjVdYsLX+PfD7NFEnANaKg= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -494,6 +496,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= +github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -546,8 +550,14 @@ github.com/gwatts/gin-adapter v1.0.0 h1:TsmmhYTR79/RMTsfYJ2IQvI1F5KZ3ZFJxuQSYEOp github.com/gwatts/gin-adapter v1.0.0/go.mod h1:44AEV+938HsS0mjfXtBDCUZS9vONlF2gwvh8wu4sRYc= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= +github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-multierror v0.0.0-20161216184304-ed905158d874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ= +github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=