Skip to content

Let's use AI to Earn!

dizhi

I5bijibne2bbbcef2c8f9
diff --git a/@types/resources.d.ts b/@types/resources.d.ts
index 1e419250..70fb4690 100644
--- a/@types/resources.d.ts
+++ b/@types/resources.d.ts
@@ -3,7 +3,7 @@ interface Resources {
"title": "账户",
"describe": "账户页面",
"today": "今天",
- "defaultSpace": "默认空间",
+ "defaultSpace": "defaultSpace",
"addPost": "添加帖子",
"calendarMode": "日历模式",
"listModeTab": "列表模式",
@@ -45,6 +45,15 @@ interface Resources {
"recordCount": "共 {{count}} 条发布计划",
"newWork": "新建作品",
"noRecords": "暂无发布计划"
+ },
+ "chooseSpace": "选择空间",
+ "pleaseChooseSpace": "请选择空间",
+ "accountAddedToSpace": "账号已添加到空间",
+ "noNewAccountDetected": "未检测到新账号,稍后可在账号管理器中手动调整空间",
+ "ipInfo": {
+ "loading": "获取IP信息中...",
+ "error": "IP信息获取失败",
+ "tooltip": "ASN: {{asn}}\n组织: {{org}}"
}
},
"cgmaterial": {
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss
index b1bc9180..70d39220 100644
--- a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss
+++ b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.module.scss
@@ -29,6 +29,50 @@
color: var(--grayColor6);
}
+ .accountSidebar-groupLabel {
+ display: flex;
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 8px;
+ width: 100%;
+ }
+
+ .accountSidebar-groupName {
+ font-weight: 500;
+ }
+
+ .accountSidebar-ipInfo {
+ font-size: var(--fs-xs);
+ color: var(--grayColor6);
+ max-width: 130px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ .accountSidebar-ipLoading {
+ color: var(--colorPrimary5);
+ font-style: italic;
+ }
+
+ .accountSidebar-ipText {
+ cursor: help;
+ padding: 2px 6px;
+ background: var(--grayColor2);
+ border-radius: 4px;
+ transition: all 0.2s ease;
+
+ &:hover {
+ background: var(--grayColor3);
+ color: var(--grayColor7);
+ }
+ }
+
+ .accountSidebar-ipError {
+ color: var(--errorColor);
+ font-style: italic;
+ }
+
.accountSidebar-top {
flex-shrink: 0;
padding: 0 10px;
@@ -270,8 +314,12 @@
}
&-left {
display: flex;
+ align-items: center;
+ flex: 1;
+ min-width: 0;
}
&-name {
+ font-weight: 500;
}
&-count {
color: var(--grayColor8);
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx
index c646d8c9..494db832 100644
--- a/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx
+++ b/src/app/[lng]/accounts/components/AccountSidebar/AccountSidebar.tsx
@@ -25,6 +25,7 @@ import { AccountStatus } from "@/app/config/accountConfig";
import { SocialAccount } from "@/api/types/account.type";
import { getOssUrl } from "@/utils/oss";
import { useTransClient } from "@/app/i18n/client";
+import { getIpLocation, IpLocationInfo, formatLocationInfo } from "@/utils/ipLocation";
export interface IAccountSidebarRef {}
@@ -152,6 +153,10 @@ const AccountSidebar = memo(
const userManageModalRef = useRef<IUserManageModalRef>(null);
const [mcpManagerModalOpen, setMcpManagerModalOpen] = useState(false);
const mcpManagerModalRef = useRef<IMCPManagerModalRef>(null);
+
+ // IP地理位置信息状态
+ const [ipLocationInfo, setIpLocationInfo] = useState<IpLocationInfo | null>(null);
+ const [ipLocationLoading, setIpLocationLoading] = useState(false);
// 在组件内部过滤账号列表,而不是在 useAccountStore 中过滤
const accountList = useMemo(() => {
@@ -164,6 +169,24 @@ const AccountSidebar = memo(
return accountGroupList.find((v) => v.isDefault)?.id;
}, [accountGroupList]);
+ // 获取IP地理位置信息
+ useEffect(() => {
+ const fetchIpLocation = async () => {
+ try {
+ setIpLocationLoading(true);
+ const info = await getIpLocation();
+ setIpLocationInfo(info);
+ } catch (error) {
+ console.error('获取IP地理位置信息失败:', error);
+ } finally {
+ setIpLocationLoading(false);
+ }
+ };
+
+ // 只在组件挂载时获取一次IP信息
+ fetchIpLocation();
+ }, []);
+
return (
<>
<UserManageModal
@@ -225,19 +248,41 @@ const AccountSidebar = memo(
key={defaultActiveKey}
defaultActiveKey={defaultActiveKey}
items={accountGroupList.map((v) => {
+ // 为默认分组添加IP和地址信息
+ const isDefaultGroup = v.isDefault;
+ const showIpInfo = isDefaultGroup && ipLocationInfo;
+
return {
key: v.id,
label: (
<>
- {v.name}
- <span className="accountSidebar-userCount">
- {v.children?.length}/
- {
- v.children?.map(
- (v) => v.status === AccountStatus.USABLE,
- ).length
- }
- </span>
+ <div className="accountSidebar-groupLabel">
+ <span className="accountSidebar-groupName">{v.name}</span>
+ <span className="accountSidebar-userCount">
+ {v.children?.length}/
+ {
+ v.children?.map(
+ (v) => v.status === AccountStatus.USABLE,
+ ).length
+ }
+ </span>
+ {/* 在默认分组中显示IP和地址信息 */}
+ {isDefaultGroup && (
+ <div className="accountSidebar-ipInfo">
+ {ipLocationLoading ? (
+ <span className="accountSidebar-ipLoading">{t("ipInfo.loading")}</span>
+ ) : showIpInfo ? (
+ <Tooltip title={t("ipInfo.tooltip", { asn: ipLocationInfo.asn, org: ipLocationInfo.org })}>
+ <span className="accountSidebar-ipText">
+ {formatLocationInfo(ipLocationInfo)}
+ </span>
+ </Tooltip>
+ ) : (
+ <span className="accountSidebar-ipError">{t("ipInfo.error")}</span>
+ )}
+ </div>
+ )}
+ </div>
</>
),
children: (
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx b/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx
index 1c840d6c..f8b77ed0 100644
--- a/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx
+++ b/src/app/[lng]/accounts/components/AccountSidebar/UserManageModal.tsx
@@ -18,6 +18,8 @@ import {
Table,
TableProps,
Tooltip,
+ Card,
+ Space,
} from "antd";
import styles from "./AccountSidebar.module.scss";
import { useAccountStore } from "@/store/account";
@@ -26,6 +28,8 @@ import {
CheckCircleOutlined,
DeleteOutlined,
WarningOutlined,
+ GlobalOutlined,
+ EnvironmentOutlined,
} from "@ant-design/icons";
import UserManageSidebar from "./UserManageSidebar";
import { SocialAccount } from "@/api/types/account.type";
@@ -35,6 +39,7 @@ import AvatarPlat from "@/components/AvatarPlat";
import { deleteAccountsApi, updateAccountApi } from "@/api/account";
import { useTransClient } from "@/app/i18n/client";
import AddAccountModal from "../AddAccountModal";
+import { getIpLocation, IpLocationInfo, formatLocationInfo } from "@/utils/ipLocation";
export interface IUserManageModalRef {
setActiveGroup: (groupId: string) => void;
@@ -73,6 +78,132 @@ const UserGroupSelect = ({
);
};
+// 空间信息展示组件
+const SpaceInfoCard = ({
+ activeGroup,
+ accountGroupList,
+ allUser
+}: {
+ activeGroup: string;
+ accountGroupList: any[];
+ allUser: string;
+}) => {
+ const { t } = useTransClient("account");
+ const [ipLocationInfo, setIpLocationInfo] = useState<IpLocationInfo | null>(null);
+ const [ipLocationLoading, setIpLocationLoading] = useState(false);
+
+ // 获取IP地理位置信息
+ useEffect(() => {
+ const fetchIpLocation = async () => {
+ try {
+ setIpLocationLoading(true);
+ const info = await getIpLocation();
+ setIpLocationInfo(info);
+ } catch (error) {
+ console.error('获取IP地理位置信息失败:', error);
+ } finally {
+ setIpLocationLoading(false);
+ }
+ };
+
+ // 只在组件挂载时获取一次IP信息
+ fetchIpLocation();
+ }, []);
+
+ // 如果是全部账号,不显示信息卡片
+ if (activeGroup === allUser) {
+ return null;
+ }
+
+ // 获取当前选中的空间信息
+ const currentSpace = accountGroupList.find(group => group.id === activeGroup);
+ if (!currentSpace) return null;
+
+ return (
+ <Card
+ size="small"
+ style={{
+ marginBottom: '16px',
+ backgroundColor: 'var(--grayColor1)',
+ border: '1px solid var(--grayColor3)'
+ }}
+ >
+ <Space direction="vertical" size="small" style={{ width: '100%' }}>
+ {/* <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
+ <span style={{
+ fontSize: 'var(--fs-xs)',
+ color: 'var(--grayColor6)',
+ backgroundColor: 'var(--grayColor2)',
+ padding: '2px 8px',
+ borderRadius: '12px'
+ }}>
+ {currentSpace.children?.length || 0} 个账号
+ </span>
+ </div> */}
+
+ {/* 默认空间显示IP和属地信息 */}
+ {currentSpace.isDefault && (
+ <div style={{
+ display: 'flex',
+ alignItems: 'center',
+ gap: '8px',
+ padding: '8px',
+ backgroundColor: 'var(--grayColor2)',
+ borderRadius: '6px'
+ }}>
+ <GlobalOutlined style={{ color: 'var(--colorPrimary5)' }} />
+ <span style={{ fontSize: 'var(--fs-xs)', color: 'var(--grayColor7)' }}>
+ {t("ipInfo.loading")}
+ </span>
+ {ipLocationLoading ? (
+ <span style={{ color: 'var(--colorPrimary5)', fontStyle: 'italic' }}>
+ {t("ipInfo.loading")}
+ </span>
+ ) : ipLocationInfo ? (
+ <Tooltip title={t("ipInfo.tooltip", { asn: ipLocationInfo.asn, org: ipLocationInfo.org })}>
+ <span style={{
+ color: 'var(--grayColor7)',
+ cursor: 'help',
+ fontWeight: '500'
+ }}>
+ {formatLocationInfo(ipLocationInfo)}
+ </span>
+ </Tooltip>
+ ) : (
+ <span style={{ color: 'var(--errorColor)', fontStyle: 'italic' }}>
+ {t("ipInfo.error")}
+ </span>
+ )}
+ </div>
+ )}
+
+ {/* 空间创建时间等信息 */}
+ <div style={{
+ fontSize: 'var(--fs-xs)',
+ color: 'var(--grayColor6)',
+ display: 'flex',
+ alignItems: 'center',
+ gap: '4px'
+ }}>
+ <EnvironmentOutlined />
+ <span>空间ID: {currentSpace.id}</span>
+ {currentSpace.isDefault && (
+ <span style={{
+ color: 'var(--colorPrimary5)',
+ backgroundColor: 'var(--colorPrimary1)',
+ padding: '1px 6px',
+ borderRadius: '10px',
+ fontSize: 'var(--fs-xs)'
+ }}>
+ defaultSpace
+ </span>
+ )}
+ </div>
+ </Space>
+ </Card>
+ );
+};
+
const UserManageModal = memo(
forwardRef(
(
@@ -373,6 +504,13 @@ const UserManageModal = memo(
/>
<div className="userManage-content">
+ {/* 空间信息卡片 - 显示在右侧上方 */}
+ <SpaceInfoCard
+ activeGroup={activeGroup}
+ accountGroupList={accountGroupList}
+ allUser={allUser.current}
+ />
+
<div className="userManage-content-head" style={{ marginBottom: "8px", display: "flex", justifyContent: "flex-end" }}>
<Button type="primary" onClick={openAddAccountFlow}>{t("addAccount")}</Button>
</div>
diff --git a/src/app/[lng]/accounts/components/AccountSidebar/UserManageSidebar.tsx b/src/app/[lng]/accounts/components/AccountSidebar/UserManageSidebar.tsx
index 626accf2..dc208af9 100644
--- a/src/app/[lng]/accounts/components/AccountSidebar/UserManageSidebar.tsx
+++ b/src/app/[lng]/accounts/components/AccountSidebar/UserManageSidebar.tsx
@@ -99,27 +99,15 @@ const UserManageSidebar = memo(
color: "var(--colorPrimary6)",
}}
>
- {rightClickOperateData!.name}
+ {rightClickOperateData?.name}
</span>
- ,删除后该列表下的账号将被移动到
- <span
- style={{
- color: "var(--colorPrimary6)",
- }}
- >
- 默认列表
- </span>
- 中
+ ?
</>
),
- async onOk() {
- const res = await deleteAccountGroupApi([
- rightClickOperateData!.id,
- ]);
- if (res?.data) {
- message.success("删除成功!");
- await getAccountList();
- }
+ onOk: async () => {
+ await deleteAccountGroupApi([rightClickOperateData!.id]);
+ await getAccountGroup();
+ message.success("删除成功");
},
});
}}
@@ -129,15 +117,14 @@ const UserManageSidebar = memo(
</ControlledMenu>
<Modal
- title={createGroupId === "-1" ? "新建空间" : "重命名空间"}
open={openCreateGroup}
+ title={createGroupId === "-1" ? "新建空间" : "重命名空间"}
onCancel={createGroupCancel}
footer={
<>
<Button onClick={createGroupCancel}>取消</Button>
<Button
type="primary"
- disabled={groupName.length === 0}
onClick={async () => {
setCreateGroupLoading(true);
if (createGroupId === "-1") {
diff --git a/src/app/[lng]/demo/ipTest.tsx b/src/app/[lng]/demo/ipTest.tsx
new file mode 100644
index 00000000..76dc15b0
--- /dev/null
+++ b/src/app/[lng]/demo/ipTest.tsx
@@ -0,0 +1,121 @@
+/**
+ * IP地理位置获取测试页面
+ * 用于测试IP获取功能是否正常工作
+ */
+
+import { useState } from 'react';
+import { Button, Card, Space, Typography } from 'antd';
+import { getIpLocation, IpLocationInfo } from '@/utils/ipLocation';
+
+const { Title, Text, Paragraph } = Typography;
+
+const IpTestPage = () => {
+ const [ipInfo, setIpInfo] = useState<IpLocationInfo | null>(null);
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+
+ /**
+ * 测试获取IP地理位置信息
+ */
+ const handleTestIpLocation = async () => {
+ try {
+ setLoading(true);
+ setError(null);
+ const info = await getIpLocation();
+ setIpInfo(info);
+ } catch (err) {
+ setError(err instanceof Error ? err.message : '获取IP信息失败');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ return (
+ <div style={{ padding: '20px', maxWidth: '800px', margin: '0 auto' }}>
+ <Title level={2}>IP地理位置获取测试</Title>
+
+ <Card title="功能说明" style={{ marginBottom: '20px' }}>
+ <Paragraph>
+ 此页面用于测试IP地理位置获取功能。点击下方按钮将调用JSONP接口获取当前IP地址和地理位置信息。
+ </Paragraph>
+ <Paragraph>
+ <Text code>https://ping0.cc/geo/jsonp/callback</Text> 接口将返回以下信息:
+ </Paragraph>
+ <ul>
+ <li><Text strong>IP地址</Text>:当前访问者的公网IP地址</li>
+ <li><Text strong>地理位置</Text>:IP地址对应的地理位置信息</li>
+ <li><Text strong>ASN</Text>:自治系统号码</li>
+ <li><Text strong>组织</Text>:网络服务提供商信息</li>
+ </ul>
+ </Card>
+
+ <Card title="测试结果" style={{ marginBottom: '20px' }}>
+ <Space direction="vertical" style={{ width: '100%' }}>
+ <Button
+ type="primary"
+ onClick={handleTestIpLocation}
+ loading={loading}
+ size="large"
+ >
+ {loading ? '获取中...' : '获取IP地理位置信息'}
+ </Button>
+
+ {error && (
+ <Card size="small" style={{ backgroundColor: '#fff2f0', borderColor: '#ffccc7' }}>
+ <Text type="danger">错误信息:{error}</Text>
+ </Card>
+ )}
+
+ {ipInfo && (
+ <Card size="small" style={{ backgroundColor: '#f6ffed', borderColor: '#b7eb8f' }}>
+ <Space direction="vertical" style={{ width: '100%' }}>
+ <div>
+ <Text strong>IP地址:</Text>
+ <Text copyable>{ipInfo.ip}</Text>
+ </div>
+ <div>
+ <Text strong>地理位置:</Text>
+ <Text>{ipInfo.location}</Text>
+ </div>
+ <div>
+ <Text strong>ASN:</Text>
+ <Text code>{ipInfo.asn}</Text>
+ </div>
+ <div>
+ <Text strong>组织:</Text>
+ <Text>{ipInfo.org}</Text>
+ </div>
+ </Space>
+ </Card>
+ )}
+ </Space>
+ </Card>
+
+ <Card title="技术实现" style={{ marginBottom: '20px' }}>
+ <Paragraph>
+ <Text strong>实现方式:</Text> 使用JSONP(JSON with Padding)技术调用第三方IP地理位置服务
+ </Paragraph>
+ <Paragraph>
+ <Text strong>核心代码:</Text>
+ </Paragraph>
+ <pre style={{ backgroundColor: '#f5f5f5', padding: '10px', borderRadius: '4px' }}>
+{`// 创建动态回调函数
+const callbackName = \`ipLocationCallback_\${Date.now()}_\${Math.random()}\`;
+
+// 定义回调函数
+window[callbackName] = (ip, location, asn, org) => {
+ // 处理返回的数据
+ resolve({ ip, location, asn, org });
+};
+
+// 动态加载script标签
+const script = document.createElement('script');
+script.src = \`https://ping0.cc/geo/jsonp/\${callbackName}\`;
+document.head.appendChild(script);`}
+ </pre>
+ </Card>
+ </div>
+ );
+};
+
+export default IpTestPage;
diff --git a/src/app/i18n/locales/en/account.json b/src/app/i18n/locales/en/account.json
index 798e71be..473952ab 100644
--- a/src/app/i18n/locales/en/account.json
+++ b/src/app/i18n/locales/en/account.json
@@ -48,5 +48,10 @@
"chooseSpace": "Choose Space",
"pleaseChooseSpace": "Please choose a space",
"accountAddedToSpace": "Account has been added to the space",
- "noNewAccountDetected": "No new account detected; you can adjust the space later in Account Manager"
+ "noNewAccountDetected": "No new account detected; you can adjust the space later in Account Manager",
+ "ipInfo": {
+ "loading": "Getting IP info...",
+ "error": "Failed to get IP info",
+ "tooltip": "ASN: {{asn}}\nOrganization: {{org}}"
+ }
}
\ No newline at end of file
diff --git a/src/app/i18n/locales/zh-CN/account.json b/src/app/i18n/locales/zh-CN/account.json
index 83742caa..7088b388 100644
--- a/src/app/i18n/locales/zh-CN/account.json
+++ b/src/app/i18n/locales/zh-CN/account.json
@@ -2,7 +2,7 @@
"title": "账户",
"describe": "账户页面",
"today": "今天",
- "defaultSpace": "默认空间",
+ "defaultSpace": "defaultSpace",
"addPost": "添加帖子",
"calendarMode": "日历模式",
"listModeTab": "列表模式",
@@ -48,5 +48,10 @@
"chooseSpace": "选择空间",
"pleaseChooseSpace": "请选择空间",
"accountAddedToSpace": "账号已添加到空间",
- "noNewAccountDetected": "未检测到新账号,稍后可在账号管理器中手动调整空间"
+ "noNewAccountDetected": "未检测到新账号,稍后可在账号管理器中手动调整空间",
+ "ipInfo": {
+ "loading": "获取IP信息中...",
+ "error": "IP信息获取失败",
+ "tooltip": "ASN: {{asn}}\n组织: {{org}}"
+ }
}
\ No newline at end of file
diff --git a/src/utils/ipLocation.ts b/src/utils/ipLocation.ts
new file mode 100644
index 00000000..7a8e050e
--- /dev/null
+++ b/src/utils/ipLocation.ts
@@ -0,0 +1,71 @@
+/**
+ * IP地理位置获取工具
+ * 使用JSONP方式调用IP地理位置服务
+ */
+
+export interface IpLocationInfo {
+ ip: string;
+ location: string;
+ asn: string;
+ org: string;
+}
+
+/**
+ * 获取IP地理位置信息
+ * @returns Promise<IpLocationInfo>
+ */
+export const getIpLocation = (): Promise<IpLocationInfo> => {
+ return new Promise((resolve, reject) => {
+ // 创建全局回调函数
+ const callbackName = `ipLocationCallback_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
+
+ // 定义回调函数
+ (window as any)[callbackName] = (ip: string, location: string, asn: string, org: string) => {
+ // 清理回调函数和script标签
+ delete (window as any)[callbackName];
+ const script = document.getElementById(`ip-location-script-${callbackName}`);
+ if (script) {
+ document.head.removeChild(script);
+ }
+
+ resolve({ ip, location, asn, org });
+ };
+
+ // 创建script标签
+ const script = document.createElement('script');
+ script.id = `ip-location-script-${callbackName}`;
+ script.src = `https://ping0.cc/geo/jsonp/${callbackName}`;
+ script.onerror = () => {
+ // 清理回调函数
+ delete (window as any)[callbackName];
+ reject(new Error('获取IP地理位置信息失败'));
+ };
+
+ // 设置超时
+ const timeout = setTimeout(() => {
+ delete (window as any)[callbackName];
+ const scriptElement = document.getElementById(`ip-location-script-${callbackName}`);
+ if (scriptElement) {
+ document.head.removeChild(scriptElement);
+ }
+ reject(new Error('获取IP地理位置信息超时'));
+ }, 10000);
+
+ // 监听加载完成
+ script.onload = () => {
+ clearTimeout(timeout);
+ };
+
+ // 添加到页面
+ document.head.appendChild(script);
+ });
+};
+
+/**
+ * 格式化地理位置信息
+ * @param info IP地理位置信息
+ * @returns 格式化后的字符串
+ */
+export const formatLocationInfo = (info: IpLocationInfo): string => {
+ return `${info.ip} | ${info.location}`;
+};