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
dd2beeba
authored
Dec 06, 2024
by
Calcium-Ion
Committed by
GitHub
Dec 06, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #597 from daggeryu/patch-3
fix 关键词搜索加标签聚合时,大于1个空标签渠道无法展开的问题
parents
246c3fa4
c296dfbe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
12 deletions
+86
-12
controller/channel.go
+30
-8
model/channel.go
+52
-0
web/src/components/ChannelsTable.js
+4
-4
No files found.
controller/channel.go
View file @
dd2beeba
...
...
@@ -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 @
dd2beeba
...
...
@@ -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 @
dd2beeba
...
...
@@ -484,7 +484,7 @@ const ChannelsTable = () => {
if
(
!
enableTagMode
)
{
channelDates
.
push
(
channels
[
i
]);
}
else
{
let
tag
=
channels
[
i
].
tag
;
let
tag
=
channels
[
i
].
tag
?
channels
[
i
].
tag
:
""
;
// find from channelTags
let
tagIndex
=
channelTags
[
tag
];
let
tagChannelDates
=
undefined
;
...
...
@@ -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