mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-16 13:13:41 +08:00
✨ feat: add notifier (#144)
* ♻️ refactor: email refactor * ✨ feat: add notifier
This commit is contained in:
@@ -171,7 +171,6 @@ const EditModal = ({ open, channelId, onCancel, onOk, groupOptions }) => {
|
||||
|
||||
const submit = async (values, { setErrors, setStatus, setSubmitting }) => {
|
||||
setSubmitting(true);
|
||||
console.log(values);
|
||||
values = trims(values);
|
||||
if (values.base_url && values.base_url.endsWith('/')) {
|
||||
values.base_url = values.base_url.slice(0, values.base_url.length - 1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
import { showInfo, showError, renderNumber } from 'utils/common';
|
||||
import { API } from 'utils/api';
|
||||
@@ -76,6 +76,19 @@ const StyledMenu = styled((props) => (
|
||||
}
|
||||
}));
|
||||
|
||||
function statusInfo(status) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '启用';
|
||||
case 2:
|
||||
return '手动';
|
||||
case 3:
|
||||
return '自动';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
export default function ChannelTableRow({ item, manageChannel, handleOpenModal, setModalChannelId }) {
|
||||
const [open, setOpen] = useState(null);
|
||||
const [openTest, setOpenTest] = useState(false);
|
||||
@@ -189,6 +202,14 @@ export default function ChannelTableRow({ item, manageChannel, handleOpenModal,
|
||||
await manageChannel(item.id, 'delete', '');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
setStatusSwitch(item.status);
|
||||
setPriority(item.priority);
|
||||
setWeight(item.weight);
|
||||
setItemBalance(item.balance);
|
||||
setResponseTimeData({ test_time: item.test_time, response_time: item.response_time });
|
||||
}, [item]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<TableRow tabIndex={item.id}>
|
||||
@@ -219,6 +240,7 @@ export default function ChannelTableRow({ item, manageChannel, handleOpenModal,
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<TableSwitch id={`switch-${item.id}`} checked={statusSwitch === 1} onChange={handleStatus} />
|
||||
{statusInfo(statusSwitch)}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
|
||||
@@ -335,7 +335,7 @@ export default function ChannelPage() {
|
||||
搜索
|
||||
</Button>
|
||||
<Button onClick={testAllChannels} startIcon={<IconBrandSpeedtest width={'18px'} />}>
|
||||
测试启用渠道
|
||||
测试所有渠道
|
||||
</Button>
|
||||
<Button onClick={updateAllChannelsBalance} startIcon={<IconCoinYuan width={'18px'} />}>
|
||||
更新启用余额
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import PropTypes from 'prop-types';
|
||||
import { useState } from 'react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
import {
|
||||
@@ -52,6 +52,21 @@ function createMenu(menuItems) {
|
||||
);
|
||||
}
|
||||
|
||||
function statusInfo(status) {
|
||||
switch (status) {
|
||||
case 1:
|
||||
return '已启用';
|
||||
case 2:
|
||||
return '已禁用';
|
||||
case 3:
|
||||
return '已过期';
|
||||
case 4:
|
||||
return '已耗尽';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
|
||||
export default function TokensTableRow({ item, manageToken, handleOpenModal, setModalTokenId }) {
|
||||
const [open, setOpen] = useState(null);
|
||||
const [menuItems, setMenuItems] = useState(null);
|
||||
@@ -164,6 +179,10 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
|
||||
}))
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setStatusSwitch(item.status);
|
||||
}, [item.status]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<TableRow tabIndex={item.id}>
|
||||
@@ -172,18 +191,7 @@ export default function TokensTableRow({ item, manageToken, handleOpenModal, set
|
||||
<TableCell>
|
||||
<Tooltip
|
||||
title={(() => {
|
||||
switch (statusSwitch) {
|
||||
case 1:
|
||||
return '已启用';
|
||||
case 2:
|
||||
return '已禁用';
|
||||
case 3:
|
||||
return '已过期';
|
||||
case 4:
|
||||
return '已耗尽';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
return statusInfo(statusSwitch);
|
||||
})()}
|
||||
placement="top"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user