🚧 补全余额查询web操作

This commit is contained in:
Martial BE 2023-12-22 11:01:19 +08:00
parent fe72f85554
commit 5a8fef00e5
No known key found for this signature in database
GPG Key ID: D06C32DF0EDB9084

View File

@ -1,7 +1,8 @@
import PropTypes from 'prop-types';
import { useState } from 'react';
import { showInfo } from 'utils/common';
import { showInfo, showError } from 'utils/common';
import { API } from 'utils/api';
import { CHANNEL_OPTIONS } from 'constants/ChannelConstants';
import {
@ -19,6 +20,7 @@ import {
DialogContent,
DialogContentText,
DialogTitle,
Tooltip,
Button
} from '@mui/material';
@ -36,6 +38,7 @@ export default function ChannelTableRow({ item, manageChannel, handleOpenModal,
const [statusSwitch, setStatusSwitch] = useState(item.status);
const [priorityValve, setPriority] = useState(item.priority);
const [responseTimeData, setResponseTimeData] = useState({ test_time: item.test_time, response_time: item.response_time });
const [itemBalance, setItemBalance] = useState(item.balance);
const handleDeleteOpen = () => {
handleCloseMenu();
@ -77,6 +80,18 @@ export default function ChannelTableRow({ item, manageChannel, handleOpenModal,
}
};
const updateChannelBalance = async () => {
const res = await API.get(`/api/channel/update_balance/${item.id}`);
const { success, message, balance } = res.data;
if (success) {
setItemBalance(balance);
showInfo(`余额更新成功!`);
} else {
showError(message);
}
};
const handleDelete = async () => {
handleCloseMenu();
await manageChannel(item.id, 'delete', '');
@ -116,7 +131,11 @@ export default function ChannelTableRow({ item, manageChannel, handleOpenModal,
handle_action={handleResponseTime}
/>
</TableCell>
<TableCell>{item.balance}</TableCell>
<TableCell>
<Tooltip title={'点击更新余额'} placement="top" onClick={updateChannelBalance}>
{renderBalance(itemBalance)}
</Tooltip>
</TableCell>
<TableCell>
<FormControl sx={{ m: 1, width: '70px' }} variant="standard">
<InputLabel htmlFor={`priority-${item.id}`}>优先级</InputLabel>
@ -192,3 +211,24 @@ ChannelTableRow.propTypes = {
handleOpenModal: PropTypes.func,
setModalChannelId: PropTypes.func
};
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>;
}
}