From ad1049b0cfe9a9abef171a2f6308f6296d186d69 Mon Sep 17 00:00:00 2001 From: JustSong Date: Thu, 22 Jun 2023 21:19:43 +0800 Subject: [PATCH] feat: support search channels by key (close #185) --- model/channel.go | 4 ++-- web/src/components/ChannelsTable.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/model/channel.go b/model/channel.go index e53efc20..e99f4d10 100644 --- a/model/channel.go +++ b/model/channel.go @@ -8,7 +8,7 @@ import ( type Channel struct { Id int `json:"id"` Type int `json:"type" gorm:"default:0"` - Key string `json:"key" gorm:"not null"` + Key string `json:"key" gorm:"not null;index"` Status int `json:"status" gorm:"default:1"` Name string `json:"name" gorm:"index"` Weight int `json:"weight"` @@ -36,7 +36,7 @@ func GetAllChannels(startIdx int, num int, selectAll bool) ([]*Channel, error) { } func SearchChannels(keyword string) (channels []*Channel, err error) { - err = DB.Omit("key").Where("id = ? or name LIKE ?", keyword, keyword+"%").Find(&channels).Error + err = DB.Omit("key").Where("id = ? or name LIKE ? or key = ?", keyword, keyword+"%", keyword).Find(&channels).Error return channels, err } diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index be72ac8c..30c0c534 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -263,7 +263,7 @@ const ChannelsTable = () => { icon='search' fluid iconPosition='left' - placeholder='搜索渠道的 ID 和名称 ...' + placeholder='搜索渠道的 ID,名称和密钥 ...' value={searchKeyword} loading={searching} onChange={handleKeywordChange}