2023-04-22 13:41:16 +00:00
|
|
|
|
import React, { useEffect, useState } from 'react';
|
2023-10-14 08:32:01 +00:00
|
|
|
|
import { Button, Form, Input, Label, Message, Pagination, Popup, Table } from 'semantic-ui-react';
|
2023-04-22 13:41:16 +00:00
|
|
|
|
import { Link } from 'react-router-dom';
|
2023-10-14 08:32:01 +00:00
|
|
|
|
import { API, setPromptShown, shouldShowPrompt, showError, showInfo, showSuccess, timestamp2string } from '../helpers';
|
2023-04-22 13:41:16 +00:00
|
|
|
|
|
2023-04-23 07:42:23 +00:00
|
|
|
|
import { CHANNEL_OPTIONS, ITEMS_PER_PAGE } from '../constants';
|
2023-06-17 02:08:04 +00:00
|
|
|
|
import { renderGroup, renderNumber } from '../helpers/render';
|
2023-04-22 13:41:16 +00:00
|
|
|
|
|
2023-04-23 07:42:23 +00:00
|
|
|
|
function renderTimestamp(timestamp) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{timestamp2string(timestamp)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let type2label = undefined;
|
|
|
|
|
|
|
|
|
|
function renderType(type) {
|
|
|
|
|
if (!type2label) {
|
|
|
|
|
type2label = new Map;
|
|
|
|
|
for (let i = 0; i < CHANNEL_OPTIONS.length; i++) {
|
|
|
|
|
type2label[CHANNEL_OPTIONS[i].value] = CHANNEL_OPTIONS[i];
|
|
|
|
|
}
|
|
|
|
|
type2label[0] = { value: 0, text: '未知类型', color: 'grey' };
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}
|
2023-09-17 11:18:16 +00:00
|
|
|
|
return <Label basic color={type2label[type]?.color}>{type2label[type]?.text}</Label>;
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-11 13:04:41 +00:00
|
|
|
|
function renderBalance(type, balance) {
|
2023-06-17 02:08:04 +00:00
|
|
|
|
switch (type) {
|
|
|
|
|
case 1: // OpenAI
|
2023-07-03 12:43:42 +00:00
|
|
|
|
return <span>${balance.toFixed(2)}</span>;
|
|
|
|
|
case 4: // CloseAI
|
|
|
|
|
return <span>¥{balance.toFixed(2)}</span>;
|
2023-06-17 02:08:04 +00:00
|
|
|
|
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>;
|
2023-06-17 07:20:51 +00:00
|
|
|
|
case 12: // API2GPT
|
|
|
|
|
return <span>¥{balance.toFixed(2)}</span>;
|
2023-06-29 13:34:17 +00:00
|
|
|
|
case 13: // AIGC2D
|
|
|
|
|
return <span>{renderNumber(balance)}</span>;
|
2023-06-17 02:08:04 +00:00
|
|
|
|
default:
|
|
|
|
|
return <span>不支持</span>;
|
2023-06-11 13:04:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-22 13:41:16 +00:00
|
|
|
|
const ChannelsTable = () => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
const [channels, setChannels] = useState([]);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
|
const [activePage, setActivePage] = useState(1);
|
|
|
|
|
const [searchKeyword, setSearchKeyword] = useState('');
|
|
|
|
|
const [searching, setSearching] = useState(false);
|
2023-05-21 08:09:54 +00:00
|
|
|
|
const [updatingBalance, setUpdatingBalance] = useState(false);
|
2023-10-14 08:32:01 +00:00
|
|
|
|
const [showPrompt, setShowPrompt] = useState(shouldShowPrompt("channel-test"));
|
2023-04-22 13:41:16 +00:00
|
|
|
|
|
2023-04-23 07:42:23 +00:00
|
|
|
|
const loadChannels = async (startIdx) => {
|
|
|
|
|
const res = await API.get(`/api/channel/?p=${startIdx}`);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
if (success) {
|
|
|
|
|
if (startIdx === 0) {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
setChannels(data);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
} else {
|
2023-07-02 07:55:49 +00:00
|
|
|
|
let newChannels = [...channels];
|
|
|
|
|
newChannels.splice(startIdx * ITEMS_PER_PAGE, data.length, ...data);
|
2023-04-23 07:42:23 +00:00
|
|
|
|
setChannels(newChannels);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
setLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onPaginationChange = (e, { activePage }) => {
|
|
|
|
|
(async () => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
if (activePage === Math.ceil(channels.length / ITEMS_PER_PAGE) + 1) {
|
2023-04-22 13:41:16 +00:00
|
|
|
|
// In this case we have to load more data and then append them.
|
2023-04-23 07:42:23 +00:00
|
|
|
|
await loadChannels(activePage - 1);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}
|
|
|
|
|
setActivePage(activePage);
|
|
|
|
|
})();
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-15 08:20:01 +00:00
|
|
|
|
const refresh = async () => {
|
|
|
|
|
setLoading(true);
|
2023-07-02 07:55:49 +00:00
|
|
|
|
await loadChannels(activePage - 1);
|
2023-05-21 08:09:54 +00:00
|
|
|
|
};
|
2023-05-15 08:20:01 +00:00
|
|
|
|
|
2023-04-22 13:41:16 +00:00
|
|
|
|
useEffect(() => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
loadChannels(0)
|
2023-04-22 13:41:16 +00:00
|
|
|
|
.then()
|
|
|
|
|
.catch((reason) => {
|
|
|
|
|
showError(reason);
|
|
|
|
|
});
|
|
|
|
|
}, []);
|
|
|
|
|
|
2023-10-02 05:06:27 +00:00
|
|
|
|
const manageChannel = async (id, action, idx, value) => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
let data = { id };
|
|
|
|
|
let res;
|
|
|
|
|
switch (action) {
|
|
|
|
|
case 'delete':
|
|
|
|
|
res = await API.delete(`/api/channel/${id}/`);
|
|
|
|
|
break;
|
|
|
|
|
case 'enable':
|
|
|
|
|
data.status = 1;
|
|
|
|
|
res = await API.put('/api/channel/', data);
|
|
|
|
|
break;
|
|
|
|
|
case 'disable':
|
|
|
|
|
data.status = 2;
|
|
|
|
|
res = await API.put('/api/channel/', data);
|
|
|
|
|
break;
|
2023-09-17 11:18:16 +00:00
|
|
|
|
case 'priority':
|
2023-10-02 05:06:27 +00:00
|
|
|
|
if (value === '') {
|
2023-09-17 11:18:16 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-02 05:06:27 +00:00
|
|
|
|
data.priority = parseInt(value);
|
|
|
|
|
res = await API.put('/api/channel/', data);
|
|
|
|
|
break;
|
|
|
|
|
case 'weight':
|
|
|
|
|
if (value === '') {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
data.weight = parseInt(value);
|
|
|
|
|
if (data.weight < 0) {
|
|
|
|
|
data.weight = 0;
|
|
|
|
|
}
|
2023-09-17 11:18:16 +00:00
|
|
|
|
res = await API.put('/api/channel/', data);
|
|
|
|
|
break;
|
2023-04-23 07:42:23 +00:00
|
|
|
|
}
|
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
if (success) {
|
|
|
|
|
showSuccess('操作成功完成!');
|
|
|
|
|
let channel = res.data.data;
|
|
|
|
|
let newChannels = [...channels];
|
|
|
|
|
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
|
|
|
|
if (action === 'delete') {
|
|
|
|
|
newChannels[realIdx].deleted = true;
|
2023-04-22 13:41:16 +00:00
|
|
|
|
} else {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
newChannels[realIdx].status = channel.status;
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}
|
2023-04-23 07:42:23 +00:00
|
|
|
|
setChannels(newChannels);
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
2023-04-22 13:41:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renderStatus = (status) => {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case 1:
|
2023-04-23 07:42:23 +00:00
|
|
|
|
return <Label basic color='green'>已启用</Label>;
|
2023-04-22 13:41:16 +00:00
|
|
|
|
case 2:
|
|
|
|
|
return (
|
2023-10-02 05:06:27 +00:00
|
|
|
|
<Popup
|
|
|
|
|
trigger={<Label basic color='red'>
|
|
|
|
|
已禁用
|
|
|
|
|
</Label>}
|
|
|
|
|
content='本渠道被手动禁用'
|
|
|
|
|
basic
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
case 3:
|
|
|
|
|
return (
|
|
|
|
|
<Popup
|
|
|
|
|
trigger={<Label basic color='yellow'>
|
|
|
|
|
已禁用
|
|
|
|
|
</Label>}
|
|
|
|
|
content='本渠道被程序自动禁用'
|
|
|
|
|
basic
|
|
|
|
|
/>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
);
|
|
|
|
|
default:
|
|
|
|
|
return (
|
|
|
|
|
<Label basic color='grey'>
|
|
|
|
|
未知状态
|
|
|
|
|
</Label>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-15 03:35:38 +00:00
|
|
|
|
const renderResponseTime = (responseTime) => {
|
|
|
|
|
let time = responseTime / 1000;
|
2023-05-21 08:09:54 +00:00
|
|
|
|
time = time.toFixed(2) + ' 秒';
|
2023-05-15 03:35:38 +00:00
|
|
|
|
if (responseTime === 0) {
|
|
|
|
|
return <Label basic color='grey'>未测试</Label>;
|
|
|
|
|
} else if (responseTime <= 1000) {
|
|
|
|
|
return <Label basic color='green'>{time}</Label>;
|
|
|
|
|
} else if (responseTime <= 3000) {
|
|
|
|
|
return <Label basic color='olive'>{time}</Label>;
|
|
|
|
|
} else if (responseTime <= 5000) {
|
|
|
|
|
return <Label basic color='yellow'>{time}</Label>;
|
|
|
|
|
} else {
|
|
|
|
|
return <Label basic color='red'>{time}</Label>;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-23 07:42:23 +00:00
|
|
|
|
const searchChannels = async () => {
|
2023-04-22 13:41:16 +00:00
|
|
|
|
if (searchKeyword === '') {
|
|
|
|
|
// if keyword is blank, load files instead.
|
2023-04-23 07:42:23 +00:00
|
|
|
|
await loadChannels(0);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
setActivePage(1);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setSearching(true);
|
2023-04-23 07:42:23 +00:00
|
|
|
|
const res = await API.get(`/api/channel/search?keyword=${searchKeyword}`);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
if (success) {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
setChannels(data);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
setActivePage(1);
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
setSearching(false);
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-15 03:35:38 +00:00
|
|
|
|
const testChannel = async (id, name, idx) => {
|
2023-05-15 02:48:52 +00:00
|
|
|
|
const res = await API.get(`/api/channel/test/${id}/`);
|
|
|
|
|
const { success, message, time } = res.data;
|
|
|
|
|
if (success) {
|
2023-05-15 03:35:38 +00:00
|
|
|
|
let newChannels = [...channels];
|
|
|
|
|
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
|
|
|
|
newChannels[realIdx].response_time = time * 1000;
|
|
|
|
|
newChannels[realIdx].test_time = Date.now() / 1000;
|
|
|
|
|
setChannels(newChannels);
|
2023-05-15 04:56:28 +00:00
|
|
|
|
showInfo(`通道 ${name} 测试成功,耗时 ${time.toFixed(2)} 秒。`);
|
2023-05-15 02:48:52 +00:00
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
2023-05-15 03:35:38 +00:00
|
|
|
|
};
|
2023-05-15 02:48:52 +00:00
|
|
|
|
|
2023-05-15 04:36:55 +00:00
|
|
|
|
const testAllChannels = async () => {
|
|
|
|
|
const res = await API.get(`/api/channel/test`);
|
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
if (success) {
|
2023-12-03 12:10:57 +00:00
|
|
|
|
showInfo('已成功开始测试所有通道,请刷新页面查看结果。');
|
2023-05-15 04:36:55 +00:00
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
2023-05-21 08:09:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-10-14 09:25:48 +00:00
|
|
|
|
const deleteAllDisabledChannels = async () => {
|
|
|
|
|
const res = await API.delete(`/api/channel/disabled`);
|
2023-10-02 05:06:27 +00:00
|
|
|
|
const { success, message, data } = res.data;
|
|
|
|
|
if (success) {
|
2023-10-14 09:25:48 +00:00
|
|
|
|
showSuccess(`已删除所有禁用渠道,共计 ${data} 个`);
|
2023-10-02 05:06:27 +00:00
|
|
|
|
await refresh();
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-21 08:09:54 +00:00
|
|
|
|
const updateChannelBalance = async (id, name, idx) => {
|
|
|
|
|
const res = await API.get(`/api/channel/update_balance/${id}/`);
|
|
|
|
|
const { success, message, balance } = res.data;
|
|
|
|
|
if (success) {
|
|
|
|
|
let newChannels = [...channels];
|
|
|
|
|
let realIdx = (activePage - 1) * ITEMS_PER_PAGE + idx;
|
|
|
|
|
newChannels[realIdx].balance = balance;
|
|
|
|
|
newChannels[realIdx].balance_updated_time = Date.now() / 1000;
|
|
|
|
|
setChannels(newChannels);
|
|
|
|
|
showInfo(`通道 ${name} 余额更新成功!`);
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const updateAllChannelsBalance = async () => {
|
|
|
|
|
setUpdatingBalance(true);
|
|
|
|
|
const res = await API.get(`/api/channel/update_balance`);
|
|
|
|
|
const { success, message } = res.data;
|
|
|
|
|
if (success) {
|
|
|
|
|
showInfo('已更新完毕所有已启用通道余额!');
|
|
|
|
|
} else {
|
|
|
|
|
showError(message);
|
|
|
|
|
}
|
|
|
|
|
setUpdatingBalance(false);
|
|
|
|
|
};
|
2023-05-15 04:36:55 +00:00
|
|
|
|
|
2023-04-22 13:41:16 +00:00
|
|
|
|
const handleKeywordChange = async (e, { value }) => {
|
|
|
|
|
setSearchKeyword(value.trim());
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-23 07:42:23 +00:00
|
|
|
|
const sortChannel = (key) => {
|
|
|
|
|
if (channels.length === 0) return;
|
2023-04-22 13:41:16 +00:00
|
|
|
|
setLoading(true);
|
2023-04-23 07:42:23 +00:00
|
|
|
|
let sortedChannels = [...channels];
|
2023-11-10 13:20:05 +00:00
|
|
|
|
sortedChannels.sort((a, b) => {
|
|
|
|
|
if (!isNaN(a[key])) {
|
|
|
|
|
// If the value is numeric, subtract to sort
|
|
|
|
|
return a[key] - b[key];
|
|
|
|
|
} else {
|
|
|
|
|
// If the value is not numeric, sort as strings
|
2023-06-21 15:42:55 +00:00
|
|
|
|
return ('' + a[key]).localeCompare(b[key]);
|
2023-11-10 13:20:05 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2023-04-23 07:42:23 +00:00
|
|
|
|
if (sortedChannels[0].id === channels[0].id) {
|
|
|
|
|
sortedChannels.reverse();
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}
|
2023-04-23 07:42:23 +00:00
|
|
|
|
setChannels(sortedChannels);
|
2023-04-22 13:41:16 +00:00
|
|
|
|
setLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-10 13:20:05 +00:00
|
|
|
|
|
2023-04-22 13:41:16 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
<Form onSubmit={searchChannels}>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
<Form.Input
|
|
|
|
|
icon='search'
|
|
|
|
|
fluid
|
|
|
|
|
iconPosition='left'
|
2023-06-22 13:19:43 +00:00
|
|
|
|
placeholder='搜索渠道的 ID,名称和密钥 ...'
|
2023-04-22 13:41:16 +00:00
|
|
|
|
value={searchKeyword}
|
|
|
|
|
loading={searching}
|
|
|
|
|
onChange={handleKeywordChange}
|
|
|
|
|
/>
|
|
|
|
|
</Form>
|
2023-10-14 08:32:01 +00:00
|
|
|
|
{
|
|
|
|
|
showPrompt && (
|
|
|
|
|
<Message onDismiss={() => {
|
|
|
|
|
setShowPrompt(false);
|
|
|
|
|
setPromptShown("channel-test");
|
|
|
|
|
}}>
|
|
|
|
|
当前版本测试是通过按照 OpenAI API 格式使用 gpt-3.5-turbo
|
|
|
|
|
模型进行非流式请求实现的,因此测试报错并不一定代表通道不可用,该功能后续会修复。
|
2023-04-22 13:41:16 +00:00
|
|
|
|
|
2023-10-14 08:32:01 +00:00
|
|
|
|
另外,OpenAI 渠道已经不再支持通过 key 获取余额,因此余额显示为 0。对于支持的渠道类型,请点击余额进行刷新。
|
|
|
|
|
</Message>
|
|
|
|
|
)
|
|
|
|
|
}
|
2023-06-17 11:23:25 +00:00
|
|
|
|
<Table basic compact size='small'>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
<Table.Header>
|
|
|
|
|
<Table.Row>
|
|
|
|
|
<Table.HeaderCell
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
sortChannel('id');
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
ID
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Table.HeaderCell>
|
|
|
|
|
<Table.HeaderCell
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
sortChannel('name');
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
名称
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Table.HeaderCell>
|
2023-06-07 15:26:00 +00:00
|
|
|
|
<Table.HeaderCell
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
sortChannel('group');
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
分组
|
|
|
|
|
</Table.HeaderCell>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
<Table.HeaderCell
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
sortChannel('type');
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
类型
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Table.HeaderCell>
|
|
|
|
|
<Table.HeaderCell
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
sortChannel('status');
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
状态
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Table.HeaderCell>
|
|
|
|
|
<Table.HeaderCell
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
2023-05-15 03:35:38 +00:00
|
|
|
|
sortChannel('response_time');
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-05-15 03:35:38 +00:00
|
|
|
|
响应时间
|
2023-04-23 07:42:23 +00:00
|
|
|
|
</Table.HeaderCell>
|
|
|
|
|
<Table.HeaderCell
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
2023-05-21 08:09:54 +00:00
|
|
|
|
sortChannel('balance');
|
2023-04-23 07:42:23 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2023-05-21 08:09:54 +00:00
|
|
|
|
余额
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Table.HeaderCell>
|
2023-09-17 11:18:16 +00:00
|
|
|
|
<Table.HeaderCell
|
2023-10-02 05:06:27 +00:00
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
sortChannel('priority');
|
|
|
|
|
}}
|
2023-09-17 11:18:16 +00:00
|
|
|
|
>
|
|
|
|
|
优先级
|
|
|
|
|
</Table.HeaderCell>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
<Table.HeaderCell>操作</Table.HeaderCell>
|
|
|
|
|
</Table.Row>
|
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
|
|
<Table.Body>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
{channels
|
2023-04-22 13:41:16 +00:00
|
|
|
|
.slice(
|
|
|
|
|
(activePage - 1) * ITEMS_PER_PAGE,
|
|
|
|
|
activePage * ITEMS_PER_PAGE
|
|
|
|
|
)
|
2023-04-23 07:42:23 +00:00
|
|
|
|
.map((channel, idx) => {
|
|
|
|
|
if (channel.deleted) return <></>;
|
2023-04-22 13:41:16 +00:00
|
|
|
|
return (
|
2023-04-23 07:42:23 +00:00
|
|
|
|
<Table.Row key={channel.id}>
|
|
|
|
|
<Table.Cell>{channel.id}</Table.Cell>
|
|
|
|
|
<Table.Cell>{channel.name ? channel.name : '无'}</Table.Cell>
|
2023-06-07 15:26:00 +00:00
|
|
|
|
<Table.Cell>{renderGroup(channel.group)}</Table.Cell>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
<Table.Cell>{renderType(channel.type)}</Table.Cell>
|
|
|
|
|
<Table.Cell>{renderStatus(channel.status)}</Table.Cell>
|
2023-05-21 08:09:54 +00:00
|
|
|
|
<Table.Cell>
|
|
|
|
|
<Popup
|
|
|
|
|
content={channel.test_time ? renderTimestamp(channel.test_time) : '未测试'}
|
|
|
|
|
key={channel.id}
|
|
|
|
|
trigger={renderResponseTime(channel.response_time)}
|
|
|
|
|
basic
|
|
|
|
|
/>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell>
|
|
|
|
|
<Popup
|
2023-07-29 11:32:06 +00:00
|
|
|
|
trigger={<span onClick={() => {
|
|
|
|
|
updateChannelBalance(channel.id, channel.name, idx);
|
|
|
|
|
}} style={{ cursor: 'pointer' }}>
|
|
|
|
|
{renderBalance(channel.type, channel.balance)}
|
|
|
|
|
</span>}
|
2023-08-12 16:45:04 +00:00
|
|
|
|
content='点击更新'
|
2023-05-21 08:09:54 +00:00
|
|
|
|
basic
|
|
|
|
|
/>
|
|
|
|
|
</Table.Cell>
|
2023-09-17 11:18:16 +00:00
|
|
|
|
<Table.Cell>
|
|
|
|
|
<Popup
|
2023-10-02 05:06:27 +00:00
|
|
|
|
trigger={<Input type='number' defaultValue={channel.priority} onBlur={(event) => {
|
|
|
|
|
manageChannel(
|
|
|
|
|
channel.id,
|
|
|
|
|
'priority',
|
|
|
|
|
idx,
|
|
|
|
|
event.target.value
|
|
|
|
|
);
|
|
|
|
|
}}>
|
|
|
|
|
<input style={{ maxWidth: '60px' }} />
|
|
|
|
|
</Input>}
|
|
|
|
|
content='渠道选择优先级,越高越优先'
|
|
|
|
|
basic
|
2023-09-17 11:18:16 +00:00
|
|
|
|
/>
|
|
|
|
|
</Table.Cell>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
<Table.Cell>
|
|
|
|
|
<div>
|
2023-05-15 02:48:52 +00:00
|
|
|
|
<Button
|
|
|
|
|
size={'small'}
|
|
|
|
|
positive
|
|
|
|
|
onClick={() => {
|
2023-05-15 03:35:38 +00:00
|
|
|
|
testChannel(channel.id, channel.name, idx);
|
2023-05-15 02:48:52 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
测试
|
|
|
|
|
</Button>
|
2023-07-29 11:32:06 +00:00
|
|
|
|
{/*<Button*/}
|
|
|
|
|
{/* size={'small'}*/}
|
|
|
|
|
{/* positive*/}
|
|
|
|
|
{/* loading={updatingBalance}*/}
|
|
|
|
|
{/* onClick={() => {*/}
|
|
|
|
|
{/* updateChannelBalance(channel.id, channel.name, idx);*/}
|
|
|
|
|
{/* }}*/}
|
|
|
|
|
{/*>*/}
|
|
|
|
|
{/* 更新余额*/}
|
|
|
|
|
{/*</Button>*/}
|
2023-05-15 02:41:48 +00:00
|
|
|
|
<Popup
|
|
|
|
|
trigger={
|
|
|
|
|
<Button size='small' negative>
|
|
|
|
|
删除
|
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
on='click'
|
|
|
|
|
flowing
|
|
|
|
|
hoverable
|
2023-04-22 13:41:16 +00:00
|
|
|
|
>
|
2023-05-15 02:41:48 +00:00
|
|
|
|
<Button
|
|
|
|
|
negative
|
|
|
|
|
onClick={() => {
|
|
|
|
|
manageChannel(channel.id, 'delete', idx);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
删除渠道 {channel.name}
|
|
|
|
|
</Button>
|
|
|
|
|
</Popup>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
<Button
|
|
|
|
|
size={'small'}
|
|
|
|
|
onClick={() => {
|
2023-04-23 07:42:23 +00:00
|
|
|
|
manageChannel(
|
|
|
|
|
channel.id,
|
|
|
|
|
channel.status === 1 ? 'disable' : 'enable',
|
2023-04-22 13:41:16 +00:00
|
|
|
|
idx
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
{channel.status === 1 ? '禁用' : '启用'}
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
size={'small'}
|
|
|
|
|
as={Link}
|
2023-04-23 07:42:23 +00:00
|
|
|
|
to={'/channel/edit/' + channel.id}
|
2023-04-22 13:41:16 +00:00
|
|
|
|
>
|
|
|
|
|
编辑
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
</Table.Row>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</Table.Body>
|
|
|
|
|
|
|
|
|
|
<Table.Footer>
|
|
|
|
|
<Table.Row>
|
2023-09-17 11:18:16 +00:00
|
|
|
|
<Table.HeaderCell colSpan='9'>
|
2023-04-23 07:42:23 +00:00
|
|
|
|
<Button size='small' as={Link} to='/channel/add' loading={loading}>
|
|
|
|
|
添加新的渠道
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Button>
|
2023-05-15 04:36:55 +00:00
|
|
|
|
<Button size='small' loading={loading} onClick={testAllChannels}>
|
2024-01-01 09:09:12 +00:00
|
|
|
|
测试所有渠道
|
2023-05-15 04:36:55 +00:00
|
|
|
|
</Button>
|
2023-08-12 16:45:04 +00:00
|
|
|
|
<Button size='small' onClick={updateAllChannelsBalance}
|
2024-01-01 09:09:12 +00:00
|
|
|
|
loading={loading || updatingBalance}>更新已启用渠道余额</Button>
|
2023-10-02 05:06:27 +00:00
|
|
|
|
<Popup
|
|
|
|
|
trigger={
|
|
|
|
|
<Button size='small' loading={loading}>
|
2023-10-14 09:25:48 +00:00
|
|
|
|
删除禁用渠道
|
2023-10-02 05:06:27 +00:00
|
|
|
|
</Button>
|
|
|
|
|
}
|
|
|
|
|
on='click'
|
|
|
|
|
flowing
|
|
|
|
|
hoverable
|
|
|
|
|
>
|
2023-10-14 09:25:48 +00:00
|
|
|
|
<Button size='small' loading={loading} negative onClick={deleteAllDisabledChannels}>
|
2023-10-02 05:06:27 +00:00
|
|
|
|
确认删除
|
|
|
|
|
</Button>
|
|
|
|
|
</Popup>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
<Pagination
|
|
|
|
|
floated='right'
|
|
|
|
|
activePage={activePage}
|
|
|
|
|
onPageChange={onPaginationChange}
|
|
|
|
|
size='small'
|
|
|
|
|
siblingRange={1}
|
|
|
|
|
totalPages={
|
2023-04-23 07:42:23 +00:00
|
|
|
|
Math.ceil(channels.length / ITEMS_PER_PAGE) +
|
|
|
|
|
(channels.length % ITEMS_PER_PAGE === 0 ? 1 : 0)
|
2023-04-22 13:41:16 +00:00
|
|
|
|
}
|
|
|
|
|
/>
|
2023-05-15 08:20:01 +00:00
|
|
|
|
<Button size='small' onClick={refresh} loading={loading}>刷新</Button>
|
2023-04-22 13:41:16 +00:00
|
|
|
|
</Table.HeaderCell>
|
|
|
|
|
</Table.Row>
|
|
|
|
|
</Table.Footer>
|
|
|
|
|
</Table>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ChannelsTable;
|