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
44d57602
authored
Mar 15, 2024
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Remember and automatically set page-size (close #118)
parent
859697f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
54 deletions
+4
-54
web/src/components/ChannelsTable.js
+4
-54
No files found.
web/src/components/ChannelsTable.js
View file @
44d57602
...
...
@@ -49,27 +49,6 @@ function renderType(type) {
return
<
Tag
size
=
'large'
color
=
{
type2label
[
type
]?.
color
}
>
{
type2label
[
type
]?.
text
}
<
/Tag>
;
}
function
renderBalance
(
type
,
balance
)
{
switch
(
type
)
{
case
1
:
// OpenAI
return
<
span
>
$
{
balance
.
toFixed
(
2
)}
<
/span>
;
case
4
:
// CloseAI
return
<
span
>
¥
{
balance
.
toFixed
(
2
)}
<
/span>
;
case
8
:
// 自定义
return
<
span
>
$
{
balance
.
toFixed
(
2
)}
<
/span>
;
case
5
:
// OpenAI-SB
return
<
span
>
¥
{(
balance
/
10000
).
toFixed
(
2
)}
<
/span>
;
case
10
:
// AI Proxy
return
<
span
>
{
renderNumber
(
balance
)}
<
/span>
;
case
12
:
// API2GPT
return
<
span
>
¥
{
balance
.
toFixed
(
2
)}
<
/span>
;
case
13
:
// AIGC2D
return
<
span
>
{
renderNumber
(
balance
)}
<
/span>
;
default
:
return
<
span
>
不支持
<
/span>
;
}
}
const
ChannelsTable
=
()
=>
{
const
columns
=
[
// {
...
...
@@ -332,8 +311,10 @@ const ChannelsTable = () => {
useEffect
(()
=>
{
// console.log('default effect')
const
localIdSort
=
localStorage
.
getItem
(
'id-sort'
)
===
'true'
;
const
localPageSize
=
parseInt
(
localStorage
.
getItem
(
'page-size'
))
||
ITEMS_PER_PAGE
;
setIdSort
(
localIdSort
)
loadChannels
(
0
,
pageSize
,
localIdSort
)
setPageSize
(
localPageSize
)
loadChannels
(
0
,
localPageSize
,
localIdSort
)
.
then
()
.
catch
((
reason
)
=>
{
showError
(
reason
);
...
...
@@ -341,16 +322,6 @@ const ChannelsTable = () => {
fetchGroups
().
then
();
},
[]);
// useEffect(() => {
// console.log('search effect')
// searchChannels()
// }, [searchGroup]);
// useEffect(() => {
// localStorage.setItem('id-sort', idSort + '');
// refresh()
// }, [idSort]);
const
manageChannel
=
async
(
id
,
action
,
record
,
value
)
=>
{
let
data
=
{
id
};
let
res
;
...
...
@@ -549,28 +520,6 @@ const ChannelsTable = () => {
}
}
const
sortChannel
=
(
key
)
=>
{
if
(
channels
.
length
===
0
)
return
;
setLoading
(
true
);
let
sortedChannels
=
[...
channels
];
if
(
typeof
sortedChannels
[
0
][
key
]
===
'string'
)
{
sortedChannels
.
sort
((
a
,
b
)
=>
{
return
(
''
+
a
[
key
]).
localeCompare
(
b
[
key
]);
});
}
else
{
sortedChannels
.
sort
((
a
,
b
)
=>
{
if
(
a
[
key
]
===
b
[
key
])
return
0
;
if
(
a
[
key
]
>
b
[
key
])
return
-
1
;
if
(
a
[
key
]
<
b
[
key
])
return
1
;
});
}
if
(
sortedChannels
[
0
].
id
===
channels
[
0
].
id
)
{
sortedChannels
.
reverse
();
}
setChannels
(
sortedChannels
);
setLoading
(
false
);
};
let
pageData
=
channels
.
slice
((
activePage
-
1
)
*
pageSize
,
activePage
*
pageSize
);
const
handlePageChange
=
page
=>
{
...
...
@@ -583,6 +532,7 @@ const ChannelsTable = () => {
};
const
handlePageSizeChange
=
async
(
size
)
=>
{
localStorage
.
setItem
(
'page-size'
,
size
+
''
)
setPageSize
(
size
)
setActivePage
(
1
)
loadChannels
(
0
,
size
,
idSort
)
...
...
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