mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-18 00:16:37 +08:00
feat: Remember and automatically set page-size (close #118)
This commit is contained in:
parent
6ab1b3a524
commit
dfdeadf1a5
@ -49,27 +49,6 @@ function renderType(type) {
|
|||||||
return <Tag size='large' color={type2label[type]?.color}>{type2label[type]?.text}</Tag>;
|
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 ChannelsTable = () => {
|
||||||
const columns = [
|
const columns = [
|
||||||
// {
|
// {
|
||||||
@ -332,8 +311,10 @@ const ChannelsTable = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// console.log('default effect')
|
// console.log('default effect')
|
||||||
const localIdSort = localStorage.getItem('id-sort') === 'true';
|
const localIdSort = localStorage.getItem('id-sort') === 'true';
|
||||||
|
const localPageSize = parseInt(localStorage.getItem('page-size')) || ITEMS_PER_PAGE;
|
||||||
setIdSort(localIdSort)
|
setIdSort(localIdSort)
|
||||||
loadChannels(0, pageSize, localIdSort)
|
setPageSize(localPageSize)
|
||||||
|
loadChannels(0, localPageSize, localIdSort)
|
||||||
.then()
|
.then()
|
||||||
.catch((reason) => {
|
.catch((reason) => {
|
||||||
showError(reason);
|
showError(reason);
|
||||||
@ -341,16 +322,6 @@ const ChannelsTable = () => {
|
|||||||
fetchGroups().then();
|
fetchGroups().then();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// console.log('search effect')
|
|
||||||
// searchChannels()
|
|
||||||
// }, [searchGroup]);
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// localStorage.setItem('id-sort', idSort + '');
|
|
||||||
// refresh()
|
|
||||||
// }, [idSort]);
|
|
||||||
|
|
||||||
const manageChannel = async (id, action, record, value) => {
|
const manageChannel = async (id, action, record, value) => {
|
||||||
let data = {id};
|
let data = {id};
|
||||||
let res;
|
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);
|
let pageData = channels.slice((activePage - 1) * pageSize, activePage * pageSize);
|
||||||
|
|
||||||
const handlePageChange = page => {
|
const handlePageChange = page => {
|
||||||
@ -583,6 +532,7 @@ const ChannelsTable = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handlePageSizeChange = async(size) => {
|
const handlePageSizeChange = async(size) => {
|
||||||
|
localStorage.setItem('page-size', size + '')
|
||||||
setPageSize(size)
|
setPageSize(size)
|
||||||
setActivePage(1)
|
setActivePage(1)
|
||||||
loadChannels(0, size, idSort)
|
loadChannels(0, size, idSort)
|
||||||
|
Loading…
Reference in New Issue
Block a user