feat: 优化网站分组 (#372)

This commit is contained in:
zhengkunwang223 2023-03-22 21:42:30 +08:00 committed by GitHub
parent 66a345364f
commit 8d675c81c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 76 additions and 492 deletions

View File

@ -35,7 +35,6 @@ var (
commandService = service.ServiceGroupApp.CommandService
websiteGroupService = service.ServiceGroupApp.WebsiteGroupService
websiteService = service.ServiceGroupApp.WebsiteService
websiteDnsAccountService = service.ServiceGroupApp.WebsiteDnsAccountService
websiteSSLService = service.ServiceGroupApp.WebsiteSSLService

View File

@ -1,89 +0,0 @@
package v1
import (
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/gin-gonic/gin"
)
// @Tags Website Group
// @Summary List website groups
// @Description 获取网站组
// @Success 200 {anrry} model.WebsiteGroup
// @Security ApiKeyAuth
// @Router /websites/groups [get]
func (b *BaseApi) GetWebGroups(c *gin.Context) {
list, err := websiteGroupService.GetGroups()
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, list)
}
// @Tags Website Group
// @Summary Create website group
// @Description 创建网站组
// @Accept json
// @Param request body request.WebsiteGroupCreate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/groups [post]
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"创建网站组 [name]","formatEN":"Create website groups [name]"}
func (b *BaseApi) CreateWebGroup(c *gin.Context) {
var req request.WebsiteGroupCreate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteGroupService.CreateGroup(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
// @Tags Website Group
// @Summary Update website group
// @Description 更新网站组
// @Accept json
// @Param request body request.WebsiteGroupUpdate true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/groups/update [post]
// @x-panel-log {"bodyKeys":["name"],"paramKeys":[],"BeforeFuntions":[],"formatZH":"更新网站组 [name]","formatEN":"Update website groups [name]"}
func (b *BaseApi) UpdateWebGroup(c *gin.Context) {
var req request.WebsiteGroupUpdate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteGroupService.UpdateGroup(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
// @Tags Website Group
// @Summary Delete website group
// @Description 删除网站组
// @Accept json
// @Param request body request.WebsiteResourceReq true "request"
// @Success 200
// @Security ApiKeyAuth
// @Router /websites/groups/del [post]
// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFuntions":[{"input_colume":"id","input_value":"id","isList":false,"db":"website_groups","output_colume":"name","output_value":"name"}],"formatZH":"删除网站组 [name]","formatEN":"Delete website group [name]"}
func (b *BaseApi) DeleteWebGroup(c *gin.Context) {
var req request.WebsiteResourceReq
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteGroupService.DeleteGroup(req.ID); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}

View File

@ -1,11 +0,0 @@
package model
type WebsiteGroup struct {
BaseModel
Name string `gorm:"type:varchar(64);not null" json:"name"`
Default bool `json:"default"`
}
func (w WebsiteGroup) TableName() string {
return "website_groups"
}

View File

@ -19,7 +19,6 @@ type RepoGroup struct {
BackupRepo
WebsiteRepo
WebsiteDomainRepo
WebsiteGroupRepo
WebsiteDnsAccountRepo
WebsiteSSLRepo
WebsiteAcmeAccountRepo

View File

@ -64,6 +64,6 @@ func (u *GroupRepo) Delete(opts ...DBOption) error {
return db.Delete(&model.Group{}).Error
}
func (w GroupRepo) CancelDefault() error {
func (u *GroupRepo) CancelDefault() error {
return global.DB.Model(&model.Group{}).Where("`is_default` = 1").Updates(map[string]interface{}{"is_default": 0}).Error
}

View File

@ -1,44 +0,0 @@
package repo
import (
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/global"
"gorm.io/gorm/clause"
)
type WebsiteGroupRepo struct {
}
func (w WebsiteGroupRepo) Page(page, size int, opts ...DBOption) (int64, []model.WebsiteGroup, error) {
var groups []model.WebsiteGroup
db := getDb(opts...).Model(&model.WebsiteGroup{})
count := int64(0)
db = db.Count(&count)
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.Order("`default` desc").Find(&groups).Error; err != nil {
return groups, err
}
return groups, nil
}
func (w WebsiteGroupRepo) Create(app *model.WebsiteGroup) error {
return getDb().Omit(clause.Associations).Create(app).Error
}
func (w WebsiteGroupRepo) Save(app *model.WebsiteGroup) error {
return getDb().Omit(clause.Associations).Save(app).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
}

View File

@ -28,7 +28,6 @@ type ServiceGroup struct {
SettingService
BackupService
WebsiteGroupService
WebsiteService
WebsiteDnsAccountService
WebsiteSSLService
@ -68,7 +67,6 @@ var (
backupRepo = repo.RepoGroupApp.BackupRepo
websiteRepo = repo.NewIWebsiteRepo()
websiteGroupRepo = repo.RepoGroupApp.WebsiteGroupRepo
websiteDomainRepo = repo.RepoGroupApp.WebsiteDomainRepo
websiteDnsRepo = repo.RepoGroupApp.WebsiteDnsAccountRepo
websiteSSLRepo = repo.NewISSLRepo()

View File

@ -22,7 +22,7 @@ func NewIGroupService() IGroupService {
}
func (u *GroupService) List(req dto.GroupSearch) ([]dto.GroupInfo, error) {
groups, err := groupRepo.GetList(commonRepo.WithByType(req.Type), commonRepo.WithOrderBy("created_at desc"))
groups, err := groupRepo.GetList(commonRepo.WithByType(req.Type), commonRepo.WithOrderBy("is_default desc"), commonRepo.WithOrderBy("created_at desc"))
if err != nil {
return nil, constant.ErrRecordNotFound
}

View File

@ -1,61 +0,0 @@
package service
import (
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/buserr"
"github.com/1Panel-dev/1Panel/backend/constant"
)
type WebsiteGroupService struct {
}
func (w WebsiteGroupService) CreateGroup(create request.WebsiteGroupCreate) error {
groups, _ := websiteGroupRepo.GetBy(commonRepo.WithByName(create.Name))
if len(groups) > 0 {
return buserr.New(constant.ErrNameIsExist)
}
return websiteGroupRepo.Create(&model.WebsiteGroup{
Name: create.Name,
})
}
func (w WebsiteGroupService) GetGroups() ([]model.WebsiteGroup, error) {
return websiteGroupRepo.GetBy()
}
func (w WebsiteGroupService) UpdateGroup(update request.WebsiteGroupUpdate) error {
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 {
exists, _ := websiteGroupRepo.GetBy(commonRepo.WithByName(update.Name))
for _, exist := range exists {
if exist.ID != update.ID {
return buserr.New(constant.ErrNameIsExist)
}
}
return websiteGroupRepo.Save(&model.WebsiteGroup{
BaseModel: model.BaseModel{
ID: update.ID,
},
Name: update.Name,
})
}
}
func (w WebsiteGroupService) DeleteGroup(id uint) error {
websites, _ := websiteRepo.GetBy(websiteRepo.WithGroupID(id))
if len(websites) > 0 {
return buserr.New(constant.ErrGroupIsUsed)
}
return websiteGroupRepo.DeleteBy(commonRepo.WithByID(id))
}

View File

@ -20,6 +20,7 @@ func Init() {
migrations.AddTableWebsite,
migrations.AddTableDatabaseMysql,
migrations.AddTableSnap,
migrations.AddDefaultGroup,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)

View File

@ -211,14 +211,7 @@ var AddTableDatabaseMysql = &gormigrate.Migration{
var AddTableWebsite = &gormigrate.Migration{
ID: "20201009-add-table-website",
Migrate: func(tx *gorm.DB) error {
if err := tx.AutoMigrate(&model.Website{}, &model.WebsiteDomain{}, &model.WebsiteGroup{}, &model.WebsiteDnsAccount{}, &model.WebsiteSSL{}, &model.WebsiteAcmeAccount{}); err != nil {
return err
}
item := &model.WebsiteGroup{
Name: "默认",
Default: true,
}
if err := tx.Create(item).Error; err != nil {
if err := tx.AutoMigrate(&model.Website{}, &model.WebsiteDomain{}, &model.WebsiteDnsAccount{}, &model.WebsiteSSL{}, &model.WebsiteAcmeAccount{}); err != nil {
return err
}
return nil
@ -234,3 +227,17 @@ var AddTableSnap = &gormigrate.Migration{
return nil
},
}
var AddDefaultGroup = &gormigrate.Migration{
ID: "2023022-change-default-group",
Migrate: func(tx *gorm.DB) error {
defaultGroup := &model.Group{
Name: "默认",
IsDefault: true,
Type: "website",
}
tx.Create(defaultGroup)
tx.Debug().Model(&model.Website{}).Where("1 = 1").Update("website_group_id", defaultGroup.ID)
return tx.Migrator().DropTable("website_groups")
},
}

View File

@ -10,14 +10,14 @@ type WebsiteGroupRouter struct {
}
func (a *WebsiteGroupRouter) InitWebsiteGroupRouter(Router *gin.RouterGroup) {
groupRouter := Router.Group("websites/groups")
groupRouter := Router.Group("groups")
groupRouter.Use(middleware.JwtAuth()).Use(middleware.SessionAuth()).Use(middleware.PasswordExpired())
baseApi := v1.ApiGroupApp.BaseApi
{
groupRouter.GET("", baseApi.GetWebGroups)
groupRouter.POST("", baseApi.CreateWebGroup)
groupRouter.POST("/update", baseApi.UpdateWebGroup)
groupRouter.POST("/del", baseApi.DeleteWebGroup)
groupRouter.POST("", baseApi.CreateGroup)
groupRouter.POST("/del", baseApi.DeleteGroup)
groupRouter.POST("/update", baseApi.UpdateGroup)
groupRouter.POST("/search", baseApi.ListGroup)
}
}

View File

@ -26,11 +26,6 @@ func (s *HostRouter) InitHostRouter(Router *gin.RouterGroup) {
hostRouter.POST("/test/byid/:id", baseApi.TestByID)
hostRouter.GET(":id", baseApi.GetHostInfo)
hostRouter.POST("/group", baseApi.CreateGroup)
hostRouter.POST("/group/del", baseApi.DeleteGroup)
hostRouter.POST("/group/update", baseApi.UpdateGroup)
hostRouter.POST("/group/search", baseApi.ListGroup)
hostRouter.GET("/command", baseApi.ListCommand)
hostRouter.POST("/command", baseApi.CreateCommand)
hostRouter.POST("/command/del", baseApi.DeleteCommand)

View File

@ -79,17 +79,6 @@ export namespace Website {
content: string;
}
export interface Group extends CommonModel {
name: string;
default: boolean;
}
export interface GroupOp {
name: string;
id?: number;
default: boolean;
}
export interface Domain {
websiteId: number;
port: number;

View File

@ -0,0 +1,15 @@
import { Group } from '../interface/group';
import http from '@/api';
export const GetGroupList = (params: Group.GroupSearch) => {
return http.post<Array<Group.GroupInfo>>(`/groups/search`, params);
};
export const CreateGroup = (params: Group.GroupCreate) => {
return http.post<Group.GroupCreate>(`/groups`, params);
};
export const UpdateGroup = (params: Group.GroupUpdate) => {
return http.post(`/groups/update`, params);
};
export const DeleteGroup = (id: number) => {
return http.post(`/groups/del`, { id: id });
};

View File

@ -1,7 +1,6 @@
import http from '@/api';
import { ResPage } from '../interface';
import { Command } from '../interface/command';
import { Group } from '../interface/group';
import { Host } from '../interface/host';
import { Base64 } from 'js-base64';
import { deepCopy } from '@/utils/util';
@ -55,20 +54,6 @@ export const deleteHost = (params: { ids: number[] }) => {
return http.post(`/hosts/del`, params);
};
// group
export const GetGroupList = (params: Group.GroupSearch) => {
return http.post<Array<Group.GroupInfo>>(`/hosts/group/search`, params);
};
export const CreateGroup = (params: Group.GroupCreate) => {
return http.post<Group.GroupCreate>(`/hosts/group`, params);
};
export const UpdateGroup = (params: Group.GroupUpdate) => {
return http.post(`/hosts/group/update`, params);
};
export const DeleteGroup = (id: number) => {
return http.post(`/hosts/group/del`, { id: id });
};
// command
export const getCommandList = () => {
return http.get<Array<Command.CommandInfo>>(`/hosts/command`, {});

View File

@ -43,22 +43,6 @@ export const DeleteWebsite = (req: Website.WebSiteDel) => {
return http.post<any>(`/websites/del`, req);
};
export const ListGroups = () => {
return http.get<Website.Group[]>(`/websites/groups`);
};
export const CreateGroup = (req: Website.GroupOp) => {
return http.post<any>(`/websites/groups`, req);
};
export const UpdateGroup = (req: Website.GroupOp) => {
return http.post<any>(`/websites/groups/update`, req);
};
export const DeleteGroup = (req: Website.DelReq) => {
return http.post<any>(`/websites/groups/del`, req);
};
export const ListDomains = (id: number) => {
return http.get<Website.Domain[]>(`/websites/domains/${id}`);
};

View File

@ -59,7 +59,7 @@
import { ref } from 'vue';
import i18n from '@/lang';
import ComplexTable from '@/components/complex-table/index.vue';
import { CreateGroup, DeleteGroup, GetGroupList, UpdateGroup } from '@/api/modules/host';
import { CreateGroup, DeleteGroup, GetGroupList, UpdateGroup } from '@/api/modules/group';
import Header from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
import { Group } from '@/api/interface/group';

View File

@ -38,7 +38,8 @@
import { ref, reactive } from 'vue';
import type { ElForm } from 'element-plus';
import { Rules } from '@/global/form-rules';
import { editHostGroup, GetGroupList } from '@/api/modules/host';
import { editHostGroup } from '@/api/modules/host';
import { GetGroupList } from '@/api/modules/group';
import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message';

View File

@ -84,7 +84,8 @@ import GroupDialog from '@/components/group/index.vue';
import GroupChangeDialog from '@/views/host/terminal/host/change-group/index.vue';
import OperateDialog from '@/views/host/terminal/host/operate/index.vue';
import ComplexTable from '@/components/complex-table/index.vue';
import { deleteHost, GetGroupList, searchHosts } from '@/api/modules/host';
import { deleteHost, searchHosts } from '@/api/modules/host';
import { GetGroupList } from '@/api/modules/group';
import { reactive, ref } from 'vue';
import i18n from '@/lang';
import { Host } from '@/api/interface/host';

View File

@ -77,7 +77,8 @@
import { ref, reactive } from 'vue';
import type { ElForm } from 'element-plus';
import { Rules } from '@/global/form-rules';
import { addHost, editHost, testByInfo, GetGroupList } from '@/api/modules/host';
import { addHost, editHost, testByInfo } from '@/api/modules/host';
import { GetGroupList } from '@/api/modules/group';
import i18n from '@/lang';
import { MsgError, MsgSuccess } from '@/utils/message';

View File

@ -29,14 +29,14 @@
</template>
<script lang="ts" setup>
import { Website } from '@/api/interface/website';
import { GetWebsite, UpdateWebsite } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
import { computed, onMounted, reactive, ref } from 'vue';
import { ListGroups } from '@/api/modules/website';
import { FormInstance } from 'element-plus';
import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message';
import { GetGroupList } from '@/api/modules/group';
import { Group } from '@/api/interface/group';
const websiteForm = ref<FormInstance>();
const props = defineProps({
@ -59,7 +59,7 @@ let rules = ref({
primaryDomain: [Rules.requiredInput],
webSiteGroupId: [Rules.requiredSelect],
});
let groups = ref<Website.Group[]>([]);
let groups = ref<Group.GroupInfo[]>([]);
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
@ -78,14 +78,14 @@ const submit = async (formEl: FormInstance | undefined) => {
});
});
};
const search = () => {
ListGroups().then((res) => {
groups.value = res.data;
GetWebsite(websiteId.value).then((res) => {
form.primaryDomain = res.data.primaryDomain;
form.remark = res.data.remark;
form.webSiteGroupId = res.data.webSiteGroupId;
});
const search = async () => {
const res = await GetGroupList({ type: 'website' });
groups.value = res.data;
GetWebsite(websiteId.value).then((res) => {
form.primaryDomain = res.data.primaryDomain;
form.remark = res.data.remark;
form.webSiteGroupId = res.data.webSiteGroupId;
});
};

View File

@ -187,9 +187,8 @@
<script lang="ts" setup name="CreateWebSite">
import DrawerHeader from '@/components/drawer-header/index.vue';
import { App } from '@/api/interface/app';
import { Website } from '@/api/interface/website';
import { GetApp, GetAppDetail, SearchApp, GetAppInstalled } from '@/api/modules/app';
import { CreateWebsite, ListGroups, PreCheck } from '@/api/modules/website';
import { CreateWebsite, PreCheck } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
import i18n from '@/lang';
import { ElForm, FormInstance } from 'element-plus';
@ -197,6 +196,8 @@ import { reactive, ref } from 'vue';
import Params from '@/views/app-store/detail/params/index.vue';
import Check from '../check/index.vue';
import { MsgSuccess } from '@/utils/message';
import { GetGroupList } from '@/api/modules/group';
import { Group } from '@/api/interface/group';
const websiteForm = ref<FormInstance>();
const website = ref({
@ -235,7 +236,8 @@ let rules = ref<any>({
let open = ref(false);
let loading = ref(false);
let groups = ref<Website.Group[]>([]);
let groups = ref<Group.GroupInfo[]>([]);
let appInstalles = ref<App.AppInstalled[]>([]);
let appReq = reactive({
type: 'website',
@ -321,11 +323,12 @@ const acceptParams = async (installPath: string) => {
websiteForm.value.resetFields();
}
staticPath.value = installPath + '/www/sites/';
await ListGroups().then((res) => {
groups.value = res.data;
website.value.webSiteGroupId = res.data[0].id;
open.value = true;
});
const res = await GetGroupList({ type: 'website' });
groups.value = res.data;
open.value = true;
website.value.webSiteGroupId = res.data[0].id;
searchAppInstalled();
};

View File

@ -1,190 +0,0 @@
<template>
<el-drawer :close-on-click-modal="false" v-model="open" size="50%" :before-close="handleClose">
<template #header>
<Header :header="$t('website.group')" :back="handleClose"></Header>
</template>
<ComplexTable :data="data" @search="search()">
<template #toolbar>
<el-button type="primary" @click="openCreate">{{ $t('website.createGroup') }}</el-button>
</template>
<el-table-column :label="$t('commons.table.name')" prop="name">
<template #default="{ row }">
<span v-if="!row.edit">
{{ row.name }}
<span v-if="row.default">({{ $t('website.default') }})</span>
</span>
<el-form ref="groupForm" :model="row" :rules="rules">
<el-form-item prop="name" v-if="row.edit">
<el-input v-model="row.name"></el-input>
</el-form-item>
</el-form>
</template>
</el-table-column>
<el-table-column :label="$t('commons.table.operate')">
<template #default="{ row, $index }">
<div>
<el-button link v-if="row.edit" type="primary" @click="saveGroup(groupForm, row, false)">
{{ $t('commons.button.save') }}
</el-button>
<el-button link v-if="!row.edit" type="primary" @click="editGroup($index)">
{{ $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(groupForm, row, true)"
>
{{ $t('website.setDefault') }}
</el-button>
</div>
</template>
</el-table-column>
</ComplexTable>
</el-drawer>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import i18n from '@/lang';
import ComplexTable from '@/components/complex-table/index.vue';
import { ListGroups, CreateGroup, DeleteGroup, UpdateGroup } from '@/api/modules/website';
import Header from '@/components/drawer-header/index.vue';
import { MsgSuccess } from '@/utils/message';
import { Rules } from '@/global/form-rules';
import { FormInstance } from 'element-plus';
interface groupData {
id: number;
name: string;
edit: boolean;
default: boolean;
}
let rules = ref<any>({
name: [Rules.name],
});
const groupForm = ref<FormInstance>();
let open = ref(false);
let data = ref<groupData[]>([]);
const handleClose = () => {
open.value = false;
data.value = [];
};
const search = () => {
data.value = [];
ListGroups().then((res) => {
for (const d of res.data) {
const g = {
id: d.id,
name: d.name,
default: d.default,
edit: false,
};
data.value.push(g);
}
});
};
const saveGroup = async (formEl: FormInstance, create: groupData, isDefault: boolean) => {
if (!formEl) return;
await formEl.validate((valid) => {
if (!valid) {
return;
}
const group = {
name: create.name,
id: create.id,
default: create.default,
};
if (isDefault) {
group.default = isDefault;
}
if (create.id == 0) {
CreateGroup(group).then(() => {
MsgSuccess(i18n.global.t('commons.msg.createSuccess'));
search();
});
} else {
UpdateGroup(group).then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));
search();
});
}
});
};
const acceptParams = async () => {
open.value = true;
search();
};
const openCreate = () => {
for (const d of data.value) {
if (d.name == '') {
return;
}
if (d.edit) {
d.edit = false;
}
}
const g = {
id: 0,
name: '',
default: false,
edit: true,
};
data.value.push(g);
};
const deleteGroup = (index: number) => {
const group = data.value[index];
if (group.id > 0) {
DeleteGroup({ id: group.id }).then(() => {
data.value.splice(index, 1);
MsgSuccess(i18n.global.t('commons.msg.deleteSuccess'));
});
} else {
data.value.splice(index, 1);
}
};
const editGroup = (index: number) => {
for (const i in data.value) {
const d = data.value[i];
if (d.name == '') {
data.value.splice(Number(i), 1);
}
if (d.edit) {
d.edit = false;
}
}
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;
search();
}
};
defineExpose({ acceptParams });
</script>

View File

@ -145,10 +145,10 @@
<NginxConfig v-if="openNginxConfig" v-loading="loading" :containerName="containerName" :status="nginxStatus" />
<CreateWebSite ref="createRef" @close="search" />
<DeleteWebsite ref="deleteRef" @close="search" />
<WebSiteGroup ref="groupRef" />
<UploadDialog ref="uploadRef" />
<Backups ref="dialogBackupRef" />
<DefaultServer ref="defaultRef" />
<GroupDialog @search="search" ref="groupRef" />
</div>
</template>
@ -163,8 +163,8 @@ import ComplexTable from '@/components/complex-table/index.vue';
import { onMounted, reactive, ref } from '@vue/runtime-core';
import CreateWebSite from './create/index.vue';
import DeleteWebsite from './delete/index.vue';
import WebSiteGroup from './group/index.vue';
import { ListGroups, OpWebsite, SearchWebsites, UpdateWebsite } from '@/api/modules/website';
import GroupDialog from '@/components/group/index.vue';
import { OpWebsite, SearchWebsites, UpdateWebsite } from '@/api/modules/website';
import { Website } from '@/api/interface/website';
import AppStatus from '@/components/app-status/index.vue';
import NginxConfig from './nginx/index.vue';
@ -177,6 +177,8 @@ import { MsgSuccess } from '@/utils/message';
import { useI18n } from 'vue-i18n';
import { VideoPlay, VideoPause } from '@element-plus/icons-vue';
import MsgInfo from '@/components/msg-info/index.vue';
import { GetGroupList } from '@/api/modules/group';
import { Group } from '@/api/interface/group';
const shortcuts = [
{
@ -209,7 +211,7 @@ const dialogBackupRef = ref();
const defaultRef = ref();
const data = ref();
let dateRefs: Map<number, any> = new Map();
let groups = ref<Website.Group[]>([]);
let groups = ref<Group.GroupInfo[]>([]);
const paginationConfig = reactive({
currentPage: 1,
@ -238,9 +240,8 @@ const search = async () => {
};
const listGroup = async () => {
await ListGroups().then((res) => {
groups.value = res.data;
});
const res = await GetGroupList({ type: 'website' });
groups.value = res.data;
};
const setting = () => {
@ -359,7 +360,7 @@ const openCreate = () => {
};
const openGroup = () => {
groupRef.value.acceptParams();
groupRef.value.acceptParams({ type: 'website' });
};
const openDefault = () => {