Skip to content

Let's use AI to Earn!

mcp第二层展示

daoyian8970fb31f05e
diff --git a/src/api/mcp.ts b/src/api/mcp.ts
index 8fe0e7f4..59dc659f 100644
--- a/src/api/mcp.ts
+++ b/src/api/mcp.ts
@@ -47,7 +47,7 @@ export const apiDeleteMCPKey = (key: string) => {
* @returns
*/
export const apiGetMCPKeyInfo = (key: string) => {
- return request<MCPKey>({
+ return request({
url: `channel/skKey/info/${key}`,
method: "GET",
});
@@ -79,15 +79,31 @@ export const apiCreateMCPRef = (data: any) => {
});
};
+/**
+ * 解除MCP Key关联
+ * @param data 解除关联参数
+ * @returns
+ */
+export const apiDeleteMCPRef = (data: any) => {
+ return request({
+ url: "channel/skKey/ref",
+ method: "DELETE",
+ data,
+ });
+};
+
/**
* 获取MCP Key关联列表
* @param pageNo 页码
* @param pageSize 每页大小
* @returns
*/
-export const apiGetMCPRefList = (pageNo: number, pageSize: number) => {
+export const apiGetMCPRefList = (pageNo: number, pageSize: number, key: string) => {
return request({
url: `channel/skKey/ref/list/${pageNo}/${pageSize}`,
method: "GET",
+ params: {
+ key,
+ },
});
};
\ No newline at end of file
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.module.scss b/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.module.scss
new file mode 100644
index 00000000..c2126a81
--- /dev/null
+++ b/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.module.scss
@@ -0,0 +1,77 @@
+.mcpKeyDetailModal {
+ .keyInfo {
+ margin-bottom: 24px;
+ padding: 16px;
+ background: #f8f9fa;
+ border-radius: 8px;
+
+ .keyHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 12px;
+
+ .keyName {
+ .label {
+ font-weight: 500;
+ color: #666;
+ margin-right: 8px;
+ }
+
+ .value {
+ font-weight: 600;
+ color: #333;
+ }
+ }
+ }
+
+ .keyValue {
+ margin-bottom: 12px;
+
+ .label {
+ font-weight: 500;
+ color: #666;
+ margin-right: 8px;
+ }
+
+ .value {
+ font-family: 'Courier New', monospace;
+ background: #fff;
+ padding: 4px 8px;
+ border-radius: 4px;
+ border: 1px solid #d9d9d9;
+ color: #333;
+ }
+ }
+
+ .keyMeta {
+ display: flex;
+ gap: 24px;
+
+ .metaItem {
+ .label {
+ font-weight: 500;
+ color: #666;
+ margin-right: 8px;
+ }
+ }
+ }
+ }
+
+ .refList {
+ .sectionTitle {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ font-weight: 600;
+ font-size: 16px;
+ margin-bottom: 16px;
+ color: #333;
+ }
+
+ .emptyState {
+ padding: 40px 0;
+ text-align: center;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.tsx b/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.tsx
new file mode 100644
index 00000000..54bd6286
--- /dev/null
+++ b/src/app/[lng]/accounts/components/AccountSidebar/MCPKeyDetailModal.tsx
@@ -0,0 +1,233 @@
+import React, { forwardRef, memo, useImperativeHandle, useState, useEffect } from "react";
+import { Modal, Button, List, Avatar, Tag, Space, message, Empty, Pagination, Popconfirm } from "antd";
+import { CopyOutlined, DeleteOutlined, KeyOutlined, UserOutlined } from "@ant-design/icons";
+import { SocialAccount } from "@/api/types/account.type";
+import { apiGetMCPRefList, apiDeleteMCPRef } from "@/api/mcp";
+import styles from "./MCPKeyDetailModal.module.scss";
+
+export interface IMCPKeyDetailModalRef {
+ open: (keyInfo: any) => void;
+ close: () => void;
+}
+
+export interface IMCPKeyDetailModalProps {
+ open: boolean;
+ onClose: (open: boolean) => void;
+ keyInfo?: any;
+}
+
+const MCPKeyDetailModal = memo(
+ forwardRef<IMCPKeyDetailModalRef, IMCPKeyDetailModalProps>(
+ ({ open, onClose, keyInfo: propKeyInfo }, ref) => {
+ const [keyInfo, setKeyInfo] = useState<any>(null);
+ const [refList, setRefList] = useState<any[]>([]);
+ const [loading, setLoading] = useState(false);
+ const [currentPage, setCurrentPage] = useState(1);
+ const [pageSize, setPageSize] = useState(10);
+ const [total, setTotal] = useState(0);
+
+ // 获取关联账户列表
+ const fetchRefList = async () => {
+ if (!keyInfo?.key) return;
+
+ try {
+ setLoading(true);
+ const res: any = await apiGetMCPRefList(currentPage, pageSize, keyInfo.key);
+ if (res?.code === 0) {
+ setRefList(res.data.list || []);
+ setTotal(res.data.total || 0);
+ }
+ } catch (error) {
+ message.error('获取关联账户列表失败');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ if (open && keyInfo) {
+ fetchRefList();
+ }
+ }, [open, keyInfo, currentPage, pageSize]);
+
+ const handleCopyKey = (key: string) => {
+ navigator.clipboard.writeText(key);
+ message.success('Key已复制到剪贴板');
+ };
+
+ const handleUnlinkAccount = async (accountId: string) => {
+ try {
+ const res = await apiDeleteMCPRef({
+ key: keyInfo.key,
+ accountId: accountId
+ });
+ if (res?.code === 0) {
+ message.success('解除关联成功');
+ fetchRefList(); // 刷新列表
+ } else {
+ message.error('解除关联失败');
+ }
+ } catch (error) {
+ message.error('解除关联失败');
+ }
+ };
+
+ // 当props中的keyInfo变化时,更新内部状态
+ useEffect(() => {
+ if (propKeyInfo) {
+ setKeyInfo(propKeyInfo);
+ setCurrentPage(1);
+ setRefList([]);
+ setTotal(0);
+ }
+ }, [propKeyInfo]);
+
+ useImperativeHandle(ref, () => ({
+ open: (keyInfo: any) => {
+ setKeyInfo(keyInfo);
+ setCurrentPage(1);
+ setRefList([]);
+ setTotal(0);
+ },
+ close: () => {
+ setKeyInfo(null);
+ setRefList([]);
+ setTotal(0);
+ },
+ }));
+
+ return (
+ <Modal
+ title={
+ <div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
+ <KeyOutlined style={{ color: '#625BF2' }} />
+ MCP Key 详情
+ </div>
+ }
+ open={open}
+ onCancel={() => onClose(false)}
+ footer={null}
+ width={800}
+ className={styles.mcpKeyDetailModal}
+ >
+ {keyInfo && (
+ <>
+ {/* Key基本信息 */}
+ <div className={styles.keyInfo}>
+ <div className={styles.keyHeader}>
+ <div className={styles.keyName}>
+ <span className={styles.label}>Key名称:</span>
+ <span className={styles.value}>{keyInfo.name}</span>
+ </div>
+ <Space>
+ <Tag color={keyInfo.status === 0 ? 'green' : 'red'}>
+ {keyInfo.status === 0 ? '可用' : '不可用'}
+ </Tag>
+ <Button
+ type="link"
+ icon={<CopyOutlined />}
+ onClick={() => handleCopyKey(keyInfo.key)}
+ >
+ 复制Key
+ </Button>
+ </Space>
+ </div>
+
+ <div className={styles.keyValue}>
+ <span className={styles.label}>Key值:</span>
+ <span className={styles.value}>{keyInfo.key}</span>
+ </div>
+
+ <div className={styles.keyMeta}>
+ <div className={styles.metaItem}>
+ <span className={styles.label}>创建时间:</span>
+ <span>{keyInfo.createdAt}</span>
+ </div>
+ <div className={styles.metaItem}>
+ <span className={styles.label}>关联账户:</span>
+ <span>{total} 个</span>
+ </div>
+ </div>
+ </div>
+
+ {/* 关联账户列表 */}
+ <div className={styles.refList}>
+ <div className={styles.sectionTitle}>
+ <UserOutlined />
+ 关联账户列表
+ </div>
+
+ {refList.length === 0 && !loading ? (
+ <div className={styles.emptyState}>
+ <Empty description="暂无关联账户" />
+ </div>
+ ) : (
+ <>
+ <List
+ className={styles.refList}
+ dataSource={refList}
+ loading={loading}
+ renderItem={(item) => (
+ <List.Item
+ actions={[
+ <Popconfirm
+ title="确定要解除关联吗?"
+ onConfirm={() => handleUnlinkAccount(item.accountId)}
+ okText="确定"
+ cancelText="取消"
+ >
+ <Button
+ key="unlink"
+ type="link"
+ danger
+ icon={<DeleteOutlined />}
+ >
+ 解除关联
+ </Button>
+ </Popconfirm>
+ ]}
+ >
+ <List.Item.Meta
+ avatar={<Avatar src={item.account?.avatar} />}
+ title={item.account?.nickname || '未知账户'}
+ description={
+ <div>
+ <div>账户ID: {item.accountId}</div>
+ <div>关联时间: {item.createdAt}</div>
+ </div>
+ }
+ />
+ </List.Item>
+ )}
+ />
+
+ {total > 0 && (
+ <div style={{ marginTop: 16, textAlign: 'right' }}>
+ <Pagination
+ current={currentPage}
+ pageSize={pageSize}
+ total={total}
+ showSizeChanger
+ showQuickJumper
+ showTotal={(total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`}
+ onChange={(page, size) => {
+ setCurrentPage(page);
+ setPageSize(size);
+ }}
+ />
+ </div>
+ )}
+ </>
+ )}
+ </div>
+ </>
+ )}
+ </Modal>
+ );
+ }
+ )
+);
+
+MCPKeyDetailModal.displayName = "MCPKeyDetailModal";
+
+export default MCPKeyDetailModal;
\ No newline at end of file
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx b/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx
index 6d31c09f..b5d0c08e 100644
--- a/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx
+++ b/src/app/[lng]/accounts/components/AccountSidebar/MCPManagerModal.tsx
@@ -9,6 +9,7 @@ import {
apiGetMCPKeyList,
apiCreateMCPRef,
} from "@/api/mcp";
+import MCPKeyDetailModal from "./MCPKeyDetailModal";
import styles from "./MCPManagerModal.module.scss";
export interface IMCPManagerModalRef {
@@ -34,6 +35,8 @@ const MCPManagerModal = memo(
const [total, setTotal] = useState(0);
const [createForm] = Form.useForm();
const [showAccountSelector, setShowAccountSelector] = useState(false);
+ const [showDetailModal, setShowDetailModal] = useState(false);
+ const [selectedKeyInfo, setSelectedKeyInfo] = useState<any>(null);
// 获取MCP Key列表
const fetchMCPKeys = async () => {
@@ -166,40 +169,51 @@ const MCPManagerModal = memo(
</div>
) : (
<>
- <List
- className={styles.mcpKeyList}
- dataSource={mcpKeys}
- loading={loading}
- renderItem={(item) => (
- <List.Item
- actions={[
- <Button
- key="copy"
- type="link"
- icon={<CopyOutlined />}
- onClick={() => handleCopyKey(item.key)}
+ <List
+ className={styles.mcpKeyList}
+ dataSource={mcpKeys}
+ loading={loading}
+ renderItem={(item) => (
+ <List.Item
+ actions={[
+ <Button
+ key="copy"
+ type="link"
+ icon={<CopyOutlined />}
+ onClick={() => handleCopyKey(item.key)}
+ >
+ 复制
+ </Button>,
+ <Button
+ key="detail"
+ type="link"
+ icon={<KeyOutlined />}
+ onClick={() => {
+ setSelectedKeyInfo(item);
+ setShowDetailModal(true);
+ }}
+ >
+ 详情
+ </Button>,
+ <Button
+ key="delete"
+ type="link"
+ danger
+ icon={<DeleteOutlined />}
+ onClick={() => handleDeleteKey(item.key)}
+ loading={loading}
+ >
+ 删除
+ </Button>
+ ]}
>
- 复制
- </Button>,
- <Button
- key="delete"
- type="link"
- danger
- icon={<DeleteOutlined />}
- onClick={() => handleDeleteKey(item.key)}
- loading={loading}
- >
- 删除
- </Button>
- ]}
- >
<List.Item.Meta
avatar={<Avatar style={{ background: 'linear-gradient(90deg, #625BF2 0%, #925BF2 100%)' }}>MCP</Avatar>}
title={
<Space>
<span>{item.name}</span>
- <Tag color={item.status === 'active' ? 'green' : 'red'}>
- {item.status === 'active' ? '活跃' : '非活跃'}
+ <Tag color={item.status === 0 ? 'green' : 'red'}>
+ {item.status === 0 ? '可用' : '不可用'}
</Tag>
</Space>
}
@@ -345,6 +359,17 @@ const MCPManagerModal = memo(
isCancelChooseAccount: true,
}}
/>
+
+ <MCPKeyDetailModal
+ open={showDetailModal}
+ onClose={(open) => {
+ setShowDetailModal(open);
+ if (!open) {
+ setSelectedKeyInfo(null);
+ }
+ }}
+ keyInfo={selectedKeyInfo}
+ />
</>
);
}