|
|
@@ -7,14 +7,14 @@ import {
|
|
|
showInfo,
|
|
|
showSuccess,
|
|
|
showWarning,
|
|
|
- timestamp2string,
|
|
|
+ timestamp2string
|
|
|
} from '../helpers';
|
|
|
|
|
|
import { CHANNEL_OPTIONS, ITEMS_PER_PAGE } from '../constants';
|
|
|
import {
|
|
|
renderGroup,
|
|
|
renderNumberWithPoint,
|
|
|
- renderQuota,
|
|
|
+ renderQuota
|
|
|
} from '../helpers/render';
|
|
|
import {
|
|
|
Button, Divider,
|
|
|
@@ -28,11 +28,12 @@ import {
|
|
|
Table,
|
|
|
Tag,
|
|
|
Tooltip,
|
|
|
- Typography,
|
|
|
+ Typography
|
|
|
} from '@douyinfe/semi-ui';
|
|
|
import EditChannel from '../pages/Channel/EditChannel';
|
|
|
import { IconTreeTriangleDown } from '@douyinfe/semi-icons';
|
|
|
import { loadChannelModels } from './utils.js';
|
|
|
+import EditTagModal from '../pages/Channel/EditTagModal.js';
|
|
|
|
|
|
function renderTimestamp(timestamp) {
|
|
|
return <>{timestamp2string(timestamp)}</>;
|
|
|
@@ -49,7 +50,7 @@ function renderType(type) {
|
|
|
type2label[0] = { value: 0, text: '未知类型', color: 'grey' };
|
|
|
}
|
|
|
return (
|
|
|
- <Tag size='large' color={type2label[type]?.color}>
|
|
|
+ <Tag size="large" color={type2label[type]?.color}>
|
|
|
{type2label[type]?.text}
|
|
|
</Tag>
|
|
|
);
|
|
|
@@ -64,11 +65,11 @@ const ChannelsTable = () => {
|
|
|
// },
|
|
|
{
|
|
|
title: 'ID',
|
|
|
- dataIndex: 'id',
|
|
|
+ dataIndex: 'id'
|
|
|
},
|
|
|
{
|
|
|
title: '名称',
|
|
|
- dataIndex: 'name',
|
|
|
+ dataIndex: 'name'
|
|
|
},
|
|
|
{
|
|
|
title: '分组',
|
|
|
@@ -77,20 +78,20 @@ const ChannelsTable = () => {
|
|
|
return (
|
|
|
<div>
|
|
|
<Space spacing={2}>
|
|
|
- {text.split(',').map((item, index) => {
|
|
|
+ {text?.split(',').map((item, index) => {
|
|
|
return renderGroup(item);
|
|
|
})}
|
|
|
</Space>
|
|
|
</div>
|
|
|
);
|
|
|
- },
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '类型',
|
|
|
dataIndex: 'type',
|
|
|
render: (text, record, index) => {
|
|
|
return <div>{renderType(text)}</div>;
|
|
|
- },
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '状态',
|
|
|
@@ -98,7 +99,7 @@ const ChannelsTable = () => {
|
|
|
render: (text, record, index) => {
|
|
|
if (text === 3) {
|
|
|
if (record.other_info === '') {
|
|
|
- record.other_info = '{}'
|
|
|
+ record.other_info = '{}';
|
|
|
}
|
|
|
let otherInfo = JSON.parse(record.other_info);
|
|
|
let reason = otherInfo['status_reason'];
|
|
|
@@ -113,181 +114,246 @@ const ChannelsTable = () => {
|
|
|
} else {
|
|
|
return renderStatus(text);
|
|
|
}
|
|
|
- },
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '响应时间',
|
|
|
dataIndex: 'response_time',
|
|
|
render: (text, record, index) => {
|
|
|
return <div>{renderResponseTime(text)}</div>;
|
|
|
- },
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '已用/剩余',
|
|
|
dataIndex: 'expired_time',
|
|
|
render: (text, record, index) => {
|
|
|
- return (
|
|
|
- <div>
|
|
|
- <Space spacing={1}>
|
|
|
- <Tooltip content={'已用额度'}>
|
|
|
- <Tag color='white' type='ghost' size='large'>
|
|
|
- {renderQuota(record.used_quota)}
|
|
|
- </Tag>
|
|
|
- </Tooltip>
|
|
|
- <Tooltip content={'剩余额度' + record.balance + ',点击更新'}>
|
|
|
- <Tag
|
|
|
- color='white'
|
|
|
- type='ghost'
|
|
|
- size='large'
|
|
|
- onClick={() => {
|
|
|
- updateChannelBalance(record);
|
|
|
- }}
|
|
|
- >
|
|
|
- ${renderNumberWithPoint(record.balance)}
|
|
|
- </Tag>
|
|
|
- </Tooltip>
|
|
|
- </Space>
|
|
|
- </div>
|
|
|
- );
|
|
|
- },
|
|
|
+ if (record.children === undefined) {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <Space spacing={1}>
|
|
|
+ <Tooltip content={'已用额度'}>
|
|
|
+ <Tag color="white" type="ghost" size="large">
|
|
|
+ {renderQuota(record.used_quota)}
|
|
|
+ </Tag>
|
|
|
+ </Tooltip>
|
|
|
+ <Tooltip content={'剩余额度' + record.balance + ',点击更新'}>
|
|
|
+ <Tag
|
|
|
+ color="white"
|
|
|
+ type="ghost"
|
|
|
+ size="large"
|
|
|
+ onClick={() => {
|
|
|
+ updateChannelBalance(record);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ ${renderNumberWithPoint(record.balance)}
|
|
|
+ </Tag>
|
|
|
+ </Tooltip>
|
|
|
+ </Space>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return <Tooltip content={'已用额度'}>
|
|
|
+ <Tag color="white" type="ghost" size="large">
|
|
|
+ {renderQuota(record.used_quota)}
|
|
|
+ </Tag>
|
|
|
+ </Tooltip>;
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '优先级',
|
|
|
dataIndex: 'priority',
|
|
|
render: (text, record, index) => {
|
|
|
- return (
|
|
|
- <div>
|
|
|
- <InputNumber
|
|
|
- style={{ width: 70 }}
|
|
|
- name='priority'
|
|
|
- onBlur={(e) => {
|
|
|
- manageChannel(record.id, 'priority', record, e.target.value);
|
|
|
- }}
|
|
|
- keepFocus={true}
|
|
|
- innerButtons
|
|
|
- defaultValue={record.priority}
|
|
|
- min={-999}
|
|
|
- />
|
|
|
- </div>
|
|
|
- );
|
|
|
- },
|
|
|
+ if (record.children === undefined) {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <InputNumber
|
|
|
+ style={{ width: 70 }}
|
|
|
+ name="priority"
|
|
|
+ onBlur={(e) => {
|
|
|
+ manageChannel(record.id, 'priority', record, e.target.value);
|
|
|
+ }}
|
|
|
+ keepFocus={true}
|
|
|
+ innerButtons
|
|
|
+ defaultValue={record.priority}
|
|
|
+ min={-999}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return <>
|
|
|
+ <Button theme="outline" type="primary">修改</Button>
|
|
|
+ </>;
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '权重',
|
|
|
dataIndex: 'weight',
|
|
|
render: (text, record, index) => {
|
|
|
- return (
|
|
|
- <div>
|
|
|
- <InputNumber
|
|
|
- style={{ width: 70 }}
|
|
|
- name='weight'
|
|
|
- onBlur={(e) => {
|
|
|
- manageChannel(record.id, 'weight', record, e.target.value);
|
|
|
- }}
|
|
|
- keepFocus={true}
|
|
|
- innerButtons
|
|
|
- defaultValue={record.weight}
|
|
|
- min={0}
|
|
|
- />
|
|
|
- </div>
|
|
|
- );
|
|
|
- },
|
|
|
+ if (record.children === undefined) {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <InputNumber
|
|
|
+ style={{ width: 70 }}
|
|
|
+ name="weight"
|
|
|
+ onBlur={(e) => {
|
|
|
+ manageChannel(record.id, 'weight', record, e.target.value);
|
|
|
+ }}
|
|
|
+ keepFocus={true}
|
|
|
+ innerButtons
|
|
|
+ defaultValue={record.weight}
|
|
|
+ min={0}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return (
|
|
|
+ <Button
|
|
|
+ theme="outline"
|
|
|
+ type="primary"
|
|
|
+ >
|
|
|
+ 修改
|
|
|
+ </Button>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
{
|
|
|
title: '',
|
|
|
dataIndex: 'operate',
|
|
|
- render: (text, record, index) => (
|
|
|
- <div>
|
|
|
- <SplitButtonGroup
|
|
|
- style={{ marginRight: 1 }}
|
|
|
- aria-label='测试操作项目组'
|
|
|
- >
|
|
|
- <Button
|
|
|
- theme='light'
|
|
|
- onClick={() => {
|
|
|
- testChannel(record, '');
|
|
|
- }}
|
|
|
- >
|
|
|
- 测试
|
|
|
- </Button>
|
|
|
- <Dropdown
|
|
|
- trigger='click'
|
|
|
- position='bottomRight'
|
|
|
- menu={record.test_models}
|
|
|
- >
|
|
|
+ render: (text, record, index) => {
|
|
|
+ if (record.children === undefined) {
|
|
|
+ return (
|
|
|
+ <div>
|
|
|
+ <SplitButtonGroup
|
|
|
+ style={{ marginRight: 1 }}
|
|
|
+ aria-label="测试单个渠道操作项目组"
|
|
|
+ >
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ onClick={() => {
|
|
|
+ testChannel(record, '');
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 测试
|
|
|
+ </Button>
|
|
|
+ <Dropdown
|
|
|
+ trigger="click"
|
|
|
+ position="bottomRight"
|
|
|
+ menu={record.test_models}
|
|
|
+ >
|
|
|
+ <Button
|
|
|
+ style={{ padding: '8px 4px' }}
|
|
|
+ type="primary"
|
|
|
+ icon={<IconTreeTriangleDown />}
|
|
|
+ ></Button>
|
|
|
+ </Dropdown>
|
|
|
+ </SplitButtonGroup>
|
|
|
+ {/*<Button theme='light' type='primary' style={{marginRight: 1}} onClick={()=>testChannel(record)}>测试</Button>*/}
|
|
|
+ <Popconfirm
|
|
|
+ title="确定是否要删除此渠道?"
|
|
|
+ content="此修改将不可逆"
|
|
|
+ okType={'danger'}
|
|
|
+ position={'left'}
|
|
|
+ onConfirm={() => {
|
|
|
+ manageChannel(record.id, 'delete', record).then(() => {
|
|
|
+ removeRecord(record.id);
|
|
|
+ });
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Button theme="light" type="danger" style={{ marginRight: 1 }}>
|
|
|
+ 删除
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ {record.status === 1 ? (
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ type="warning"
|
|
|
+ style={{ marginRight: 1 }}
|
|
|
+ onClick={async () => {
|
|
|
+ manageChannel(record.id, 'disable', record);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 禁用
|
|
|
+ </Button>
|
|
|
+ ) : (
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ type="secondary"
|
|
|
+ style={{ marginRight: 1 }}
|
|
|
+ onClick={async () => {
|
|
|
+ manageChannel(record.id, 'enable', record);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 启用
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
<Button
|
|
|
- style={{ padding: '8px 4px' }}
|
|
|
- type='primary'
|
|
|
- icon={<IconTreeTriangleDown />}
|
|
|
- ></Button>
|
|
|
- </Dropdown>
|
|
|
- </SplitButtonGroup>
|
|
|
- {/*<Button theme='light' type='primary' style={{marginRight: 1}} onClick={()=>testChannel(record)}>测试</Button>*/}
|
|
|
- <Popconfirm
|
|
|
- title='确定是否要删除此渠道?'
|
|
|
- content='此修改将不可逆'
|
|
|
- okType={'danger'}
|
|
|
- position={'left'}
|
|
|
- onConfirm={() => {
|
|
|
- manageChannel(record.id, 'delete', record).then(() => {
|
|
|
- removeRecord(record.id);
|
|
|
- });
|
|
|
- }}
|
|
|
- >
|
|
|
- <Button theme='light' type='danger' style={{ marginRight: 1 }}>
|
|
|
- 删除
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- {record.status === 1 ? (
|
|
|
- <Button
|
|
|
- theme='light'
|
|
|
- type='warning'
|
|
|
- style={{ marginRight: 1 }}
|
|
|
- onClick={async () => {
|
|
|
- manageChannel(record.id, 'disable', record);
|
|
|
- }}
|
|
|
- >
|
|
|
- 禁用
|
|
|
- </Button>
|
|
|
- ) : (
|
|
|
- <Button
|
|
|
- theme='light'
|
|
|
- type='secondary'
|
|
|
- style={{ marginRight: 1 }}
|
|
|
- onClick={async () => {
|
|
|
- manageChannel(record.id, 'enable', record);
|
|
|
- }}
|
|
|
- >
|
|
|
- 启用
|
|
|
- </Button>
|
|
|
- )}
|
|
|
- <Button
|
|
|
- theme='light'
|
|
|
- type='tertiary'
|
|
|
- style={{ marginRight: 1 }}
|
|
|
- onClick={() => {
|
|
|
- setEditingChannel(record);
|
|
|
- setShowEdit(true);
|
|
|
- }}
|
|
|
- >
|
|
|
- 编辑
|
|
|
- </Button>
|
|
|
- <Popconfirm
|
|
|
- title='确定是否要复制此渠道?'
|
|
|
- content='复制渠道的所有信息'
|
|
|
- okType={'danger'}
|
|
|
- position={'left'}
|
|
|
- onConfirm={async () => {
|
|
|
- copySelectedChannel(record.id);
|
|
|
- }}
|
|
|
- >
|
|
|
- <Button theme='light' type='primary' style={{ marginRight: 1 }}>
|
|
|
- 复制
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- </div>
|
|
|
- ),
|
|
|
- },
|
|
|
+ theme="light"
|
|
|
+ type="tertiary"
|
|
|
+ style={{ marginRight: 1 }}
|
|
|
+ onClick={() => {
|
|
|
+ setEditingChannel(record);
|
|
|
+ setShowEdit(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 编辑
|
|
|
+ </Button>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定是否要复制此渠道?"
|
|
|
+ content="复制渠道的所有信息"
|
|
|
+ okType={'danger'}
|
|
|
+ position={'left'}
|
|
|
+ onConfirm={async () => {
|
|
|
+ copySelectedChannel(record.id);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Button theme="light" type="primary" style={{ marginRight: 1 }}>
|
|
|
+ 复制
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ type="secondary"
|
|
|
+ style={{ marginRight: 1 }}
|
|
|
+ onClick={async () => {
|
|
|
+ manageTag(record.key, 'enable');
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 启用全部
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ type="warning"
|
|
|
+ style={{ marginRight: 1 }}
|
|
|
+ onClick={async () => {
|
|
|
+ manageTag(record.key, 'disable');
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 禁用全部
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ type="tertiary"
|
|
|
+ style={{ marginRight: 1 }}
|
|
|
+ onClick={() => {
|
|
|
+ setShowEditTag(true);
|
|
|
+ setEditingTag(record.key);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ 编辑
|
|
|
+ </Button>
|
|
|
+ </>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
];
|
|
|
|
|
|
const [channels, setChannels] = useState([]);
|
|
|
@@ -301,15 +367,17 @@ const ChannelsTable = () => {
|
|
|
const [updatingBalance, setUpdatingBalance] = useState(false);
|
|
|
const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
|
|
|
const [showPrompt, setShowPrompt] = useState(
|
|
|
- shouldShowPrompt('channel-test'),
|
|
|
+ shouldShowPrompt('channel-test')
|
|
|
);
|
|
|
const [channelCount, setChannelCount] = useState(pageSize);
|
|
|
const [groupOptions, setGroupOptions] = useState([]);
|
|
|
const [showEdit, setShowEdit] = useState(false);
|
|
|
const [enableBatchDelete, setEnableBatchDelete] = useState(false);
|
|
|
const [editingChannel, setEditingChannel] = useState({
|
|
|
- id: undefined,
|
|
|
+ id: undefined
|
|
|
});
|
|
|
+ const [showEditTag, setShowEditTag] = useState(false);
|
|
|
+ const [editingTag, setEditingTag] = useState('');
|
|
|
const [selectedChannels, setSelectedChannels] = useState([]);
|
|
|
|
|
|
const removeRecord = (id) => {
|
|
|
@@ -325,39 +393,82 @@ const ChannelsTable = () => {
|
|
|
};
|
|
|
|
|
|
const setChannelFormat = (channels) => {
|
|
|
+ let channelDates = [];
|
|
|
+ let channelTags = {};
|
|
|
for (let i = 0; i < channels.length; i++) {
|
|
|
- // if (channels[i].type === 8) {
|
|
|
- // showWarning(
|
|
|
- // '检测到您使用了“自定义渠道”类型,请更换为“OpenAI”渠道类型!',
|
|
|
- // );
|
|
|
- // showWarning('下个版本将不再支持“自定义渠道”类型!');
|
|
|
- // }
|
|
|
channels[i].key = '' + channels[i].id;
|
|
|
- let test_models = [];
|
|
|
- channels[i].models.split(',').forEach((item, index) => {
|
|
|
- test_models.push({
|
|
|
- node: 'item',
|
|
|
- name: item,
|
|
|
- onClick: () => {
|
|
|
- testChannel(channels[i], item);
|
|
|
- },
|
|
|
+
|
|
|
+ if (channels[i].tag === '' || channels[i].tag === null) {
|
|
|
+ let test_models = [];
|
|
|
+ channels[i].models.split(',').forEach((item, index) => {
|
|
|
+ test_models.push({
|
|
|
+ node: 'item',
|
|
|
+ name: item,
|
|
|
+ onClick: () => {
|
|
|
+ testChannel(channels[i], item);
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
- });
|
|
|
- channels[i].test_models = test_models;
|
|
|
+ channels[i].test_models = test_models;
|
|
|
+ channelDates.push(channels[i]);
|
|
|
+ } else {
|
|
|
+ let tag = channels[i].tag;
|
|
|
+ // find from channelTags
|
|
|
+ let tagIndex = channelTags[tag];
|
|
|
+ let tagChannelDates = undefined;
|
|
|
+ if (tagIndex === undefined) {
|
|
|
+ // not found, create a new tag
|
|
|
+ channelTags[tag] = 1;
|
|
|
+ tagChannelDates = {
|
|
|
+ key: tag,
|
|
|
+ id: tag,
|
|
|
+ tag: tag,
|
|
|
+ name: '标签:' + tag,
|
|
|
+ group: '',
|
|
|
+ used_quota: 0,
|
|
|
+ response_time: 0
|
|
|
+ };
|
|
|
+ tagChannelDates.children = [];
|
|
|
+ channelDates.push(tagChannelDates);
|
|
|
+ } else {
|
|
|
+ // found, add to the tag
|
|
|
+ tagChannelDates = channelDates.find((item) => item.key === tag);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tagChannelDates.group === '') {
|
|
|
+ tagChannelDates.group = channels[i].group;
|
|
|
+ } else {
|
|
|
+ let channelGroupsStr = channels[i].group;
|
|
|
+ channelGroupsStr.split(',').forEach((item, index) => {
|
|
|
+ if (tagChannelDates.group.indexOf(item) === -1) {
|
|
|
+ tagChannelDates.group += item + ',';
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ tagChannelDates.children.push(channels[i]);
|
|
|
+ if (channels[i].status === 1) {
|
|
|
+ tagChannelDates.status = 1;
|
|
|
+ }
|
|
|
+ tagChannelDates.used_quota += channels[i].used_quota;
|
|
|
+ tagChannelDates.response_time += channels[i].response_time;
|
|
|
+ tagChannelDates.response_time = tagChannelDates.response_time / 2;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
// data.key = '' + data.id
|
|
|
- setChannels(channels);
|
|
|
- if (channels.length >= pageSize) {
|
|
|
- setChannelCount(channels.length + pageSize);
|
|
|
+ setChannels(channelDates);
|
|
|
+ if (channelDates.length >= pageSize) {
|
|
|
+ setChannelCount(channelDates.length + pageSize);
|
|
|
} else {
|
|
|
- setChannelCount(channels.length);
|
|
|
+ setChannelCount(channelDates.length);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const loadChannels = async (startIdx, pageSize, idSort) => {
|
|
|
setLoading(true);
|
|
|
const res = await API.get(
|
|
|
- `/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`,
|
|
|
+ `/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`
|
|
|
);
|
|
|
if (res === undefined) {
|
|
|
return;
|
|
|
@@ -379,7 +490,7 @@ const ChannelsTable = () => {
|
|
|
|
|
|
const copySelectedChannel = async (id) => {
|
|
|
const channelToCopy = channels.find(
|
|
|
- (channel) => String(channel.id) === String(id),
|
|
|
+ (channel) => String(channel.id) === String(id)
|
|
|
);
|
|
|
console.log(channelToCopy);
|
|
|
channelToCopy.name += '_复制';
|
|
|
@@ -472,29 +583,63 @@ const ChannelsTable = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const manageTag = async (tag, action) => {
|
|
|
+ console.log(tag, action);
|
|
|
+ let res;
|
|
|
+ switch (action) {
|
|
|
+ case 'enable':
|
|
|
+ res = await API.post('/api/channel/tag/enabled', {
|
|
|
+ tag: tag
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 'disable':
|
|
|
+ res = await API.post('/api/channel/tag/disabled', {
|
|
|
+ tag: tag
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ const { success, message } = res.data;
|
|
|
+ if (success) {
|
|
|
+ showSuccess('操作成功完成!');
|
|
|
+ let newChannels = [...channels];
|
|
|
+ for (let i = 0; i < newChannels.length; i++) {
|
|
|
+ if (newChannels[i].tag === tag) {
|
|
|
+ let status = action === 'enable' ? 1 : 2;
|
|
|
+ newChannels[i]?.children?.forEach((channel) => {
|
|
|
+ channel.status = status;
|
|
|
+ });
|
|
|
+ newChannels[i].status = status;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ setChannels(newChannels);
|
|
|
+ } else {
|
|
|
+ showError(message);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const renderStatus = (status) => {
|
|
|
switch (status) {
|
|
|
case 1:
|
|
|
return (
|
|
|
- <Tag size='large' color='green'>
|
|
|
+ <Tag size="large" color="green">
|
|
|
已启用
|
|
|
</Tag>
|
|
|
);
|
|
|
case 2:
|
|
|
return (
|
|
|
- <Tag size='large' color='yellow'>
|
|
|
+ <Tag size="large" color="yellow">
|
|
|
已禁用
|
|
|
</Tag>
|
|
|
);
|
|
|
case 3:
|
|
|
return (
|
|
|
- <Tag size='large' color='yellow'>
|
|
|
+ <Tag size="large" color="yellow">
|
|
|
自动禁用
|
|
|
</Tag>
|
|
|
);
|
|
|
default:
|
|
|
return (
|
|
|
- <Tag size='large' color='grey'>
|
|
|
+ <Tag size="large" color="grey">
|
|
|
未知状态
|
|
|
</Tag>
|
|
|
);
|
|
|
@@ -506,31 +651,31 @@ const ChannelsTable = () => {
|
|
|
time = time.toFixed(2) + ' 秒';
|
|
|
if (responseTime === 0) {
|
|
|
return (
|
|
|
- <Tag size='large' color='grey'>
|
|
|
+ <Tag size="large" color="grey">
|
|
|
未测试
|
|
|
</Tag>
|
|
|
);
|
|
|
} else if (responseTime <= 1000) {
|
|
|
return (
|
|
|
- <Tag size='large' color='green'>
|
|
|
+ <Tag size="large" color="green">
|
|
|
{time}
|
|
|
</Tag>
|
|
|
);
|
|
|
} else if (responseTime <= 3000) {
|
|
|
return (
|
|
|
- <Tag size='large' color='lime'>
|
|
|
+ <Tag size="large" color="lime">
|
|
|
{time}
|
|
|
</Tag>
|
|
|
);
|
|
|
} else if (responseTime <= 5000) {
|
|
|
return (
|
|
|
- <Tag size='large' color='yellow'>
|
|
|
+ <Tag size="large" color="yellow">
|
|
|
{time}
|
|
|
</Tag>
|
|
|
);
|
|
|
} else {
|
|
|
return (
|
|
|
- <Tag size='large' color='red'>
|
|
|
+ <Tag size="large" color="red">
|
|
|
{time}
|
|
|
</Tag>
|
|
|
);
|
|
|
@@ -546,7 +691,7 @@ const ChannelsTable = () => {
|
|
|
}
|
|
|
setSearching(true);
|
|
|
const res = await API.get(
|
|
|
- `/api/channel/search?keyword=${searchKeyword}&group=${searchGroup}&model=${searchModel}`,
|
|
|
+ `/api/channel/search?keyword=${searchKeyword}&group=${searchGroup}&model=${searchModel}`
|
|
|
);
|
|
|
const { success, message, data } = res.data;
|
|
|
if (success) {
|
|
|
@@ -649,14 +794,15 @@ const ChannelsTable = () => {
|
|
|
|
|
|
let pageData = channels.slice(
|
|
|
(activePage - 1) * pageSize,
|
|
|
- activePage * pageSize,
|
|
|
+ activePage * pageSize
|
|
|
);
|
|
|
|
|
|
const handlePageChange = (page) => {
|
|
|
setActivePage(page);
|
|
|
if (page === Math.ceil(channels.length / pageSize) + 1) {
|
|
|
// In this case we have to load more data and then append them.
|
|
|
- loadChannels(page - 1, pageSize, idSort).then((r) => {});
|
|
|
+ loadChannels(page - 1, pageSize, idSort).then((r) => {
|
|
|
+ });
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -682,8 +828,8 @@ const ChannelsTable = () => {
|
|
|
setGroupOptions(
|
|
|
res.data.data.map((group) => ({
|
|
|
label: group,
|
|
|
- value: group,
|
|
|
- })),
|
|
|
+ value: group
|
|
|
+ }))
|
|
|
);
|
|
|
} catch (error) {
|
|
|
showError(error.message);
|
|
|
@@ -698,8 +844,8 @@ const ChannelsTable = () => {
|
|
|
if (record.status !== 1) {
|
|
|
return {
|
|
|
style: {
|
|
|
- background: 'var(--semi-color-disabled-border)',
|
|
|
- },
|
|
|
+ background: 'var(--semi-color-disabled-border)'
|
|
|
+ }
|
|
|
};
|
|
|
} else {
|
|
|
return {};
|
|
|
@@ -707,217 +853,224 @@ const ChannelsTable = () => {
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
- <>
|
|
|
- <EditChannel
|
|
|
- refresh={refresh}
|
|
|
- visible={showEdit}
|
|
|
- handleClose={closeEdit}
|
|
|
- editingChannel={editingChannel}
|
|
|
- />
|
|
|
- <Form
|
|
|
- onSubmit={() => {
|
|
|
- searchChannels(searchKeyword, searchGroup, searchModel);
|
|
|
- }}
|
|
|
- labelPosition='left'
|
|
|
+ <>
|
|
|
+ <EditTagModal
|
|
|
+ visible={showEditTag}
|
|
|
+ tag={editingTag}
|
|
|
+ handleClose={() => setShowEditTag(false)}
|
|
|
+ refresh={refresh}
|
|
|
+ />
|
|
|
+ <EditChannel
|
|
|
+ refresh={refresh}
|
|
|
+ visible={showEdit}
|
|
|
+ handleClose={closeEdit}
|
|
|
+ editingChannel={editingChannel}
|
|
|
+ />
|
|
|
+ <Form
|
|
|
+ onSubmit={() => {
|
|
|
+ searchChannels(searchKeyword, searchGroup, searchModel);
|
|
|
+ }}
|
|
|
+ labelPosition="left"
|
|
|
+ >
|
|
|
+ <div style={{ display: 'flex' }}>
|
|
|
+ <Space>
|
|
|
+ <Form.Input
|
|
|
+ field="search_keyword"
|
|
|
+ label="搜索渠道关键词"
|
|
|
+ placeholder="ID,名称和密钥 ..."
|
|
|
+ value={searchKeyword}
|
|
|
+ loading={searching}
|
|
|
+ onChange={(v) => {
|
|
|
+ setSearchKeyword(v.trim());
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <Form.Input
|
|
|
+ field="search_model"
|
|
|
+ label="模型"
|
|
|
+ placeholder="模型关键字"
|
|
|
+ value={searchModel}
|
|
|
+ loading={searching}
|
|
|
+ onChange={(v) => {
|
|
|
+ setSearchModel(v.trim());
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <Form.Select
|
|
|
+ field="group"
|
|
|
+ label="分组"
|
|
|
+ optionList={[{ label: '选择分组', value: null }, ...groupOptions]}
|
|
|
+ initValue={null}
|
|
|
+ onChange={(v) => {
|
|
|
+ setSearchGroup(v);
|
|
|
+ searchChannels(searchKeyword, v, searchModel);
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <Button
|
|
|
+ label="查询"
|
|
|
+ type="primary"
|
|
|
+ htmlType="submit"
|
|
|
+ className="btn-margin-right"
|
|
|
+ style={{ marginRight: 8 }}
|
|
|
+ >
|
|
|
+ 查询
|
|
|
+ </Button>
|
|
|
+ </Space>
|
|
|
+ </div>
|
|
|
+ </Form>
|
|
|
+ <Divider style={{ marginBottom: 15 }} />
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ display: isMobile() ? '' : 'flex',
|
|
|
+ marginTop: isMobile() ? 0 : -45,
|
|
|
+ zIndex: 999,
|
|
|
+ pointerEvents: 'none'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Space
|
|
|
+ style={{ pointerEvents: 'auto', marginTop: isMobile() ? 0 : 45 }}
|
|
|
>
|
|
|
- <div style={{display: 'flex'}}>
|
|
|
- <Space>
|
|
|
- <Form.Input
|
|
|
- field='search_keyword'
|
|
|
- label='搜索渠道关键词'
|
|
|
- placeholder='ID,名称和密钥 ...'
|
|
|
- value={searchKeyword}
|
|
|
- loading={searching}
|
|
|
- onChange={(v) => {
|
|
|
- setSearchKeyword(v.trim());
|
|
|
- }}
|
|
|
- />
|
|
|
- <Form.Input
|
|
|
- field='search_model'
|
|
|
- label='模型'
|
|
|
- placeholder='模型关键字'
|
|
|
- value={searchModel}
|
|
|
- loading={searching}
|
|
|
- onChange={(v) => {
|
|
|
- setSearchModel(v.trim());
|
|
|
- }}
|
|
|
- />
|
|
|
- <Form.Select
|
|
|
- field='group'
|
|
|
- label='分组'
|
|
|
- optionList={[{label: '选择分组', value: null}, ...groupOptions]}
|
|
|
- initValue={null}
|
|
|
- onChange={(v) => {
|
|
|
- setSearchGroup(v);
|
|
|
- searchChannels(searchKeyword, v, searchModel);
|
|
|
- }}
|
|
|
- />
|
|
|
- <Button
|
|
|
- label='查询'
|
|
|
- type='primary'
|
|
|
- htmlType='submit'
|
|
|
- className='btn-margin-right'
|
|
|
- style={{marginRight: 8}}
|
|
|
- >
|
|
|
- 查询
|
|
|
- </Button>
|
|
|
- </Space>
|
|
|
- </div>
|
|
|
- </Form>
|
|
|
- <Divider style={{marginBottom:15}}/>
|
|
|
- <div
|
|
|
- style={{
|
|
|
- display: isMobile() ? '' : 'flex',
|
|
|
- marginTop: isMobile() ? 0 : -45,
|
|
|
- zIndex: 999,
|
|
|
- pointerEvents: 'none',
|
|
|
+ <Typography.Text strong>使用ID排序</Typography.Text>
|
|
|
+ <Switch
|
|
|
+ checked={idSort}
|
|
|
+ label="使用ID排序"
|
|
|
+ uncheckedText="关"
|
|
|
+ aria-label="是否用ID排序"
|
|
|
+ onChange={(v) => {
|
|
|
+ localStorage.setItem('id-sort', v + '');
|
|
|
+ setIdSort(v);
|
|
|
+ loadChannels(0, pageSize, v)
|
|
|
+ .then()
|
|
|
+ .catch((reason) => {
|
|
|
+ showError(reason);
|
|
|
+ });
|
|
|
+ }}
|
|
|
+ ></Switch>
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ type="primary"
|
|
|
+ style={{ marginRight: 8 }}
|
|
|
+ onClick={() => {
|
|
|
+ setEditingChannel({
|
|
|
+ id: undefined
|
|
|
+ });
|
|
|
+ setShowEdit(true);
|
|
|
}}
|
|
|
- >
|
|
|
- <Space
|
|
|
- style={{pointerEvents: 'auto', marginTop: isMobile() ? 0 : 45}}
|
|
|
>
|
|
|
- <Typography.Text strong>使用ID排序</Typography.Text>
|
|
|
- <Switch
|
|
|
- checked={idSort}
|
|
|
- label='使用ID排序'
|
|
|
- uncheckedText='关'
|
|
|
- aria-label='是否用ID排序'
|
|
|
- onChange={(v) => {
|
|
|
- localStorage.setItem('id-sort', v + '');
|
|
|
- setIdSort(v);
|
|
|
- loadChannels(0, pageSize, v)
|
|
|
- .then()
|
|
|
- .catch((reason) => {
|
|
|
- showError(reason);
|
|
|
- });
|
|
|
- }}
|
|
|
- ></Switch>
|
|
|
- <Button
|
|
|
- theme='light'
|
|
|
- type='primary'
|
|
|
- style={{marginRight: 8}}
|
|
|
- onClick={() => {
|
|
|
- setEditingChannel({
|
|
|
- id: undefined,
|
|
|
- });
|
|
|
- setShowEdit(true);
|
|
|
- }}
|
|
|
- >
|
|
|
- 添加渠道
|
|
|
+ 添加渠道
|
|
|
+ </Button>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定?"
|
|
|
+ okType={'warning'}
|
|
|
+ onConfirm={testAllChannels}
|
|
|
+ position={isMobile() ? 'top' : 'top'}
|
|
|
+ >
|
|
|
+ <Button theme="light" type="warning" style={{ marginRight: 8 }}>
|
|
|
+ 测试所有通道
|
|
|
</Button>
|
|
|
- <Popconfirm
|
|
|
- title='确定?'
|
|
|
- okType={'warning'}
|
|
|
- onConfirm={testAllChannels}
|
|
|
- position={isMobile() ? 'top' : 'top'}
|
|
|
- >
|
|
|
- <Button theme='light' type='warning' style={{marginRight: 8}}>
|
|
|
- 测试所有通道
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- <Popconfirm
|
|
|
- title='确定?'
|
|
|
- okType={'secondary'}
|
|
|
- onConfirm={updateAllChannelsBalance}
|
|
|
- >
|
|
|
- <Button theme='light' type='secondary' style={{marginRight: 8}}>
|
|
|
- 更新所有已启用通道余额
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- <Popconfirm
|
|
|
- title='确定是否要删除禁用通道?'
|
|
|
- content='此修改将不可逆'
|
|
|
- okType={'danger'}
|
|
|
- onConfirm={deleteAllDisabledChannels}
|
|
|
- >
|
|
|
- <Button theme='light' type='danger' style={{marginRight: 8}}>
|
|
|
- 删除禁用通道
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
+ </Popconfirm>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定?"
|
|
|
+ okType={'secondary'}
|
|
|
+ onConfirm={updateAllChannelsBalance}
|
|
|
+ >
|
|
|
+ <Button theme="light" type="secondary" style={{ marginRight: 8 }}>
|
|
|
+ 更新所有已启用通道余额
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定是否要删除禁用通道?"
|
|
|
+ content="此修改将不可逆"
|
|
|
+ okType={'danger'}
|
|
|
+ onConfirm={deleteAllDisabledChannels}
|
|
|
+ >
|
|
|
+ <Button theme="light" type="danger" style={{ marginRight: 8 }}>
|
|
|
+ 删除禁用通道
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
|
|
|
+ <Button
|
|
|
+ theme="light"
|
|
|
+ type="primary"
|
|
|
+ style={{ marginRight: 8 }}
|
|
|
+ onClick={refresh}
|
|
|
+ >
|
|
|
+ 刷新
|
|
|
+ </Button>
|
|
|
+ </Space>
|
|
|
+ </div>
|
|
|
+ <div style={{ marginTop: 20 }}>
|
|
|
+ <Space>
|
|
|
+ <Typography.Text strong>开启批量删除</Typography.Text>
|
|
|
+ <Switch
|
|
|
+ label="开启批量删除"
|
|
|
+ uncheckedText="关"
|
|
|
+ aria-label="是否开启批量删除"
|
|
|
+ onChange={(v) => {
|
|
|
+ setEnableBatchDelete(v);
|
|
|
+ }}
|
|
|
+ ></Switch>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定是否要删除所选通道?"
|
|
|
+ content="此修改将不可逆"
|
|
|
+ okType={'danger'}
|
|
|
+ onConfirm={batchDeleteChannels}
|
|
|
+ disabled={!enableBatchDelete}
|
|
|
+ position={'top'}
|
|
|
+ >
|
|
|
<Button
|
|
|
- theme='light'
|
|
|
- type='primary'
|
|
|
- style={{marginRight: 8}}
|
|
|
- onClick={refresh}
|
|
|
+ disabled={!enableBatchDelete}
|
|
|
+ theme="light"
|
|
|
+ type="danger"
|
|
|
+ style={{ marginRight: 8 }}
|
|
|
>
|
|
|
- 刷新
|
|
|
+ 删除所选通道
|
|
|
</Button>
|
|
|
- </Space>
|
|
|
- </div>
|
|
|
- <div style={{marginTop: 20}}>
|
|
|
- <Space>
|
|
|
- <Typography.Text strong>开启批量删除</Typography.Text>
|
|
|
- <Switch
|
|
|
- label='开启批量删除'
|
|
|
- uncheckedText='关'
|
|
|
- aria-label='是否开启批量删除'
|
|
|
- onChange={(v) => {
|
|
|
- setEnableBatchDelete(v);
|
|
|
- }}
|
|
|
- ></Switch>
|
|
|
- <Popconfirm
|
|
|
- title='确定是否要删除所选通道?'
|
|
|
- content='此修改将不可逆'
|
|
|
- okType={'danger'}
|
|
|
- onConfirm={batchDeleteChannels}
|
|
|
- disabled={!enableBatchDelete}
|
|
|
- position={'top'}
|
|
|
- >
|
|
|
- <Button
|
|
|
- disabled={!enableBatchDelete}
|
|
|
- theme='light'
|
|
|
- type='danger'
|
|
|
- style={{marginRight: 8}}
|
|
|
- >
|
|
|
- 删除所选通道
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- <Popconfirm
|
|
|
- title='确定是否要修复数据库一致性?'
|
|
|
- content='进行该操作时,可能导致渠道访问错误,请仅在数据库出现问题时使用'
|
|
|
- okType={'warning'}
|
|
|
- onConfirm={fixChannelsAbilities}
|
|
|
- position={'top'}
|
|
|
- >
|
|
|
- <Button theme='light' type='secondary' style={{marginRight: 8}}>
|
|
|
- 修复数据库一致性
|
|
|
- </Button>
|
|
|
- </Popconfirm>
|
|
|
- </Space>
|
|
|
- </div>
|
|
|
+ </Popconfirm>
|
|
|
+ <Popconfirm
|
|
|
+ title="确定是否要修复数据库一致性?"
|
|
|
+ content="进行该操作时,可能导致渠道访问错误,请仅在数据库出现问题时使用"
|
|
|
+ okType={'warning'}
|
|
|
+ onConfirm={fixChannelsAbilities}
|
|
|
+ position={'top'}
|
|
|
+ >
|
|
|
+ <Button theme="light" type="secondary" style={{ marginRight: 8 }}>
|
|
|
+ 修复数据库一致性
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
+ </Space>
|
|
|
+ </div>
|
|
|
|
|
|
- <Table
|
|
|
- className={'channel-table'}
|
|
|
- style={{marginTop: 15}}
|
|
|
- columns={columns}
|
|
|
- dataSource={pageData}
|
|
|
- pagination={{
|
|
|
- currentPage: activePage,
|
|
|
- pageSize: pageSize,
|
|
|
- total: channelCount,
|
|
|
- pageSizeOpts: [10, 20, 50, 100],
|
|
|
- showSizeChanger: true,
|
|
|
- formatPageText: (page) => '',
|
|
|
- onPageSizeChange: (size) => {
|
|
|
- handlePageSizeChange(size).then();
|
|
|
- },
|
|
|
- onPageChange: handlePageChange,
|
|
|
- }}
|
|
|
- loading={loading}
|
|
|
- onRow={handleRow}
|
|
|
- rowSelection={
|
|
|
- enableBatchDelete
|
|
|
- ? {
|
|
|
- onChange: (selectedRowKeys, selectedRows) => {
|
|
|
- // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
|
|
|
- setSelectedChannels(selectedRows);
|
|
|
- },
|
|
|
- }
|
|
|
- : null
|
|
|
+
|
|
|
+ <Table
|
|
|
+ className={'channel-table'}
|
|
|
+ style={{ marginTop: 15 }}
|
|
|
+ columns={columns}
|
|
|
+ dataSource={pageData}
|
|
|
+ pagination={{
|
|
|
+ currentPage: activePage,
|
|
|
+ pageSize: pageSize,
|
|
|
+ total: channelCount,
|
|
|
+ pageSizeOpts: [10, 20, 50, 100],
|
|
|
+ showSizeChanger: true,
|
|
|
+ formatPageText: (page) => '',
|
|
|
+ onPageSizeChange: (size) => {
|
|
|
+ handlePageSizeChange(size).then();
|
|
|
+ },
|
|
|
+ onPageChange: handlePageChange
|
|
|
+ }}
|
|
|
+ loading={loading}
|
|
|
+ onRow={handleRow}
|
|
|
+ rowSelection={
|
|
|
+ enableBatchDelete
|
|
|
+ ? {
|
|
|
+ onChange: (selectedRowKeys, selectedRows) => {
|
|
|
+ // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
|
|
|
+ setSelectedChannels(selectedRows);
|
|
|
+ }
|
|
|
}
|
|
|
- />
|
|
|
- </>
|
|
|
+ : null
|
|
|
+ }
|
|
|
+ />
|
|
|
+ </>
|
|
|
);
|
|
|
};
|
|
|
|