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
d43c5d60
authored
Feb 15, 2025
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor: Improve channel property update mechanism (fix #761)
parent
27a1e493
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
18 deletions
+40
-18
web/src/components/ChannelsTable.js
+40
-18
No files found.
web/src/components/ChannelsTable.js
View file @
d43c5d60
...
@@ -798,16 +798,52 @@ const ChannelsTable = () => {
...
@@ -798,16 +798,52 @@ const ChannelsTable = () => {
setSearching
(
false
);
setSearching
(
false
);
};
};
const
updateChannelProperty
=
(
channelId
,
updateFn
)
=>
{
// Create a new copy of channels array
const
newChannels
=
[...
channels
];
// Find and update the correct channel
newChannels
.
forEach
(
channel
=>
{
if
(
channel
.
children
!==
undefined
)
{
// If this is a tag group, search in its children
channel
.
children
.
forEach
(
child
=>
{
if
(
child
.
id
===
channelId
)
{
updateFn
(
child
);
}
});
}
else
if
(
channel
.
id
===
channelId
)
{
// Direct channel match
updateFn
(
channel
);
}
});
// Update state with new array to trigger re-render
setChannels
(
newChannels
);
};
const
testChannel
=
async
(
record
,
model
)
=>
{
const
testChannel
=
async
(
record
,
model
)
=>
{
const
res
=
await
API
.
get
(
`/api/channel/test/
${
record
.
id
}
?model=
${
model
}
`
);
const
res
=
await
API
.
get
(
`/api/channel/test/
${
record
.
id
}
?model=
${
model
}
`
);
const
{
success
,
message
,
time
}
=
res
.
data
;
const
{
success
,
message
,
time
}
=
res
.
data
;
if
(
success
)
{
if
(
success
)
{
record
.
response_time
=
time
*
1000
;
updateChannelProperty
(
record
.
id
,
(
channel
)
=>
{
record
.
test_time
=
Date
.
now
()
/
1000
;
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
)));
showInfo
(
t
(
'通道 ${name} 测试成功,耗时 ${time.toFixed(2)} 秒。'
).
replace
(
'${name}'
,
record
.
name
).
replace
(
'${time.toFixed(2)}'
,
time
.
toFixed
(
2
)));
}
else
{
showError
(
message
);
}
};
// 刷新列表
const
updateChannelBalance
=
async
(
record
)
=>
{
await
refresh
();
const
res
=
await
API
.
get
(
`/api/channel/update_balance/
${
record
.
id
}
/`
);
const
{
success
,
message
,
balance
}
=
res
.
data
;
if
(
success
)
{
updateChannelProperty
(
record
.
id
,
(
channel
)
=>
{
channel
.
balance
=
balance
;
channel
.
balance_updated_time
=
Date
.
now
()
/
1000
;
});
showInfo
(
t
(
'通道 ${name} 余额更新成功!'
).
replace
(
'${name}'
,
record
.
name
));
}
else
{
}
else
{
showError
(
message
);
showError
(
message
);
}
}
...
@@ -834,20 +870,6 @@ const ChannelsTable = () => {
...
@@ -834,20 +870,6 @@ const ChannelsTable = () => {
}
}
};
};
const
updateChannelBalance
=
async
(
record
)
=>
{
const
res
=
await
API
.
get
(
`/api/channel/update_balance/
${
record
.
id
}
/`
);
const
{
success
,
message
,
balance
}
=
res
.
data
;
if
(
success
)
{
record
.
balance
=
balance
;
record
.
balance_updated_time
=
Date
.
now
()
/
1000
;
showInfo
(
t
(
'通道 ${name} 余额更新成功!'
).
replace
(
'${name}'
,
record
.
name
));
// 刷新列表
await
refresh
();
}
else
{
showError
(
message
);
}
};
const
updateAllChannelsBalance
=
async
()
=>
{
const
updateAllChannelsBalance
=
async
()
=>
{
setUpdatingBalance
(
true
);
setUpdatingBalance
(
true
);
const
res
=
await
API
.
get
(
`/api/channel/update_balance`
);
const
res
=
await
API
.
get
(
`/api/channel/update_balance`
);
...
...
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