Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c296dfbe
authored
Dec 06, 2024
by
CalciumIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 兼容渠道搜索下标签聚合功能
parent
4c1aa96a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
11 deletions
+85
-11
controller/channel.go
+30
-8
model/channel.go
+52
-0
web/src/components/ChannelsTable.js
+3
-3
No files found.
controller/channel.go
View file @
c296dfbe
...
...
@@ -168,18 +168,40 @@ func SearchChannels(c *gin.Context) {
group
:=
c
.
Query
(
"group"
)
modelKeyword
:=
c
.
Query
(
"model"
)
idSort
,
_
:=
strconv
.
ParseBool
(
c
.
Query
(
"id_sort"
))
channels
,
err
:=
model
.
SearchChannels
(
keyword
,
group
,
modelKeyword
,
idSort
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
enableTagMode
,
_
:=
strconv
.
ParseBool
(
c
.
Query
(
"tag_mode"
))
channelData
:=
make
([]
*
model
.
Channel
,
0
)
if
enableTagMode
{
tags
,
err
:=
model
.
SearchTags
(
keyword
,
group
,
modelKeyword
,
idSort
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
}
for
_
,
tag
:=
range
tags
{
if
tag
!=
nil
&&
*
tag
!=
""
{
tagChannel
,
err
:=
model
.
GetChannelsByTag
(
*
tag
)
if
err
==
nil
{
channelData
=
append
(
channelData
,
tagChannel
...
)
}
}
}
}
else
{
channels
,
err
:=
model
.
SearchChannels
(
keyword
,
group
,
modelKeyword
,
idSort
)
if
err
!=
nil
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
err
.
Error
(),
})
return
}
channelData
=
channels
}
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
true
,
"message"
:
""
,
"data"
:
channel
s
,
"data"
:
channel
Data
,
})
return
}
...
...
model/channel.go
View file @
c296dfbe
...
...
@@ -410,3 +410,55 @@ func GetPaginatedTags(offset int, limit int) ([]*string, error) {
err
:=
DB
.
Model
(
&
Channel
{})
.
Select
(
"DISTINCT tag"
)
.
Where
(
"tag != ''"
)
.
Offset
(
offset
)
.
Limit
(
limit
)
.
Find
(
&
tags
)
.
Error
return
tags
,
err
}
func
SearchTags
(
keyword
string
,
group
string
,
model
string
,
idSort
bool
)
([]
*
string
,
error
)
{
var
tags
[]
*
string
keyCol
:=
"`key`"
groupCol
:=
"`group`"
modelsCol
:=
"`models`"
// 如果是 PostgreSQL,使用双引号
if
common
.
UsingPostgreSQL
{
keyCol
=
`"key"`
groupCol
=
`"group"`
modelsCol
=
`"models"`
}
order
:=
"priority desc"
if
idSort
{
order
=
"id desc"
}
// 构造基础查询
baseQuery
:=
DB
.
Model
(
&
Channel
{})
.
Omit
(
keyCol
)
// 构造WHERE子句
var
whereClause
string
var
args
[]
interface
{}
if
group
!=
""
&&
group
!=
"null"
{
var
groupCondition
string
if
common
.
UsingMySQL
{
groupCondition
=
`CONCAT(',', `
+
groupCol
+
`, ',') LIKE ?`
}
else
{
// sqlite, PostgreSQL
groupCondition
=
`(',' || `
+
groupCol
+
` || ',') LIKE ?`
}
whereClause
=
"(id = ? OR name LIKE ? OR "
+
keyCol
+
" = ?) AND "
+
modelsCol
+
` LIKE ? AND `
+
groupCondition
args
=
append
(
args
,
common
.
String2Int
(
keyword
),
"%"
+
keyword
+
"%"
,
keyword
,
"%"
+
model
+
"%"
,
"%,"
+
group
+
",%"
)
}
else
{
whereClause
=
"(id = ? OR name LIKE ? OR "
+
keyCol
+
" = ?) AND "
+
modelsCol
+
" LIKE ?"
args
=
append
(
args
,
common
.
String2Int
(
keyword
),
"%"
+
keyword
+
"%"
,
keyword
,
"%"
+
model
+
"%"
)
}
err
:=
baseQuery
.
Where
(
whereClause
,
args
...
)
.
Select
(
"DISTINCT tag"
)
.
Where
(
"tag != ''"
)
.
Order
(
order
)
.
Find
(
&
tags
)
.
Error
if
err
!=
nil
{
return
nil
,
err
}
return
tags
,
nil
}
web/src/components/ChannelsTable.js
View file @
c296dfbe
...
...
@@ -768,7 +768,7 @@ const ChannelsTable = () => {
}
};
const
searchChannels
=
async
(
searchKeyword
,
searchGroup
,
searchModel
)
=>
{
const
searchChannels
=
async
(
searchKeyword
,
searchGroup
,
searchModel
,
enableTagMode
)
=>
{
if
(
searchKeyword
===
''
&&
searchGroup
===
''
&&
searchModel
===
''
)
{
await
loadChannels
(
0
,
pageSize
,
idSort
,
enableTagMode
);
setActivePage
(
1
);
...
...
@@ -982,7 +982,7 @@ const ChannelsTable = () => {
/
>
<
Form
onSubmit
=
{()
=>
{
searchChannels
(
searchKeyword
,
searchGroup
,
searchModel
);
searchChannels
(
searchKeyword
,
searchGroup
,
searchModel
,
enableTagMode
);
}}
labelPosition
=
"left"
>
...
...
@@ -1015,7 +1015,7 @@ const ChannelsTable = () => {
initValue
=
{
null
}
onChange
=
{(
v
)
=>
{
setSearchGroup
(
v
);
searchChannels
(
searchKeyword
,
v
,
searchModel
);
searchChannels
(
searchKeyword
,
v
,
searchModel
,
enableTagMode
);
}}
/
>
<
Button
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment