Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f592178d83 | ||
|
|
1ebac24a3b | ||
|
|
875a7bf906 | ||
|
|
bf79191194 | ||
|
|
24ee3078d8 | ||
|
|
302277bad2 | ||
|
|
6724801d60 | ||
|
|
aa2fd609c6 | ||
|
|
6b758c3acd | ||
|
|
d55cc3e216 | ||
|
|
60c9698cdd | ||
|
|
c16bab66ee | ||
|
|
060bcf7f73 | ||
|
|
8394afe581 | ||
|
|
85140f8bdc | ||
|
|
ff725d766f | ||
|
|
cbfc4310b5 | ||
|
|
714e19a4fc | ||
|
|
50637087ae | ||
|
|
fa23805b5c | ||
|
|
d6dea1f1e8 | ||
|
|
915a2bcf9e | ||
|
|
77ca12045d | ||
|
|
88325a0ba9 |
No files matched your search
@@ -937,5 +937,17 @@
|
|||||||
"Failed to load resource group detail": "获取资源组详情失败",
|
"Failed to load resource group detail": "获取资源组详情失败",
|
||||||
"Resource Group Detail": "资源组详情",
|
"Resource Group Detail": "资源组详情",
|
||||||
"Current display time is UTC time": "当前显示时间为UTC时间",
|
"Current display time is UTC time": "当前显示时间为UTC时间",
|
||||||
"View Resource Group Detail": "查看资源组详情"
|
"View Resource Group Detail": "查看资源组详情",
|
||||||
|
"Configure tags bar display": "配置标签栏显示",
|
||||||
|
"Failed to load orders": "加载订单失败",
|
||||||
|
"Transaction Time": "交易时间",
|
||||||
|
"All": "全部",
|
||||||
|
"Purchase": "消费",
|
||||||
|
"No orders found": "无订单",
|
||||||
|
"Account Balance": "账户余额",
|
||||||
|
"View your balance and transaction history": "查看您的余额和交易历史",
|
||||||
|
"Display tags bar": "显示标签栏",
|
||||||
|
"Front end displays tags bar and allows users to filter products based on tags.": "前端显示标签栏,允许用户根据标签过滤产品。",
|
||||||
|
"Tags Bar": "标签栏",
|
||||||
|
"Auth Key Name": "认证密钥名称"
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,7 @@ import {
|
|||||||
Palette,
|
Palette,
|
||||||
SquareMenu,
|
SquareMenu,
|
||||||
TableOfContents,
|
TableOfContents,
|
||||||
|
Tags,
|
||||||
Trello,
|
Trello,
|
||||||
XIcon,
|
XIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
@@ -161,6 +162,12 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
|||||||
icon: <SquareMenu size={16} />,
|
icon: <SquareMenu size={16} />,
|
||||||
description: "Configure site navigation and menus",
|
description: "Configure site navigation and menus",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: SettingModalTab.TAGS_BAR,
|
||||||
|
label: "Tags Bar",
|
||||||
|
icon: <Tags size={16} />,
|
||||||
|
description: "Configure tags bar display",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: SettingModalTab.FAQ,
|
key: SettingModalTab.FAQ,
|
||||||
label: "FAQ",
|
label: "FAQ",
|
||||||
@@ -240,6 +247,7 @@ const SystemSettingsModal: React.FC<SystemSettingsModalProps> = ({
|
|||||||
items: groupItems([
|
items: groupItems([
|
||||||
SettingModalTab.THEME,
|
SettingModalTab.THEME,
|
||||||
SettingModalTab.NAVIGATION,
|
SettingModalTab.NAVIGATION,
|
||||||
|
SettingModalTab.TAGS_BAR,
|
||||||
SettingModalTab.FAQ,
|
SettingModalTab.FAQ,
|
||||||
]),
|
]),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { AdminConfig, EmailConfig } from "@/types/system";
|
|||||||
import { LoginSettingsContent } from "./LoginSettingsContent";
|
import { LoginSettingsContent } from "./LoginSettingsContent";
|
||||||
import { EmailConfigForm } from "@/components/system-setting/EmailConfigForm";
|
import { EmailConfigForm } from "@/components/system-setting/EmailConfigForm";
|
||||||
import { LanguageSetting } from "@/components/system-setting/LanguageSetting";
|
import { LanguageSetting } from "@/components/system-setting/LanguageSetting";
|
||||||
|
import { TagsBarSetting } from "../system-setting/TagsBarSetting";
|
||||||
|
|
||||||
interface SystemSettingsRightContentProps {
|
interface SystemSettingsRightContentProps {
|
||||||
filteredKeys: string[];
|
filteredKeys: string[];
|
||||||
@@ -201,6 +202,13 @@ const SystemSettingsRightContent: React.FC<SystemSettingsRightContentProps> = ({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{section.key === "tagsBar" && (
|
||||||
|
<TagsBarSetting
|
||||||
|
isEnabled={!!platformConfig.tag_bar_display}
|
||||||
|
onSave={onSavePlatformConfig}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{section.key === "faq" && (
|
{section.key === "faq" && (
|
||||||
<FaqSettings
|
<FaqSettings
|
||||||
onSave={saveFaqConfig}
|
onSave={saveFaqConfig}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export enum SettingModalTab {
|
|||||||
CODE_INJECTION = "code-injection",
|
CODE_INJECTION = "code-injection",
|
||||||
XPACK_EXPLORE = "xpack-explore",
|
XPACK_EXPLORE = "xpack-explore",
|
||||||
NAVIGATION = "navigation",
|
NAVIGATION = "navigation",
|
||||||
|
TAGS_BAR = "tagsBar",
|
||||||
FAQ = "faq",
|
FAQ = "faq",
|
||||||
CHANGE_PASSWORD = "change-password",
|
CHANGE_PASSWORD = "change-password",
|
||||||
EMAIL_LOGIN_SETTINGS = "email-login-settings",
|
EMAIL_LOGIN_SETTINGS = "email-login-settings",
|
||||||
|
|||||||
@@ -0,0 +1,388 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState, useCallback, useRef, useEffect } from "react";
|
||||||
|
import {
|
||||||
|
Table,
|
||||||
|
TableHeader,
|
||||||
|
TableColumn,
|
||||||
|
TableBody,
|
||||||
|
TableRow,
|
||||||
|
TableCell,
|
||||||
|
Button,
|
||||||
|
Pagination,
|
||||||
|
Tooltip,
|
||||||
|
Spinner,
|
||||||
|
Chip,
|
||||||
|
Dropdown,
|
||||||
|
DropdownTrigger,
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownItem,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { Calendar, HelpCircle, Filter } from "lucide-react";
|
||||||
|
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||||
|
import i18n from "@/shared/lib/i18n";
|
||||||
|
import { toast } from "react-hot-toast";
|
||||||
|
import { fetchAdminAPI } from "@/rpc/admin-api";
|
||||||
|
|
||||||
|
export interface OrderItem {
|
||||||
|
id: string;
|
||||||
|
amount: string;
|
||||||
|
balance: string;
|
||||||
|
order_id: string;
|
||||||
|
// 支付类型,stripe默认值
|
||||||
|
payment_type: string;
|
||||||
|
// 支付状态,0=未支付,1=已支付,2=支付失败
|
||||||
|
payment_state: number;
|
||||||
|
description: string;
|
||||||
|
// 充值时间
|
||||||
|
create_at: string;
|
||||||
|
// 交易时间,确认订单时间,只有充值完成后才有
|
||||||
|
confirm_at: string;
|
||||||
|
// 订单类型,充值(recharge),消费(purchase),退款(refund),冲正(reversal)
|
||||||
|
order_type: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AccountBalanceTableProps {
|
||||||
|
userId?: string;
|
||||||
|
source?: "client" | "admin";
|
||||||
|
}
|
||||||
|
|
||||||
|
const AccountBalanceTable: React.FC<AccountBalanceTableProps> = ({ userId, source }) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const [items, setItems] = useState<OrderItem[]>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [pagination, setPagination] = useState({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
|
const [selectedType, setSelectedType] = useState<string>("all");
|
||||||
|
const [selectedStatus, setSelectedStatus] = useState<string>("all");
|
||||||
|
const resourceGroupsParams = useRef({
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: "",
|
||||||
|
orderType: "",
|
||||||
|
status: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const pages = Math.ceil(pagination.total / pagination.pageSize);
|
||||||
|
const currentPage = Number(pagination.page);
|
||||||
|
|
||||||
|
const fetchOrders = useCallback(
|
||||||
|
async (
|
||||||
|
page: number,
|
||||||
|
page_size: number,
|
||||||
|
order_type?: string,
|
||||||
|
status?: string
|
||||||
|
): Promise<{ data: OrderItem[]; total: number; page: number; page_size: number }> => {
|
||||||
|
try {
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
page: page.toString(),
|
||||||
|
page_size: page_size.toString(),
|
||||||
|
});
|
||||||
|
if (order_type) params.append("order_type", order_type);
|
||||||
|
if (status) params.append("status", status);
|
||||||
|
if (userId) params.append("user_id", userId);
|
||||||
|
|
||||||
|
// 根据是否有 userId 来决定使用哪个 API
|
||||||
|
const apiUrl = userId
|
||||||
|
? `/api/order/list/by_user?${params.toString()}`
|
||||||
|
: `/api/user/order/list?${params.toString()}`;
|
||||||
|
|
||||||
|
const response = source === "client" ? await fetchAPI<OrderItem[]>(apiUrl) : await fetchAdminAPI<OrderItem[]>(apiUrl);
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load orders"));
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
data: response.data || [],
|
||||||
|
total: response.page?.total || 0,
|
||||||
|
page: response.page?.page || page,
|
||||||
|
page_size: response.page?.page_size || page_size,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching orders:", error);
|
||||||
|
return {
|
||||||
|
data: [],
|
||||||
|
total: 0,
|
||||||
|
page,
|
||||||
|
page_size,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[userId]
|
||||||
|
);
|
||||||
|
|
||||||
|
const loadOrders = useCallback(
|
||||||
|
async (
|
||||||
|
page: number = 1,
|
||||||
|
pageSize: number = 10,
|
||||||
|
keyword: string = "",
|
||||||
|
orderType: string = "",
|
||||||
|
status: string = ""
|
||||||
|
) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await fetchOrders(
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
orderType || undefined,
|
||||||
|
status || undefined
|
||||||
|
);
|
||||||
|
setItems(response.data);
|
||||||
|
setPagination({
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
total: response.total,
|
||||||
|
});
|
||||||
|
resourceGroupsParams.current = {
|
||||||
|
page: response.page,
|
||||||
|
pageSize: response.page_size,
|
||||||
|
keyword,
|
||||||
|
orderType,
|
||||||
|
status,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error(t("Failed to load orders"), error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[fetchOrders]
|
||||||
|
);
|
||||||
|
|
||||||
|
const formatDate = (dateString: string) => {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<Calendar className="w-3 h-3 text-gray-500" />
|
||||||
|
<span className="text-sm text-gray-600">
|
||||||
|
{new Date(dateString).toLocaleString()}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化金额,带正负号和美元符号
|
||||||
|
const formatAmount = (amount: string | number): string => {
|
||||||
|
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
||||||
|
if (isNaN(numAmount)) return '$0.00';
|
||||||
|
const absAmount = Math.abs(numAmount).toFixed(2);
|
||||||
|
if (numAmount > 0) {
|
||||||
|
return `+$${absAmount}`;
|
||||||
|
} else if (numAmount < 0) {
|
||||||
|
return `-$${absAmount}`;
|
||||||
|
}
|
||||||
|
return `$${absAmount}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 格式化余额,只显示美元符号,不带正负号
|
||||||
|
const formatBalance = (balance: string | number): string => {
|
||||||
|
const numBalance = typeof balance === 'string' ? parseFloat(balance) : balance;
|
||||||
|
if (isNaN(numBalance)) return '$0.00';
|
||||||
|
|
||||||
|
return `$${Math.abs(numBalance).toFixed(2)}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStatusColor = (status: number) => {
|
||||||
|
switch (status) {
|
||||||
|
case 1:
|
||||||
|
return "success";
|
||||||
|
case 2:
|
||||||
|
return "danger";
|
||||||
|
default:
|
||||||
|
return "warning";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPageChange = (page: number) => {
|
||||||
|
const { pageSize, orderType, status } = resourceGroupsParams.current;
|
||||||
|
loadOrders(page, pageSize, "", orderType, status);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTypeChange = (value: string) => {
|
||||||
|
setSelectedType(value);
|
||||||
|
const orderType = value === "all" ? "" : value;
|
||||||
|
const { status } = resourceGroupsParams.current;
|
||||||
|
loadOrders(1, pagination.pageSize, "", orderType, status);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleStatusChange = (value: string) => {
|
||||||
|
setSelectedStatus(value);
|
||||||
|
const status = value === "all" ? "" : value;
|
||||||
|
const { orderType } = resourceGroupsParams.current;
|
||||||
|
loadOrders(1, pagination.pageSize, "", orderType, status);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
loadOrders(1, 10, "");
|
||||||
|
}, [loadOrders]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Table
|
||||||
|
aria-label="Orders table"
|
||||||
|
classNames={{
|
||||||
|
wrapper: "min-h-[400px]",
|
||||||
|
}}
|
||||||
|
removeWrapper
|
||||||
|
>
|
||||||
|
<TableHeader>
|
||||||
|
<TableColumn>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
<span>{t("Transaction Time")}</span>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t("Type")}</span>
|
||||||
|
<Dropdown>
|
||||||
|
<DropdownTrigger>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
aria-label="Filter by type"
|
||||||
|
>
|
||||||
|
<Filter
|
||||||
|
className={`w-4 h-4 ${
|
||||||
|
selectedType !== "all" ? "text-primary" : ""
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</DropdownTrigger>
|
||||||
|
<DropdownMenu
|
||||||
|
aria-label="Type filter"
|
||||||
|
selectionMode="single"
|
||||||
|
selectedKeys={[selectedType]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected = Array.from(keys)[0] as string;
|
||||||
|
handleTypeChange(selected);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownItem key="all">{t("All")}</DropdownItem>
|
||||||
|
<DropdownItem key="recharge">{t("Recharge")}</DropdownItem>
|
||||||
|
<DropdownItem key="purchase">{t("Purchase")}</DropdownItem>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
|
<TableColumn>{t("Description")}</TableColumn>
|
||||||
|
<TableColumn>{t("Amount")}</TableColumn>
|
||||||
|
<TableColumn>{t("Balance")}</TableColumn>
|
||||||
|
<TableColumn>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t("Status")}</span>
|
||||||
|
<Dropdown>
|
||||||
|
<DropdownTrigger>
|
||||||
|
<Button
|
||||||
|
isIconOnly
|
||||||
|
size="sm"
|
||||||
|
variant="light"
|
||||||
|
aria-label="Filter by status"
|
||||||
|
>
|
||||||
|
<Filter
|
||||||
|
className={`w-4 h-4 ${
|
||||||
|
selectedStatus !== "all" ? "text-primary" : ""
|
||||||
|
}`}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</DropdownTrigger>
|
||||||
|
<DropdownMenu
|
||||||
|
aria-label="Status filter"
|
||||||
|
selectionMode="single"
|
||||||
|
selectedKeys={[selectedStatus]}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selected = Array.from(keys)[0] as string;
|
||||||
|
handleStatusChange(selected);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DropdownItem key="all">{t("All")}</DropdownItem>
|
||||||
|
<DropdownItem key="0">{t("Pending")}</DropdownItem>
|
||||||
|
<DropdownItem key="1">{t("Completed")}</DropdownItem>
|
||||||
|
<DropdownItem key="2">{t("Failed")}</DropdownItem>
|
||||||
|
</DropdownMenu>
|
||||||
|
</Dropdown>
|
||||||
|
</div>
|
||||||
|
</TableColumn>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody
|
||||||
|
items={items}
|
||||||
|
isLoading={loading}
|
||||||
|
loadingContent={<Spinner />}
|
||||||
|
emptyContent={t("No orders found")}
|
||||||
|
>
|
||||||
|
{(order) => (
|
||||||
|
<TableRow key={order.id}>
|
||||||
|
<TableCell>{formatDate(order.payment_state === 0 ? order.create_at : order.confirm_at)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
order.order_type === "recharge"
|
||||||
|
? "text-green-500"
|
||||||
|
: "text-red-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
order.order_type === "recharge" ? t("Recharge") : t("Purchase")
|
||||||
|
}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{order.description}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
order.order_type === "recharge"
|
||||||
|
? "text-green-500"
|
||||||
|
: "text-red-500"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{formatAmount(order.amount)}
|
||||||
|
</span>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>{formatBalance(order.balance)}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Chip
|
||||||
|
className="capitalize"
|
||||||
|
color={getStatusColor(order.payment_state)}
|
||||||
|
size="sm"
|
||||||
|
variant="flat"
|
||||||
|
>
|
||||||
|
{t(
|
||||||
|
order.payment_state === 1
|
||||||
|
? "Completed"
|
||||||
|
: order.payment_state === 2
|
||||||
|
? "Failed"
|
||||||
|
: "Pending"
|
||||||
|
)}
|
||||||
|
</Chip>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
|
||||||
|
{pages > 1 && (
|
||||||
|
<div className="flex w-full justify-center">
|
||||||
|
<Pagination
|
||||||
|
showControls
|
||||||
|
color="primary"
|
||||||
|
variant="light"
|
||||||
|
page={currentPage}
|
||||||
|
total={pages}
|
||||||
|
onChange={onPageChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AccountBalanceTable;
|
||||||
@@ -53,6 +53,10 @@ const OverviewPage: React.FC = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchApiKeys();
|
fetchApiKeys();
|
||||||
|
if (sessionStorage.getItem('create_new_authorization')) {
|
||||||
|
handleNewKey();
|
||||||
|
sessionStorage.removeItem('create_new_authorization');
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// create new auth key
|
// create new auth key
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import { formatCurrency } from "@/shared/utils/currency";
|
|||||||
// Import dashboard content components
|
// Import dashboard content components
|
||||||
import DashboardOverview from "@/components/dashboard/DashboardOverview";
|
import DashboardOverview from "@/components/dashboard/DashboardOverview";
|
||||||
import WalletManagement from "@/components/wallet/WalletManagement";
|
import WalletManagement from "@/components/wallet/WalletManagement";
|
||||||
|
import UserAccountBalance from "@/components/dashboard/UserAccountBalance";
|
||||||
import { Home, Key, Wallet } from "lucide-react";
|
import { Home, Key, Wallet } from "lucide-react";
|
||||||
import { Avatar, Card, CardBody, Button, Divider } from "@nextui-org/react";
|
import { Avatar, Card, CardBody, Button, Divider, Link } from "@nextui-org/react";
|
||||||
import { RechargeModal } from "@/shared/components/modal/RechargeModal";
|
import { RechargeModal } from "@/shared/components/modal/RechargeModal";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import { ChangePasswordModal } from "@/components/common/ChangePasswordModal";
|
import { ChangePasswordModal } from "@/components/common/ChangePasswordModal";
|
||||||
@@ -41,7 +42,7 @@ const DashboardContent: React.FC = () => {
|
|||||||
const [isRechargeModalOpen, setIsRechargeModalOpen] = useState(false);
|
const [isRechargeModalOpen, setIsRechargeModalOpen] = useState(false);
|
||||||
const getInitialTab = (): TabKey => {
|
const getInitialTab = (): TabKey => {
|
||||||
const tabFromUrl = searchParams.get("tab") as TabKey;
|
const tabFromUrl = searchParams.get("tab") as TabKey;
|
||||||
if (tabFromUrl && [TabKey.OVERVIEW, TabKey.WALLET].includes(tabFromUrl)) {
|
if (tabFromUrl && [TabKey.OVERVIEW, TabKey.WALLET, TabKey.USER_ACCOUNT].includes(tabFromUrl)) {
|
||||||
return tabFromUrl;
|
return tabFromUrl;
|
||||||
}
|
}
|
||||||
return TabKey.OVERVIEW;
|
return TabKey.OVERVIEW;
|
||||||
@@ -158,8 +159,15 @@ const DashboardContent: React.FC = () => {
|
|||||||
<Wallet size={16} />
|
<Wallet size={16} />
|
||||||
<span>
|
<span>
|
||||||
{t("Balance: {{amount}}", {
|
{t("Balance: {{amount}}", {
|
||||||
amount: formatCurrency(user?.wallet?.balance || 0),
|
amount: "",
|
||||||
})}
|
}).replace("{{amount}}", "")}
|
||||||
|
<Link
|
||||||
|
href="#"
|
||||||
|
className="text-xs cursor-pointer"
|
||||||
|
onPress={() => handleTabNavigate(TabKey.USER_ACCOUNT)}
|
||||||
|
>
|
||||||
|
{formatCurrency(user?.wallet?.balance || 0)}
|
||||||
|
</Link>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -187,6 +195,7 @@ const DashboardContent: React.FC = () => {
|
|||||||
{activeTab === TabKey.WALLET && (
|
{activeTab === TabKey.WALLET && (
|
||||||
<WalletManagement onRecharge={() => setIsRechargeModalOpen(true)} />
|
<WalletManagement onRecharge={() => setIsRechargeModalOpen(true)} />
|
||||||
)}
|
)}
|
||||||
|
{activeTab === TabKey.USER_ACCOUNT && <UserAccountBalance />}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||||
|
import AccountBalanceTable from "./AccountBalanceTable";
|
||||||
|
|
||||||
|
const UserAccountBalance: React.FC = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DashboardDemoContent
|
||||||
|
title={t("Account Balance")}
|
||||||
|
description={t("View your balance and transaction history")}
|
||||||
|
>
|
||||||
|
<div className="space-y-6 w-full">
|
||||||
|
<AccountBalanceTable source="client" />
|
||||||
|
</div>
|
||||||
|
</DashboardDemoContent>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UserAccountBalance;
|
||||||
@@ -4,12 +4,19 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { HeroSection } from "../../shared/components/marketplace/HeroSection";
|
import { HeroSection } from "../../shared/components/marketplace/HeroSection";
|
||||||
import { ServiceListSection } from "@/shared/components/marketplace/ServiceListSection";
|
import { ServiceListSection } from "@/shared/components/marketplace/ServiceListSection";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
import { ServiceData } from "@/shared/types/marketplace";
|
import { ServiceData } from "@/shared/types/marketplace";
|
||||||
import { fetchServices } from "@/services/marketplaceService";
|
import { fetchServices } from "@/services/marketplaceService";
|
||||||
import { Spinner } from "@nextui-org/react";
|
import { Spinner } from "@nextui-org/react";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface MarketplaceMainProps {
|
interface MarketplaceMainProps {
|
||||||
initialServices: ServiceData[];
|
initialServices: ServiceData[];
|
||||||
|
availableTags: string[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
selectedTag: string;
|
||||||
|
setSelectedTag: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
initialTotal: number;
|
initialTotal: number;
|
||||||
initialPage: number;
|
initialPage: number;
|
||||||
initialSearch: string;
|
initialSearch: string;
|
||||||
@@ -19,6 +26,11 @@ interface MarketplaceMainProps {
|
|||||||
|
|
||||||
export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
||||||
initialServices,
|
initialServices,
|
||||||
|
availableTags,
|
||||||
|
isTagBarDisplay,
|
||||||
|
selectedTag,
|
||||||
|
setSelectedTag,
|
||||||
|
currentTheme,
|
||||||
initialTotal,
|
initialTotal,
|
||||||
initialPage,
|
initialPage,
|
||||||
initialSearch,
|
initialSearch,
|
||||||
@@ -33,16 +45,18 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
|||||||
const [total, setTotal] = useState(initialTotal);
|
const [total, setTotal] = useState(initialTotal);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
// load services data
|
// load services data
|
||||||
const loadServices = async (page: number, search: string) => {
|
const loadServices = async (page: number, search: string, tag: string = "ALL") => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const result = await fetchServices({
|
const result = await fetchServices({
|
||||||
page,
|
page,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
keyword: search,
|
keyword: search,
|
||||||
|
// 如果需要,可以在这里添加tag参数传递给API
|
||||||
|
tag: tag !== "ALL" ? tag : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
setServices(result.data.services);
|
setServices(result.data.services);
|
||||||
setTotal(result.page.total);
|
setTotal(result.page.total);
|
||||||
setCurrentPage(page);
|
setCurrentPage(page);
|
||||||
@@ -79,13 +93,20 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
|||||||
// when page number changes, reload
|
// when page number changes, reload
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
updateURL(page, searchQuery);
|
updateURL(page, searchQuery);
|
||||||
loadServices(page, searchQuery);
|
loadServices(page, searchQuery, selectedTag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// handle search submit
|
// handle search submit
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
updateURL(1, searchQuery);
|
updateURL(1, searchQuery);
|
||||||
loadServices(1, searchQuery);
|
loadServices(1, searchQuery, selectedTag);
|
||||||
|
};
|
||||||
|
|
||||||
|
// handle tag change
|
||||||
|
const handleTagChange = (tag: string) => {
|
||||||
|
setSelectedTag(tag);
|
||||||
|
setCurrentPage(1);
|
||||||
|
loadServices(1, searchQuery, tag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// if there is an error, show error message
|
// if there is an error, show error message
|
||||||
@@ -102,9 +123,25 @@ export const MarketplaceMain: React.FC<MarketplaceMainProps> = ({
|
|||||||
{/* Hero Section */}
|
{/* Hero Section */}
|
||||||
<HeroSection
|
<HeroSection
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
onSearchChange={setSearchQuery}
|
onSearchChange={setSearchQuery}
|
||||||
onSearch={handleSearch}
|
onSearch={handleSearch}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<>
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Server List Section */}
|
{/* Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ interface AddServerModalProps {
|
|||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
name: string;
|
name: string;
|
||||||
|
id: string;
|
||||||
onSaveServer: (name: string, isDefault: boolean) => Promise<void>;
|
onSaveServer: (name: string, isDefault: boolean) => Promise<void>;
|
||||||
type: "add" | "edit";
|
type: "add" | "edit";
|
||||||
isDefault: boolean;
|
isDefault: boolean;
|
||||||
@@ -13,6 +14,7 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
|
|||||||
isOpen,
|
isOpen,
|
||||||
onClose,
|
onClose,
|
||||||
name,
|
name,
|
||||||
|
id,
|
||||||
onSaveServer,
|
onSaveServer,
|
||||||
type,
|
type,
|
||||||
isDefault,
|
isDefault,
|
||||||
@@ -49,12 +51,17 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
|
|||||||
{type === "add" ? t("Create New Resource Group") : t("Edit Resource Group")}
|
{type === "add" ? t("Create New Resource Group") : t("Edit Resource Group")}
|
||||||
</ModalHeader>
|
</ModalHeader>
|
||||||
<ModalBody>
|
<ModalBody>
|
||||||
<Input
|
{
|
||||||
label={t("Resource Group Name")}
|
!['allow-all', 'deny-all'].includes(id) && <>
|
||||||
value={serverName}
|
<Input
|
||||||
placeholder={t("Edit Resource Group Name")}
|
label={t("Resource Group Name")}
|
||||||
onChange={(e) => setServerName(e.target.value)}
|
value={serverName}
|
||||||
/>
|
placeholder={t("Edit Resource Group Name")}
|
||||||
|
onChange={(e) => setServerName(e.target.value)}
|
||||||
|
maxLength={255}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<span className="text-sm font-medium">
|
<span className="text-sm font-medium">
|
||||||
@@ -73,9 +80,9 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</ModalBody>
|
</ModalBody>
|
||||||
<ModalFooter>
|
<ModalFooter>
|
||||||
<Button
|
<Button
|
||||||
color="danger"
|
color="danger"
|
||||||
variant="light"
|
variant="light"
|
||||||
onPress={onClose}
|
onPress={onClose}
|
||||||
isDisabled={isLoading}
|
isDisabled={isLoading}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
|||||||
{resourceGroupDetail?.name}
|
{resourceGroupDetail?.name}
|
||||||
</h2>
|
</h2>
|
||||||
<div className="flex gap-2 h-[32px]">
|
<div className="flex gap-2 h-[32px]">
|
||||||
{showOptions && currentGroupId && <>
|
{currentGroupId && <>
|
||||||
<Button
|
<Button
|
||||||
isIconOnly
|
isIconOnly
|
||||||
size="sm"
|
size="sm"
|
||||||
@@ -114,7 +114,9 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
|
|||||||
onPress={() => onEditGroup(currentGroupId)}
|
onPress={() => onEditGroup(currentGroupId)}
|
||||||
>
|
>
|
||||||
<Edit2 size={18} />
|
<Edit2 size={18} />
|
||||||
</Button>
|
</Button></>
|
||||||
|
}
|
||||||
|
{showOptions && currentGroupId && <>
|
||||||
<Button
|
<Button
|
||||||
isIconOnly
|
isIconOnly
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -330,6 +330,7 @@ const ResourceGroupManagement: React.FC = () => {
|
|||||||
setEditingGroup(null);
|
setEditingGroup(null);
|
||||||
}}
|
}}
|
||||||
name={editingGroup?.name || ""}
|
name={editingGroup?.name || ""}
|
||||||
|
id={editingGroup?.id || ""}
|
||||||
isDefault={editingGroup?.isDefault || false}
|
isDefault={editingGroup?.isDefault || false}
|
||||||
onSaveServer={handleSaveGroup}
|
onSaveServer={handleSaveGroup}
|
||||||
type={editingGroup ? "edit" : "add"}
|
type={editingGroup ? "edit" : "add"}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { Switch } from "@nextui-org/react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
|
||||||
|
export type TagsBarSettingConfig = {
|
||||||
|
tag_bar_display: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface TagsBarSettingProps {
|
||||||
|
isEnabled: boolean;
|
||||||
|
onSave: (config: TagsBarSettingConfig) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TagsBarSetting: React.FC<TagsBarSettingProps> = ({
|
||||||
|
isEnabled,
|
||||||
|
onSave,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
{/* showcase in xpack */}
|
||||||
|
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<span className="text-sm font-medium">
|
||||||
|
{t("Display tags bar")}
|
||||||
|
</span>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
{t(
|
||||||
|
"Front end displays tags bar and allows users to filter products based on tags."
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Switch
|
||||||
|
isSelected={isEnabled}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
onSave({
|
||||||
|
tag_bar_display: value
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
color="primary"
|
||||||
|
size="sm"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -9,7 +9,7 @@ import { Home as ClassicHome } from "./classic/Home";
|
|||||||
import { Home as CreativeHome } from "./creative/Home";
|
import { Home as CreativeHome } from "./creative/Home";
|
||||||
import { Home as TemuHome } from "./temu/Home";
|
import { Home as TemuHome } from "./temu/Home";
|
||||||
import { ServiceData } from "@/shared/types/marketplace";
|
import { ServiceData } from "@/shared/types/marketplace";
|
||||||
import { fetchServices } from "@/services/marketplaceService";
|
import { fetchServices, fetchTagsList } from "@/services/marketplaceService";
|
||||||
import { Navigation } from "@/shared/components/Navigation";
|
import { Navigation } from "@/shared/components/Navigation";
|
||||||
import { MarketplaceMain } from "../marketplace/Main";
|
import { MarketplaceMain } from "../marketplace/Main";
|
||||||
import { Footer } from "@/shared/components/Footer";
|
import { Footer } from "@/shared/components/Footer";
|
||||||
@@ -53,18 +53,36 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
const [currentPage, setCurrentPage] = useState(initialPage);
|
const [currentPage, setCurrentPage] = useState(initialPage);
|
||||||
const [total, setTotal] = useState(initialTotal);
|
const [total, setTotal] = useState(initialTotal);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const isTagBarDisplay = platformConfig.tag_bar_display || false;
|
||||||
|
// 可用的标签列表(这里可以从API获取或配置)
|
||||||
|
const [availableTags, setAvailableTags] = useState<string[]>([]);
|
||||||
|
const [selectedTag, setSelectedTag] = useState("ALL");
|
||||||
// search suggestion
|
// search suggestion
|
||||||
const searchSuggestions = ["Search MCP servers"];
|
const searchSuggestions = ["Search MCP servers"];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadTagsList = async () => {
|
||||||
|
const tags = await fetchTagsList();
|
||||||
|
setAvailableTags(tags);
|
||||||
|
};
|
||||||
|
loadTagsList();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// handle tag change
|
||||||
|
const handleTagChange = (tag: string) => {
|
||||||
|
setSelectedTag(tag);
|
||||||
|
setCurrentPage(1);
|
||||||
|
loadServices(1, searchQuery, tag);
|
||||||
|
};
|
||||||
// loading service data
|
// loading service data
|
||||||
const loadServices = async (page: number, search: string) => {
|
const loadServices = async (page: number, search: string, tag: string = "ALL") => {
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const result = await fetchServices({
|
const result = await fetchServices({
|
||||||
page,
|
page,
|
||||||
page_size: pageSize,
|
page_size: pageSize,
|
||||||
keyword: search,
|
keyword: search,
|
||||||
|
tag: tag !== "ALL" ? tag : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
setServices(result.data.services);
|
setServices(result.data.services);
|
||||||
@@ -103,13 +121,13 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
// page change handler
|
// page change handler
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
updateURL(page, searchQuery);
|
updateURL(page, searchQuery);
|
||||||
loadServices(page, searchQuery);
|
loadServices(page, searchQuery, selectedTag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// search submit handler
|
// search submit handler
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
updateURL(1, searchQuery);
|
updateURL(1, searchQuery);
|
||||||
loadServices(1, searchQuery);
|
loadServices(1, searchQuery, selectedTag);
|
||||||
};
|
};
|
||||||
|
|
||||||
// search input change handler
|
// search input change handler
|
||||||
@@ -122,6 +140,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.MODERN:
|
case Theme.MODERN:
|
||||||
return (
|
return (
|
||||||
<ModernHome
|
<ModernHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -139,6 +162,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.CLASSIC:
|
case Theme.CLASSIC:
|
||||||
return (
|
return (
|
||||||
<ClassicHome
|
<ClassicHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -156,6 +184,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.CREATIVE:
|
case Theme.CREATIVE:
|
||||||
return (
|
return (
|
||||||
<CreativeHome
|
<CreativeHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -173,6 +206,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
case Theme.TEMU:
|
case Theme.TEMU:
|
||||||
return (
|
return (
|
||||||
<TemuHome
|
<TemuHome
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
handleTagChange={handleTagChange}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
searchQuery={searchQuery}
|
searchQuery={searchQuery}
|
||||||
services={services}
|
services={services}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
@@ -194,6 +232,11 @@ export const ThemeSelector: React.FC<ThemeSelectorProps> = ({
|
|||||||
<Navigation items={navigationItems} />
|
<Navigation items={navigationItems} />
|
||||||
<main className="flex-1">
|
<main className="flex-1">
|
||||||
<MarketplaceMain
|
<MarketplaceMain
|
||||||
|
currentTheme={currentTheme}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
setSelectedTag={setSelectedTag}
|
||||||
|
isTagBarDisplay={isTagBarDisplay}
|
||||||
|
availableTags={availableTags}
|
||||||
initialServices={services}
|
initialServices={services}
|
||||||
initialTotal={total}
|
initialTotal={total}
|
||||||
initialPage={currentPage}
|
initialPage={currentPage}
|
||||||
|
|||||||
@@ -24,11 +24,18 @@ import { Footer } from "./Footer";
|
|||||||
import { Navigation } from "./Navigation";
|
import { Navigation } from "./Navigation";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -50,6 +57,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -83,9 +95,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<h1 className="text-4xl lg:text-5xl font-bold mb-6 text-slate-800">
|
<h1 className="text-4xl lg:text-5xl font-bold mb-6 text-slate-800">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -93,8 +105,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-xl text-gray-600 max-w-3xl mx-auto leading-relaxed">
|
<p className="text-xl text-gray-600 max-w-3xl mx-auto leading-relaxed">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -140,6 +152,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<div className="pt-10">
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Server List Section */}
|
{/* Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="mx-auto h-[200px] flex items-center justify-center">
|
<div className="mx-auto h-[200px] flex items-center justify-center">
|
||||||
@@ -148,7 +175,7 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-gray-50 py-16">
|
<div className={`bg-gray-50 ${isTagBarDisplay ? 'py-10' : 'py-16'}`}>
|
||||||
<div className="mx-auto px-6 max-w-7xl">
|
<div className="mx-auto px-6 max-w-7xl">
|
||||||
{/* Server Grid */}
|
{/* Server Grid */}
|
||||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
|||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -17,6 +18,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed top-0 left-0 right-0 z-50">
|
<div className="fixed top-0 left-0 right-0 z-50">
|
||||||
{/* Classic Header */}
|
{/* Classic Header */}
|
||||||
@@ -26,21 +34,27 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
<DynamicLogo alt="Platform Logo" className="h-[32px] text-white" />
|
<DynamicLogo alt="Platform Logo" className="h-[32px] text-white" />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex space-x-2">
|
<div className="flex space-x-2">
|
||||||
<Button
|
{
|
||||||
onPress={handleLogin}
|
!userToken && (
|
||||||
variant="light"
|
<>
|
||||||
className="hidden sm:block text-white text-sm px-4 py-1 rounded-sm font-medium"
|
<Button
|
||||||
size="sm"
|
onPress={handleLogin}
|
||||||
>
|
variant="light"
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
className="hidden sm:block text-white text-sm px-4 py-1 rounded-sm font-medium"
|
||||||
</Button>
|
size="sm"
|
||||||
|
>
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
className="bg-red-600 hover:bg-red-700 text-white text-sm px-4 py-1 rounded-sm font-medium"
|
className="bg-red-600 hover:bg-red-700 text-white text-sm px-4 py-1 rounded-sm font-medium"
|
||||||
size="sm"
|
size="sm"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
{t("Get Started")}
|
{userToken ? t("Dashboard") : t("Get Started")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -24,11 +24,18 @@ import { Footer } from "./Footer";
|
|||||||
import { Navigation } from "./Navigation";
|
import { Navigation } from "./Navigation";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -50,6 +57,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -102,9 +114,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<span className="bg-clip-text text-transparent bg-gradient-to-r from-pink-600 via-red-500 to-orange-600">
|
<span className="bg-clip-text text-transparent bg-gradient-to-r from-pink-600 via-red-500 to-orange-600">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</h1>
|
</h1>
|
||||||
@@ -113,8 +125,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-lg font-medium max-w-3xl mx-auto leading-relaxed text-gray-700">
|
<p className="text-lg font-medium max-w-3xl mx-auto leading-relaxed text-gray-700">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -166,6 +178,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<>
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Creative Server List Section */}
|
{/* Creative Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="relative z-10 mx-auto h-[200px] flex items-center justify-center">
|
<div className="relative z-10 mx-auto h-[200px] flex items-center justify-center">
|
||||||
@@ -177,7 +204,7 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="relative z-10">
|
<div className="relative z-10">
|
||||||
<div className="relative mx-auto px-6 py-16 max-w-8xl">
|
<div className={`relative mx-auto px-6 ${isTagBarDisplay ? 'py-12' : 'py-16'} max-w-8xl`}>
|
||||||
{/* Creative Server Grid */}
|
{/* Creative Server Grid */}
|
||||||
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
<div className="flex flex-wrap justify-center gap-4 mb-12">
|
||||||
{services.map((service, index) => {
|
{services.map((service, index) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -16,6 +16,7 @@ import { ArrowRightIcon } from "lucide-react";
|
|||||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -26,6 +27,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Creative Navigation */}
|
{/* Creative Navigation */}
|
||||||
@@ -65,16 +73,22 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||||
<div className="hidden sm:flex gap-2">
|
<div className="hidden sm:flex gap-2">
|
||||||
<Button onPress={handleLogin} variant="light">
|
{
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
!userToken && (
|
||||||
</Button>
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
className="bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 hover:from-pink-600 hover:via-red-600 hover:to-orange-600 text-white shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105 flex items-center justify-center gap-4 pr-1 h-[45px]"
|
className="bg-gradient-to-r from-pink-500 via-red-500 to-orange-500 hover:from-pink-600 hover:via-red-600 hover:to-orange-600 text-white shadow-lg hover:shadow-xl transition-all duration-300 hover:scale-105 flex items-center justify-center gap-4 pr-1 h-[45px]"
|
||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
@@ -89,7 +103,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
@@ -101,7 +115,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
|
|||||||
@@ -26,11 +26,18 @@ import { Navigation } from "./Navigation";
|
|||||||
import { Footer } from "./Footer";
|
import { Footer } from "./Footer";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -52,6 +59,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -78,7 +90,7 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<Navigation items={navItems} />
|
<Navigation items={navItems} />
|
||||||
{/* Modern Hero Section */}
|
{/* Modern Hero Section */}
|
||||||
<div className="pt-32">
|
<div className="pt-32">
|
||||||
<div className="mx-auto px-6 py-20 max-w-6xl">
|
<div className={`mx-auto px-6 max-w-6xl ${isTagBarDisplay ? 'py-16' : 'py-20'}`}>
|
||||||
<div className="text-center mb-16">
|
<div className="text-center mb-16">
|
||||||
{/* Modern Icon */}
|
{/* Modern Icon */}
|
||||||
<div className="flex justify-center mb-8">
|
<div className="flex justify-center mb-8">
|
||||||
@@ -91,9 +103,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-gray-900 leading-tight">
|
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-gray-900 leading-tight">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -101,8 +113,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-lg text-gray-600 max-w-2xl mx-auto leading-relaxed">
|
<p className="text-lg text-gray-600 max-w-2xl mx-auto leading-relaxed">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -145,6 +157,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<>
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
{/* Server List Section */}
|
{/* Server List Section */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -16,6 +16,7 @@ import { ArrowRightIcon } from "lucide-react";
|
|||||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -25,7 +26,12 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Modern Navigation */}
|
{/* Modern Navigation */}
|
||||||
@@ -61,16 +67,22 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||||
<div className="hidden sm:flex gap-2">
|
<div className="hidden sm:flex gap-2">
|
||||||
<Button onPress={handleLogin} variant="light">
|
{
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
!userToken && (
|
||||||
</Button>
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
color="primary"
|
||||||
className="bg-gradient-to-r from-blue-500 to-purple-600 text-white hover:from-blue-600 hover:to-purple-700 flex items-center justify-center gap-4 pr-1 h-[45px] shadow-lg"
|
className="bg-gradient-to-r from-blue-500 to-purple-600 text-white hover:from-blue-600 hover:to-purple-700 flex items-center justify-center gap-4 pr-1 h-[45px] shadow-lg"
|
||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
@@ -85,7 +97,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
@@ -97,7 +109,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md">{t("Get Started")}</b>
|
<b className="text-md">{userToken ? t("Dashboard") : t("Get Started")}</b>
|
||||||
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-white/20 flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
|
|||||||
@@ -23,11 +23,18 @@ import { Footer } from "./Footer";
|
|||||||
import { Navigation } from "./Navigation";
|
import { Navigation } from "./Navigation";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { Faq } from "@/components/marketplace/Faq";
|
import { Faq } from "@/components/marketplace/Faq";
|
||||||
|
import { TagFilter } from "@/shared/components/marketplace/TagFilter";
|
||||||
|
import { ThemeType } from "@/shared/types/system";
|
||||||
|
|
||||||
interface HomeProps {
|
interface HomeProps {
|
||||||
// 状态
|
// 状态
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
|
availableTags: string[];
|
||||||
|
selectedTag: string;
|
||||||
|
handleTagChange: (tag: string) => void;
|
||||||
|
currentTheme: ThemeType;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
@@ -49,6 +56,11 @@ interface HomeProps {
|
|||||||
export const Home: React.FC<HomeProps> = ({
|
export const Home: React.FC<HomeProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
services,
|
services,
|
||||||
|
isTagBarDisplay,
|
||||||
|
availableTags,
|
||||||
|
selectedTag,
|
||||||
|
handleTagChange,
|
||||||
|
currentTheme,
|
||||||
currentPage,
|
currentPage,
|
||||||
total,
|
total,
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -95,9 +107,9 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-white">
|
<h1 className="text-4xl lg:text-6xl font-bold mb-6 text-white">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.headline ||
|
platformConfig.headline ||
|
||||||
platformConfig.name ||
|
platformConfig.name ||
|
||||||
_DefaultPlatformConfig.headline ||
|
_DefaultPlatformConfig.headline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
@@ -105,8 +117,8 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
<p className="text-xl text-white/90 mb-8 max-w-2xl mx-auto">
|
<p className="text-xl text-white/90 mb-8 max-w-2xl mx-auto">
|
||||||
{t(
|
{t(
|
||||||
platformConfig.subheadline ||
|
platformConfig.subheadline ||
|
||||||
_DefaultPlatformConfig.subheadline ||
|
_DefaultPlatformConfig.subheadline ||
|
||||||
""
|
""
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -139,6 +151,21 @@ export const Home: React.FC<HomeProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* filter section */}
|
||||||
|
{
|
||||||
|
isTagBarDisplay && (
|
||||||
|
<div className="pt-12">
|
||||||
|
<TagFilter
|
||||||
|
theme={currentTheme}
|
||||||
|
tags={availableTags}
|
||||||
|
selectedTag={selectedTag}
|
||||||
|
onTagChange={handleTagChange}
|
||||||
|
maxWidthPercent={80}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
{/* Products Section */}
|
{/* Products Section */}
|
||||||
<div className="mx-auto px-6 py-12 max-w-7xl">
|
<div className="mx-auto px-6 py-12 max-w-7xl">
|
||||||
{/* Section Header */}
|
{/* Section Header */}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
import { Button } from "@nextui-org/react";
|
import { Button } from "@nextui-org/react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -16,6 +16,7 @@ import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
|||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
import { NavigationItem } from "@/shared/components/Navigation";
|
import { NavigationItem } from "@/shared/components/Navigation";
|
||||||
import { ArrowRightIcon } from "lucide-react";
|
import { ArrowRightIcon } from "lucide-react";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
|
||||||
interface NavigationProps {
|
interface NavigationProps {
|
||||||
items?: NavigationItem[];
|
items?: NavigationItem[];
|
||||||
@@ -26,6 +27,13 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Temu Style Navigation */}
|
{/* Temu Style Navigation */}
|
||||||
@@ -64,15 +72,21 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
<NavbarContent justify="end" className="items-center gap-2 sm:gap-4">
|
||||||
<div className="hidden sm:flex items-center gap-2">
|
<div className="hidden sm:flex items-center gap-2">
|
||||||
<Button onPress={handleLogin} variant="light">
|
{
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
!userToken && (
|
||||||
</Button>
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
<Button
|
<Button
|
||||||
className="bg-orange-500 hover:bg-orange-600 text-white font-semibold px-6 h-[40px] transition-all duration-200"
|
className="bg-orange-500 hover:bg-orange-600 text-white font-semibold px-6 h-[40px] transition-all duration-200"
|
||||||
radius="md"
|
radius="md"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
{t("Get Started")}
|
{userToken ? t("Dashboard") : t("Get Started")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="sm:hidden">
|
<div className="sm:hidden">
|
||||||
@@ -81,7 +95,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
{t("Sign In")}
|
{userToken ? t("Dashboard") : t("Sign In")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</NavbarContent>
|
</NavbarContent>
|
||||||
@@ -100,7 +114,7 @@ export const Navigation: React.FC<NavigationProps> = ({ items }) => {
|
|||||||
radius="md"
|
radius="md"
|
||||||
onPress={handleLogin}
|
onPress={handleLogin}
|
||||||
>
|
>
|
||||||
{t("Sign In")}
|
{userToken ? t("Dashboard") : t("Sign In")}
|
||||||
</Button>
|
</Button>
|
||||||
</NavbarMenuItem>
|
</NavbarMenuItem>
|
||||||
</NavbarMenu>
|
</NavbarMenu>
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { Button} from "@nextui-org/react";
|
||||||
|
import { ChevronLeftIcon } from "lucide-react";
|
||||||
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
|
import { withComponentInjection } from "@/shared/hooks/useComponentInjection";
|
||||||
|
import AccountBalanceTable from "../dashboard/AccountBalanceTable";
|
||||||
|
|
||||||
|
interface UserBalanceDetailProps {
|
||||||
|
userId: string;
|
||||||
|
userEmail: string;
|
||||||
|
onCancel: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BaseUserBalanceDetail: React.FC<UserBalanceDetailProps> = ({
|
||||||
|
userId,
|
||||||
|
userEmail,
|
||||||
|
onCancel,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full py-8 h-full flex flex-col">
|
||||||
|
{/* page title */}
|
||||||
|
<div className="flex items-center justify-between mb-6 px-8">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Button isIconOnly onPress={onCancel} variant="flat" size="sm">
|
||||||
|
<ChevronLeftIcon className="w-5 h-5" />
|
||||||
|
</Button>
|
||||||
|
<h1 className="text-2xl font-bold">
|
||||||
|
{t("Account Balance")}
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{t("Email")}: </span>{userEmail || '-'}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="px-8">
|
||||||
|
<AccountBalanceTable userId={userId} source="admin" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export const UserBalanceDetail = withComponentInjection(
|
||||||
|
"components/user-management/UserBalanceDetail",
|
||||||
|
BaseUserBalanceDetail
|
||||||
|
);
|
||||||
@@ -7,6 +7,9 @@ import { UserTable } from "./UserTable";
|
|||||||
import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal";
|
import { DeleteConfirmModal } from "@/shared/components/modal/DeleteConfirmModal";
|
||||||
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
import DashboardDemoContent from "@/shared/components/DashboardDemoContent";
|
||||||
import { useUserManagement } from "@/hooks/useUserManagement";
|
import { useUserManagement } from "@/hooks/useUserManagement";
|
||||||
|
import { UserBalanceDetail } from "./UserBalanceDetail";
|
||||||
|
|
||||||
|
type ViewMode = "list" | "detail";
|
||||||
|
|
||||||
const UserManagement: React.FC = () => {
|
const UserManagement: React.FC = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -28,6 +31,11 @@ const UserManagement: React.FC = () => {
|
|||||||
user: null as User | null,
|
user: null as User | null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [viewMode, setViewMode] = useState<ViewMode>('list');
|
||||||
|
const [selectedUserId, setSelectedUserId] = useState<string | null>(null);
|
||||||
|
const [selectedUserEmail, setSelectedUserEmail] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
||||||
const handleDeleteUserClick = useCallback((user: User) => {
|
const handleDeleteUserClick = useCallback((user: User) => {
|
||||||
setDeleteModal({
|
setDeleteModal({
|
||||||
isOpen: true,
|
isOpen: true,
|
||||||
@@ -35,6 +43,18 @@ const UserManagement: React.FC = () => {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleViewUserBalanceDetail = useCallback((user: User) => {
|
||||||
|
setSelectedUserId(user.id);
|
||||||
|
setSelectedUserEmail(user.email);
|
||||||
|
setViewMode('detail');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCloseUserBalanceDetail = useCallback(() => {
|
||||||
|
setSelectedUserId(null);
|
||||||
|
setSelectedUserEmail(null);
|
||||||
|
setViewMode('list');
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleConfirmDelete = useCallback(async () => {
|
const handleConfirmDelete = useCallback(async () => {
|
||||||
if (deleteModal.user) {
|
if (deleteModal.user) {
|
||||||
try {
|
try {
|
||||||
@@ -61,6 +81,16 @@ const UserManagement: React.FC = () => {
|
|||||||
[handleRechargeUser]
|
[handleRechargeUser]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (viewMode === "detail" ) {
|
||||||
|
return (
|
||||||
|
<UserBalanceDetail
|
||||||
|
userId={selectedUserId || ''}
|
||||||
|
userEmail={selectedUserEmail || ''}
|
||||||
|
onCancel={handleCloseUserBalanceDetail}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardDemoContent
|
<DashboardDemoContent
|
||||||
title={t("User")}
|
title={t("User")}
|
||||||
@@ -74,6 +104,7 @@ const UserManagement: React.FC = () => {
|
|||||||
fetchUsers={fetchUsers}
|
fetchUsers={fetchUsers}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
onDelete={handleDeleteUserClick}
|
onDelete={handleDeleteUserClick}
|
||||||
|
viewUserBalanceDetail={handleViewUserBalanceDetail}
|
||||||
onRecharge={handleRecharge}
|
onRecharge={handleRecharge}
|
||||||
pagination={pagination}
|
pagination={pagination}
|
||||||
onPageChange={setPage}
|
onPageChange={setPage}
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ import {
|
|||||||
Spinner,
|
Spinner,
|
||||||
Select,
|
Select,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
|
Link
|
||||||
} from "@nextui-org/react";
|
} from "@nextui-org/react";
|
||||||
import { useTranslation } from "@/shared/lib/useTranslation";
|
import { useTranslation } from "@/shared/lib/useTranslation";
|
||||||
import { User } from "@/types/user";
|
import { User } from "@/types/user";
|
||||||
import { Trash2, CreditCard, Calendar, HelpCircle } from "lucide-react";
|
import { Trash2, CreditCard, Calendar, HelpCircle } from "lucide-react";
|
||||||
|
|
||||||
import { AdminRechargeModal } from "@/components/user-management/AdminRechargeModal";
|
import { AdminRechargeModal } from "@/components/user-management/AdminRechargeModal";
|
||||||
import { fetchSimpleResourceGroups, updateUserResourceGroup } from "@/api/resourceGroup.api";
|
import { fetchSimpleResourceGroups, updateUserResourceGroup } from "@/api/resourceGroup.api";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
@@ -27,6 +29,7 @@ interface UserTableProps {
|
|||||||
fetchUsers: () => void;
|
fetchUsers: () => void;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
onDelete: (user: User) => void;
|
onDelete: (user: User) => void;
|
||||||
|
viewUserBalanceDetail: (userId: User) => void;
|
||||||
onRecharge: (id: string, amount: number) => Promise<boolean>;
|
onRecharge: (id: string, amount: number) => Promise<boolean>;
|
||||||
pagination: {
|
pagination: {
|
||||||
page: number;
|
page: number;
|
||||||
@@ -40,6 +43,7 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
users,
|
users,
|
||||||
fetchUsers,
|
fetchUsers,
|
||||||
loading = false,
|
loading = false,
|
||||||
|
viewUserBalanceDetail,
|
||||||
onDelete,
|
onDelete,
|
||||||
onRecharge,
|
onRecharge,
|
||||||
pagination,
|
pagination,
|
||||||
@@ -135,7 +139,7 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableColumn>{t("Email")}</TableColumn>
|
<TableColumn>{t("Email")}</TableColumn>
|
||||||
<TableColumn width={250}>{t("Resource Group")}</TableColumn>
|
<TableColumn width={250}>{t("Resource Group")}</TableColumn>
|
||||||
<TableColumn>
|
<TableColumn width={200}>
|
||||||
<div className="flex items-center gap-1">
|
<div className="flex items-center gap-1">
|
||||||
<span>{t("Register Date")}</span>
|
<span>{t("Register Date")}</span>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
@@ -148,8 +152,8 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</TableColumn>
|
</TableColumn>
|
||||||
<TableColumn>{t("Balance")}</TableColumn>
|
<TableColumn width={120}>{t("Balance")}</TableColumn>
|
||||||
<TableColumn>{t("Actions")}</TableColumn>
|
<TableColumn width={100}>{t("Actions")}</TableColumn>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody
|
<TableBody
|
||||||
items={items}
|
items={items}
|
||||||
@@ -185,7 +189,15 @@ export const UserTable: React.FC<UserTableProps> = ({
|
|||||||
</Select>
|
</Select>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{formatDate(user.created_at)}</TableCell>
|
<TableCell>{formatDate(user.created_at)}</TableCell>
|
||||||
<TableCell>{user.balance.toFixed(2) || "-"}</TableCell>
|
<TableCell>
|
||||||
|
<Link
|
||||||
|
href="#"
|
||||||
|
className="text-xs cursor-pointer"
|
||||||
|
onPress={() => viewUserBalanceDetail(user)}
|
||||||
|
>
|
||||||
|
{user.balance.toFixed(2) || "-"}
|
||||||
|
</Link>
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<div className="relative flex items-center gap-2">
|
<div className="relative flex items-center gap-2">
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ interface FetchServicesParams {
|
|||||||
page?: number;
|
page?: number;
|
||||||
page_size?: number;
|
page_size?: number;
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
|
tag?: string;
|
||||||
}
|
}
|
||||||
interface ServicesResponseData {
|
interface ServicesResponseData {
|
||||||
services: ServiceData[];
|
services: ServiceData[];
|
||||||
@@ -42,6 +43,7 @@ export async function fetchServices(
|
|||||||
page_size: _BasePageDetail.page_size,
|
page_size: _BasePageDetail.page_size,
|
||||||
page: _BasePageDetail.page,
|
page: _BasePageDetail.page,
|
||||||
keyword: "",
|
keyword: "",
|
||||||
|
tag: "",
|
||||||
}
|
}
|
||||||
): Promise<ServicesResponse> {
|
): Promise<ServicesResponse> {
|
||||||
// Build query parameters
|
// Build query parameters
|
||||||
@@ -50,7 +52,7 @@ export async function fetchServices(
|
|||||||
if (params.page_size)
|
if (params.page_size)
|
||||||
queryParams.append("page_size", params.page_size.toString());
|
queryParams.append("page_size", params.page_size.toString());
|
||||||
if (params.keyword) queryParams.append("keyword", params.keyword);
|
if (params.keyword) queryParams.append("keyword", params.keyword);
|
||||||
|
if (params.tag) queryParams.append("tag", params.tag);
|
||||||
const response = await fetchAPI<BaseMCPService[]>(
|
const response = await fetchAPI<BaseMCPService[]>(
|
||||||
`/api/web/mcp_services${queryParams.toString() ? "?" + queryParams.toString() : ""}`
|
`/api/web/mcp_services${queryParams.toString() ? "?" + queryParams.toString() : ""}`
|
||||||
);
|
);
|
||||||
@@ -99,3 +101,26 @@ export async function fetchServiceById(
|
|||||||
|
|
||||||
return convertMcpService([response.data])[0];
|
return convertMcpService([response.data])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch tags list
|
||||||
|
*/
|
||||||
|
export async function fetchTagsList(
|
||||||
|
): Promise<string[] | []> {
|
||||||
|
const response = await fetchAPI<string[]>(
|
||||||
|
`/api/web/mcp_tags`,
|
||||||
|
{
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.success) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data || []
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Navbar,
|
Navbar,
|
||||||
NavbarContent,
|
NavbarContent,
|
||||||
@@ -15,6 +15,7 @@ import { useAuth } from "@/shared/lib/useAuth";
|
|||||||
import { ArrowRightIcon } from "lucide-react";
|
import { ArrowRightIcon } from "lucide-react";
|
||||||
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
import { DynamicLogo } from "@/shared/components/DynamicLogo";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useSharedStore } from "../store/share";
|
||||||
export type NavigationItem = {
|
export type NavigationItem = {
|
||||||
label: string;
|
label: string;
|
||||||
href: string;
|
href: string;
|
||||||
@@ -45,6 +46,13 @@ function NavigationClient({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
|
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* Main Navigation */}
|
{/* Main Navigation */}
|
||||||
@@ -97,9 +105,17 @@ function NavigationClient({
|
|||||||
{langNode ? (
|
{langNode ? (
|
||||||
langNode
|
langNode
|
||||||
) : (
|
) : (
|
||||||
<Button onPress={handleLogin} variant="light">
|
<>
|
||||||
<b className="text-md"> {t("Sign In")}</b>
|
{
|
||||||
</Button>
|
!userToken && (
|
||||||
|
<>
|
||||||
|
<Button onPress={handleLogin} variant="light">
|
||||||
|
<b className="text-md"> {t("Sign In")}</b>
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Desktop Auth Button */}
|
{/* Desktop Auth Button */}
|
||||||
@@ -110,7 +126,7 @@ function NavigationClient({
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={onLogin || handleLogin}
|
onPress={onLogin || handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md"> {t(signinText)}</b>
|
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
|
||||||
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
@@ -128,7 +144,7 @@ function NavigationClient({
|
|||||||
onPress={onLogin || handleLogin}
|
onPress={onLogin || handleLogin}
|
||||||
size="sm"
|
size="sm"
|
||||||
>
|
>
|
||||||
<b className="text-md"> {t(signinText)}</b>
|
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@@ -156,7 +172,7 @@ function NavigationClient({
|
|||||||
radius="full"
|
radius="full"
|
||||||
onPress={onLogin || handleLogin}
|
onPress={onLogin || handleLogin}
|
||||||
>
|
>
|
||||||
<b className="text-md"> {t(signinText)}</b>
|
<b className="text-md"> {userToken ? t("Dashboard") : t(signinText) }</b>
|
||||||
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
<div className="w-8 h-8 bg-gradient-to-r from-primary to-[#9ab0f2] flex items-center justify-center rounded-full">
|
||||||
<ArrowRightIcon
|
<ArrowRightIcon
|
||||||
size={16}
|
size={16}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
|
|
||||||
interface HeroSectionProps {
|
interface HeroSectionProps {
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
|
isTagBarDisplay: boolean;
|
||||||
onSearchChange: (value: string) => void;
|
onSearchChange: (value: string) => void;
|
||||||
onSearch?: () => void;
|
onSearch?: () => void;
|
||||||
searchSuggestions?: string[];
|
searchSuggestions?: string[];
|
||||||
@@ -16,6 +17,7 @@ interface HeroSectionProps {
|
|||||||
|
|
||||||
export const HeroSection: React.FC<HeroSectionProps> = ({
|
export const HeroSection: React.FC<HeroSectionProps> = ({
|
||||||
searchQuery,
|
searchQuery,
|
||||||
|
isTagBarDisplay,
|
||||||
onSearchChange,
|
onSearchChange,
|
||||||
onSearch,
|
onSearch,
|
||||||
searchSuggestions = [],
|
searchSuggestions = [],
|
||||||
@@ -77,7 +79,7 @@ export const HeroSection: React.FC<HeroSectionProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative overflow-hidden mx-auto p-6 py-24 max-w-7xl">
|
<div className={`relative overflow-hidden mx-auto p-6 ${isTagBarDisplay ? 'py-12' : 'py-24'} max-w-7xl`}>
|
||||||
<div className="text-center mb-12">
|
<div className="text-center mb-12">
|
||||||
<h1 className="text-5xl lg:text-6xl font-bold mb-6 leading-tight">
|
<h1 className="text-5xl lg:text-6xl font-bold mb-6 leading-tight">
|
||||||
{t(
|
{t(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react";
|
import { Card, Chip, Button, Select, SelectItem } from "@nextui-org/react";
|
||||||
import { FlipButton } from "@/shared/components/FlipButton";
|
import { FlipButton } from "@/shared/components/FlipButton";
|
||||||
import { useAuth } from "@/shared/lib/useAuth";
|
import { useAuth } from "@/shared/lib/useAuth";
|
||||||
@@ -9,7 +9,16 @@ import { usePlatformConfig } from "@/shared/contexts/PlatformConfigContext";
|
|||||||
import { Copy } from "lucide-react";
|
import { Copy } from "lucide-react";
|
||||||
import { copyToClipboard } from "@/shared/utils/clipboard";
|
import { copyToClipboard } from "@/shared/utils/clipboard";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
|
import { useSharedStore } from "@/shared/store/share";
|
||||||
|
import { fetchAPI } from "@/shared/rpc/common-function";
|
||||||
|
import i18n from "@/shared/lib/i18n";
|
||||||
|
|
||||||
|
type apiKeyList = {
|
||||||
|
name: string;
|
||||||
|
apikey: string;
|
||||||
|
create_time: string;
|
||||||
|
apikey_id: number;
|
||||||
|
}
|
||||||
interface ServerConfigProps {
|
interface ServerConfigProps {
|
||||||
mcpName?: string;
|
mcpName?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
@@ -20,6 +29,18 @@ interface ServerConfigProps {
|
|||||||
|
|
||||||
type McpType = "sse" | "streamable-http";
|
type McpType = "sse" | "streamable-http";
|
||||||
|
|
||||||
|
// 辅助函数:将 API Key 掩码显示,只保留前2位和后4位
|
||||||
|
const maskApiKey = (apiKey: string): string => {
|
||||||
|
if (!apiKey || apiKey.length <= 6) {
|
||||||
|
return apiKey; // 如果太短就直接返回
|
||||||
|
}
|
||||||
|
const prefix = apiKey.slice(0, 2);
|
||||||
|
const suffix = apiKey.slice(-4);
|
||||||
|
const maskedLength = apiKey.length - 6;
|
||||||
|
const masked = '*'.repeat(maskedLength);
|
||||||
|
return `${prefix}${masked}${suffix}`;
|
||||||
|
};
|
||||||
|
|
||||||
export const ServerConfig: React.FC<ServerConfigProps> = ({
|
export const ServerConfig: React.FC<ServerConfigProps> = ({
|
||||||
mcpName,
|
mcpName,
|
||||||
url = process.env.NEXT_PUBLIC_MCP_URL,
|
url = process.env.NEXT_PUBLIC_MCP_URL,
|
||||||
@@ -31,6 +52,49 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
|||||||
const { handleLogin } = useAuth();
|
const { handleLogin } = useAuth();
|
||||||
const { platformConfig } = usePlatformConfig();
|
const { platformConfig } = usePlatformConfig();
|
||||||
const [mcpType, setMcpType] = useState<McpType>("sse");
|
const [mcpType, setMcpType] = useState<McpType>("sse");
|
||||||
|
// API Key List
|
||||||
|
const [apiKeys, setApiKeys] = useState<{ key: string, label: string }[]>([]);
|
||||||
|
// Selected API Key
|
||||||
|
const [selectedApiKey, setSelectedApiKey] = useState<string | null>(null);
|
||||||
|
// User Token
|
||||||
|
const [userToken, setUserToken] = useState<string | null>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
const userToken = useSharedStore?.getState?.().user_token
|
||||||
|
setUserToken(userToken);
|
||||||
|
if (userToken) {
|
||||||
|
const data = await fetchApiKeys()
|
||||||
|
if (data.length > 0) {
|
||||||
|
setApiKeys(data.map((item) => ({
|
||||||
|
key: item.apikey,
|
||||||
|
label: item.name,
|
||||||
|
})));
|
||||||
|
setSelectedApiKey(data[0].apikey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fetchData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const fetchApiKeys = useCallback(
|
||||||
|
async (
|
||||||
|
): Promise<apiKeyList[]> => {
|
||||||
|
try {
|
||||||
|
|
||||||
|
const response = await fetchAPI<apiKeyList[]>('/api/apikey/list');
|
||||||
|
if (!response.success) {
|
||||||
|
toast.error(response.error_message || i18n.t("Failed to load api keys"));
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
return response.data || []
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching api keys:", error);
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const mcpTypeOptions = [
|
const mcpTypeOptions = [
|
||||||
{ key: "sse", label: "SSE (Server-Sent Events)" },
|
{ key: "sse", label: "SSE (Server-Sent Events)" },
|
||||||
@@ -40,8 +104,8 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
|||||||
const getCodeContent = () => {
|
const getCodeContent = () => {
|
||||||
const serverUrl =
|
const serverUrl =
|
||||||
mcpType === "streamable-http"
|
mcpType === "streamable-http"
|
||||||
? `${url}/streamable-http?authkey={Your-${platformConfig?.name}-Auth-Key}`
|
? `${url}/streamable-http?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`
|
||||||
: `${url}?authkey={Your-${platformConfig?.name}-Auth-Key}`;
|
: `${url}?authkey=${selectedApiKey ? selectedApiKey : `{Your-${platformConfig?.name}-Auth-Key}`}`;
|
||||||
|
|
||||||
return `{
|
return `{
|
||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
@@ -63,16 +127,62 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCreateNewAuthorization = () => {
|
||||||
|
sessionStorage.setItem('create_new_authorization', 'true');
|
||||||
|
handleLogin()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`min-w-full ${className} flex-shrink-0`}>
|
<div className={`min-w-full ${className} flex-shrink-0`}>
|
||||||
<div className="mb-2 mt-1">
|
<div className="mb-2 mt-1">
|
||||||
{
|
{
|
||||||
visitor || can_invoke ? <>
|
visitor || can_invoke ? <>
|
||||||
<FlipButton
|
{
|
||||||
className="w-full rounded-md"
|
!userToken ? <>
|
||||||
text={t("Sign up to get the auth key")}
|
<FlipButton
|
||||||
onPress={handleLogin}
|
className="w-full rounded-md"
|
||||||
/>
|
text={t("Sign up to get the auth key")}
|
||||||
|
onPress={handleLogin}
|
||||||
|
/>
|
||||||
|
</> : <>
|
||||||
|
{
|
||||||
|
apiKeys.length ?
|
||||||
|
<>
|
||||||
|
<Select
|
||||||
|
label={t("Auth Key")}
|
||||||
|
placeholder={t("Auth Key Name")}
|
||||||
|
selectedKeys={selectedApiKey ? [selectedApiKey] : []}
|
||||||
|
onSelectionChange={(keys) => {
|
||||||
|
const selectedKey = Array.from(keys)[0] as string;
|
||||||
|
setSelectedApiKey(selectedKey);
|
||||||
|
}}
|
||||||
|
className="w-full"
|
||||||
|
size="sm"
|
||||||
|
classNames={{
|
||||||
|
trigger: " bg-black text-white data-[hover=true]:bg-dark-200",
|
||||||
|
label: "!text-default-200",
|
||||||
|
value: "!text-white",
|
||||||
|
popoverContent: "bg-black text-white",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{apiKeys.map((option) => (
|
||||||
|
<SelectItem key={option.key} value={option.key}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</>
|
||||||
|
:
|
||||||
|
<>
|
||||||
|
<FlipButton
|
||||||
|
className="w-full rounded-md"
|
||||||
|
text={t("Create New Authorization")}
|
||||||
|
onPress={handleCreateNewAuthorization}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
}
|
||||||
</> : <>
|
</> : <>
|
||||||
<div className="w-full rounded-lg bg-[#F3126033] md:pr-2 h-[40px] md:h-[50px] shadow-lg flex items-center justify-center">
|
<div className="w-full rounded-lg bg-[#F3126033] md:pr-2 h-[40px] md:h-[50px] shadow-lg flex items-center justify-center">
|
||||||
<p className="text-[#C20E4D] text-center font-bold text-lg leading-none">
|
<p className="text-[#C20E4D] text-center font-bold text-lg leading-none">
|
||||||
@@ -140,7 +250,7 @@ export const ServerConfig: React.FC<ServerConfigProps> = ({
|
|||||||
{mcpType === "streamable-http"
|
{mcpType === "streamable-http"
|
||||||
? `${url}/streamable-http?authkey=`
|
? `${url}/streamable-http?authkey=`
|
||||||
: `${url}?authkey=`}
|
: `${url}?authkey=`}
|
||||||
<span className="text-success">{`{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
<span className="text-success">{selectedApiKey ? maskApiKey(selectedApiKey) : `{Your-${platformConfig?.name}-Auth-Key}`}</span>
|
||||||
{`"
|
{`"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,309 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
|
import {
|
||||||
|
Modal,
|
||||||
|
ModalContent,
|
||||||
|
ModalHeader,
|
||||||
|
ModalBody,
|
||||||
|
ModalFooter,
|
||||||
|
Button,
|
||||||
|
} from "@nextui-org/react";
|
||||||
|
import { Theme, ThemeType } from "@/shared/types/system";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
interface TagFilterProps {
|
||||||
|
tags: string[];
|
||||||
|
theme: ThemeType;
|
||||||
|
selectedTag: string;
|
||||||
|
onTagChange: (tag: string) => void;
|
||||||
|
maxWidthPercent?: number; // 最大宽度百分比,默认80%
|
||||||
|
}
|
||||||
|
|
||||||
|
export const TagFilter: React.FC<TagFilterProps> = ({
|
||||||
|
tags,
|
||||||
|
theme,
|
||||||
|
selectedTag,
|
||||||
|
onTagChange,
|
||||||
|
maxWidthPercent = 80,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
// 是否打开标签筛选弹窗
|
||||||
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
|
// 临时选中的标签
|
||||||
|
const [tempSelectedTag, setTempSelectedTag] = useState<string | null>(null);
|
||||||
|
// 可见的标签
|
||||||
|
const [visibleTags, setVisibleTags] = useState<string[]>(["ALL", ...tags]);
|
||||||
|
// 是否显示更多按钮
|
||||||
|
const [showMore, setShowMore] = useState(false);
|
||||||
|
// 从弹窗选择的额外标签
|
||||||
|
const [extraTag, setExtraTag] = useState<string | null>(null);
|
||||||
|
// 容器引用
|
||||||
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
// 标签容器引用
|
||||||
|
const tagsContainerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
|
||||||
|
// 根据主题获取颜色配置
|
||||||
|
const getThemeColors = () => {
|
||||||
|
switch (theme) {
|
||||||
|
case Theme.DEFAULT:
|
||||||
|
case Theme.MODERN:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#C8DCFF] text-[#1E40AF]",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#C8DCFF]/50",
|
||||||
|
};
|
||||||
|
case Theme.CLASSIC:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#475569] text-white",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#475569]/50",
|
||||||
|
};
|
||||||
|
case Theme.TEMU:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#F97316] text-white",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#F97316]/50",
|
||||||
|
};
|
||||||
|
case Theme.CREATIVE:
|
||||||
|
return {
|
||||||
|
selected: "to-orange-500 via-red-500 from-pink-500 bg-gradient-to-r text-white",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#EF5082]/50",
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
selected: "bg-[#C8DCFF] text-[#1E40AF]",
|
||||||
|
unselected: "text-gray-700 hover:bg-gray-200",
|
||||||
|
shadow: "shadow-lg shadow-[#C8DCFF]/50",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const themeColors = getThemeColors();
|
||||||
|
|
||||||
|
// 计算哪些标签可以显示
|
||||||
|
useEffect(() => {
|
||||||
|
const calculateVisibleTags = () => {
|
||||||
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
|
const containerWidth = containerRef.current.offsetWidth;
|
||||||
|
const maxWidth = (containerWidth * maxWidthPercent) / 100;
|
||||||
|
|
||||||
|
// More按钮的宽度(估算)
|
||||||
|
const moreButtonWidth = 80;
|
||||||
|
|
||||||
|
// 创建临时元素来测量标签宽度
|
||||||
|
const tempDiv = document.createElement("div");
|
||||||
|
tempDiv.style.position = "absolute";
|
||||||
|
tempDiv.style.visibility = "hidden";
|
||||||
|
tempDiv.style.whiteSpace = "nowrap";
|
||||||
|
tempDiv.className = "px-6 py-2 rounded-full text-sm font-medium";
|
||||||
|
document.body.appendChild(tempDiv);
|
||||||
|
|
||||||
|
let currentWidth = 0;
|
||||||
|
const visible: string[] = ["ALL"];
|
||||||
|
let needsMore = false;
|
||||||
|
|
||||||
|
// 先计算常规标签
|
||||||
|
for (const tag of tags) {
|
||||||
|
if (tag === extraTag) continue; // 跳过额外标签,稍后处理
|
||||||
|
|
||||||
|
tempDiv.textContent = tag;
|
||||||
|
const tagWidth = tempDiv.offsetWidth; // 不加间距
|
||||||
|
|
||||||
|
if (currentWidth + tagWidth + moreButtonWidth > maxWidth) {
|
||||||
|
needsMore = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
currentWidth += tagWidth;
|
||||||
|
visible.push(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理额外标签或当前选中的标签
|
||||||
|
// 如果当前选中的标签不在可见列表中(除了ALL),需要作为额外标签显示
|
||||||
|
const tagToShow = extraTag || (selectedTag !== "ALL" && !visible.includes(selectedTag) ? selectedTag : null);
|
||||||
|
|
||||||
|
if (tagToShow && tagToShow !== "ALL" && !visible.includes(tagToShow)) {
|
||||||
|
tempDiv.textContent = tagToShow;
|
||||||
|
const tagWidth = tempDiv.offsetWidth; // 不加间距
|
||||||
|
|
||||||
|
// 检查是否还有空间显示额外标签
|
||||||
|
if (currentWidth + tagWidth + moreButtonWidth <= maxWidth) {
|
||||||
|
// 空间足够,直接添加
|
||||||
|
currentWidth += tagWidth;
|
||||||
|
visible.push(tagToShow);
|
||||||
|
} else {
|
||||||
|
// 空间不够,替换掉最后一个常规标签(保留 ALL)
|
||||||
|
if (visible.length > 1) {
|
||||||
|
visible.pop(); // 移除最后一个标签
|
||||||
|
visible.push(tagToShow); // 添加额外标签
|
||||||
|
needsMore = true; // 确保显示 More 按钮
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.removeChild(tempDiv);
|
||||||
|
|
||||||
|
setVisibleTags(visible);
|
||||||
|
setShowMore(needsMore);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 延迟执行以确保DOM已渲染
|
||||||
|
setTimeout(calculateVisibleTags, 0);
|
||||||
|
|
||||||
|
// 监听窗口大小变化
|
||||||
|
window.addEventListener("resize", calculateVisibleTags);
|
||||||
|
return () => window.removeEventListener("resize", calculateVisibleTags);
|
||||||
|
}, [tags, extraTag, selectedTag, maxWidthPercent]);
|
||||||
|
|
||||||
|
const handleTagClick = (tag: string) => {
|
||||||
|
// 如果点击的是额外标签以外的标签,清除额外标签
|
||||||
|
if (extraTag && tag !== extraTag) {
|
||||||
|
setExtraTag(null);
|
||||||
|
}
|
||||||
|
onTagChange(tag);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalOpen = () => {
|
||||||
|
// 打开弹窗时,初始化临时选中的标签为当前选中的标签
|
||||||
|
setTempSelectedTag(selectedTag);
|
||||||
|
setIsModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalConfirm = () => {
|
||||||
|
if (tempSelectedTag) {
|
||||||
|
// 如果选择的是 ALL 或者已经在可见标签中的标签,不设置为额外标签
|
||||||
|
if (tempSelectedTag === "ALL" || visibleTags.includes(tempSelectedTag)) {
|
||||||
|
setExtraTag(null);
|
||||||
|
} else {
|
||||||
|
// 否则设置为额外标签
|
||||||
|
setExtraTag(tempSelectedTag);
|
||||||
|
}
|
||||||
|
onTagChange(tempSelectedTag);
|
||||||
|
}
|
||||||
|
setIsModalOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalCancel = () => {
|
||||||
|
setTempSelectedTag(null);
|
||||||
|
setIsModalOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleModalTagClick = (tag: string) => {
|
||||||
|
setTempSelectedTag(tag);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div ref={containerRef} className="w-full px-6 py-6">
|
||||||
|
<div className="mx-auto max-w-7xl text-center">
|
||||||
|
<div
|
||||||
|
ref={tagsContainerRef}
|
||||||
|
className="inline-flex items-center border-1 bg-[#fff] rounded-full transition-all duration-300"
|
||||||
|
>
|
||||||
|
{visibleTags.map((tag) => {
|
||||||
|
const isSelected = selectedTag === tag;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={tag}
|
||||||
|
onClick={() => handleTagClick(tag)}
|
||||||
|
className={`
|
||||||
|
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||||
|
whitespace-nowrap
|
||||||
|
${
|
||||||
|
isSelected
|
||||||
|
? `${themeColors.selected} ${themeColors.shadow}`
|
||||||
|
: themeColors.unselected
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
{tag}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
{showMore && (
|
||||||
|
<button
|
||||||
|
onClick={handleModalOpen}
|
||||||
|
className="px-4 py-2 text-sm font-medium text-blue-500 hover:text-blue-600 transition-colors whitespace-nowrap"
|
||||||
|
>
|
||||||
|
More
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* More Modal */}
|
||||||
|
<Modal
|
||||||
|
isOpen={isModalOpen}
|
||||||
|
onClose={handleModalCancel}
|
||||||
|
size="2xl"
|
||||||
|
scrollBehavior="inside"
|
||||||
|
>
|
||||||
|
<ModalContent>
|
||||||
|
<ModalHeader className="flex flex-col gap-1">
|
||||||
|
Tag Filter
|
||||||
|
</ModalHeader>
|
||||||
|
<ModalBody>
|
||||||
|
<div className="flex flex-wrap gap-3 py-4">
|
||||||
|
<button
|
||||||
|
onClick={() => handleModalTagClick("ALL")}
|
||||||
|
className={`
|
||||||
|
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||||
|
${
|
||||||
|
tempSelectedTag === "ALL"
|
||||||
|
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
|
||||||
|
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
ALL
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{tags.map((tag) => {
|
||||||
|
const isSelected = tempSelectedTag === tag;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={tag}
|
||||||
|
onClick={() => handleModalTagClick(tag)}
|
||||||
|
className={`
|
||||||
|
px-6 py-2 rounded-full text-sm font-medium transition-all duration-200
|
||||||
|
${
|
||||||
|
isSelected
|
||||||
|
? "bg-blue-500 text-white shadow-lg shadow-blue-500/50"
|
||||||
|
: "bg-gray-100 text-gray-700 hover:bg-gray-200"
|
||||||
|
}
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
{tag}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button
|
||||||
|
color="default"
|
||||||
|
variant="light"
|
||||||
|
onPress={handleModalCancel}
|
||||||
|
>
|
||||||
|
{t("Cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
onPress={handleModalConfirm}
|
||||||
|
isDisabled={!tempSelectedTag}
|
||||||
|
>
|
||||||
|
{t("Confirm")}
|
||||||
|
</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ export enum TabKey {
|
|||||||
OVERVIEW = "overview",
|
OVERVIEW = "overview",
|
||||||
WALLET = "wallet",
|
WALLET = "wallet",
|
||||||
ACCOUNT = "account",
|
ACCOUNT = "account",
|
||||||
|
USER_ACCOUNT = "user-account",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SidebarSubItem {
|
export interface SidebarSubItem {
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export interface PlatformConfig {
|
|||||||
facebook_description?: string; // facebook description
|
facebook_description?: string; // facebook description
|
||||||
facebook_image_url?: string; // facebook image url
|
facebook_image_url?: string; // facebook image url
|
||||||
meta_description?: string; // meta description
|
meta_description?: string; // meta description
|
||||||
|
tag_bar_display?: boolean; // whether to display tags bar
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
INSERT INTO `sys_config` (`id`,`key`, `value`,`description`,`created_at`,`updated_at`)
|
||||||
|
VALUES ('xpack-tag-bar-display','tag_bar_display', 'true', 'Display tag bar on the top of the page', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||||
|
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`), `description` = VALUES(`description`), `updated_at` = CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO `sys_config` (`id`,`key`, `value`,`description`,`created_at`,`updated_at`)
|
||||||
|
VALUES ('xpack-version','version', '1.3.0', 'The user interface supports viewing the transaction list.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||||
|
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`), `description` = VALUES(`description`), `updated_at` = CURRENT_TIMESTAMP;
|
||||||
@@ -7,6 +7,7 @@ KEY_SUBHEADLINE = "subheadline"
|
|||||||
KEY_LANGUAGE = "language"
|
KEY_LANGUAGE = "language"
|
||||||
KEY_THEME = "theme"
|
KEY_THEME = "theme"
|
||||||
KEY_ABOUT_PAGE = "about_page"
|
KEY_ABOUT_PAGE = "about_page"
|
||||||
|
KEY_TAG_BAR_DISPLAY = "tag_bar_display"
|
||||||
KEY_ADMIN_USERNAME = "admin_username"
|
KEY_ADMIN_USERNAME = "admin_username"
|
||||||
KEY_ADMIN_PASSWORD = "admin_password"
|
KEY_ADMIN_PASSWORD = "admin_password"
|
||||||
KEY_LOGIN_GOOGLE_CLIENT = "login_google_client_id"
|
KEY_LOGIN_GOOGLE_CLIENT = "login_google_client_id"
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ def account_login(body: dict = Body(...), auth_service: AuthService = Depends(ge
|
|||||||
if token:
|
if token:
|
||||||
return ResponseUtils.success({"user_token": token})
|
return ResponseUtils.success({"user_token": token})
|
||||||
else:
|
else:
|
||||||
return ResponseUtils.error(message="login failed", code=401)
|
return ResponseUtils.error(message="login failed, please enter the correct account or password", code=401)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/google/sign", response_model=dict)
|
@router.post("/google/sign", response_model=dict)
|
||||||
@@ -95,7 +95,7 @@ def google_login(request: Request, body: dict = Body(...), auth_service: AuthSer
|
|||||||
if token:
|
if token:
|
||||||
return ResponseUtils.success({"user_token": token})
|
return ResponseUtils.success({"user_token": token})
|
||||||
else:
|
else:
|
||||||
return ResponseUtils.error(message=f"login failed: {redirect_uri}", code=401)
|
return ResponseUtils.error(message=f"login failed, please check the redirect_uri: {redirect_uri}", code=401)
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/logout", response_model=dict)
|
@router.delete("/logout", response_model=dict)
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ def get_config(
|
|||||||
"facebook_image_url": values.get(KEY_FACEBOOK_IMAGE_URL, ""),
|
"facebook_image_url": values.get(KEY_FACEBOOK_IMAGE_URL, ""),
|
||||||
"social_account_facebook_url": values.get(KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
"social_account_facebook_url": values.get(KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
||||||
"social_account_x_url": values.get(KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
"social_account_x_url": values.get(KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
||||||
|
"tag_bar_display": values.get(KEY_TAG_BAR_DISPLAY, "false").lower() in ("true", "t", "yes", "y", "1"),
|
||||||
},
|
},
|
||||||
"faq": faq,
|
"faq": faq,
|
||||||
"embeded_html": embeded_html,
|
"embeded_html": embeded_html,
|
||||||
|
|||||||
@@ -270,6 +270,20 @@ def get_mcp_service_simple_list(
|
|||||||
logger.error(f"Failed to get service simple list: {str(e)}")
|
logger.error(f"Failed to get service simple list: {str(e)}")
|
||||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||||
|
|
||||||
|
@router.get("/service/tags", summary="Get MCP service tags")
|
||||||
|
def get_mcp_service_tags(
|
||||||
|
request: Request,
|
||||||
|
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||||
|
):
|
||||||
|
if not UserUtils.is_admin(request):
|
||||||
|
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||||
|
try:
|
||||||
|
tags = mcp_manager_service.get_tags_list(enabled_only=False)
|
||||||
|
return ResponseUtils.success(data=tags)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to get service tags: {str(e)}")
|
||||||
|
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||||
|
|
||||||
@router.get("/service/resource_group/list", summary="Get MCP service's resource group list")
|
@router.get("/service/resource_group/list", summary="Get MCP service's resource group list")
|
||||||
def get_mcp_service_resource_group_list(
|
def get_mcp_service_resource_group_list(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -360,4 +374,4 @@ def unbind_group(
|
|||||||
return ResponseUtils.success()
|
return ResponseUtils.success()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to unbind resource groups: {str(e)}")
|
logger.error(f"Failed to unbind resource groups: {str(e)}")
|
||||||
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
return ResponseUtils.error(error_msg=error_msg.INTERNAL_ERROR)
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
|
from os import stat
|
||||||
|
from typing import Optional, List
|
||||||
from fastapi import APIRouter, Depends, Query
|
from fastapi import APIRouter, Depends, Query
|
||||||
|
from services.common.models.user_wallet_history import TransactionType
|
||||||
from sqlalchemy import table
|
from sqlalchemy import table
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from services.common.database import get_db
|
from services.common.database import get_db
|
||||||
@@ -52,3 +55,39 @@ def get_user_order_list(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return ResponseUtils.success_page(data=result, total=total, page_num=page, page_size=page_size)
|
return ResponseUtils.success_page(data=result, total=total, page_num=page, page_size=page_size)
|
||||||
|
|
||||||
|
@router.get("/list/by_user", summary="Get user order list by user id")
|
||||||
|
def get_user_order_list_by_user_id(
|
||||||
|
user_id: str = Query(..., description="User ID"),
|
||||||
|
page: int = Query(1, description="Current page number"),
|
||||||
|
page_size: int = Query(15, description="Number of items per page"),
|
||||||
|
order_type: Optional[str] = Query(None, description="Order type"),
|
||||||
|
status: Optional[str] = Query(None, description="Order status"),
|
||||||
|
user_service: UserService = Depends(get_user_service),
|
||||||
|
user_wallet_history_service: UserWalletHistoryService = Depends(get_user_wallet_history_service),
|
||||||
|
):
|
||||||
|
"""Get paginated list of user order history by user id."""
|
||||||
|
user = user_service.get_by_id(user_id)
|
||||||
|
if not user:
|
||||||
|
return ResponseUtils.error(message="not found user", code=404)
|
||||||
|
offset = (page - 1) * page_size
|
||||||
|
order_type_list = []
|
||||||
|
if order_type:
|
||||||
|
# 将字符串转成列表,中间使用逗号分隔
|
||||||
|
ots = order_type.split(",")
|
||||||
|
for ot in ots:
|
||||||
|
ot = ot.strip()
|
||||||
|
if ot == "purchase":
|
||||||
|
order_type_list.append("api_call")
|
||||||
|
elif ot == "recharge":
|
||||||
|
order_type_list.append("deposit")
|
||||||
|
else:
|
||||||
|
order_type_list.append(ot)
|
||||||
|
status_list: Optional[List[int]] = []
|
||||||
|
if status:
|
||||||
|
sl = status.split(",")
|
||||||
|
for s in sl:
|
||||||
|
status_list.append(int(s.strip()))
|
||||||
|
total, orders = user_wallet_history_service.success_order_list_by_user(user_id, offset, page_size, order_type_list, status_list)
|
||||||
|
|
||||||
|
return ResponseUtils.success_page(data=orders, total=total, page_num=page, page_size=page_size)
|
||||||
@@ -144,6 +144,7 @@ def get_sysconfig(
|
|||||||
"social_account_facebook_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
"social_account_facebook_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, ""),
|
||||||
"social_account_x_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
"social_account_x_url": small_values.get(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, ""),
|
||||||
"cname_a_ip": cname_a_ip,
|
"cname_a_ip": cname_a_ip,
|
||||||
|
"tag_bar_display": small_values.get(sys_config_key.KEY_TAG_BAR_DISPLAY, "").lower() in ("true", "t", "yes", "y", "1"),
|
||||||
},
|
},
|
||||||
"account": {
|
"account": {
|
||||||
"username": admin_username,
|
"username": admin_username,
|
||||||
@@ -219,6 +220,9 @@ def set_sysconfig(
|
|||||||
facebook_image_url = platform.get("facebook_image_url")
|
facebook_image_url = platform.get("facebook_image_url")
|
||||||
social_account_facebook_url = platform.get("social_account_facebook_url")
|
social_account_facebook_url = platform.get("social_account_facebook_url")
|
||||||
social_account_x_url = platform.get("social_account_x_url")
|
social_account_x_url = platform.get("social_account_x_url")
|
||||||
|
tag_bar_display = platform.get("tag_bar_display")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
account = body.get("account", {})
|
account = body.get("account", {})
|
||||||
admin_username = account.get("username")
|
admin_username = account.get("username")
|
||||||
@@ -270,6 +274,7 @@ def set_sysconfig(
|
|||||||
(sys_config_key.KEY_FACEBOOK_IMAGE_URL, facebook_image_url, "Facebook image URL"),
|
(sys_config_key.KEY_FACEBOOK_IMAGE_URL, facebook_image_url, "Facebook image URL"),
|
||||||
(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, social_account_facebook_url, "Facebook URL"),
|
(sys_config_key.KEY_SOCIAL_ACCOUNT_FACEBOOK_URL, social_account_facebook_url, "Facebook URL"),
|
||||||
(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, social_account_x_url, "X URL"),
|
(sys_config_key.KEY_SOCIAL_ACCOUNT_X_URL, social_account_x_url, "X URL"),
|
||||||
|
(sys_config_key.KEY_TAG_BAR_DISPLAY, tag_bar_display, "Tag bar display"),
|
||||||
(sys_config_key.KEY_LOGIN_GOOGLE_CLIENT, login_google_client, "Google login client ID"),
|
(sys_config_key.KEY_LOGIN_GOOGLE_CLIENT, login_google_client, "Google login client ID"),
|
||||||
(sys_config_key.KEY_LOGIN_GOOGLE_SECRET, login_google_secret, "Google login client secret"),
|
(sys_config_key.KEY_LOGIN_GOOGLE_SECRET, login_google_secret, "Google login client secret"),
|
||||||
(sys_config_key.KEY_LOGIN_GOOGLE_ENABLE, login_google_enable, "Google login enabled"),
|
(sys_config_key.KEY_LOGIN_GOOGLE_ENABLE, login_google_enable, "Google login enabled"),
|
||||||
@@ -318,6 +323,7 @@ def set_sysconfig(
|
|||||||
"facebook_image_url": facebook_image_url,
|
"facebook_image_url": facebook_image_url,
|
||||||
"social_account_facebook_url": social_account_facebook_url,
|
"social_account_facebook_url": social_account_facebook_url,
|
||||||
"social_account_x_url": social_account_x_url,
|
"social_account_x_url": social_account_x_url,
|
||||||
|
"tag_bar_display": tag_bar_display,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use background reporting to avoid blocking the main configuration update
|
# Use background reporting to avoid blocking the main configuration update
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from fastapi import APIRouter, Depends, Request,Body
|
from fastapi import APIRouter, Depends, Request,Body,Query
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from services.common.database import get_db
|
from services.common.database import get_db
|
||||||
from services.admin_service.constants.user_task import user_task_ids
|
from services.admin_service.constants.user_task import user_task_ids
|
||||||
@@ -10,6 +10,9 @@ from services.admin_service.services.user_wallet_service import UserWalletServic
|
|||||||
from services.admin_service.services.user_task_service import UserTaskService
|
from services.admin_service.services.user_task_service import UserTaskService
|
||||||
from services.admin_service.services.auth_service import AuthService
|
from services.admin_service.services.auth_service import AuthService
|
||||||
from services.admin_service.services.resource_group_service import ResourceGroupService
|
from services.admin_service.services.resource_group_service import ResourceGroupService
|
||||||
|
from services.admin_service.services.user_wallet_history_service import UserWalletHistoryService
|
||||||
|
|
||||||
|
from typing import Optional,List
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@@ -27,6 +30,10 @@ def get_user_task_service(db: Session = Depends(get_db)) -> UserTaskService:
|
|||||||
def get_resource_group_service(db: Session = Depends(get_db)) -> ResourceGroupService:
|
def get_resource_group_service(db: Session = Depends(get_db)) -> ResourceGroupService:
|
||||||
return ResourceGroupService(db)
|
return ResourceGroupService(db)
|
||||||
|
|
||||||
|
def get_order_service(db: Session = Depends(get_db)) -> UserWalletHistoryService:
|
||||||
|
return UserWalletHistoryService(db)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/info", response_model=dict)
|
@router.get("/info", response_model=dict)
|
||||||
def get_user(request: Request, user_wallet: UserWalletService = Depends(get_user_wallet), user_task: UserTaskService = Depends(get_user_task_service), resource_group_service: ResourceGroupService = Depends(get_resource_group_service)):
|
def get_user(request: Request, user_wallet: UserWalletService = Depends(get_user_wallet), user_task: UserTaskService = Depends(get_user_task_service), resource_group_service: ResourceGroupService = Depends(get_resource_group_service)):
|
||||||
"""Get current user information and wallet balance."""
|
"""Get current user information and wallet balance."""
|
||||||
@@ -87,3 +94,37 @@ def update_password(
|
|||||||
|
|
||||||
return ResponseUtils.error(message="not found user", code=404)
|
return ResponseUtils.error(message="not found user", code=404)
|
||||||
|
|
||||||
|
@router.get("/order/list", summary="Get order list")
|
||||||
|
def get_order_list(
|
||||||
|
request: Request,
|
||||||
|
page: int = Query(1, description="Current page number"),
|
||||||
|
page_size: int = Query(15, description="Number of items per page"),
|
||||||
|
order_type: Optional[str] = Query(None, description="Order type"),
|
||||||
|
status: Optional[str] = Query(None, description="Order status"),
|
||||||
|
user_wallet_history_service: UserWalletHistoryService = Depends(get_order_service),
|
||||||
|
):
|
||||||
|
"""Get order list."""
|
||||||
|
user = UserUtils.get_request_user(request)
|
||||||
|
if not user:
|
||||||
|
return ResponseUtils.error(message="not found user", code=404)
|
||||||
|
offset = (page - 1) * page_size
|
||||||
|
order_type_list = []
|
||||||
|
if order_type:
|
||||||
|
# 将字符串转成列表,中间使用逗号分隔
|
||||||
|
ots = order_type.split(",")
|
||||||
|
for ot in ots:
|
||||||
|
ot = ot.strip()
|
||||||
|
if ot == "purchase":
|
||||||
|
order_type_list.append("api_call")
|
||||||
|
elif ot == "recharge":
|
||||||
|
order_type_list.append("deposit")
|
||||||
|
else:
|
||||||
|
order_type_list.append(ot)
|
||||||
|
status_list: Optional[List[int]] = []
|
||||||
|
if status:
|
||||||
|
sl = status.split(",")
|
||||||
|
for s in sl:
|
||||||
|
status_list.append(int(s.strip()))
|
||||||
|
total, orders = user_wallet_history_service.success_order_list_by_user(user.id, offset, page_size, order_type_list, status_list)
|
||||||
|
|
||||||
|
return ResponseUtils.success_page(data=orders, total=total, page_num=page, page_size=page_size)
|
||||||
@@ -29,6 +29,7 @@ def get_public_mcp_services(
|
|||||||
keyword: Optional[str] = Query(None, description="Search keyword"),
|
keyword: Optional[str] = Query(None, description="Search keyword"),
|
||||||
page: Optional[int] = Query(1, description="Page number (starts from 1)"),
|
page: Optional[int] = Query(1, description="Page number (starts from 1)"),
|
||||||
page_size: Optional[int] = Query(10, description="Page size (default 10)"),
|
page_size: Optional[int] = Query(10, description="Page size (default 10)"),
|
||||||
|
tag: Optional[str] = Query(None, description="Filter by tag"),
|
||||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||||
):
|
):
|
||||||
"""Get paginated list of public MCP services with keyword search."""
|
"""Get paginated list of public MCP services with keyword search."""
|
||||||
@@ -43,12 +44,19 @@ def get_public_mcp_services(
|
|||||||
|
|
||||||
# Get service list - let any exception bubble up to middleware
|
# Get service list - let any exception bubble up to middleware
|
||||||
service_list, total = mcp_manager_service.get_public_services_paginated(
|
service_list, total = mcp_manager_service.get_public_services_paginated(
|
||||||
keyword=search_keyword, page=validated_page, page_size=validated_page_size
|
keyword=search_keyword, page=validated_page, page_size=validated_page_size, tag=tag
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"Successfully retrieved {len(service_list)} services")
|
logger.info(f"Successfully retrieved {len(service_list)} services")
|
||||||
return ResponseUtils.success_page(data=service_list, page_num=validated_page, page_size=validated_page_size, total=total)
|
return ResponseUtils.success_page(data=service_list, page_num=validated_page, page_size=validated_page_size, total=total)
|
||||||
|
|
||||||
|
@router.get("/mcp_tags", summary="Get public MCP tags list")
|
||||||
|
def get_public_mcp_tags(
|
||||||
|
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||||
|
):
|
||||||
|
tags = mcp_manager_service.get_tags_list(enabled_only=True)
|
||||||
|
return ResponseUtils.success(data=tags)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/mcp_service_info", summary="Get public MCP service information")
|
@router.get("/mcp_service_info", summary="Get public MCP service information")
|
||||||
def get_public_mcp_service_info(
|
def get_public_mcp_service_info(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
from sqlalchemy import func
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from services.common.models.mcp_service import McpService
|
from services.common.models.mcp_service import McpService
|
||||||
from typing import Optional, Tuple, List
|
from typing import Optional, Tuple, List
|
||||||
@@ -103,7 +104,7 @@ class McpServiceRepository:
|
|||||||
self.db.refresh(mcp_service)
|
self.db.refresh(mcp_service)
|
||||||
return mcp_service
|
return mcp_service
|
||||||
|
|
||||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10) -> Tuple[List[McpService], int]:
|
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10, tag: Optional[str] = None) -> Tuple[List[McpService], int]:
|
||||||
"""Get public service list with pagination, supports keyword search"""
|
"""Get public service list with pagination, supports keyword search"""
|
||||||
offset = (page - 1) * page_size
|
offset = (page - 1) * page_size
|
||||||
|
|
||||||
@@ -112,9 +113,21 @@ class McpServiceRepository:
|
|||||||
if keyword:
|
if keyword:
|
||||||
keyword = f"%{keyword}%"
|
keyword = f"%{keyword}%"
|
||||||
query = query.filter((McpService.name.like(keyword)) | (McpService.short_description.like(keyword)))
|
query = query.filter((McpService.name.like(keyword)) | (McpService.short_description.like(keyword)))
|
||||||
|
if tag:
|
||||||
|
normalized_tag = tag.strip()
|
||||||
|
if normalized_tag:
|
||||||
|
normalized_tags = func.replace(func.replace(McpService.tags, ", ", ","), " ,", ",")
|
||||||
|
query = query.filter(func.find_in_set(normalized_tag, normalized_tags) > 0)
|
||||||
|
|
||||||
|
|
||||||
total = query.count()
|
total = query.count()
|
||||||
|
|
||||||
services = query.order_by(McpService.created_at.desc()).offset(offset).limit(page_size).all()
|
services = query.order_by(McpService.created_at.desc()).offset(offset).limit(page_size).all()
|
||||||
|
|
||||||
return services, total
|
return services, total
|
||||||
|
|
||||||
|
def get_tags_strings(self, enabled_only: bool = False) -> List[str]:
|
||||||
|
query = self.db.query(McpService.tags).filter(McpService.tags.isnot(None)).filter(McpService.tags != "")
|
||||||
|
if enabled_only:
|
||||||
|
query = query.filter(McpService.enabled == 1)
|
||||||
|
return [row[0] for row in query.all() if row and row[0]]
|
||||||
@@ -18,8 +18,20 @@ class UserWalletHistoryRepository:
|
|||||||
|
|
||||||
def __init__(self, db: Session):
|
def __init__(self, db: Session):
|
||||||
self.db = db
|
self.db = db
|
||||||
|
|
||||||
|
def get_by_id(self, transaction_id: str) -> Optional[UserWalletHistory]:
|
||||||
|
"""
|
||||||
|
Get a user wallet history record by ID.
|
||||||
|
|
||||||
def add_deposit(self, user_id: str, amount: float, payment_method: str, transaction_id: str = "", status: int = 0) -> UserWalletHistory:
|
Args:
|
||||||
|
transaction_id: Transaction ID
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Optional[UserWalletHistory]: Found record or None
|
||||||
|
"""
|
||||||
|
return self.db.query(UserWalletHistory).filter(UserWalletHistory.id == transaction_id).first()
|
||||||
|
|
||||||
|
def add_deposit(self, user_id: str, amount: float, payment_method: str, transaction_id: str = "", status: int = 0, balance_after: float = 0.00) -> UserWalletHistory:
|
||||||
"""
|
"""
|
||||||
Create a new deposit record.
|
Create a new deposit record.
|
||||||
|
|
||||||
@@ -40,7 +52,7 @@ class UserWalletHistoryRepository:
|
|||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
payment_method=PaymentMethod(payment_method),
|
payment_method=PaymentMethod(payment_method),
|
||||||
amount=amount,
|
amount=amount,
|
||||||
balance_after=0.00,
|
balance_after=balance_after,
|
||||||
type=TransactionType.DEPOSIT,
|
type=TransactionType.DEPOSIT,
|
||||||
transaction_id=transaction_id,
|
transaction_id=transaction_id,
|
||||||
status=status,
|
status=status,
|
||||||
@@ -81,7 +93,7 @@ class UserWalletHistoryRepository:
|
|||||||
self.db.refresh(history)
|
self.db.refresh(history)
|
||||||
return history
|
return history
|
||||||
|
|
||||||
def set_balance(self,user_id: str,amount:float, payment_method: str, transaction_id: str = "", status: int = 0) -> UserWalletHistory:
|
def set_balance(self,user_id: str,amount:float, payment_method: str, transaction_id: str = "", status: int = 0, balance_after: float = 0.00) -> UserWalletHistory:
|
||||||
"""
|
"""
|
||||||
Create a new balance record.
|
Create a new balance record.
|
||||||
|
|
||||||
@@ -102,7 +114,7 @@ class UserWalletHistoryRepository:
|
|||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
payment_method=PaymentMethod(payment_method),
|
payment_method=PaymentMethod(payment_method),
|
||||||
amount=amount,
|
amount=amount,
|
||||||
balance_after=0.00,
|
balance_after=balance_after,
|
||||||
type=TransactionType.RESET,
|
type=TransactionType.RESET,
|
||||||
status=status, # 0=new, 1=completed, 2=refunded
|
status=status, # 0=new, 1=completed, 2=refunded
|
||||||
created_at=now,
|
created_at=now,
|
||||||
@@ -242,8 +254,8 @@ class UserWalletHistoryRepository:
|
|||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
return total, history
|
return total, history
|
||||||
|
|
||||||
def get_by_id(self, history_id: str) -> Optional[UserWalletHistory]:
|
def success_order_list_by_user(self, user_id: str, offset: int, limit: int, order_type: Optional[List[str]] = None, status: Optional[List[int]] = None) -> Tuple[int, List[UserWalletHistory]]:
|
||||||
"""
|
"""
|
||||||
Get user wallet history record by ID.
|
Get user wallet history record by ID.
|
||||||
|
|
||||||
@@ -253,7 +265,25 @@ class UserWalletHistoryRepository:
|
|||||||
Returns:
|
Returns:
|
||||||
Optional[UserWalletHistory]: UserWalletHistory object or None
|
Optional[UserWalletHistory]: UserWalletHistory object or None
|
||||||
"""
|
"""
|
||||||
return self.db.query(UserWalletHistory).filter(UserWalletHistory.id == history_id).first()
|
|
||||||
|
query = self.db.query(UserWalletHistory).filter(
|
||||||
|
UserWalletHistory.user_id == user_id,
|
||||||
|
)
|
||||||
|
if order_type and len(order_type) > 0:
|
||||||
|
query = query.filter(UserWalletHistory.type.in_(order_type))
|
||||||
|
if status and len(status) > 0:
|
||||||
|
query = query.filter(UserWalletHistory.status.in_(status))
|
||||||
|
total = query.count()
|
||||||
|
if total < offset:
|
||||||
|
return total, []
|
||||||
|
history = (
|
||||||
|
query
|
||||||
|
.order_by(UserWalletHistory.created_at.desc())
|
||||||
|
.offset(offset)
|
||||||
|
.limit(limit)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
|
return total, history
|
||||||
|
|
||||||
def add_consume_record(self, wallet_history: UserWalletHistory) -> Optional[UserWalletHistory]:
|
def add_consume_record(self, wallet_history: UserWalletHistory) -> Optional[UserWalletHistory]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -244,5 +244,5 @@ class AuthService:
|
|||||||
return token
|
return token
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Google login failed: {e}")
|
logger.error(f"Google login failed, error: {e}")
|
||||||
return None
|
return None
|
||||||
@@ -329,6 +329,31 @@ class McpManagerService:
|
|||||||
"""Get service list with pagination"""
|
"""Get service list with pagination"""
|
||||||
return self.mcp_service_repository.get_all_paginated(page=page, page_size=page_size)
|
return self.mcp_service_repository.get_all_paginated(page=page, page_size=page_size)
|
||||||
|
|
||||||
|
def get_tags_list(self, enabled_only: bool = False) -> List[str]:
|
||||||
|
tags_strings = self.mcp_service_repository.get_tags_strings(enabled_only=enabled_only)
|
||||||
|
tag_counts: dict[str, int] = {}
|
||||||
|
canonical: dict[str, str] = {}
|
||||||
|
|
||||||
|
for tags_str in tags_strings:
|
||||||
|
normalized_in_service: set[str] = set()
|
||||||
|
for tag in parse_tags_to_array(tags_str):
|
||||||
|
normalized = tag.casefold()
|
||||||
|
if not normalized:
|
||||||
|
continue
|
||||||
|
if normalized in normalized_in_service:
|
||||||
|
continue
|
||||||
|
normalized_in_service.add(normalized)
|
||||||
|
canonical.setdefault(normalized, tag)
|
||||||
|
|
||||||
|
for normalized in normalized_in_service:
|
||||||
|
tag_counts[normalized] = tag_counts.get(normalized, 0) + 1
|
||||||
|
|
||||||
|
sorted_normalized = sorted(
|
||||||
|
tag_counts.keys(),
|
||||||
|
key=lambda normalized: (-tag_counts[normalized], canonical[normalized].casefold()),
|
||||||
|
)
|
||||||
|
return [canonical[normalized] for normalized in sorted_normalized]
|
||||||
|
|
||||||
def create_service_from_openapi(self, openapi_data: OpenApiForAI) -> str:
|
def create_service_from_openapi(self, openapi_data: OpenApiForAI) -> str:
|
||||||
# Convert OpenApiForAI info to McpService object and McpToolApi object list, return service ID or exception.
|
# Convert OpenApiForAI info to McpService object and McpToolApi object list, return service ID or exception.
|
||||||
try:
|
try:
|
||||||
@@ -488,9 +513,9 @@ class McpManagerService:
|
|||||||
logger.error(f"Failed to update service from OpenAPI: {str(e)}")
|
logger.error(f"Failed to update service from OpenAPI: {str(e)}")
|
||||||
raise ValueError(f"Failed to update service from OpenAPI.")
|
raise ValueError(f"Failed to update service from OpenAPI.")
|
||||||
|
|
||||||
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10) -> Tuple[List[dict], int]:
|
def get_public_services_paginated(self, keyword: str, page: int = 1, page_size: int = 10, tag: Optional[str] = None) -> Tuple[List[dict], int]:
|
||||||
"""Get public services list with pagination, returns formatted data with API info"""
|
"""Get public services list with pagination, returns formatted data with API info"""
|
||||||
services, total = self.mcp_service_repository.get_public_services_paginated(keyword, page, page_size)
|
services, total = self.mcp_service_repository.get_public_services_paginated(keyword, page, page_size, tag)
|
||||||
|
|
||||||
service_list = []
|
service_list = []
|
||||||
for service in services:
|
for service in services:
|
||||||
|
|||||||
@@ -403,11 +403,21 @@ class PaymentService:
|
|||||||
try:
|
try:
|
||||||
if typ == "incr":
|
if typ == "incr":
|
||||||
self.user_wallet_history_repository.add_deposit(
|
self.user_wallet_history_repository.add_deposit(
|
||||||
user_id=user_id, amount=amount, payment_method=payment_method, transaction_id=transaction_id,status=1
|
user_id=user_id,
|
||||||
|
amount=amount,
|
||||||
|
payment_method=payment_method,
|
||||||
|
transaction_id=transaction_id,
|
||||||
|
status=1,
|
||||||
|
balance_after=new_balance,
|
||||||
)
|
)
|
||||||
elif typ == "set":
|
elif typ == "set":
|
||||||
self.user_wallet_history_repository.set_balance(
|
self.user_wallet_history_repository.set_balance(
|
||||||
user_id=user_id, amount=amount, payment_method=payment_method, transaction_id=transaction_id,status=1
|
user_id=user_id,
|
||||||
|
amount=amount,
|
||||||
|
payment_method=payment_method,
|
||||||
|
transaction_id=transaction_id,
|
||||||
|
status=1,
|
||||||
|
balance_after=new_balance,
|
||||||
)
|
)
|
||||||
self._delete_wallet_cache(user_id)
|
self._delete_wallet_cache(user_id)
|
||||||
logger.info(f"Successfully updated balance for user_id {user_id}: {current_wallet.balance} -> {new_balance}")
|
logger.info(f"Successfully updated balance for user_id {user_id}: {current_wallet.balance} -> {new_balance}")
|
||||||
|
|||||||
@@ -45,11 +45,12 @@ class ResourceGroupService:
|
|||||||
def update_group(self, gid: str, body: dict) -> bool:
|
def update_group(self, gid: str, body: dict) -> bool:
|
||||||
if not gid:
|
if not gid:
|
||||||
raise ValueError("Group ID is required")
|
raise ValueError("Group ID is required")
|
||||||
existing = self.group_repo.get_by_id(gid)
|
|
||||||
if not existing:
|
|
||||||
raise ValueError("Resource group not found")
|
|
||||||
try:
|
try:
|
||||||
if gid != "deny-all" and gid != "allow-all":
|
if gid != "deny-all" and gid != "allow-all":
|
||||||
|
existing = self.group_repo.get_by_id(gid)
|
||||||
|
if not existing:
|
||||||
|
raise ValueError("Resource group not found")
|
||||||
patch = ResourceGroup()
|
patch = ResourceGroup()
|
||||||
patch.id = gid
|
patch.id = gid
|
||||||
patch.name = body.get("name", existing.name)
|
patch.name = body.get("name", existing.name)
|
||||||
@@ -68,9 +69,10 @@ class ResourceGroupService:
|
|||||||
def delete_group(self, gid: str, migrate_id: Optional[str] = None) -> bool:
|
def delete_group(self, gid: str, migrate_id: Optional[str] = None) -> bool:
|
||||||
try:
|
try:
|
||||||
if migrate_id:
|
if migrate_id:
|
||||||
migrate_group = self.group_repo.get_by_id(migrate_id)
|
if migrate_id != "deny-all" and migrate_id != "allow-all":
|
||||||
if not migrate_group:
|
migrate_group = self.group_repo.get_by_id(migrate_id)
|
||||||
raise ValueError("Migrate resource group not found")
|
if not migrate_group:
|
||||||
|
raise ValueError("Migrate resource group not found")
|
||||||
self.map_repo.migrate_services(gid, migrate_id, commit=False)
|
self.map_repo.migrate_services(gid, migrate_id, commit=False)
|
||||||
current_default = self.sys_repo.get_value_by_key(KEY_DEFAULT_RESOURCE_GROUP)
|
current_default = self.sys_repo.get_value_by_key(KEY_DEFAULT_RESOURCE_GROUP)
|
||||||
if current_default == gid:
|
if current_default == gid:
|
||||||
@@ -85,7 +87,9 @@ class ResourceGroupService:
|
|||||||
raise ValueError("Resource group not found")
|
raise ValueError("Resource group not found")
|
||||||
users = self.user_repo.update_resource_group_by_group_id(gid, migrate_id or "deny-all", commit=False)
|
users = self.user_repo.update_resource_group_by_group_id(gid, migrate_id or "deny-all", commit=False)
|
||||||
if not users:
|
if not users:
|
||||||
raise ValueError("Failed to update user resource group")
|
self.db.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
cache_key = f"xpack:user:{user.id}"
|
cache_key = f"xpack:user:{user.id}"
|
||||||
self.redis.set(cache_key, user, 600)
|
self.redis.set(cache_key, user, 600)
|
||||||
@@ -177,10 +181,19 @@ class ResourceGroupService:
|
|||||||
"enabled": True, # 统一为 bool
|
"enabled": True, # 统一为 bool
|
||||||
"is_default": "deny-all" == default_group,
|
"is_default": "deny-all" == default_group,
|
||||||
}
|
}
|
||||||
if len(data) < page_size:
|
s_index = (page - 1) * page_size
|
||||||
|
e_index = page * page_size
|
||||||
|
if total > s_index and total < e_index:
|
||||||
data.append(allow_all)
|
data.append(allow_all)
|
||||||
if len(data) < page_size:
|
if total < e_index-1:
|
||||||
|
data.append(deny_all)
|
||||||
|
elif total < s_index and s_index - total == 1:
|
||||||
data.append(deny_all)
|
data.append(deny_all)
|
||||||
|
elif total == s_index:
|
||||||
|
data.append(allow_all)
|
||||||
|
data.append(deny_all)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return data,total+2
|
return data,total+2
|
||||||
|
|
||||||
@@ -353,7 +366,7 @@ class ResourceGroupService:
|
|||||||
"created_at": str(s.created_at) if s.created_at else None,
|
"created_at": str(s.created_at) if s.created_at else None,
|
||||||
"updated_at": str(s.updated_at) if s.updated_at else None,
|
"updated_at": str(s.updated_at) if s.updated_at else None,
|
||||||
}
|
}
|
||||||
for s in (service_map[sid] for sid in sids)
|
for s in (service_map[sid] for sid in sids if sid in service_map)
|
||||||
],total
|
],total
|
||||||
def get_unbind_services(self, gid: str) -> List[dict]:
|
def get_unbind_services(self, gid: str) -> List[dict]:
|
||||||
if gid == "deny-all" or gid == "allow-all":
|
if gid == "deny-all" or gid == "allow-all":
|
||||||
|
|||||||
@@ -3,11 +3,16 @@ from services.common.models.user_wallet_history import UserWalletHistory
|
|||||||
from services.admin_service.repositories.user_wallet_history_repository import UserWalletHistoryRepository
|
from services.admin_service.repositories.user_wallet_history_repository import UserWalletHistoryRepository
|
||||||
from typing import Optional, Dict, Any, List, Tuple
|
from typing import Optional, Dict, Any, List, Tuple
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from services.common.models.user_wallet_history import TransactionType
|
||||||
|
from services.admin_service.repositories.mcp_service_repository import McpServiceRepository
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserWalletHistoryService:
|
class UserWalletHistoryService:
|
||||||
def __init__(self, db: Session):
|
def __init__(self, db: Session):
|
||||||
self.user_wallet_history_repository = UserWalletHistoryRepository(db)
|
self.user_wallet_history_repository = UserWalletHistoryRepository(db)
|
||||||
|
self.mcp_service_repository = McpServiceRepository(db)
|
||||||
|
|
||||||
def add_deposit(self, user_id: str, amount: float, payment_method: str) -> UserWalletHistory:
|
def add_deposit(self, user_id: str, amount: float, payment_method: str) -> UserWalletHistory:
|
||||||
return self.user_wallet_history_repository.add_deposit(user_id, amount, payment_method)
|
return self.user_wallet_history_repository.add_deposit(user_id, amount, payment_method)
|
||||||
@@ -18,6 +23,48 @@ class UserWalletHistoryService:
|
|||||||
def success_deposit_order_list(self, offset: int, limit: int) -> Tuple[int, List[UserWalletHistory]]:
|
def success_deposit_order_list(self, offset: int, limit: int) -> Tuple[int, List[UserWalletHistory]]:
|
||||||
return self.user_wallet_history_repository.success_deposit_order_list(offset, limit)
|
return self.user_wallet_history_repository.success_deposit_order_list(offset, limit)
|
||||||
|
|
||||||
|
def success_order_list_by_user(self, user_id: str, offset: int, limit: int, order_type: Optional[List[str]] = None, status: Optional[List[int]] = None) -> Tuple[int, List[dict]]:
|
||||||
|
total, orders = self.user_wallet_history_repository.success_order_list_by_user(user_id, offset, limit, order_type, status)
|
||||||
|
if total == 0:
|
||||||
|
return total, []
|
||||||
|
result = []
|
||||||
|
for order in orders:
|
||||||
|
confirm_at = ""
|
||||||
|
if order.status == 1:
|
||||||
|
confirm_at = order.updated_at
|
||||||
|
info = {
|
||||||
|
"id": order.id,
|
||||||
|
"user_id": order.user_id,
|
||||||
|
"order_id": order.transaction_id,
|
||||||
|
"payment_type": order.payment_method,
|
||||||
|
"payment_state": order.status,
|
||||||
|
"amount": order.amount,
|
||||||
|
"create_at": order.created_at,
|
||||||
|
"confirm_at": confirm_at,
|
||||||
|
}
|
||||||
|
if order.type == TransactionType.API_CALL:
|
||||||
|
info["order_type"] = "purchase"
|
||||||
|
try:
|
||||||
|
callback_data = json.loads(order.callback_data)
|
||||||
|
service = self.mcp_service_repository.get_by_id(callback_data["service_id"])
|
||||||
|
if service:
|
||||||
|
info["description"] = service.name
|
||||||
|
except:
|
||||||
|
info["description"] = "-"
|
||||||
|
info["balance"] = order.balance_after
|
||||||
|
elif order.type == TransactionType.DEPOSIT:
|
||||||
|
info["order_type"] = "recharge"
|
||||||
|
if order.status == 1:
|
||||||
|
info["balance"] = order.balance_after
|
||||||
|
else:
|
||||||
|
info["balance"] = "-"
|
||||||
|
info["description"] = order.payment_method
|
||||||
|
else:
|
||||||
|
info["order_type"] = order.type
|
||||||
|
result.append(info)
|
||||||
|
return total, result
|
||||||
|
return total, orders
|
||||||
|
|
||||||
def order_list(self, payment_method: str, status: int, start: Optional[datetime] = None, end: Optional[datetime] = None) -> List[UserWalletHistory]:
|
def order_list(self, payment_method: str, status: int, start: Optional[datetime] = None, end: Optional[datetime] = None) -> List[UserWalletHistory]:
|
||||||
return self.user_wallet_history_repository.order_list(payment_method, status, start, end)
|
return self.user_wallet_history_repository.order_list(payment_method, status, start, end)
|
||||||
|
|
||||||
|
|||||||
@@ -293,40 +293,42 @@ class HttpRequestBuilder:
|
|||||||
"""
|
"""
|
||||||
if not hasattr(tool_config, 'request_body_schema') or not tool_config.request_body_schema or tool_config.method.value not in ["POST", "PUT", "PATCH"]:
|
if not hasattr(tool_config, 'request_body_schema') or not tool_config.request_body_schema or tool_config.method.value not in ["POST", "PUT", "PATCH"]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# First try to parse as parameters list (similar to query/path parameters)
|
request_body = {}
|
||||||
body_params = self._safe_parse_params(tool_config.request_body_schema, 'body')
|
body_params = self._safe_parse_params(tool_config.request_body_schema, 'body')
|
||||||
if body_params:
|
if body_params:
|
||||||
# If it's a list of parameters, process them like query parameters
|
|
||||||
request_body = {}
|
|
||||||
for param in body_params:
|
for param in body_params:
|
||||||
if isinstance(param, dict) and "name" in param:
|
if isinstance(param, dict):
|
||||||
param_name = param["name"]
|
name = param.get("name")
|
||||||
if param_name in arguments:
|
if name and name in arguments:
|
||||||
request_body[param_name] = arguments[param_name]
|
request_body[name] = arguments[name]
|
||||||
|
else:
|
||||||
|
t = param.get("type")
|
||||||
|
if t == "object":
|
||||||
|
props = param.get("properties")
|
||||||
|
if isinstance(props, dict):
|
||||||
|
for prop_name in props.keys():
|
||||||
|
if prop_name in arguments:
|
||||||
|
request_body[prop_name] = arguments[prop_name]
|
||||||
if request_body:
|
if request_body:
|
||||||
# logger.debug(f"Built request body from parameters: {request_body}")
|
|
||||||
return request_body
|
return request_body
|
||||||
else:
|
try:
|
||||||
# If not a parameters list, try to parse as JSON schema object
|
body_schema = json.loads(tool_config.request_body_schema)
|
||||||
try:
|
if isinstance(body_schema, dict):
|
||||||
body_schema = json.loads(tool_config.request_body_schema)
|
props = body_schema.get("properties")
|
||||||
logger.debug(f"Request body schema: {body_schema}")
|
if isinstance(props, dict):
|
||||||
|
for prop_name in props.keys():
|
||||||
if isinstance(body_schema, dict) and "properties" in body_schema:
|
|
||||||
request_body = {}
|
|
||||||
for prop_name in body_schema["properties"]:
|
|
||||||
if prop_name in arguments:
|
if prop_name in arguments:
|
||||||
request_body[prop_name] = arguments[prop_name]
|
request_body[prop_name] = arguments[prop_name]
|
||||||
|
else:
|
||||||
if request_body:
|
for key in body_schema.keys():
|
||||||
# logger.debug(f"Built request body from schema: {request_body}")
|
if key in arguments:
|
||||||
return request_body
|
request_body[key] = arguments[key]
|
||||||
except json.JSONDecodeError:
|
if request_body:
|
||||||
logger.warning(f"Failed to parse request body schema as JSON")
|
return request_body
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
logger.warning(f"Failed to parse request body schema as JSON")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Request body schema parsing failed: {e}")
|
logger.warning(f"Request body schema parsing failed: {e}")
|
||||||
|
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ class Config:
|
|||||||
"/api/auth/account/sign",
|
"/api/auth/account/sign",
|
||||||
"/api/auth/email/send_captcha",
|
"/api/auth/email/send_captcha",
|
||||||
"/api/auth/google/sign",
|
"/api/auth/google/sign",
|
||||||
|
"/api/web/mcp_tags",
|
||||||
"/api/web/mcp_services",
|
"/api/web/mcp_services",
|
||||||
"/api/web/mcp_service_info",
|
"/api/web/mcp_service_info",
|
||||||
"/api/payment/callback_stripe",
|
"/api/payment/callback_stripe",
|
||||||
|
|||||||
@@ -125,6 +125,8 @@ class CacheUtils:
|
|||||||
else:
|
else:
|
||||||
logger.warning(f"Unexpected cache value type for key {cache_key}: {type(cache_value)}")
|
logger.warning(f"Unexpected cache value type for key {cache_key}: {type(cache_value)}")
|
||||||
return None
|
return None
|
||||||
|
if isinstance(model_data,list):
|
||||||
|
return model_data
|
||||||
return SqlalchemyUtils.dict_to_model(model_class, model_data)
|
return SqlalchemyUtils.dict_to_model(model_class, model_data)
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -145,7 +147,10 @@ class CacheUtils:
|
|||||||
bool: True if successful, False otherwise
|
bool: True if successful, False otherwise
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
model_dict = SqlalchemyUtils.model_to_dict(model)
|
if isinstance(model, list):
|
||||||
|
return CacheUtils.set_sqlalchemy_list_cache(cache_key, model, expire_time)
|
||||||
|
else:
|
||||||
|
model_dict = SqlalchemyUtils.model_to_dict(model)
|
||||||
serialized_data = json.dumps(model_dict, ensure_ascii=False)
|
serialized_data = json.dumps(model_dict, ensure_ascii=False)
|
||||||
redis_client.set(cache_key, serialized_data, ex=expire_time)
|
redis_client.set(cache_key, serialized_data, ex=expire_time)
|
||||||
return True
|
return True
|
||||||
@@ -203,11 +208,15 @@ class CacheUtils:
|
|||||||
if not isinstance(model_list, list):
|
if not isinstance(model_list, list):
|
||||||
logger.error(f"Expected list for cache key {cache_key}, got {type(model_list)}")
|
logger.error(f"Expected list for cache key {cache_key}, got {type(model_list)}")
|
||||||
return False
|
return False
|
||||||
|
data = []
|
||||||
model_dict_list = [SqlalchemyUtils.model_to_dict(model) for model in model_list]
|
for model in model_list:
|
||||||
serialized_data = json.dumps(model_dict_list, ensure_ascii=False)
|
if isinstance(model,dict):
|
||||||
|
data.append(SqlalchemyUtils.model_to_dict(model))
|
||||||
|
else:
|
||||||
|
data.append(model)
|
||||||
|
serialized_data = json.dumps(data, ensure_ascii=False)
|
||||||
redis_client.set(cache_key, serialized_data, ex=expire_time)
|
redis_client.set(cache_key, serialized_data, ex=expire_time)
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to set SQLAlchemy list cache for key {cache_key}: {e}")
|
logger.error(f"Failed to set SQLAlchemy list cache for key aaa {cache_key}: {e}")
|
||||||
return False
|
return False
|
||||||
Reference in new issue
Block a user