diff --git a/internal/web/actions/default/servers/iplists/deleteItems.go b/internal/web/actions/default/servers/iplists/deleteItems.go new file mode 100644 index 00000000..7aad71cf --- /dev/null +++ b/internal/web/actions/default/servers/iplists/deleteItems.go @@ -0,0 +1,37 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package iplists + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/types" + "strings" +) + +type DeleteItemsAction struct { + actionutils.ParentAction +} + +func (this *DeleteItemsAction) RunPost(params struct { + ItemIds []int64 +}) { + if len(params.ItemIds) == 0 { + this.Success() + } + + var itemIdStrings = []string{} + for _, itemId := range params.ItemIds { + itemIdStrings = append(itemIdStrings, types.String(itemId)) + } + + defer this.CreateLogInfo("批量删除IP名单中的IP:" + strings.Join(itemIdStrings, ", ")) + + _, err := this.RPC().IPItemRPC().DeleteIPItems(this.AdminContext(), &pb.DeleteIPItemsRequest{IpItemIds: params.ItemIds}) + if err != nil { + this.ErrorPage(err) + return + } + + this.Success() +} diff --git a/internal/web/actions/default/servers/iplists/init.go b/internal/web/actions/default/servers/iplists/init.go index aa567d7b..bac82765 100644 --- a/internal/web/actions/default/servers/iplists/init.go +++ b/internal/web/actions/default/servers/iplists/init.go @@ -21,6 +21,7 @@ func init() { GetPost("/export", new(ExportAction)). Get("/exportData", new(ExportDataAction)). Post("/delete", new(DeleteAction)). + Post("/deleteItems", new(DeleteItemsAction)). GetPost("/test", new(TestAction)). GetPost("/update", new(UpdateAction)). Get("/items", new(ItemsAction)). diff --git a/web/public/js/components/iplist/ip-list-table.js b/web/public/js/components/iplist/ip-list-table.js index 6c3864af..6b5b4510 100644 --- a/web/public/js/components/iplist/ip-list-table.js +++ b/web/public/js/components/iplist/ip-list-table.js @@ -3,7 +3,9 @@ Vue.component("ip-list-table", { data: function () { return { items: this.vItems, - keyword: (this.vKeyword != null) ? this.vKeyword : "" + keyword: (this.vKeyword != null) ? this.vKeyword : "", + selectedAll: false, + hasSelectedItems: false } }, methods: { @@ -18,12 +20,71 @@ Vue.component("ip-list-table", { width: "50em", height: "30em" }) + }, + changeSelectedAll: function () { + let boxes = this.$refs.itemCheckBox + if (boxes == null) { + return + } + + let that = this + boxes.forEach(function (box) { + box.checked = that.selectedAll + }) + + this.hasSelectedItems = this.selectedAll + }, + changeSelected: function (e) { + let that = this + that.hasSelectedItems = false + let boxes = that.$refs.itemCheckBox + if (boxes == null) { + return + } + boxes.forEach(function (box) { + if (box.checked) { + that.hasSelectedItems = true + } + }) + }, + deleteAll: function () { + let boxes = this.$refs.itemCheckBox + if (boxes == null) { + return + } + let itemIds = [] + boxes.forEach(function (box) { + if (box.checked) { + itemIds.push(box.value) + } + }) + if (itemIds.length == 0) { + return + } + + Tea.action("/servers/iplists/deleteItems") + .post() + .params({ + itemIds: itemIds + }) + .success(function () { + teaweb.successToast("批量删除成功", 2000, teaweb.reload) + }) } }, template: `
+
+ [批量删除] +
+ @@ -34,6 +95,12 @@ Vue.component("ip-list-table", { +
+
+ + +
+
IP 类型 级别
+
+ + +
+
{{item.ipFrom}}