Skip to content

Commit b5af560

Browse files
committed
IP名单中可以批量删除最多10000个IP
1 parent 5622636 commit b5af560

File tree

5 files changed

+112
-4
lines changed

5 files changed

+112
-4
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright 2023 Liuxiangchao [email protected]. All rights reserved.
2+
3+
package iplists
4+
5+
import (
6+
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
7+
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
8+
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
9+
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
10+
"github.com/iwind/TeaGo/types"
11+
"strings"
12+
)
13+
14+
type DeleteCountAction struct {
15+
actionutils.ParentAction
16+
}
17+
18+
func (this *DeleteCountAction) RunPost(params struct {
19+
Ip string
20+
Keyword string
21+
GlobalOnly bool
22+
Unread bool
23+
EventLevel string
24+
ListType string
25+
26+
Count int64
27+
}) {
28+
29+
var count = params.Count
30+
if count <= 0 || count >= 100_000 {
31+
this.Fail("'count' 参数错误")
32+
return
33+
}
34+
35+
itemIdsResp, err := this.RPC().IPItemRPC().ListAllIPItemIds(this.AdminContext(), &pb.ListAllIPItemIdsRequest{
36+
Keyword: params.Keyword,
37+
GlobalOnly: params.GlobalOnly,
38+
Unread: params.Unread,
39+
EventLevel: params.EventLevel,
40+
ListType: params.ListType,
41+
Ip: params.Ip,
42+
Offset: 0,
43+
Size: count,
44+
})
45+
if err != nil {
46+
this.ErrorPage(err)
47+
return
48+
}
49+
50+
var itemIds = itemIdsResp.IpItemIds
51+
52+
if len(itemIds) == 0 {
53+
this.Success()
54+
}
55+
56+
// 记录日志
57+
defer func() {
58+
var itemIdStrings = []string{}
59+
for _, itemId := range itemIds {
60+
itemIdStrings = append(itemIdStrings, types.String(itemId))
61+
}
62+
63+
var itemIdsDescription = ""
64+
if len(itemIdStrings) > 10 {
65+
itemIdsDescription = strings.Join(itemIdStrings[:10], ", ") + " ..."
66+
} else {
67+
itemIdsDescription = strings.Join(itemIdStrings, ", ")
68+
}
69+
this.CreateLogInfo(codes.IPList_LogDeleteIPBatch, itemIdsDescription)
70+
}()
71+
72+
_, err = this.RPC().IPItemRPC().DeleteIPItems(this.AdminContext(), &pb.DeleteIPItemsRequest{IpItemIds: itemIds})
73+
if err != nil {
74+
this.ErrorPage(err)
75+
return
76+
}
77+
78+
// 通知左侧菜单Badge更新
79+
helpers.NotifyIPItemsCountChanges()
80+
81+
this.Success()
82+
}

internal/web/actions/default/servers/iplists/index.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (this *IndexAction) RunGet(params struct {
6363
}
6464
var count = countResp.Count
6565
var page = this.NewPage(count)
66+
this.Data["totalItems"] = count
6667
this.Data["page"] = page.AsHTML()
6768

6869
itemsResp, err := this.RPC().IPItemRPC().ListAllEnabledIPItems(this.AdminContext(), &pb.ListAllEnabledIPItemsRequest{

internal/web/actions/default/servers/iplists/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func init() {
2222
Get("/exportData", new(ExportDataAction)).
2323
Post("/delete", new(DeleteAction)).
2424
Post("/deleteItems", new(DeleteItemsAction)).
25+
Post("/deleteCount", new(DeleteCountAction)).
2526
GetPost("/test", new(TestAction)).
2627
GetPost("/update", new(UpdateAction)).
2728
Get("/items", new(ItemsAction)).

web/public/js/components/iplist/ip-list-table.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
Vue.component("ip-list-table", {
2-
props: ["v-items", "v-keyword", "v-show-search-button"],
2+
props: ["v-items", "v-keyword", "v-show-search-button", "v-total"/** total items >= items length **/],
33
data: function () {
4+
let maxDeletes = 10000
5+
if (this.vTotal != null && this.vTotal > 0 && this.vTotal < maxDeletes) {
6+
maxDeletes = this.vTotal
7+
}
8+
49
return {
510
items: this.vItems,
611
keyword: (this.vKeyword != null) ? this.vKeyword : "",
712
selectedAll: false,
8-
hasSelectedItems: false
13+
hasSelectedItems: false,
14+
15+
MaxDeletes: maxDeletes
916
}
1017
},
1118
methods: {
@@ -71,6 +78,21 @@ Vue.component("ip-list-table", {
7178
teaweb.successToast("批量删除成功", 1200, teaweb.reload)
7279
})
7380
},
81+
deleteCount: function () {
82+
let that = this
83+
teaweb.confirm("确定要批量删除当前列表中的" + this.MaxDeletes + "个IP吗?", function () {
84+
let query = window.location.search
85+
if (query.startsWith("?")) {
86+
query = query.substring(1)
87+
}
88+
Tea.action("/servers/iplists/deleteCount?" + query)
89+
.post()
90+
.params({count: that.MaxDeletes})
91+
.success(function () {
92+
teaweb.successToast("批量删除成功", 1200, teaweb.reload)
93+
})
94+
})
95+
},
7496
formatSeconds: function (seconds) {
7597
if (seconds < 60) {
7698
return seconds + "秒"
@@ -86,7 +108,9 @@ Vue.component("ip-list-table", {
86108
},
87109
template: `<div>
88110
<div v-show="hasSelectedItems">
89-
<a href="" @click.prevent="deleteAll">[批量删除]</a>
111+
<button class="ui button basic" type="button" @click.prevent="deleteAll">批量删除所选</button>
112+
&nbsp; &nbsp;
113+
<button class="ui button basic" type="button" @click.prevent="deleteCount" v-if="vTotal != null && vTotal >= MaxDeletes">批量删除{{MaxDeletes}}个</button>
90114
</div>
91115
<table class="ui table selectable celled" v-if="items.length > 0">
92116
<thead>

web/views/@default/servers/iplists/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@
5050

5151
<p class="comment" v-if="items.length == 0">暂时还没有IP。</p>
5252

53-
<ip-list-table v-if="items.length > 0" :v-items="items" @update-item="updateItem" @delete-item="deleteItem" :v-keyword="keyword" :v-show-search-button="true"></ip-list-table>
53+
<ip-list-table v-if="items.length > 0" :v-items="items" @update-item="updateItem" @delete-item="deleteItem" :v-keyword="keyword" :v-show-search-button="true" :v-total="totalItems"></ip-list-table>
5454

5555
<div class="page" v-html="page"></div>

0 commit comments

Comments
 (0)