ChannelsTable.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. import React, {useEffect, useState} from 'react';
  2. import {
  3. API,
  4. isMobile,
  5. shouldShowPrompt,
  6. showError,
  7. showInfo,
  8. showSuccess,
  9. timestamp2string
  10. } from '../helpers';
  11. import {CHANNEL_OPTIONS, ITEMS_PER_PAGE} from '../constants';
  12. import {renderGroup, renderNumber, renderNumberWithPoint, renderQuota, renderQuotaWithPrompt} from '../helpers/render';
  13. import {
  14. Avatar,
  15. Tag,
  16. Table,
  17. Button,
  18. Popover,
  19. Form,
  20. Modal,
  21. Popconfirm,
  22. Space,
  23. Tooltip,
  24. Switch,
  25. Typography, InputNumber, Dropdown, SplitButtonGroup
  26. } from "@douyinfe/semi-ui";
  27. import EditChannel from "../pages/Channel/EditChannel";
  28. import {IconTreeTriangleDown} from "@douyinfe/semi-icons";
  29. function renderTimestamp(timestamp) {
  30. return (
  31. <>
  32. {timestamp2string(timestamp)}
  33. </>
  34. );
  35. }
  36. let type2label = undefined;
  37. function renderType(type) {
  38. if (!type2label) {
  39. type2label = new Map;
  40. for (let i = 0; i < CHANNEL_OPTIONS.length; i++) {
  41. type2label[CHANNEL_OPTIONS[i].value] = CHANNEL_OPTIONS[i];
  42. }
  43. type2label[0] = {value: 0, text: '未知类型', color: 'grey'};
  44. }
  45. return <Tag size='large' color={type2label[type]?.color}>{type2label[type]?.text}</Tag>;
  46. }
  47. function renderBalance(type, balance) {
  48. switch (type) {
  49. case 1: // OpenAI
  50. return <span>${balance.toFixed(2)}</span>;
  51. case 4: // CloseAI
  52. return <span>¥{balance.toFixed(2)}</span>;
  53. case 8: // 自定义
  54. return <span>${balance.toFixed(2)}</span>;
  55. case 5: // OpenAI-SB
  56. return <span>¥{(balance / 10000).toFixed(2)}</span>;
  57. case 10: // AI Proxy
  58. return <span>{renderNumber(balance)}</span>;
  59. case 12: // API2GPT
  60. return <span>¥{balance.toFixed(2)}</span>;
  61. case 13: // AIGC2D
  62. return <span>{renderNumber(balance)}</span>;
  63. default:
  64. return <span>不支持</span>;
  65. }
  66. }
  67. const ChannelsTable = () => {
  68. const columns = [
  69. // {
  70. // title: '',
  71. // dataIndex: 'checkbox',
  72. // className: 'checkbox',
  73. // },
  74. {
  75. title: 'ID',
  76. dataIndex: 'id',
  77. },
  78. {
  79. title: '名称',
  80. dataIndex: 'name',
  81. },
  82. {
  83. title: '分组',
  84. dataIndex: 'group',
  85. render: (text, record, index) => {
  86. return (
  87. <div>
  88. <Space spacing={2}>
  89. {
  90. text.split(',').map((item, index) => {
  91. return (renderGroup(item))
  92. })
  93. }
  94. </Space>
  95. </div>
  96. );
  97. },
  98. },
  99. {
  100. title: '类型',
  101. dataIndex: 'type',
  102. render: (text, record, index) => {
  103. return (
  104. <div>
  105. {renderType(text)}
  106. </div>
  107. );
  108. },
  109. },
  110. {
  111. title: '状态',
  112. dataIndex: 'status',
  113. render: (text, record, index) => {
  114. return (
  115. <div>
  116. {renderStatus(text)}
  117. </div>
  118. );
  119. },
  120. },
  121. {
  122. title: '响应时间',
  123. dataIndex: 'response_time',
  124. render: (text, record, index) => {
  125. return (
  126. <div>
  127. {renderResponseTime(text)}
  128. </div>
  129. );
  130. },
  131. },
  132. {
  133. title: '已用/剩余',
  134. dataIndex: 'expired_time',
  135. render: (text, record, index) => {
  136. return (
  137. <div>
  138. <Space spacing={1}>
  139. <Tooltip content={'已用额度'}>
  140. <Tag color='white' type='ghost' size='large'>{renderQuota(record.used_quota)}</Tag>
  141. </Tooltip>
  142. <Tooltip content={'剩余额度' + record.balance + ',点击更新'}>
  143. <Tag color='white' type='ghost' size='large' onClick={() => {updateChannelBalance(record)}}>${renderNumberWithPoint(record.balance)}</Tag>
  144. </Tooltip>
  145. </Space>
  146. </div>
  147. );
  148. },
  149. },
  150. {
  151. title: '优先级',
  152. dataIndex: 'priority',
  153. render: (text, record, index) => {
  154. return (
  155. <div>
  156. <InputNumber
  157. style={{width: 70}}
  158. name='priority'
  159. onChange={value => {
  160. manageChannel(record.id, 'priority', record, value);
  161. }}
  162. defaultValue={record.priority}
  163. min={-999}
  164. />
  165. </div>
  166. );
  167. },
  168. },
  169. {
  170. title: '权重',
  171. dataIndex: 'weight',
  172. render: (text, record, index) => {
  173. return (
  174. <div>
  175. <InputNumber
  176. style={{width: 70}}
  177. name='weight'
  178. onChange={value => {
  179. manageChannel(record.id, 'weight', record, value);
  180. }}
  181. defaultValue={record.weight}
  182. min={0}
  183. />
  184. </div>
  185. );
  186. },
  187. },
  188. {
  189. title: '',
  190. dataIndex: 'operate',
  191. render: (text, record, index) => (
  192. <div>
  193. <SplitButtonGroup style={{marginRight: 1}} aria-label="测试操作项目组">
  194. <Button theme="light" onClick={()=>{testChannel(record, '')}}>测试</Button>
  195. <Dropdown trigger="click" position="bottomRight" menu={record.test_models}
  196. >
  197. <Button style={ { padding: '8px 4px'}} type="primary" icon={<IconTreeTriangleDown />}></Button>
  198. </Dropdown>
  199. </SplitButtonGroup>
  200. {/*<Button theme='light' type='primary' style={{marginRight: 1}} onClick={()=>testChannel(record)}>测试</Button>*/}
  201. <Popconfirm
  202. title="确定是否要删除此渠道?"
  203. content="此修改将不可逆"
  204. okType={'danger'}
  205. position={'left'}
  206. onConfirm={() => {
  207. manageChannel(record.id, 'delete', record).then(
  208. () => {
  209. removeRecord(record.id);
  210. }
  211. )
  212. }}
  213. >
  214. <Button theme='light' type='danger' style={{marginRight: 1}}>删除</Button>
  215. </Popconfirm>
  216. {
  217. record.status === 1 ?
  218. <Button theme='light' type='warning' style={{marginRight: 1}} onClick={
  219. async () => {
  220. manageChannel(
  221. record.id,
  222. 'disable',
  223. record
  224. )
  225. }
  226. }>禁用</Button> :
  227. <Button theme='light' type='secondary' style={{marginRight: 1}} onClick={
  228. async () => {
  229. manageChannel(
  230. record.id,
  231. 'enable',
  232. record
  233. );
  234. }
  235. }>启用</Button>
  236. }
  237. <Button theme='light' type='tertiary' style={{marginRight: 1}} onClick={
  238. () => {
  239. setEditingChannel(record);
  240. setShowEdit(true);
  241. }
  242. }>编辑</Button>
  243. </div>
  244. ),
  245. },
  246. ];
  247. const [channels, setChannels] = useState([]);
  248. const [loading, setLoading] = useState(true);
  249. const [activePage, setActivePage] = useState(1);
  250. const [idSort, setIdSort] = useState(false);
  251. const [searchKeyword, setSearchKeyword] = useState('');
  252. const [searchGroup, setSearchGroup] = useState('');
  253. const [searching, setSearching] = useState(false);
  254. const [updatingBalance, setUpdatingBalance] = useState(false);
  255. const [pageSize, setPageSize] = useState(ITEMS_PER_PAGE);
  256. const [showPrompt, setShowPrompt] = useState(shouldShowPrompt("channel-test"));
  257. const [channelCount, setChannelCount] = useState(pageSize);
  258. const [groupOptions, setGroupOptions] = useState([]);
  259. const [showEdit, setShowEdit] = useState(false);
  260. const [enableBatchDelete, setEnableBatchDelete] = useState(false);
  261. const [editingChannel, setEditingChannel] = useState({
  262. id: undefined,
  263. });
  264. const [selectedChannels, setSelectedChannels] = useState([]);
  265. const removeRecord = id => {
  266. let newDataSource = [...channels];
  267. if (id != null) {
  268. let idx = newDataSource.findIndex(data => data.id === id);
  269. if (idx > -1) {
  270. newDataSource.splice(idx, 1);
  271. setChannels(newDataSource);
  272. }
  273. }
  274. };
  275. const setChannelFormat = (channels) => {
  276. for (let i = 0; i < channels.length; i++) {
  277. channels[i].key = '' + channels[i].id;
  278. let test_models = []
  279. channels[i].models.split(',').forEach((item, index) => {
  280. test_models.push({
  281. node: 'item',
  282. name: item,
  283. onClick: () => {
  284. testChannel(channels[i], item)
  285. }
  286. })
  287. })
  288. channels[i].test_models = test_models
  289. }
  290. // data.key = '' + data.id
  291. setChannels(channels);
  292. if (channels.length >= pageSize) {
  293. setChannelCount(channels.length + pageSize);
  294. } else {
  295. setChannelCount(channels.length);
  296. }
  297. }
  298. const loadChannels = async (startIdx, pageSize, idSort) => {
  299. setLoading(true);
  300. const res = await API.get(`/api/channel/?p=${startIdx}&page_size=${pageSize}&id_sort=${idSort}`);
  301. const {success, message, data} = res.data;
  302. if (success) {
  303. if (startIdx === 0) {
  304. setChannelFormat(data);
  305. } else {
  306. let newChannels = [...channels];
  307. newChannels.splice(startIdx * pageSize, data.length, ...data);
  308. setChannelFormat(newChannels);
  309. }
  310. } else {
  311. showError(message);
  312. }
  313. setLoading(false);
  314. };
  315. const refresh = async () => {
  316. await loadChannels(activePage - 1, pageSize, idSort);
  317. };
  318. useEffect(() => {
  319. // console.log('default effect')
  320. const localIdSort = localStorage.getItem('id-sort') === 'true';
  321. setIdSort(localIdSort)
  322. loadChannels(0, pageSize, localIdSort)
  323. .then()
  324. .catch((reason) => {
  325. showError(reason);
  326. });
  327. fetchGroups().then();
  328. }, []);
  329. // useEffect(() => {
  330. // console.log('search effect')
  331. // searchChannels()
  332. // }, [searchGroup]);
  333. // useEffect(() => {
  334. // localStorage.setItem('id-sort', idSort + '');
  335. // refresh()
  336. // }, [idSort]);
  337. const manageChannel = async (id, action, record, value) => {
  338. let data = {id};
  339. let res;
  340. switch (action) {
  341. case 'delete':
  342. res = await API.delete(`/api/channel/${id}/`);
  343. break;
  344. case 'enable':
  345. data.status = 1;
  346. res = await API.put('/api/channel/', data);
  347. break;
  348. case 'disable':
  349. data.status = 2;
  350. res = await API.put('/api/channel/', data);
  351. break;
  352. case 'priority':
  353. if (value === '') {
  354. return;
  355. }
  356. data.priority = parseInt(value);
  357. res = await API.put('/api/channel/', data);
  358. break;
  359. case 'weight':
  360. if (value === '') {
  361. return;
  362. }
  363. data.weight = parseInt(value);
  364. if (data.weight < 0) {
  365. data.weight = 0;
  366. }
  367. res = await API.put('/api/channel/', data);
  368. break;
  369. }
  370. const {success, message} = res.data;
  371. if (success) {
  372. showSuccess('操作成功完成!');
  373. let channel = res.data.data;
  374. let newChannels = [...channels];
  375. if (action === 'delete') {
  376. } else {
  377. record.status = channel.status;
  378. }
  379. setChannels(newChannels);
  380. } else {
  381. showError(message);
  382. }
  383. };
  384. const renderStatus = (status) => {
  385. switch (status) {
  386. case 1:
  387. return <Tag size='large' color='green'>已启用</Tag>;
  388. case 2:
  389. return (
  390. <Tag size='large' color='yellow'>
  391. 已禁用
  392. </Tag>
  393. );
  394. case 3:
  395. return (
  396. <Tag size='large' color='yellow'>
  397. 自动禁用
  398. </Tag>
  399. );
  400. default:
  401. return (
  402. <Tag size='large' color='grey'>
  403. 未知状态
  404. </Tag>
  405. );
  406. }
  407. };
  408. const renderResponseTime = (responseTime) => {
  409. let time = responseTime / 1000;
  410. time = time.toFixed(2) + ' 秒';
  411. if (responseTime === 0) {
  412. return <Tag size='large' color='grey'>未测试</Tag>;
  413. } else if (responseTime <= 1000) {
  414. return <Tag size='large' color='green'>{time}</Tag>;
  415. } else if (responseTime <= 3000) {
  416. return <Tag size='large' color='lime'>{time}</Tag>;
  417. } else if (responseTime <= 5000) {
  418. return <Tag size='large' color='yellow'>{time}</Tag>;
  419. } else {
  420. return <Tag size='large' color='red'>{time}</Tag>;
  421. }
  422. };
  423. const searchChannels = async (searchKeyword, searchGroup) => {
  424. if (searchKeyword === '' && searchGroup === '') {
  425. // if keyword is blank, load files instead.
  426. await loadChannels(0, pageSize, idSort);
  427. setActivePage(1);
  428. return;
  429. }
  430. setSearching(true);
  431. const res = await API.get(`/api/channel/search?keyword=${searchKeyword}&group=${searchGroup}`);
  432. const {success, message, data} = res.data;
  433. if (success) {
  434. setChannels(data);
  435. setActivePage(1);
  436. } else {
  437. showError(message);
  438. }
  439. setSearching(false);
  440. };
  441. const testChannel = async (record, model) => {
  442. const res = await API.get(`/api/channel/test/${record.id}?model=${model}`);
  443. const {success, message, time} = res.data;
  444. if (success) {
  445. let newChannels = [...channels];
  446. record.response_time = time * 1000;
  447. record.test_time = Date.now() / 1000;
  448. setChannelFormat(newChannels)
  449. showInfo(`通道 ${record.name} 测试成功,耗时 ${time.toFixed(2)} 秒。`);
  450. } else {
  451. showError(message);
  452. }
  453. };
  454. const testAllChannels = async () => {
  455. const res = await API.get(`/api/channel/test`);
  456. const {success, message} = res.data;
  457. if (success) {
  458. showInfo('已成功开始测试所有已启用通道,请刷新页面查看结果。');
  459. } else {
  460. showError(message);
  461. }
  462. };
  463. const deleteAllDisabledChannels = async () => {
  464. const res = await API.delete(`/api/channel/disabled`);
  465. const {success, message, data} = res.data;
  466. if (success) {
  467. showSuccess(`已删除所有禁用渠道,共计 ${data} 个`);
  468. await refresh();
  469. } else {
  470. showError(message);
  471. }
  472. };
  473. const updateChannelBalance = async (record) => {
  474. const res = await API.get(`/api/channel/update_balance/${record.id}/`);
  475. const {success, message, balance} = res.data;
  476. if (success) {
  477. record.balance = balance;
  478. record.balance_updated_time = Date.now() / 1000;
  479. showInfo(`通道 ${record.name} 余额更新成功!`);
  480. } else {
  481. showError(message);
  482. }
  483. };
  484. const updateAllChannelsBalance = async () => {
  485. setUpdatingBalance(true);
  486. const res = await API.get(`/api/channel/update_balance`);
  487. const {success, message} = res.data;
  488. if (success) {
  489. showInfo('已更新完毕所有已启用通道余额!');
  490. } else {
  491. showError(message);
  492. }
  493. setUpdatingBalance(false);
  494. };
  495. const batchDeleteChannels = async () => {
  496. if (selectedChannels.length === 0) {
  497. showError('请先选择要删除的通道!');
  498. return;
  499. }
  500. setLoading(true);
  501. let ids = [];
  502. selectedChannels.forEach((channel) => {
  503. ids.push(channel.id);
  504. });
  505. const res = await API.post(`/api/channel/batch`, {ids: ids});
  506. const {success, message, data} = res.data;
  507. if (success) {
  508. showSuccess(`已删除 ${data} 个通道!`);
  509. await refresh();
  510. } else {
  511. showError(message);
  512. }
  513. setLoading(false);
  514. }
  515. const fixChannelsAbilities = async () => {
  516. const res = await API.post(`/api/channel/fix`);
  517. const {success, message, data} = res.data;
  518. if (success) {
  519. showSuccess(`已修复 ${data} 个通道!`);
  520. await refresh();
  521. } else {
  522. showError(message);
  523. }
  524. }
  525. const sortChannel = (key) => {
  526. if (channels.length === 0) return;
  527. setLoading(true);
  528. let sortedChannels = [...channels];
  529. if (typeof sortedChannels[0][key] === 'string') {
  530. sortedChannels.sort((a, b) => {
  531. return ('' + a[key]).localeCompare(b[key]);
  532. });
  533. } else {
  534. sortedChannels.sort((a, b) => {
  535. if (a[key] === b[key]) return 0;
  536. if (a[key] > b[key]) return -1;
  537. if (a[key] < b[key]) return 1;
  538. });
  539. }
  540. if (sortedChannels[0].id === channels[0].id) {
  541. sortedChannels.reverse();
  542. }
  543. setChannels(sortedChannels);
  544. setLoading(false);
  545. };
  546. let pageData = channels.slice((activePage - 1) * pageSize, activePage * pageSize);
  547. const handlePageChange = page => {
  548. setActivePage(page);
  549. if (page === Math.ceil(channels.length / pageSize) + 1) {
  550. // In this case we have to load more data and then append them.
  551. loadChannels(page - 1, pageSize, idSort).then(r => {
  552. });
  553. }
  554. };
  555. const handlePageSizeChange = async(size) => {
  556. setPageSize(size)
  557. setActivePage(1)
  558. loadChannels(0, size, idSort)
  559. .then()
  560. .catch((reason) => {
  561. showError(reason);
  562. })
  563. };
  564. const fetchGroups = async () => {
  565. try {
  566. let res = await API.get(`/api/group/`);
  567. // add 'all' option
  568. // res.data.data.unshift('all');
  569. setGroupOptions(res.data.data.map((group) => ({
  570. label: group,
  571. value: group,
  572. })));
  573. } catch (error) {
  574. showError(error.message);
  575. }
  576. };
  577. const closeEdit = () => {
  578. setShowEdit(false);
  579. }
  580. const handleRow = (record, index) => {
  581. if (record.status !== 1) {
  582. return {
  583. style: {
  584. background: 'var(--semi-color-disabled-border)',
  585. },
  586. };
  587. } else {
  588. return {};
  589. }
  590. };
  591. return (
  592. <>
  593. <EditChannel refresh={refresh} visible={showEdit} handleClose={closeEdit} editingChannel={editingChannel}/>
  594. <Form onSubmit={() => {searchChannels(searchKeyword, searchGroup)}} labelPosition='left'>
  595. <div style={{display: 'flex'}}>
  596. <Space>
  597. <Form.Input
  598. field='search'
  599. label='关键词'
  600. placeholder='ID,名称和密钥 ...'
  601. value={searchKeyword}
  602. loading={searching}
  603. onChange={(v)=>{
  604. setSearchKeyword(v.trim())
  605. }}
  606. />
  607. <Form.Select field="group" label='分组' optionList={groupOptions} onChange={(v) => {
  608. setSearchGroup(v)
  609. searchChannels(searchKeyword, v)
  610. }}/>
  611. </Space>
  612. </div>
  613. </Form>
  614. <div style={{marginTop: 10, display: 'flex'}}>
  615. <Space>
  616. <Space>
  617. <Typography.Text strong>使用ID排序</Typography.Text>
  618. <Switch checked={idSort} label='使用ID排序' uncheckedText="关" aria-label="是否用ID排序" onChange={(v) => {
  619. localStorage.setItem('id-sort', v + '')
  620. setIdSort(v)
  621. loadChannels(0, pageSize, v)
  622. .then()
  623. .catch((reason) => {
  624. showError(reason);
  625. })
  626. }}></Switch>
  627. </Space>
  628. </Space>
  629. </div>
  630. <Table style={{marginTop: 15}} columns={columns} dataSource={pageData} pagination={{
  631. currentPage: activePage,
  632. pageSize: pageSize,
  633. total: channelCount,
  634. pageSizeOpts: [10, 20, 50, 100],
  635. showSizeChanger: true,
  636. formatPageText:(page) => '',
  637. onPageSizeChange: (size) => {
  638. handlePageSizeChange(size).then()
  639. },
  640. onPageChange: handlePageChange,
  641. }} loading={loading} onRow={handleRow} rowSelection={
  642. enableBatchDelete ?
  643. {
  644. onChange: (selectedRowKeys, selectedRows) => {
  645. // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  646. setSelectedChannels(selectedRows);
  647. },
  648. } : null
  649. }/>
  650. <div style={{display: isMobile()?'':'flex', marginTop: isMobile()?0:-45, zIndex: 999, position: 'relative', pointerEvents: 'none'}}>
  651. <Space style={{pointerEvents: 'auto'}}>
  652. <Button theme='light' type='primary' style={{marginRight: 8}} onClick={
  653. () => {
  654. setEditingChannel({
  655. id: undefined,
  656. });
  657. setShowEdit(true)
  658. }
  659. }>添加渠道</Button>
  660. <Popconfirm
  661. title="确定?"
  662. okType={'warning'}
  663. onConfirm={testAllChannels}
  664. position={isMobile()?'top':'top'}
  665. >
  666. <Button theme='light' type='warning' style={{marginRight: 8}}>测试所有已启用通道</Button>
  667. </Popconfirm>
  668. <Popconfirm
  669. title="确定?"
  670. okType={'secondary'}
  671. onConfirm={updateAllChannelsBalance}
  672. >
  673. <Button theme='light' type='secondary' style={{marginRight: 8}}>更新所有已启用通道余额</Button>
  674. </Popconfirm>
  675. <Popconfirm
  676. title="确定是否要删除禁用通道?"
  677. content="此修改将不可逆"
  678. okType={'danger'}
  679. onConfirm={deleteAllDisabledChannels}
  680. >
  681. <Button theme='light' type='danger' style={{marginRight: 8}}>删除禁用通道</Button>
  682. </Popconfirm>
  683. <Button theme='light' type='primary' style={{marginRight: 8}} onClick={refresh}>刷新</Button>
  684. </Space>
  685. {/*<div style={{width: '100%', pointerEvents: 'none', position: 'absolute'}}>*/}
  686. {/*</div>*/}
  687. </div>
  688. <div style={{marginTop: 20}}>
  689. <Space>
  690. <Typography.Text strong>开启批量删除</Typography.Text>
  691. <Switch label='开启批量删除' uncheckedText="关" aria-label="是否开启批量删除" onChange={(v) => {
  692. setEnableBatchDelete(v)
  693. }}></Switch>
  694. <Popconfirm
  695. title="确定是否要删除所选通道?"
  696. content="此修改将不可逆"
  697. okType={'danger'}
  698. onConfirm={batchDeleteChannels}
  699. disabled={!enableBatchDelete}
  700. position={'top'}
  701. >
  702. <Button disabled={!enableBatchDelete} theme='light' type='danger' style={{marginRight: 8}}>删除所选通道</Button>
  703. </Popconfirm>
  704. <Popconfirm
  705. title="确定是否要修复数据库一致性?"
  706. content="进行该操作时,可能导致渠道访问错误,请仅在数据库出现问题时使用"
  707. okType={'warning'}
  708. onConfirm={fixChannelsAbilities}
  709. position={'top'}
  710. >
  711. <Button theme='light' type='secondary' style={{marginRight: 8}}>修复数据库一致性</Button>
  712. </Popconfirm>
  713. </Space>
  714. </div>
  715. </>
  716. );
  717. };
  718. export default ChannelsTable;