|
|
@@ -1,7 +1,7 @@
|
|
|
-import { Button, Input, Space, Table, Tag, Typography, message } from 'antd';
|
|
|
+import { Button, Input, Popconfirm, Space, Table, Tag, Typography, message } from 'antd';
|
|
|
import type { ColumnsType, TablePaginationConfig } from 'antd/es/table';
|
|
|
import dayjs from 'dayjs';
|
|
|
-import { RefreshCw, Search, Settings2 } from 'lucide-react';
|
|
|
+import { RefreshCw, Search, Settings2, Trash2 } from 'lucide-react';
|
|
|
import { history } from '@umijs/max';
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
|
@@ -14,6 +14,7 @@ export default function ChatsPage() {
|
|
|
const [data, setData] = useState<Paged<ChatSummary>>({ items: [], total: 0, page: 1, page_size: 20 });
|
|
|
const [query, setQuery] = useState('');
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
+ const [deletingChatId, setDeletingChatId] = useState<string | null>(null);
|
|
|
|
|
|
const load = async (page = data.page, search = query) => {
|
|
|
setLoading(true);
|
|
|
@@ -35,6 +36,19 @@ export default function ChatsPage() {
|
|
|
void load(1, '');
|
|
|
}, []);
|
|
|
|
|
|
+ const removeUnavailableChat = async (record: ChatSummary) => {
|
|
|
+ setDeletingChatId(record.chat_id);
|
|
|
+ try {
|
|
|
+ await apiRequest<{ removed: boolean }>(`/chats/${record.chat_id}`, { method: 'DELETE' });
|
|
|
+ message.success(`已从管理列表移除“${record.title}”`);
|
|
|
+ await load(data.items.length === 1 && data.page > 1 ? data.page - 1 : data.page);
|
|
|
+ } catch (error) {
|
|
|
+ message.error(error instanceof Error ? error.message : '群记录移除失败');
|
|
|
+ } finally {
|
|
|
+ setDeletingChatId(null);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const columns: ColumnsType<ChatSummary> = [
|
|
|
{
|
|
|
title: '群组',
|
|
|
@@ -66,16 +80,34 @@ export default function ChatsPage() {
|
|
|
title: '操作',
|
|
|
key: 'actions',
|
|
|
fixed: 'right',
|
|
|
- width: 108,
|
|
|
- render: (_, record) => (
|
|
|
+ width: 120,
|
|
|
+ render: (_, record) => record.accessible ? (
|
|
|
<Button
|
|
|
type="link"
|
|
|
icon={<Settings2 size={16} />}
|
|
|
- disabled={!record.accessible}
|
|
|
onClick={() => history.push(`/chats/${record.chat_id}`)}
|
|
|
>
|
|
|
管理
|
|
|
</Button>
|
|
|
+ ) : (
|
|
|
+ <Popconfirm
|
|
|
+ title="移除不可用群?"
|
|
|
+ description="仅移除当前 Bot 的管理列表记录,不会删除群消息、积分或抽奖数据;Bot 以后重新在群里活动时会再次出现。"
|
|
|
+ okText="移除"
|
|
|
+ cancelText="取消"
|
|
|
+ okButtonProps={{ danger: true }}
|
|
|
+ onConfirm={() => removeUnavailableChat(record)}
|
|
|
+ >
|
|
|
+ <Button
|
|
|
+ danger
|
|
|
+ type="link"
|
|
|
+ icon={<Trash2 size={16} />}
|
|
|
+ loading={deletingChatId === record.chat_id}
|
|
|
+ aria-label={`移除不可用群 ${record.title}`}
|
|
|
+ >
|
|
|
+ 移除
|
|
|
+ </Button>
|
|
|
+ </Popconfirm>
|
|
|
),
|
|
|
},
|
|
|
];
|