From 5a8fef00e5a74f09be1a6a199eab0c9ab9985b0f Mon Sep 17 00:00:00 2001 From: Martial BE Date: Fri, 22 Dec 2023 11:01:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20=E8=A1=A5=E5=85=A8=E4=BD=99?= =?UTF-8?q?=E9=A2=9D=E6=9F=A5=E8=AF=A2web=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/views/Channel/component/TableRow.js | 44 ++++++++++++++++++++- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/web/src/views/Channel/component/TableRow.js b/web/src/views/Channel/component/TableRow.js index cedc5911..84c35b74 100644 --- a/web/src/views/Channel/component/TableRow.js +++ b/web/src/views/Channel/component/TableRow.js @@ -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} /> - {item.balance} + + + {renderBalance(itemBalance)} + + 优先级 @@ -192,3 +211,24 @@ ChannelTableRow.propTypes = { handleOpenModal: PropTypes.func, setModalChannelId: PropTypes.func }; + +function renderBalance(type, balance) { + switch (type) { + case 1: // OpenAI + return ${balance.toFixed(2)}; + case 4: // CloseAI + return ¥{balance.toFixed(2)}; + case 8: // 自定义 + return ${balance.toFixed(2)}; + case 5: // OpenAI-SB + return ¥{(balance / 10000).toFixed(2)}; + case 10: // AI Proxy + return {renderNumber(balance)}; + case 12: // API2GPT + return ¥{balance.toFixed(2)}; + case 13: // AIGC2D + return {renderNumber(balance)}; + default: + return 不支持; + } +}