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
65faa158
authored
Feb 15, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Optimize channel testing and model menu generation (fix #761)
parent
d43c5d60
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
web/src/components/ChannelsTable.js
+19
-16
No files found.
web/src/components/ChannelsTable.js
View file @
65faa158
...
...
@@ -357,6 +357,13 @@ const ChannelsTable = () => {
dataIndex
:
'operate'
,
render
:
(
text
,
record
,
index
)
=>
{
if
(
record
.
children
===
undefined
)
{
// 构建模型测试菜单
const
modelMenuItems
=
record
.
models
.
split
(
','
).
map
(
model
=>
({
node
:
'item'
,
name
:
model
,
onClick
:
()
=>
testChannel
(
record
,
model
)
}));
return
(
<
div
>
<
SplitButtonGroup
...
...
@@ -374,7 +381,7 @@ const ChannelsTable = () => {
<
Dropdown
trigger
=
"click"
position
=
"bottomRight"
menu
=
{
record
.
test_models
}
menu
=
{
modelMenuItems
}
// 使用即时生成的菜单项
>
<
Button
style
=
{{
padding
:
'8px 4px'
}}
...
...
@@ -545,17 +552,6 @@ const ChannelsTable = () => {
let
channelTags
=
{};
for
(
let
i
=
0
;
i
<
channels
.
length
;
i
++
)
{
channels
[
i
].
key
=
''
+
channels
[
i
].
id
;
let
test_models
=
[];
channels
[
i
].
models
.
split
(
','
).
forEach
((
item
,
index
)
=>
{
test_models
.
push
({
node
:
'item'
,
name
:
item
,
onClick
:
()
=>
{
testChannel
(
channels
[
i
],
item
);
}
});
});
channels
[
i
].
test_models
=
test_models
;
if
(
!
enableTagMode
)
{
channelDates
.
push
(
channels
[
i
]);
}
else
{
...
...
@@ -801,7 +797,8 @@ const ChannelsTable = () => {
const
updateChannelProperty
=
(
channelId
,
updateFn
)
=>
{
// Create a new copy of channels array
const
newChannels
=
[...
channels
];
let
updated
=
false
;
// Find and update the correct channel
newChannels
.
forEach
(
channel
=>
{
if
(
channel
.
children
!==
undefined
)
{
...
...
@@ -809,26 +806,32 @@ const ChannelsTable = () => {
channel
.
children
.
forEach
(
child
=>
{
if
(
child
.
id
===
channelId
)
{
updateFn
(
child
);
updated
=
true
;
}
});
}
else
if
(
channel
.
id
===
channelId
)
{
// Direct channel match
updateFn
(
channel
);
updated
=
true
;
}
});
// Update state with new array to trigger re-render
setChannels
(
newChannels
);
// Only update state if we actually modified a channel
if
(
updated
)
{
setChannels
(
newChannels
);
}
};
const
testChannel
=
async
(
record
,
model
)
=>
{
const
res
=
await
API
.
get
(
`/api/channel/test/
${
record
.
id
}
?model=
${
model
}
`
);
const
{
success
,
message
,
time
}
=
res
.
data
;
if
(
success
)
{
// Also update the channels state to persist the change
updateChannelProperty
(
record
.
id
,
(
channel
)
=>
{
channel
.
response_time
=
time
*
1000
;
channel
.
test_time
=
Date
.
now
()
/
1000
;
});
showInfo
(
t
(
'通道 ${name} 测试成功,耗时 ${time.toFixed(2)} 秒。'
).
replace
(
'${name}'
,
record
.
name
).
replace
(
'${time.toFixed(2)}'
,
time
.
toFixed
(
2
)));
}
else
{
showError
(
message
);
...
...
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