mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-24 02:59:16 +08:00
feat: 网站分组修改
This commit is contained in:
parent
837705f66f
commit
0e3d9d1f3f
@ -60,8 +60,9 @@ type WebSiteGroupCreate struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type WebSiteGroupUpdate struct {
|
type WebSiteGroupUpdate struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
Default bool `json:"default"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebSiteDomainCreate struct {
|
type WebSiteDomainCreate struct {
|
||||||
|
@ -2,6 +2,7 @@ package repo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
"gorm.io/gorm/clause"
|
"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{})
|
db := getDb(opts...).Model(&model.WebSiteGroup{})
|
||||||
count := int64(0)
|
count := int64(0)
|
||||||
db = db.Count(&count)
|
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
|
return count, groups, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w WebSiteGroupRepo) GetBy(opts ...DBOption) ([]model.WebSiteGroup, error) {
|
func (w WebSiteGroupRepo) GetBy(opts ...DBOption) ([]model.WebSiteGroup, error) {
|
||||||
var groups []model.WebSiteGroup
|
var groups []model.WebSiteGroup
|
||||||
db := getDb(opts...).Model(&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, err
|
||||||
}
|
}
|
||||||
return groups, nil
|
return groups, nil
|
||||||
@ -37,3 +38,7 @@ func (w WebSiteGroupRepo) Save(app *model.WebSiteGroup) error {
|
|||||||
func (w WebSiteGroupRepo) DeleteBy(opts ...DBOption) error {
|
func (w WebSiteGroupRepo) DeleteBy(opts ...DBOption) error {
|
||||||
return getDb(opts...).Delete(&model.WebSiteGroup{}).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
|
||||||
|
}
|
||||||
|
@ -19,12 +19,26 @@ func (w WebsiteGroupService) GetGroups() ([]model.WebSiteGroup, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w WebsiteGroupService) UpdateGroup(update dto.WebSiteGroupUpdate) error {
|
func (w WebsiteGroupService) UpdateGroup(update dto.WebSiteGroupUpdate) error {
|
||||||
return websiteGroupRepo.Save(&model.WebSiteGroup{
|
|
||||||
BaseModel: model.BaseModel{
|
if update.Default {
|
||||||
ID: update.ID,
|
if err := websiteGroupRepo.CancelDefault(); err != nil {
|
||||||
},
|
return err
|
||||||
Name: update.Name,
|
}
|
||||||
})
|
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 {
|
func (w WebsiteGroupService) DeleteGroup(id uint) error {
|
||||||
|
@ -70,6 +70,7 @@ export namespace WebSite {
|
|||||||
export interface GroupOp {
|
export interface GroupOp {
|
||||||
name: string;
|
name: string;
|
||||||
id?: number;
|
id?: number;
|
||||||
|
default: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Domain {
|
export interface Domain {
|
||||||
|
@ -763,6 +763,8 @@ export default {
|
|||||||
nginxPer: '性能调整',
|
nginxPer: '性能调整',
|
||||||
neverExpire: '永不过期',
|
neverExpire: '永不过期',
|
||||||
protocol: '协议',
|
protocol: '协议',
|
||||||
|
setDefault: '设为默认',
|
||||||
|
default: '默认',
|
||||||
},
|
},
|
||||||
nginx: {
|
nginx: {
|
||||||
serverNamesHashBucketSizeHelper: '服务器名字的hash表大小',
|
serverNamesHashBucketSizeHelper: '服务器名字的hash表大小',
|
||||||
|
@ -6,18 +6,38 @@
|
|||||||
</template>
|
</template>
|
||||||
<el-table-column :label="$t('commons.table.name')" prop="name">
|
<el-table-column :label="$t('commons.table.name')" prop="name">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<span v-if="!row.edit" @click="row.edit = true">{{ row.name }}</span>
|
<span v-if="!row.edit">
|
||||||
<el-input v-if="row.edit" v-model="row.name" @blur="row.edit = false"></el-input>
|
{{ row.name }}
|
||||||
|
<span v-if="row.default">({{ $t('website.default') }})</span>
|
||||||
|
</span>
|
||||||
|
<el-input v-if="row.edit" v-model="row.name"></el-input>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('commons.table.operate')">
|
<el-table-column :label="$t('commons.table.operate')">
|
||||||
<template #default="{ row, $index }">
|
<template #default="{ row, $index }">
|
||||||
<el-button link :disabled="row.default" type="primary" @click="saveGroup(row)">
|
<div>
|
||||||
{{ $t('commons.button.save') }}
|
<el-button link v-if="row.edit" type="primary" @click="saveGroup(row, false)">
|
||||||
</el-button>
|
{{ $t('commons.button.save') }}
|
||||||
<el-button link :disabled="row.default" type="primary" @click="deleteGroup($index)">
|
</el-button>
|
||||||
{{ $t('commons.button.delete') }}
|
<el-button link v-if="!row.edit" type="primary" @click="editGroup($index)">
|
||||||
</el-button>
|
{{ $t('commons.button.edit') }}
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
link
|
||||||
|
v-if="!row.edit"
|
||||||
|
:disabled="row.default"
|
||||||
|
type="primary"
|
||||||
|
@click="deleteGroup($index)"
|
||||||
|
>
|
||||||
|
{{ $t('commons.button.delete') }}
|
||||||
|
</el-button>
|
||||||
|
<el-button link v-if="row.edit" type="primary" @click="cancelEdit($index)">
|
||||||
|
{{ $t('commons.button.cancel') }}
|
||||||
|
</el-button>
|
||||||
|
<el-button link v-if="!row.edit && !row.default" type="primary" @click="saveGroup(row, true)">
|
||||||
|
{{ $t('website.setDefault') }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</ComplexTable>
|
</ComplexTable>
|
||||||
@ -39,13 +59,13 @@ interface groupData {
|
|||||||
|
|
||||||
let open = ref(false);
|
let open = ref(false);
|
||||||
let data = ref<groupData[]>([]);
|
let data = ref<groupData[]>([]);
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
open.value = false;
|
open.value = false;
|
||||||
data.value = [];
|
data.value = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
const search = () => {
|
const search = () => {
|
||||||
|
data.value = [];
|
||||||
ListGroups().then((res) => {
|
ListGroups().then((res) => {
|
||||||
for (const d of res.data) {
|
for (const d of res.data) {
|
||||||
const g = {
|
const g = {
|
||||||
@ -59,18 +79,24 @@ const search = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const saveGroup = (create: groupData) => {
|
const saveGroup = (create: groupData, isDefault: boolean) => {
|
||||||
const group = {
|
const group = {
|
||||||
name: create.name,
|
name: create.name,
|
||||||
id: create.id,
|
id: create.id,
|
||||||
|
default: create.default,
|
||||||
};
|
};
|
||||||
|
if (isDefault) {
|
||||||
|
group.default = isDefault;
|
||||||
|
}
|
||||||
if (create.id == 0) {
|
if (create.id == 0) {
|
||||||
CreateGroup(group).then(() => {
|
CreateGroup(group).then(() => {
|
||||||
ElMessage.success(i18n.global.t('commons.msg.createSuccess'));
|
ElMessage.success(i18n.global.t('commons.msg.createSuccess'));
|
||||||
|
search();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
UpdateGroup(group).then(() => {
|
UpdateGroup(group).then(() => {
|
||||||
ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
|
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 });
|
defineExpose({ acceptParams });
|
||||||
</script>
|
</script>
|
||||||
|
4
go.mod
4
go.mod
@ -66,6 +66,7 @@ require (
|
|||||||
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
|
||||||
github.com/cespare/xxhash v1.1.0 // indirect
|
github.com/cespare/xxhash v1.1.0 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // 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/cgroups v1.0.3 // indirect
|
||||||
github.com/containerd/containerd v1.6.8 // indirect
|
github.com/containerd/containerd v1.6.8 // indirect
|
||||||
github.com/containerd/continuity v0.3.0 // 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/protobuf v1.5.2 // indirect
|
||||||
github.com/golang/snappy v0.0.4 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
github.com/google/flatbuffers v1.12.1 // 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/google/uuid v1.3.0 // indirect
|
||||||
github.com/gorilla/securecookie v1.1.1 // 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/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/imdario/mergo v0.3.13 // indirect
|
github.com/imdario/mergo v0.3.13 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
|
10
go.sum
10
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 h1:LdXxtjzvZYhhUaonAaAKArG3pyC67kGL3YY+6hGG8G4=
|
||||||
github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng=
|
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/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-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-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/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.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
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-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.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/gofuzz v1.1.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=
|
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/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 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/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 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-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.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/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||||
|
Loading…
Reference in New Issue
Block a user