diff --git a/pkg/api/asset.go b/pkg/api/asset.go
index 755a068..68d19c8 100644
--- a/pkg/api/asset.go
+++ b/pkg/api/asset.go
@@ -29,8 +29,9 @@ func AssetPagingEndpoint(c echo.Context) error {
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
name := c.QueryParam("name")
protocol := c.QueryParam("protocol")
+ tags := c.QueryParam("tags")
- items, total, _ := model.FindPageAsset(pageIndex, pageSize, name, protocol)
+ items, total, _ := model.FindPageAsset(pageIndex, pageSize, name, protocol, tags)
return Success(c, H{
"total": total,
diff --git a/pkg/model/asset.go b/pkg/model/asset.go
index de39fe8..a138a1a 100644
--- a/pkg/model/asset.go
+++ b/pkg/model/asset.go
@@ -43,7 +43,7 @@ func FindAssetByConditions(protocol string) (o []Asset, err error) {
return
}
-func FindPageAsset(pageIndex, pageSize int, name, protocol string) (o []Asset, total int64, err error) {
+func FindPageAsset(pageIndex, pageSize int, name, protocol, tags string) (o []Asset, total int64, err error) {
db := global.DB
if len(name) > 0 {
db = db.Where("name like ?", "%"+name+"%")
@@ -53,6 +53,13 @@ func FindPageAsset(pageIndex, pageSize int, name, protocol string) (o []Asset, t
db = db.Where("protocol = ?", protocol)
}
+ if len(tags) > 0 {
+ tagArr := strings.Split(tags, ",")
+ for i := range tagArr {
+ db = db.Where("find_in_set(?, tags)", tagArr[i])
+ }
+ }
+
err = db.Order("created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
if o == nil {
@@ -105,5 +112,5 @@ func FindAssetTags() (o []string, err error) {
o = append(o, split...)
}
- return o, nil
+ return utils.Distinct(o), nil
}
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index a3ea0cf..4554efe 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -119,3 +119,16 @@ func IsDir(path string) bool {
func IsFile(path string) bool {
return !IsDir(path)
}
+
+// 去除重复元素
+func Distinct(list []string) []string {
+ result := make([]string, 0, len(list))
+ temp := map[string]struct{}{}
+ for _, item := range list {
+ if _, ok := temp[item]; !ok {
+ temp[item] = struct{}{}
+ result = append(result, item)
+ }
+ }
+ return result
+}
diff --git a/web/src/components/asset/Asset.js b/web/src/components/asset/Asset.js
index ab72f46..e7ec287 100644
--- a/web/src/components/asset/Asset.js
+++ b/web/src/components/asset/Asset.js
@@ -21,6 +21,7 @@ import qs from "qs";
import AssetModal from "./AssetModal";
import request from "../../common/request";
import {message} from "antd/es";
+import {isEmpty, itemRender} from "../../utils/utils";
import {
@@ -34,7 +35,6 @@ import {
SyncOutlined,
UndoOutlined
} from '@ant-design/icons';
-import {itemRender} from "../../utils/utils";
import {PROTOCOL_COLORS} from "../../common/constants";
import Logout from "../user/Logout";
@@ -77,7 +77,14 @@ class Asset extends Component {
};
async componentDidMount() {
- await this.loadTableData();
+ this.loadTableData();
+
+ let result = await request.get('/tags');
+ if (result['code'] === 1) {
+ this.setState({
+ tags: result['data']
+ })
+ }
}
async delete(id) {
@@ -151,6 +158,21 @@ class Asset extends Component {
this.loadTableData(query);
};
+ handleTagsChange = tags => {
+ console.log(tags)
+ // this.setState({
+ // tags: tags
+ // })
+ let query = {
+ ...this.state.queryParams,
+ 'pageIndex': 1,
+ 'pageSize': this.state.queryParams.pageSize,
+ 'tags': tags.join(','),
+ }
+
+ this.loadTableData(query);
+ }
+
handleSearchByProtocol = protocol => {
let query = {
...this.state.queryParams,
@@ -335,13 +357,13 @@ class Asset extends Component {
);
}
}, {
- title: 'IP',
+ title: '网络',
dataIndex: 'ip',
key: 'ip',
- }, {
- title: '端口',
- dataIndex: 'port',
- key: 'port',
+ render: (text, record) => {
+
+ return record['ip'] + ':' + record['port'];
+ }
}, {
title: '连接协议',
dataIndex: 'protocol',
@@ -361,6 +383,23 @@ class Asset extends Component {
return ();
}
}
+ }, {
+ title: '标签',
+ dataIndex: 'tags',
+ key: 'tags',
+ render: tags => {
+ if (!isEmpty(tags)) {
+ let tagDocuments = []
+ let tagArr = tags.split(',');
+ for (let i = 0; i < tagArr.length; i++) {
+ if (tags[i] === '-') {
+ continue;
+ }
+ tagDocuments.push({tagArr[i]})
+ }
+ return tagDocuments;
+ }
+ }
}, {
title: '创建日期',
dataIndex: 'created',
@@ -427,6 +466,18 @@ class Asset extends Component {
onSearch={this.handleSearchByName}
/>
+
+