Initial import of weiyuan frontend
This commit is contained in:
+880
@@ -0,0 +1,880 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { lazy, Suspense, useContext, useMemo } from 'react';
|
||||
import { Route, Routes, Navigate, useLocation } from 'react-router-dom';
|
||||
import Loading from './components/common/ui/Loading';
|
||||
import { AuthRedirect, PrivateRoute, AdminRoute, RootRoute } from './helpers';
|
||||
import NotFound from './pages/NotFound';
|
||||
import Forbidden from './pages/Forbidden';
|
||||
import { StatusContext } from './context/Status';
|
||||
import { UserContext } from './context/User';
|
||||
import SetupCheck from './components/layout/SetupCheck';
|
||||
import { CLOUD_BRAIN_UI_ENABLED } from './config/cloudBrainUi';
|
||||
import {
|
||||
getHeaderModuleRequireAuth,
|
||||
normalizeHeaderNavModules,
|
||||
normalizeOrgUserNavModules,
|
||||
isHeaderModuleEnabled,
|
||||
} from './constants/headerNavModules';
|
||||
import {
|
||||
hasEnabledOrgCenterModule,
|
||||
normalizeSidebarModulesAdmin,
|
||||
} from './constants/sidebarModules';
|
||||
import { useOrgMembership } from './hooks/common/useOrgMembership';
|
||||
|
||||
// 懒加载所有页面组件以优化首屏加载速度
|
||||
const Home = lazy(() => import('./pages/Home'));
|
||||
const About = lazy(() => import('./pages/About'));
|
||||
const UserAgreement = lazy(() => import('./pages/UserAgreement'));
|
||||
const PrivacyPolicy = lazy(() => import('./pages/PrivacyPolicy'));
|
||||
const ExperienceCenter = lazy(() => import('./pages/ExperienceCenter'));
|
||||
const KeyManagement = lazy(() => import('./pages/KeyManagement'));
|
||||
const UserCenter = lazy(() => import('./pages/UserCenter'));
|
||||
const Recharge = lazy(() => import('./pages/Recharge'));
|
||||
const Tutorial = lazy(() => import('./pages/Tutorial'));
|
||||
const Docs = lazy(() => import('./pages/Docs'));
|
||||
|
||||
// 认证相关页面懒加载
|
||||
const LoginForm = lazy(() => import('./components/auth/LoginForm'));
|
||||
const OrgLogin = lazy(() => import('./pages/OrgLogin'));
|
||||
const PartnerPortal = lazy(() => import('./pages/PartnerPortal'));
|
||||
const PartnerConsole = lazy(() => import('./pages/PartnerPortal/Console'));
|
||||
const CommissionConsole = lazy(() => import('./pages/CommissionConsole'));
|
||||
const MyCommission = lazy(() => import('./pages/MyCommission'));
|
||||
const OrgRegister = lazy(() => import('./pages/OrgRegister'));
|
||||
const RegisterForm = lazy(() => import('./components/auth/RegisterForm'));
|
||||
const PasswordResetForm = lazy(
|
||||
() => import('./components/auth/PasswordResetForm'),
|
||||
);
|
||||
const PasswordResetConfirm = lazy(
|
||||
() => import('./components/auth/PasswordResetConfirm'),
|
||||
);
|
||||
const OAuth2Callback = lazy(() => import('./components/auth/OAuth2Callback'));
|
||||
|
||||
// 控制台页面懒加载
|
||||
const User = lazy(() => import('./pages/User'));
|
||||
const Setting = lazy(() => import('./pages/Setting'));
|
||||
const Channel = lazy(() => import('./pages/Channel'));
|
||||
const Token = lazy(() => import('./pages/Token'));
|
||||
const Redemption = lazy(() => import('./pages/Redemption'));
|
||||
const TopUp = lazy(() => import('./pages/TopUp'));
|
||||
const Log = lazy(() => import('./pages/Log'));
|
||||
const Chat = lazy(() => import('./pages/Chat'));
|
||||
const Chat2Link = lazy(() => import('./pages/Chat2Link'));
|
||||
const Midjourney = lazy(() => import('./pages/Midjourney'));
|
||||
const Pricing = lazy(() => import('./pages/Pricing'));
|
||||
const SkillMarket = lazy(() => import('./pages/SkillMarket'));
|
||||
const Task = lazy(() => import('./pages/Task'));
|
||||
const ModelPage = lazy(() => import('./pages/Model'));
|
||||
const Playground = lazy(() => import('./pages/Playground'));
|
||||
const MonitorCenter = lazy(() => import('./pages/MonitorCenter'));
|
||||
const PersonalSetting = lazy(
|
||||
() => import('./components/settings/PersonalSetting'),
|
||||
);
|
||||
const Setup = lazy(() => import('./pages/Setup'));
|
||||
const Analytics = lazy(() => import('./pages/Analytics'));
|
||||
const Organization = lazy(() => import('./pages/Organization'));
|
||||
const OrgCreate = lazy(() => import('./pages/Organization/OrgCreate'));
|
||||
const AdminOrganizations = lazy(() => import('./pages/AdminOrganizations'));
|
||||
const AdminOrder = lazy(() => import('./pages/AdminOrder'));
|
||||
const AdminInvoice = lazy(() => import('./pages/AdminInvoice'));
|
||||
const Subscription = lazy(() => import('./pages/Subscription'));
|
||||
const SkillPlatform = lazy(() => import('./pages/SkillPlatform'));
|
||||
const ExpertPlatform = lazy(() => import('./pages/ExpertPlatform'));
|
||||
// WeyAi:客户端授权页(自带登录判断,不套 PrivateRoute)与桌面端下载页
|
||||
const ClientAuthorize = lazy(() => import('./pages/ClientAuthorize'));
|
||||
const WeyAiDownload = lazy(() => import('./pages/WeyAiDownload'));
|
||||
|
||||
// org_only(仅企业资源)员工被限制在企业空间:仅放行以下前缀,其余 C 端路由统一重定向 /org
|
||||
const ORG_ALLOWED_PREFIXES = [
|
||||
'/org',
|
||||
'/login',
|
||||
'/logout',
|
||||
'/oauth',
|
||||
'/forbidden',
|
||||
'/setup',
|
||||
'/register',
|
||||
// WeyAi 授权页与下载页:企业员工也要能登录 WeyAi 桌面端/网页端
|
||||
'/client/authorize',
|
||||
'/weyai/download',
|
||||
];
|
||||
// 企业员工顶栏可配置的 C 端入口 → 对应路由前缀。
|
||||
// 管理员在「企业员工顶栏配置」里放开某项时,必须同步放行其目标路由,
|
||||
// 否则会出现「按钮显示了、点了却被踢回 /org」的死按钮。
|
||||
const ORG_USER_NAV_PATHS = {
|
||||
// /pricing 为模型超市旧路径,保留放行以便旧链接经重定向进入 /market 时不被企业封锁踢回
|
||||
pricing: ['/market', '/pricing'],
|
||||
skillMarket: ['/skill-market'],
|
||||
docs: ['/docs'],
|
||||
experienceCenter: ['/experience-center'],
|
||||
keyManagement: ['/key-management'],
|
||||
userCenter: ['/user-center'],
|
||||
};
|
||||
const isOrgAllowedPath = (pathname, extraPrefixes = []) =>
|
||||
[...ORG_ALLOWED_PREFIXES, ...extraPrefixes].some(
|
||||
(p) => pathname === p || pathname.startsWith(p + '/'),
|
||||
);
|
||||
|
||||
// 模型超市旧路径 /pricing → /market。用组件而非静态 <Navigate>,
|
||||
// 以保留 query/hash(如资源过期重载的 __wl_reload 参数、外部带参分享链接)
|
||||
const PricingLegacyRedirect = () => {
|
||||
const location = useLocation();
|
||||
return (
|
||||
<Navigate
|
||||
to={{ pathname: '/market', search: location.search, hash: location.hash }}
|
||||
replace
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
function App() {
|
||||
const location = useLocation();
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const [userState] = useContext(UserContext);
|
||||
|
||||
// 获取模块权限配置
|
||||
const moduleAuthConfig = useMemo(() => {
|
||||
const headerNavModulesConfig = statusState?.status?.HeaderNavModules;
|
||||
const modules = normalizeHeaderNavModules(headerNavModulesConfig);
|
||||
|
||||
return {
|
||||
experienceCenter: getHeaderModuleRequireAuth(modules, 'experienceCenter'),
|
||||
keyManagement: getHeaderModuleRequireAuth(modules, 'keyManagement'),
|
||||
userCenter: getHeaderModuleRequireAuth(modules, 'userCenter'),
|
||||
pricing: getHeaderModuleRequireAuth(modules, 'pricing'),
|
||||
skillMarket: getHeaderModuleRequireAuth(modules, 'skillMarket'),
|
||||
docs: getHeaderModuleRequireAuth(modules, 'docs'),
|
||||
};
|
||||
}, [statusState?.status?.HeaderNavModules]);
|
||||
|
||||
const sidebarModulesAdmin = useMemo(
|
||||
() =>
|
||||
normalizeSidebarModulesAdmin(statusState?.status?.SidebarModulesAdmin),
|
||||
[statusState?.status?.SidebarModulesAdmin],
|
||||
);
|
||||
const orgCenterConfig = sidebarModulesAdmin.orgCenter || {};
|
||||
const isOrgCenterAvailable = hasEnabledOrgCenterModule(orgCenterConfig);
|
||||
// 仅 org_only 用户需要这个判断(其余用户不受 orgConfined 约束);且
|
||||
// useHeaderBar 已在每个页面调用同一 hook,API 层的 in-flight GET 去重
|
||||
// 会合并这两次 /api/org/list,不产生额外请求。
|
||||
const { isOrgAdmin, loaded: orgMembershipLoaded } = useOrgMembership(
|
||||
userState?.user?.id,
|
||||
userState?.user?.org_only_mode === true,
|
||||
);
|
||||
|
||||
// 企业员工顶栏放开的 C 端入口(模型服务/文档等)需同步放行其目标路由,
|
||||
// 使「显示即可进入」,避免点击后被企业封锁重定向。配置源与顶栏一致。
|
||||
const orgUserAllowedPrefixes = useMemo(() => {
|
||||
const orgUserNav = normalizeOrgUserNavModules(
|
||||
statusState?.status?.HeaderNavModulesOrgUser,
|
||||
);
|
||||
const prefixes = Object.entries(ORG_USER_NAV_PATHS)
|
||||
.filter(([key]) => isHeaderModuleEnabled(orgUserNav, key))
|
||||
.flatMap(([, paths]) => paths);
|
||||
// 顶栏右侧按钮(新手教程/充值)由 rightActions 配置控制,与中部导航同理:
|
||||
// 管理员放开按钮必须同步放行其目标路由,否则按钮显示了、点了却被踢回
|
||||
// /org(推广按钮打开的是 Modal,不涉及导航,无需放行)。
|
||||
if (orgUserNav.rightActions?.tutorial === true) prefixes.push('/tutorial');
|
||||
if (orgUserNav.rightActions?.recharge === true) prefixes.push('/recharge');
|
||||
// 技能超市对企业管理员不只是"浏览入口",它同时是「为企业启用平台技能」的
|
||||
// 唯一落点(企业侧 /org/skill-market 管理页已并入其中)。而企业 owner 与
|
||||
// 托管成员账号默认就是 org_only(model/organization.go 的
|
||||
// CreateOrganizationWithManagedOwnerTx、controller/organization_account.go),
|
||||
// 若运营关掉「企业员工顶栏 → 技能超市」,这些管理员会被 orgConfined 弹回
|
||||
// /org,从此无任何路径把平台技能加入企业技能库——技能库与分发页永远为空。
|
||||
// 顶栏开关的本意是收敛"员工浏览目录",不应连带阉割企业治理能力,故对
|
||||
// 管理员无条件放行该路由(页面内部仍按 skill_manage 决定是否出现启用按钮)。
|
||||
if (isOrgAdmin && !prefixes.includes('/skill-market')) {
|
||||
prefixes.push('/skill-market');
|
||||
}
|
||||
return prefixes;
|
||||
}, [statusState?.status?.HeaderNavModulesOrgUser, isOrgAdmin]);
|
||||
|
||||
// 路由级封锁:org_only 员工访问非企业路由一律回到企业空间。
|
||||
// 仅在企业中心可用时启用,避免企业中心被全局关闭时与其内部回退跳转形成重定向死循环。
|
||||
// 企业列表未到位前不做封锁判定:isOrgAdmin 首帧恒 false,此时若直接重定向,
|
||||
// 硬刷新/收藏夹直达 /skill-market 的 org_only 管理员会在放行判据还没算出来时
|
||||
// 就被弹回 /org,而重定向不可逆——之后 isOrgAdmin 变 true 也回不去。
|
||||
const orgConfined =
|
||||
userState?.user?.org_only_mode === true &&
|
||||
orgMembershipLoaded &&
|
||||
isOrgCenterAvailable &&
|
||||
!isOrgAllowedPath(location.pathname, orgUserAllowedPrefixes);
|
||||
|
||||
if (orgConfined) {
|
||||
return (
|
||||
<SetupCheck>
|
||||
<Navigate to='/org' replace />
|
||||
</SetupCheck>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SetupCheck>
|
||||
<Routes>
|
||||
<Route
|
||||
path='/'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Home />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/home'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Home />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/setup'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Setup />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route path='/forbidden' element={<Forbidden />} />
|
||||
<Route
|
||||
path='/console/models'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<ModelPage />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/channel'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Channel />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/token'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Token />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/playground'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Playground />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/monitor'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<MonitorCenter />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/analytics'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Analytics />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/my-commission'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<MyCommission />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/partner'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<PartnerConsole />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/commission'
|
||||
element={
|
||||
/* 分佣管理为 Root 专属:侧边栏一直用 isRoot() 隐藏该入口,后端结算/销售/成本/
|
||||
伙伴管理各路由组也已全部 Root 收口。这里把路由守卫对齐,避免 role=10 直接
|
||||
输 URL 进到一个读得到、写按钮全 403 的半残页面。 */
|
||||
<RootRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<CommissionConsole />
|
||||
</Suspense>
|
||||
</RootRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/experience-center-audit'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Navigate to='/console/analytics?tab=audit' replace />
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/organizations'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<AdminOrganizations />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/skill-platform'
|
||||
element={
|
||||
CLOUD_BRAIN_UI_ENABLED ? (
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<SkillPlatform />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
) : (
|
||||
<Navigate to='/console' replace />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/expert-platform'
|
||||
element={
|
||||
CLOUD_BRAIN_UI_ENABLED ? (
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<ExpertPlatform />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
) : (
|
||||
<Navigate to='/console' replace />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/order'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<AdminOrder />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/invoice'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<AdminInvoice />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
{/* 旧路由重定向到用户中心内的服务监控 */}
|
||||
<Route
|
||||
path='/service-dashboard'
|
||||
element={<Navigate to='/user-center/service-dashboard' replace />}
|
||||
/>
|
||||
<Route
|
||||
path='/experience-center/cloud-brain'
|
||||
element={
|
||||
CLOUD_BRAIN_UI_ENABLED ? (
|
||||
<PrivateRoute>
|
||||
<Suspense fallback={<Loading />} key={location.pathname}>
|
||||
<ExperienceCenter />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
) : (
|
||||
<Navigate to='/experience-center' replace />
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/experience-center/*'
|
||||
element={
|
||||
moduleAuthConfig.experienceCenter ? (
|
||||
<PrivateRoute>
|
||||
<Suspense
|
||||
fallback={<Loading></Loading>}
|
||||
key={location.pathname}
|
||||
>
|
||||
<ExperienceCenter />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
) : (
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<ExperienceCenter />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/redemption'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Redemption />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/user'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<User />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/subscription'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Subscription />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/user/reset'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<PasswordResetConfirm />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/login'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<AuthRedirect>
|
||||
<LoginForm />
|
||||
</AuthRedirect>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/org/login'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OrgLogin />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/partner'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<PartnerPortal />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/org/:slug/login'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OrgLogin />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/org/register'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OrgRegister />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/register'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<AuthRedirect>
|
||||
<RegisterForm />
|
||||
</AuthRedirect>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/reset'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<PasswordResetForm />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/oauth/github'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OAuth2Callback type='github'></OAuth2Callback>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/oauth/discord'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OAuth2Callback type='discord'></OAuth2Callback>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/oauth/oidc'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>}>
|
||||
<OAuth2Callback type='oidc'></OAuth2Callback>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/oauth/linuxdo'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OAuth2Callback type='linuxdo'></OAuth2Callback>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/oauth/wechat-open'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OAuth2Callback type='wechat/open'></OAuth2Callback>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/oauth/wechat-mp'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<OAuth2Callback type='wechat/mp'></OAuth2Callback>
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/setting'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Setting />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/personal'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<PersonalSetting />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/topup'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<TopUp />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/log'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Log />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Navigate to='/console/analytics' replace />
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/midjourney'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Midjourney />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/task'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Task />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/market'
|
||||
element={
|
||||
moduleAuthConfig.pricing ? (
|
||||
<PrivateRoute>
|
||||
<Suspense
|
||||
fallback={<Loading></Loading>}
|
||||
key={location.pathname}
|
||||
>
|
||||
<Pricing />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
) : (
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Pricing />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
/>
|
||||
{/* 模型超市旧路径兼容:外部收藏/文档中的 /pricing 链接重定向到 /market */}
|
||||
<Route path='/pricing' element={<PricingLegacyRedirect />} />
|
||||
{/* 技能超市:与模型超市同构的平台级目录页,同时是"为企业启用技能"的
|
||||
唯一入口——企业侧原 /org/skill-market 管理页已并入这里,按身份渐进
|
||||
增强(游客浏览 / 个人收藏 / 员工「我想要」/ 管理员就地为企业启用)。 */}
|
||||
<Route
|
||||
path='/skill-market'
|
||||
element={
|
||||
moduleAuthConfig.skillMarket ? (
|
||||
<PrivateRoute>
|
||||
<Suspense
|
||||
fallback={<Loading></Loading>}
|
||||
key={location.pathname}
|
||||
>
|
||||
<SkillMarket />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
) : (
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<SkillMarket />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/key-management'
|
||||
element={
|
||||
moduleAuthConfig.keyManagement ? (
|
||||
<PrivateRoute>
|
||||
<Suspense
|
||||
fallback={<Loading></Loading>}
|
||||
key={location.pathname}
|
||||
>
|
||||
<KeyManagement />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
) : (
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<KeyManagement />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/user-center/*'
|
||||
element={
|
||||
moduleAuthConfig.userCenter ? (
|
||||
<PrivateRoute>
|
||||
<Suspense fallback={<Loading></Loading>}>
|
||||
<UserCenter />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
) : (
|
||||
<Suspense fallback={<Loading></Loading>}>
|
||||
<UserCenter />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/recharge'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Recharge />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/tutorial'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Tutorial />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/docs'
|
||||
element={
|
||||
moduleAuthConfig.docs ? (
|
||||
<PrivateRoute>
|
||||
<Suspense
|
||||
fallback={<Loading></Loading>}
|
||||
key={location.pathname}
|
||||
>
|
||||
<Docs />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
) : (
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Docs />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/about'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<About />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/user-agreement'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<UserAgreement />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/privacy-policy'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<PrivacyPolicy />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/console/chat/:id?'
|
||||
element={
|
||||
<AdminRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Chat />
|
||||
</Suspense>
|
||||
</AdminRoute>
|
||||
}
|
||||
/>
|
||||
{/* 方便使用chat2link直接跳转聊天... */}
|
||||
<Route
|
||||
path='/chat2link'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<Chat2Link />
|
||||
</Suspense>
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/org/create'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
{isOrgCenterAvailable ? (
|
||||
<Suspense fallback={<Loading />}>
|
||||
<OrgCreate />
|
||||
</Suspense>
|
||||
) : (
|
||||
<Navigate to='/user-center/dashboard' replace />
|
||||
)}
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/org/*'
|
||||
element={
|
||||
<PrivateRoute>
|
||||
{isOrgCenterAvailable ? (
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Organization />
|
||||
</Suspense>
|
||||
) : (
|
||||
<Navigate to='/user-center/dashboard' replace />
|
||||
)}
|
||||
</PrivateRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/client/authorize'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<ClientAuthorize />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path='/weyai/download'
|
||||
element={
|
||||
<Suspense fallback={<Loading></Loading>} key={location.pathname}>
|
||||
<WeyAiDownload />
|
||||
</Suspense>
|
||||
}
|
||||
/>
|
||||
<Route path='*' element={<NotFound />} />
|
||||
</Routes>
|
||||
</SetupCheck>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { Card, Table, Progress } from '@douyinfe/semi-ui';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const ChannelConsumption = ({ data, title, icon, t }) => {
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
|
||||
if (!data || data.length === 0) {
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// 计算最大值用于进度条
|
||||
const maxQuota = Math.max(...data.map((item) => item.quota || 0));
|
||||
|
||||
// 计算全局序号
|
||||
const getGlobalIndex = (pageIndex) =>
|
||||
(currentPage - 1) * pageSize + pageIndex;
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: '#',
|
||||
dataIndex: 'index',
|
||||
key: 'index',
|
||||
width: 50,
|
||||
render: (_, record, index) => {
|
||||
const globalIndex = getGlobalIndex(index);
|
||||
return (
|
||||
<span
|
||||
className={`font-medium ${globalIndex < 3 ? 'text-orange-500' : 'text-gray-500'}`}
|
||||
>
|
||||
{globalIndex + 1}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('渠道名称'),
|
||||
dataIndex: 'channel_name',
|
||||
key: 'channel_name',
|
||||
render: (text) => (
|
||||
<span className='font-medium truncate' title={text}>
|
||||
{text || t('未知渠道')}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('消耗额度'),
|
||||
dataIndex: 'quota',
|
||||
key: 'quota',
|
||||
width: 180,
|
||||
render: (val, record) => (
|
||||
<div className='flex items-center gap-2'>
|
||||
<Progress
|
||||
percent={(val / maxQuota) * 100}
|
||||
showInfo={false}
|
||||
size='small'
|
||||
style={{ width: 80, height: 6 }}
|
||||
stroke='#3b82f6'
|
||||
/>
|
||||
<span className='text-sm font-medium text-gray-700 dark:text-gray-300'>
|
||||
{renderQuota(val || 0)}
|
||||
</span>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('请求次数'),
|
||||
dataIndex: 'count',
|
||||
key: 'count',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-gray-600'>{(val || 0).toLocaleString()}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('占比'),
|
||||
dataIndex: 'percent',
|
||||
key: 'percent',
|
||||
width: 80,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-gray-500'>{(val || 0).toFixed(1)}%</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
<span className='text-xs text-gray-400 ml-2'>TOP {data.length}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '0' }}
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={data}
|
||||
pagination={{
|
||||
currentPage,
|
||||
pageSize,
|
||||
showSizeChanger: true,
|
||||
pageSizeOpts: [10, 20, 30],
|
||||
showTotal: (total) => `${t('共')} ${total} ${t('条')}`,
|
||||
onPageChange: (page) => setCurrentPage(page),
|
||||
onPageSizeChange: (size) => {
|
||||
setPageSize(size);
|
||||
setCurrentPage(1);
|
||||
},
|
||||
}}
|
||||
size='small'
|
||||
rowKey={(record, index) => `${record.channel_name}-${index}`}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChannelConsumption;
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card, Table, Button } from '@douyinfe/semi-ui';
|
||||
import { IconDownload } from '@douyinfe/semi-icons';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const DailyStatsTable = ({ data, title, icon, t }) => {
|
||||
const columns = [
|
||||
{
|
||||
title: t('日期'),
|
||||
dataIndex: 'date',
|
||||
key: 'date',
|
||||
width: 120,
|
||||
fixed: 'left',
|
||||
render: (text) => <span className='font-medium'>{text}</span>,
|
||||
},
|
||||
{
|
||||
title: t('新增用户'),
|
||||
dataIndex: 'new_users',
|
||||
key: 'new_users',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-green-600'>{(val || 0).toLocaleString()}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('活跃用户'),
|
||||
dataIndex: 'active_users',
|
||||
key: 'active_users',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-blue-600'>{(val || 0).toLocaleString()}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('充值人数'),
|
||||
dataIndex: 'topup_users',
|
||||
key: 'topup_users',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (val) => <span>{(val || 0).toLocaleString()}</span>,
|
||||
},
|
||||
{
|
||||
title: t('充值金额'),
|
||||
dataIndex: 'topup_amount',
|
||||
key: 'topup_amount',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-yellow-600 font-medium'>
|
||||
¥{(val || 0).toFixed(2)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('消耗额度'),
|
||||
dataIndex: 'consume_quota',
|
||||
key: 'consume_quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-brand-deep font-medium'>
|
||||
{renderQuota(val || 0)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('请求次数'),
|
||||
dataIndex: 'requests',
|
||||
key: 'requests',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => <span>{(val || 0).toLocaleString()}</span>,
|
||||
},
|
||||
{
|
||||
title: t('Token消耗'),
|
||||
dataIndex: 'tokens',
|
||||
key: 'tokens',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => {
|
||||
const tokens = val || 0;
|
||||
if (tokens >= 1000000) {
|
||||
return <span>{(tokens / 1000000).toFixed(2)}M</span>;
|
||||
} else if (tokens >= 1000) {
|
||||
return <span>{(tokens / 1000).toFixed(1)}K</span>;
|
||||
}
|
||||
return <span>{tokens.toLocaleString()}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('人均消耗'),
|
||||
dataIndex: 'avg_consume',
|
||||
key: 'avg_consume',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (val) => (
|
||||
<span className='text-gray-600'>{renderQuota(val || 0)}</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// 导出CSV
|
||||
const handleExport = () => {
|
||||
if (!data || data.length === 0) return;
|
||||
|
||||
const headers = [
|
||||
t('日期'),
|
||||
t('新增用户'),
|
||||
t('活跃用户'),
|
||||
t('充值人数'),
|
||||
t('充值金额'),
|
||||
t('消耗额度'),
|
||||
t('请求次数'),
|
||||
t('Token消耗'),
|
||||
t('人均消耗'),
|
||||
];
|
||||
|
||||
const rows = data.map((row) => [
|
||||
row.date,
|
||||
row.new_users || 0,
|
||||
row.active_users || 0,
|
||||
row.topup_users || 0,
|
||||
row.topup_amount || 0,
|
||||
row.consume_quota || 0,
|
||||
row.requests || 0,
|
||||
row.tokens || 0,
|
||||
row.avg_consume || 0,
|
||||
]);
|
||||
|
||||
const csvContent =
|
||||
'\uFEFF' +
|
||||
[headers.join(','), ...rows.map((row) => row.join(','))].join('\n');
|
||||
|
||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = `analytics_${new Date().toISOString().split('T')[0]}.csv`;
|
||||
link.click();
|
||||
};
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center justify-between w-full'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
<Button
|
||||
icon={<IconDownload />}
|
||||
size='small'
|
||||
onClick={handleExport}
|
||||
disabled={!data || data.length === 0}
|
||||
>
|
||||
{t('导出CSV')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '0' }}
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={data || []}
|
||||
pagination={{
|
||||
pageSize: 10,
|
||||
showSizeChanger: true,
|
||||
showTotal: (total) => `${t('共')} ${total} ${t('条')}`,
|
||||
}}
|
||||
scroll={{ x: 1100 }}
|
||||
size='small'
|
||||
rowKey='date'
|
||||
empty={
|
||||
<div className='py-8 text-center text-gray-400'>{t('暂无数据')}</div>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default DailyStatsTable;
|
||||
@@ -0,0 +1,377 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import {
|
||||
Card,
|
||||
Table,
|
||||
Tag,
|
||||
Button,
|
||||
InputNumber,
|
||||
Select,
|
||||
Space,
|
||||
Modal,
|
||||
Input,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
IconRefresh,
|
||||
IconAlertTriangle,
|
||||
IconShieldStroked,
|
||||
} from '@douyinfe/semi-icons';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const formatTime = (ts) => {
|
||||
if (!ts) return '-';
|
||||
const d = new Date(ts * 1000);
|
||||
const pad = (n) => (n < 10 ? '0' + n : '' + n);
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* 高频低消耗用户监测组件
|
||||
*
|
||||
* 列:用户ID / 昵称 / 请求次数 / 总消耗 / 平均消耗 / 状态 / 最常用模型 / 最近IP / 最近活跃 / 操作
|
||||
*/
|
||||
const HighFreqLowCostUsers = ({
|
||||
loading,
|
||||
items,
|
||||
windowRange,
|
||||
filters,
|
||||
setFilters,
|
||||
fetchSuspects,
|
||||
rules,
|
||||
unbanUser,
|
||||
onOpenRuleModal,
|
||||
t,
|
||||
}) => {
|
||||
const [unbanModalVisible, setUnbanModalVisible] = useState(false);
|
||||
const [unbanRow, setUnbanRow] = useState(null);
|
||||
const [unbanReason, setUnbanReason] = useState('');
|
||||
|
||||
// 当前启用规则(仅取 enabled=true 的规则)—用于"是否命中封号阈值"标签
|
||||
// 不回落到禁用规则:否则会显示"待自动封号"红色 tag 但实际永不封号,误导管理员
|
||||
const activeRule = useMemo(
|
||||
() => (rules || []).find((r) => r.enabled),
|
||||
[rules],
|
||||
);
|
||||
|
||||
const evalRowStatus = (row) => {
|
||||
// 状态优先级:已自动封号 > 命中封号阈值(待下次扫描)> 命中预警 > 仅满足查询条件
|
||||
if (row.user_status !== undefined && row.user_status === 2) {
|
||||
return { level: 'banned', label: t('已封号'), color: 'red' };
|
||||
}
|
||||
if (!activeRule)
|
||||
return { level: 'hit', label: t('命中筛选'), color: 'grey' };
|
||||
// 仅当规则的"自动封号"总开关启用时,才判断是否命中封号阈值
|
||||
const meetsBan =
|
||||
activeRule.auto_ban_enabled &&
|
||||
activeRule.ban_min_requests > 0 &&
|
||||
row.request_count >= activeRule.ban_min_requests &&
|
||||
(activeRule.ban_max_avg_quota <= 0 ||
|
||||
row.avg_quota <= activeRule.ban_max_avg_quota) &&
|
||||
(activeRule.ban_max_total_quota <= 0 ||
|
||||
row.total_quota <= activeRule.ban_max_total_quota);
|
||||
if (meetsBan) return { level: 'ban', label: t('待自动封号'), color: 'red' };
|
||||
const meetsWarn =
|
||||
activeRule.warn_min_requests > 0 &&
|
||||
row.request_count >= activeRule.warn_min_requests &&
|
||||
(activeRule.warn_max_avg_quota <= 0 ||
|
||||
row.avg_quota <= activeRule.warn_max_avg_quota);
|
||||
if (meetsWarn) return { level: 'warn', label: t('预警'), color: 'orange' };
|
||||
return { level: 'hit', label: t('命中筛选'), color: 'grey' };
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('用户ID'),
|
||||
dataIndex: 'user_id',
|
||||
width: 100,
|
||||
render: (v) => <Text>{v}</Text>,
|
||||
},
|
||||
{
|
||||
title: t('昵称'),
|
||||
dataIndex: 'display_name',
|
||||
width: 160,
|
||||
render: (v, row) => (
|
||||
<div className='flex flex-col'>
|
||||
<Text strong>{v || row.username || `user_${row.user_id}`}</Text>
|
||||
{row.username && v && row.username !== v && (
|
||||
<Text type='tertiary' size='small'>
|
||||
@{row.username}
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('请求次数'),
|
||||
dataIndex: 'request_count',
|
||||
width: 110,
|
||||
sorter: (a, b) => a.request_count - b.request_count,
|
||||
defaultSortOrder: 'descend',
|
||||
render: (v) => <Text strong>{v.toLocaleString()}</Text>,
|
||||
},
|
||||
{
|
||||
title: t('总消耗'),
|
||||
dataIndex: 'total_quota',
|
||||
width: 120,
|
||||
sorter: (a, b) => a.total_quota - b.total_quota,
|
||||
render: (v) => <Text>{renderQuota(v, 4)}</Text>,
|
||||
},
|
||||
{
|
||||
title: t('平均消耗'),
|
||||
dataIndex: 'avg_quota',
|
||||
width: 130,
|
||||
sorter: (a, b) => a.avg_quota - b.avg_quota,
|
||||
render: (v) => (
|
||||
<Text type={v < 100 ? 'danger' : 'primary'}>{renderQuota(v, 6)}</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
width: 110,
|
||||
render: (_v, row) => {
|
||||
const s = evalRowStatus(row);
|
||||
return <Tag color={s.color}>{s.label}</Tag>;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('最常用模型'),
|
||||
dataIndex: 'top_model',
|
||||
width: 160,
|
||||
render: (v) =>
|
||||
v ? <Tag color='blue'>{v}</Tag> : <Text type='tertiary'>-</Text>,
|
||||
},
|
||||
{
|
||||
title: t('活跃 IP'),
|
||||
dataIndex: 'last_ip',
|
||||
width: 130,
|
||||
render: (v) => (v ? <Text>{v}</Text> : <Text type='tertiary'>-</Text>),
|
||||
},
|
||||
{
|
||||
title: t('最近活跃'),
|
||||
dataIndex: 'last_active_at',
|
||||
width: 150,
|
||||
render: (v) => formatTime(v),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 130,
|
||||
render: (_v, row) => {
|
||||
const isBanned = row.user_status === 2;
|
||||
const isRiskBan = isBanned && row.ban_log_id > 0;
|
||||
if (isRiskBan) {
|
||||
return (
|
||||
<Button
|
||||
size='small'
|
||||
type='primary'
|
||||
theme='light'
|
||||
onClick={() => {
|
||||
setUnbanRow(row);
|
||||
setUnbanReason('');
|
||||
setUnbanModalVisible(true);
|
||||
}}
|
||||
>
|
||||
{t('解封')}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
if (isBanned) {
|
||||
return (
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('已被手动封号')}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('监测中')}
|
||||
</Text>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const windowOptions = [
|
||||
{ value: 60, label: t('最近 1 小时') },
|
||||
{ value: 360, label: t('最近 6 小时') },
|
||||
{ value: 1440, label: t('最近 24 小时') },
|
||||
{ value: 4320, label: t('最近 3 天') },
|
||||
{ value: 10080, label: t('最近 7 天') },
|
||||
];
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center justify-between flex-wrap gap-2'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<IconAlertTriangle className='text-orange-500' />
|
||||
<span className='font-semibold'>{t('高频低消耗用户监测')}</span>
|
||||
{windowRange && windowRange.start > 0 && (
|
||||
<Text type='tertiary' size='small' className='ml-2'>
|
||||
{formatTime(windowRange.start)} ~ {formatTime(windowRange.end)}
|
||||
</Text>
|
||||
)}
|
||||
</div>
|
||||
<Space>
|
||||
<Button
|
||||
icon={<IconShieldStroked />}
|
||||
onClick={onOpenRuleModal}
|
||||
type='tertiary'
|
||||
>
|
||||
{t('风控规则')}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<IconRefresh />}
|
||||
onClick={() => fetchSuspects()}
|
||||
loading={loading}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
</Space>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
{/* 筛选区 */}
|
||||
<div className='mb-4 grid grid-cols-2 sm:grid-cols-4 gap-3 items-end'>
|
||||
<div>
|
||||
<div className='text-xs text-gray-500 mb-1'>{t('时间窗')}</div>
|
||||
<Select
|
||||
value={filters.windowMinutes}
|
||||
onChange={(v) => setFilters((f) => ({ ...f, windowMinutes: v }))}
|
||||
optionList={windowOptions}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div className='text-xs text-gray-500 mb-1'>{t('请求次数 ≥')}</div>
|
||||
<InputNumber
|
||||
value={filters.minRequests}
|
||||
onChange={(v) => setFilters((f) => ({ ...f, minRequests: v || 0 }))}
|
||||
min={1}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<div className='text-xs text-gray-500 mb-1'>
|
||||
{t('平均消耗 ≤ (quota,0=不限)')}
|
||||
</div>
|
||||
<InputNumber
|
||||
value={filters.maxAvgQuota}
|
||||
onChange={(v) => setFilters((f) => ({ ...f, maxAvgQuota: v || 0 }))}
|
||||
min={0}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
<div className='flex gap-2'>
|
||||
<Button
|
||||
type='primary'
|
||||
theme='solid'
|
||||
onClick={() => fetchSuspects()}
|
||||
loading={loading}
|
||||
block
|
||||
>
|
||||
{t('查询')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{(filters.maxAvgQuota > 0 || filters.maxTotalQuota > 0) && (
|
||||
<div className='mb-3 text-xs text-gray-500'>
|
||||
{filters.maxAvgQuota > 0 && (
|
||||
<span>
|
||||
{t('平均消耗 ≤')} {renderQuota(filters.maxAvgQuota, 6)}
|
||||
{' '}
|
||||
</span>
|
||||
)}
|
||||
{filters.maxTotalQuota > 0 && (
|
||||
<span>
|
||||
{t('总消耗 ≤')} {renderQuota(filters.maxTotalQuota, 4)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={items}
|
||||
rowKey='user_id'
|
||||
loading={loading}
|
||||
pagination={{ pageSize: 20, showTotal: true }}
|
||||
empty={t('暂无数据')}
|
||||
scroll={{ x: 1200 }}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
title={t('解封用户')}
|
||||
visible={unbanModalVisible}
|
||||
onCancel={() => setUnbanModalVisible(false)}
|
||||
onOk={async () => {
|
||||
if (!unbanRow) return;
|
||||
// unbanUser 内部会并发刷新 suspects + banLogs,无需在此重复 fetch
|
||||
const ok = await unbanUser({
|
||||
userId: unbanRow.user_id,
|
||||
banLogId: unbanRow.ban_log_id,
|
||||
reason: unbanReason,
|
||||
});
|
||||
if (ok) {
|
||||
setUnbanModalVisible(false);
|
||||
}
|
||||
}}
|
||||
okText={t('确认解封')}
|
||||
cancelText={t('取消')}
|
||||
>
|
||||
{unbanRow && (
|
||||
<div className='space-y-3'>
|
||||
<div>
|
||||
<Text type='tertiary'>{t('用户:')}</Text>
|
||||
<Text strong>
|
||||
{unbanRow.display_name || unbanRow.username}(ID:
|
||||
{unbanRow.user_id})
|
||||
</Text>
|
||||
</div>
|
||||
<div>
|
||||
<Text type='tertiary'>
|
||||
{t(
|
||||
'解封后用户账号会恢复,但被禁用的 Token 不会自动启用,需手动开启。',
|
||||
)}
|
||||
</Text>
|
||||
</div>
|
||||
<div>
|
||||
<div className='text-xs text-gray-500 mb-1'>{t('解封原因')}</div>
|
||||
<Input.TextArea
|
||||
value={unbanReason}
|
||||
onChange={setUnbanReason}
|
||||
placeholder={t('记录解封原因,便于审计')}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default HighFreqLowCostUsers;
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { Card } from '@douyinfe/semi-ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const ModelDistribution = ({ data, title, icon, t }) => {
|
||||
const pieSpec = useMemo(() => {
|
||||
if (!data || data.length === 0) return null;
|
||||
|
||||
const chartData = data.slice(0, 8).map((item) => ({
|
||||
name: item.model_name || t('未知'),
|
||||
value: item.quota || 0,
|
||||
}));
|
||||
|
||||
// 如果有更多数据,合并为"其他"
|
||||
if (data.length > 8) {
|
||||
const otherQuota = data
|
||||
.slice(8)
|
||||
.reduce((sum, item) => sum + (item.quota || 0), 0);
|
||||
chartData.push({ name: t('其他'), value: otherQuota });
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'pie',
|
||||
data: [{ id: 'modelDist', values: chartData }],
|
||||
valueField: 'value',
|
||||
categoryField: 'name',
|
||||
outerRadius: 0.8,
|
||||
innerRadius: 0.5,
|
||||
padAngle: 0.02,
|
||||
pie: {
|
||||
style: {
|
||||
cornerRadius: 4,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.name,
|
||||
value: (datum) => renderQuota(datum?.value || 0),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
legends: {
|
||||
visible: true,
|
||||
position: 'right',
|
||||
orient: 'vertical',
|
||||
item: {
|
||||
width: 100,
|
||||
label: {
|
||||
style: {
|
||||
fontSize: 11,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
label: {
|
||||
visible: false,
|
||||
},
|
||||
color: [
|
||||
'#3b82f6',
|
||||
'#10b981',
|
||||
'#f59e0b',
|
||||
'#ef4444',
|
||||
'#8b5cf6',
|
||||
'#06b6d4',
|
||||
'#f97316',
|
||||
'#84cc16',
|
||||
'#94a3b8',
|
||||
],
|
||||
};
|
||||
}, [data, t]);
|
||||
|
||||
// 排行列表
|
||||
const topModels = data?.slice(0, 5) || [];
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
{pieSpec ? (
|
||||
<div>
|
||||
<VChart
|
||||
spec={pieSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 200 }}
|
||||
/>
|
||||
<div className='mt-4 space-y-2'>
|
||||
{topModels.map((item, index) => (
|
||||
<div key={index} className='flex items-center gap-2'>
|
||||
<span className='text-xs text-gray-500 w-4'>{index + 1}</span>
|
||||
<span
|
||||
className='text-sm flex-1 truncate'
|
||||
title={item.model_name}
|
||||
>
|
||||
{item.model_name}
|
||||
</span>
|
||||
<span className='text-xs text-gray-500'>
|
||||
{item.percent?.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default ModelDistribution;
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
Users,
|
||||
UserPlus,
|
||||
DollarSign,
|
||||
Zap,
|
||||
Activity,
|
||||
Percent,
|
||||
TrendingUp,
|
||||
TrendingDown,
|
||||
} from 'lucide-react';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const OverviewCards = ({ overview, t }) => {
|
||||
if (!overview) {
|
||||
return (
|
||||
<div className='grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 mb-6'>
|
||||
{[...Array(6)].map((_, i) => (
|
||||
<Card key={i} className='animate-pulse'>
|
||||
<div className='h-20 bg-gray-200 dark:bg-gray-700 rounded'></div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const cards = [
|
||||
{
|
||||
title: t('今日活跃'),
|
||||
value: overview.dau?.toLocaleString() || '0',
|
||||
change: overview.dau_change,
|
||||
icon: <Users className='w-5 h-5' />,
|
||||
color: 'blue',
|
||||
bgColor: 'bg-blue-50 dark:bg-blue-900/20',
|
||||
iconBg: 'bg-blue-500',
|
||||
},
|
||||
{
|
||||
title: t('今日新增'),
|
||||
value: overview.new_users?.toLocaleString() || '0',
|
||||
change: overview.new_users_change,
|
||||
icon: <UserPlus className='w-5 h-5' />,
|
||||
color: 'green',
|
||||
bgColor: 'bg-green-50 dark:bg-green-900/20',
|
||||
iconBg: 'bg-green-500',
|
||||
},
|
||||
{
|
||||
title: t('今日充值'),
|
||||
value: `¥${overview.today_topup?.toFixed(2) || '0.00'}`,
|
||||
change: overview.today_topup_change,
|
||||
icon: <DollarSign className='w-5 h-5' />,
|
||||
color: 'yellow',
|
||||
bgColor: 'bg-yellow-50 dark:bg-yellow-900/20',
|
||||
iconBg: 'bg-yellow-500',
|
||||
},
|
||||
{
|
||||
title: t('今日消耗'),
|
||||
value: renderQuota(overview.today_consume || 0),
|
||||
change: overview.today_consume_change,
|
||||
icon: <Zap className='w-5 h-5' />,
|
||||
color: 'purple',
|
||||
bgColor: 'bg-brand/5 dark:bg-brand-deep/20',
|
||||
iconBg: 'bg-brand',
|
||||
},
|
||||
{
|
||||
title: t('请求次数'),
|
||||
value: overview.today_requests?.toLocaleString() || '0',
|
||||
change: null,
|
||||
icon: <Activity className='w-5 h-5' />,
|
||||
color: 'cyan',
|
||||
bgColor: 'bg-cyan-50 dark:bg-cyan-900/20',
|
||||
iconBg: 'bg-cyan-500',
|
||||
},
|
||||
{
|
||||
title: t('付费率'),
|
||||
value: `${overview.pay_rate?.toFixed(1) || '0.0'}%`,
|
||||
change: null,
|
||||
icon: <Percent className='w-5 h-5' />,
|
||||
color: 'pink',
|
||||
bgColor: 'bg-pink-50 dark:bg-pink-900/20',
|
||||
iconBg: 'bg-pink-500',
|
||||
},
|
||||
];
|
||||
|
||||
const renderChange = (change) => {
|
||||
if (change === null || change === undefined || isNaN(change)) return null;
|
||||
const isPositive = change >= 0;
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center gap-1 text-xs font-medium ${
|
||||
isPositive ? 'text-green-500' : 'text-red-500'
|
||||
}`}
|
||||
>
|
||||
{isPositive ? (
|
||||
<TrendingUp className='w-3 h-3' />
|
||||
) : (
|
||||
<TrendingDown className='w-3 h-3' />
|
||||
)}
|
||||
<span>
|
||||
{isPositive ? '+' : ''}
|
||||
{change.toFixed(1)}%
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4 mb-6'>
|
||||
{cards.map((card, index) => (
|
||||
<Card
|
||||
key={index}
|
||||
className={`${card.bgColor} border-none shadow-sm hover:shadow-md transition-shadow`}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
<div className='flex items-start justify-between'>
|
||||
<div className='flex-1'>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400 mb-1'>
|
||||
{card.title}
|
||||
</p>
|
||||
<p className='text-xl font-bold text-gray-800 dark:text-gray-100'>
|
||||
{card.value}
|
||||
</p>
|
||||
{renderChange(card.change)}
|
||||
</div>
|
||||
<div
|
||||
className={`${card.iconBg} p-2 rounded-lg text-white shadow-sm`}
|
||||
>
|
||||
{card.icon}
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default OverviewCards;
|
||||
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Table,
|
||||
Tag,
|
||||
Button,
|
||||
Modal,
|
||||
Input,
|
||||
Typography,
|
||||
Space,
|
||||
Select,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { IconRefresh } from '@douyinfe/semi-icons';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const formatTime = (ts) => {
|
||||
if (!ts) return '-';
|
||||
const d = new Date(ts * 1000);
|
||||
const pad = (n) => (n < 10 ? '0' + n : '' + n);
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* 自动封号历史 / 解封操作中心
|
||||
*
|
||||
* 职责:
|
||||
* - 持久查看所有由风控自动封号产生的记录(即使用户已经从疑似列表中消失)
|
||||
* - 解封操作的主入口(疑似列表里的解封按钮只能覆盖"封号后还有活动"的边界场景)
|
||||
*/
|
||||
const RiskControlBanLogs = ({
|
||||
loading,
|
||||
banLogs,
|
||||
banLogTotal,
|
||||
banLogStatus,
|
||||
setBanLogStatus,
|
||||
banLogPage,
|
||||
fetchBanLogs,
|
||||
unbanUser,
|
||||
t,
|
||||
}) => {
|
||||
const [unbanModalVisible, setUnbanModalVisible] = useState(false);
|
||||
const [unbanRow, setUnbanRow] = useState(null);
|
||||
const [unbanReason, setUnbanReason] = useState('');
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('封号时间'),
|
||||
dataIndex: 'ban_at',
|
||||
width: 150,
|
||||
render: (v) => formatTime(v),
|
||||
},
|
||||
{
|
||||
title: t('用户ID'),
|
||||
dataIndex: 'user_id',
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
title: t('用户名(快照)'),
|
||||
dataIndex: 'user_snapshot',
|
||||
width: 140,
|
||||
render: (v) => v || <Text type='tertiary'>-</Text>,
|
||||
},
|
||||
{
|
||||
title: t('请求次数'),
|
||||
dataIndex: 'request_count',
|
||||
width: 100,
|
||||
render: (v) => (v || 0).toLocaleString(),
|
||||
},
|
||||
{
|
||||
title: t('总消耗'),
|
||||
dataIndex: 'total_quota',
|
||||
width: 110,
|
||||
render: (v) => renderQuota(v || 0, 4),
|
||||
},
|
||||
{
|
||||
title: t('平均消耗'),
|
||||
dataIndex: 'avg_quota_x1000',
|
||||
width: 120,
|
||||
render: (v) => renderQuota((v || 0) / 1000, 6),
|
||||
},
|
||||
{
|
||||
title: t('最常用模型'),
|
||||
dataIndex: 'top_model',
|
||||
width: 150,
|
||||
render: (v) =>
|
||||
v ? <Tag color='blue'>{v}</Tag> : <Text type='tertiary'>-</Text>,
|
||||
},
|
||||
{
|
||||
title: t('活跃 IP'),
|
||||
dataIndex: 'last_ip',
|
||||
width: 130,
|
||||
render: (v) => v || <Text type='tertiary'>-</Text>,
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
render: (v) =>
|
||||
v === 1 ? (
|
||||
<Tag color='red'>{t('已封号')}</Tag>
|
||||
) : (
|
||||
<Tag color='green'>{t('已解封')}</Tag>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('解封时间'),
|
||||
dataIndex: 'unban_at',
|
||||
width: 150,
|
||||
render: (v) => (v > 0 ? formatTime(v) : <Text type='tertiary'>-</Text>),
|
||||
},
|
||||
{
|
||||
title: t('解封原因'),
|
||||
dataIndex: 'unban_reason',
|
||||
width: 180,
|
||||
render: (v) => v || <Text type='tertiary'>-</Text>,
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 110,
|
||||
fixed: 'right',
|
||||
render: (_v, row) => {
|
||||
if (row.status === 1) {
|
||||
return (
|
||||
<Button
|
||||
size='small'
|
||||
type='primary'
|
||||
theme='light'
|
||||
onClick={() => {
|
||||
setUnbanRow(row);
|
||||
setUnbanReason('');
|
||||
setUnbanModalVisible(true);
|
||||
}}
|
||||
>
|
||||
{t('解封')}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Text type='tertiary' size='small'>
|
||||
-
|
||||
</Text>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const statusOptions = [
|
||||
{ value: 0, label: t('全部') },
|
||||
{ value: 1, label: t('已封号') },
|
||||
{ value: 2, label: t('已解封') },
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className='mb-3 flex items-center justify-between flex-wrap gap-2'>
|
||||
<Space>
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('共')} {banLogTotal || 0} {t('条')}
|
||||
</Text>
|
||||
<Select
|
||||
value={banLogStatus}
|
||||
onChange={(v) => {
|
||||
setBanLogStatus(v);
|
||||
fetchBanLogs({ status: v, page: 1 });
|
||||
}}
|
||||
optionList={statusOptions}
|
||||
style={{ width: 120 }}
|
||||
size='small'
|
||||
/>
|
||||
</Space>
|
||||
<Button
|
||||
icon={<IconRefresh />}
|
||||
size='small'
|
||||
onClick={() => fetchBanLogs()}
|
||||
loading={loading}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={banLogs}
|
||||
rowKey='id'
|
||||
loading={loading}
|
||||
pagination={{
|
||||
pageSize: 20,
|
||||
showTotal: true,
|
||||
total: banLogTotal,
|
||||
// 受控分页:避免切换状态筛选后 Semi 内部页码与 hook 不同步
|
||||
currentPage: banLogPage,
|
||||
onPageChange: (page) => fetchBanLogs({ page }),
|
||||
}}
|
||||
empty={t('暂无封号记录')}
|
||||
scroll={{ x: 1400 }}
|
||||
/>
|
||||
|
||||
<Modal
|
||||
title={t('解封用户')}
|
||||
visible={unbanModalVisible}
|
||||
onCancel={() => setUnbanModalVisible(false)}
|
||||
onOk={async () => {
|
||||
if (!unbanRow) return;
|
||||
// unbanUser 内部会并发刷新 suspects + banLogs,无需在此重复 fetch
|
||||
const ok = await unbanUser({
|
||||
userId: unbanRow.user_id,
|
||||
banLogId: unbanRow.id,
|
||||
reason: unbanReason,
|
||||
});
|
||||
if (ok) {
|
||||
setUnbanModalVisible(false);
|
||||
}
|
||||
}}
|
||||
okText={t('确认解封')}
|
||||
cancelText={t('取消')}
|
||||
>
|
||||
{unbanRow && (
|
||||
<div className='space-y-3'>
|
||||
<div>
|
||||
<Text type='tertiary'>{t('用户:')}</Text>
|
||||
<Text strong>
|
||||
{unbanRow.user_snapshot || `user_${unbanRow.user_id}`}(ID:
|
||||
{unbanRow.user_id})
|
||||
</Text>
|
||||
</div>
|
||||
<div>
|
||||
<Text type='tertiary'>
|
||||
{t(
|
||||
'解封后用户账号会恢复,但被禁用的 Token 不会自动启用,需手动开启。',
|
||||
)}
|
||||
</Text>
|
||||
</div>
|
||||
<div>
|
||||
<div className='text-xs text-gray-500 mb-1'>{t('解封原因')}</div>
|
||||
<Input.TextArea
|
||||
value={unbanReason}
|
||||
onChange={setUnbanReason}
|
||||
placeholder={t('记录解封原因,便于审计')}
|
||||
rows={3}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default RiskControlBanLogs;
|
||||
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
Form,
|
||||
Switch,
|
||||
InputNumber,
|
||||
Input,
|
||||
Typography,
|
||||
Banner,
|
||||
Button,
|
||||
Space,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const defaultValues = {
|
||||
id: 0,
|
||||
name: '高频低消耗自动封号',
|
||||
enabled: false,
|
||||
window_minutes: 1440,
|
||||
scan_interval_minutes: 10,
|
||||
warn_min_requests: 500,
|
||||
warn_max_avg_quota: 50,
|
||||
auto_ban_enabled: true,
|
||||
ban_min_requests: 1000,
|
||||
ban_max_avg_quota: 5,
|
||||
ban_max_total_quota: 5000,
|
||||
notify_admin: true,
|
||||
};
|
||||
|
||||
const RiskControlRulesModal = ({
|
||||
visible,
|
||||
onClose,
|
||||
rules,
|
||||
saveRule,
|
||||
triggerScanNow,
|
||||
t,
|
||||
}) => {
|
||||
const [form, setForm] = useState(defaultValues);
|
||||
const [saving, setSaving] = useState(false);
|
||||
// 仅在 Modal 由"关闭→打开"的瞬间同步表单,避免 rules 异步到达时覆盖用户正在编辑的值
|
||||
const prevVisibleRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible && !prevVisibleRef.current) {
|
||||
if (rules && rules.length > 0) {
|
||||
setForm({ ...defaultValues, ...rules[0] });
|
||||
} else {
|
||||
setForm(defaultValues);
|
||||
}
|
||||
}
|
||||
prevVisibleRef.current = visible;
|
||||
}, [visible, rules]);
|
||||
|
||||
const setField = (k, v) => setForm((f) => ({ ...f, [k]: v }));
|
||||
|
||||
const handleSave = async (alsoScan) => {
|
||||
// 仅在启用了自动封号时校验封号阈值
|
||||
if (form.auto_ban_enabled) {
|
||||
if (
|
||||
form.ban_min_requests > 0 &&
|
||||
form.ban_min_requests < form.warn_min_requests
|
||||
) {
|
||||
Modal.warning({
|
||||
title: t('阈值不合法'),
|
||||
content: t('封号最低请求数不能低于预警阈值'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (
|
||||
form.ban_max_avg_quota > 0 &&
|
||||
form.warn_max_avg_quota > 0 &&
|
||||
form.ban_max_avg_quota > form.warn_max_avg_quota
|
||||
) {
|
||||
Modal.warning({
|
||||
title: t('阈值不合法'),
|
||||
content: t('封号平均消耗上限不能高于预警阈值'),
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
setSaving(true);
|
||||
const ok = await saveRule(form);
|
||||
setSaving(false);
|
||||
if (!ok) return;
|
||||
if (alsoScan) {
|
||||
await triggerScanNow();
|
||||
}
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={t('风控规则配置')}
|
||||
visible={visible}
|
||||
onCancel={onClose}
|
||||
footer={
|
||||
<Space>
|
||||
<Button onClick={onClose}>{t('取消')}</Button>
|
||||
<Button onClick={() => handleSave(false)} loading={saving}>
|
||||
{t('仅保存')}
|
||||
</Button>
|
||||
<Button
|
||||
type='primary'
|
||||
theme='solid'
|
||||
onClick={() => handleSave(true)}
|
||||
loading={saving}
|
||||
>
|
||||
{t('保存并立即扫描')}
|
||||
</Button>
|
||||
</Space>
|
||||
}
|
||||
width={620}
|
||||
>
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'命中"预警阈值"仅通知管理员,不动账号;命中"封号阈值"会自动封号并禁用该用户全部 Token。',
|
||||
)}
|
||||
className='mb-4'
|
||||
/>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<Form.Slot label={t('规则名称')}>
|
||||
<Input value={form.name} onChange={(v) => setField('name', v)} />
|
||||
</Form.Slot>
|
||||
|
||||
<div className='flex items-center gap-3'>
|
||||
<Switch
|
||||
checked={form.enabled}
|
||||
onChange={(v) => setField('enabled', v)}
|
||||
/>
|
||||
<Text>{t('启用此规则')}</Text>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<Form.Slot label={t('检测时间窗(分钟)')}>
|
||||
<InputNumber
|
||||
value={form.window_minutes}
|
||||
onChange={(v) => setField('window_minutes', v || 1440)}
|
||||
min={1}
|
||||
style={{ width: '100%' }}
|
||||
suffix={t('分钟')}
|
||||
/>
|
||||
</Form.Slot>
|
||||
<Form.Slot label={t('扫描频率(分钟)')}>
|
||||
<InputNumber
|
||||
value={form.scan_interval_minutes}
|
||||
onChange={(v) => setField('scan_interval_minutes', v || 10)}
|
||||
min={1}
|
||||
style={{ width: '100%' }}
|
||||
suffix={t('分钟')}
|
||||
/>
|
||||
</Form.Slot>
|
||||
</div>
|
||||
|
||||
<div className='border-l-4 border-orange-400 pl-3 py-1'>
|
||||
<Text strong className='text-orange-600'>
|
||||
⚠ {t('预警阈值(仅通知,不封号)')}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<Form.Slot label={t('最低请求数')}>
|
||||
<InputNumber
|
||||
value={form.warn_min_requests}
|
||||
onChange={(v) => setField('warn_min_requests', v || 0)}
|
||||
min={1}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Form.Slot>
|
||||
<Form.Slot
|
||||
label={
|
||||
<span>
|
||||
{t('平均消耗 ≤')}{' '}
|
||||
<Text type='tertiary' size='small'>
|
||||
({t('quota')}, ≈ {renderQuota(form.warn_max_avg_quota, 6)})
|
||||
</Text>
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<InputNumber
|
||||
value={form.warn_max_avg_quota}
|
||||
onChange={(v) => setField('warn_max_avg_quota', v || 0)}
|
||||
min={0}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Form.Slot>
|
||||
</div>
|
||||
|
||||
<div className='border-l-4 border-red-500 pl-3 py-1 flex items-center justify-between'>
|
||||
<Text strong className='text-red-600'>
|
||||
🚨 {t('封号阈值(自动封号 + 禁用所有 Token)')}
|
||||
</Text>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Text size='small' type='tertiary'>
|
||||
{t('启用自动封号')}
|
||||
</Text>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={form.auto_ban_enabled}
|
||||
onChange={(v) => setField('auto_ban_enabled', v)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{!form.auto_ban_enabled && (
|
||||
<Banner
|
||||
type='warning'
|
||||
description={t(
|
||||
'已关闭自动封号:命中阈值的用户仅会收到管理员预警通知,不会被自动处置。',
|
||||
)}
|
||||
className='mb-2'
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
className={`grid grid-cols-2 gap-4 ${form.auto_ban_enabled ? '' : 'opacity-50 pointer-events-none'}`}
|
||||
>
|
||||
<Form.Slot label={t('最低请求数')}>
|
||||
<InputNumber
|
||||
value={form.ban_min_requests}
|
||||
onChange={(v) => setField('ban_min_requests', v == null ? 0 : v)}
|
||||
min={0}
|
||||
style={{ width: '100%' }}
|
||||
disabled={!form.auto_ban_enabled}
|
||||
/>
|
||||
</Form.Slot>
|
||||
<Form.Slot
|
||||
label={
|
||||
<span>
|
||||
{t('平均消耗 ≤')}{' '}
|
||||
<Text type='tertiary' size='small'>
|
||||
({t('quota')}, ≈ {renderQuota(form.ban_max_avg_quota, 6)})
|
||||
</Text>
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<InputNumber
|
||||
value={form.ban_max_avg_quota}
|
||||
onChange={(v) => setField('ban_max_avg_quota', v || 0)}
|
||||
min={0}
|
||||
style={{ width: '100%' }}
|
||||
disabled={!form.auto_ban_enabled}
|
||||
/>
|
||||
</Form.Slot>
|
||||
</div>
|
||||
<Form.Slot
|
||||
label={
|
||||
<span>
|
||||
{t('总消耗 ≤')}{' '}
|
||||
<Text type='tertiary' size='small'>
|
||||
({t('quota')}, ≈ {renderQuota(form.ban_max_total_quota, 4)},{' '}
|
||||
{t('防误伤大客户')})
|
||||
</Text>
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<InputNumber
|
||||
value={form.ban_max_total_quota}
|
||||
onChange={(v) => setField('ban_max_total_quota', v || 0)}
|
||||
min={0}
|
||||
style={{ width: '100%' }}
|
||||
disabled={!form.auto_ban_enabled}
|
||||
/>
|
||||
</Form.Slot>
|
||||
|
||||
<div className='flex items-center gap-3 pt-2'>
|
||||
<Switch
|
||||
checked={form.notify_admin}
|
||||
onChange={(v) => setField('notify_admin', v)}
|
||||
/>
|
||||
<Text>{t('触发时通知管理员(站内 / 邮件 / Webhook)')}</Text>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default RiskControlRulesModal;
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { Card } from '@douyinfe/semi-ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
|
||||
// 支付渠道颜色映射:支付宝蓝色、微信绿色
|
||||
const CHANNEL_COLORS = {
|
||||
支付宝: '#3b82f6', // 蓝色
|
||||
微信支付: '#10b981', // 绿色
|
||||
Stripe: '#8b5cf6', // 紫色
|
||||
PayPal: '#0070ba',
|
||||
Creem: '#f59e0b', // 橙色
|
||||
易支付: '#ef4444', // 红色
|
||||
};
|
||||
const DEFAULT_COLORS = [
|
||||
'#3b82f6',
|
||||
'#10b981',
|
||||
'#8b5cf6',
|
||||
'#f59e0b',
|
||||
'#ef4444',
|
||||
'#06b6d4',
|
||||
'#f97316',
|
||||
];
|
||||
|
||||
const TopupChannelChart = ({ data, title, icon, t }) => {
|
||||
const pieSpec = useMemo(() => {
|
||||
if (!data || data.length === 0) return null;
|
||||
|
||||
const chartData = data.map((item) => ({
|
||||
name: item.payment_method || t('未知'),
|
||||
value: item.amount || 0,
|
||||
count: item.count || 0,
|
||||
}));
|
||||
|
||||
// 根据支付渠道名称生成颜色数组
|
||||
const colorList = chartData.map((item, index) => {
|
||||
return (
|
||||
CHANNEL_COLORS[item.name] ||
|
||||
DEFAULT_COLORS[index % DEFAULT_COLORS.length]
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'pie',
|
||||
data: [{ id: 'topupChannel', values: chartData }],
|
||||
valueField: 'value',
|
||||
categoryField: 'name',
|
||||
outerRadius: 0.8,
|
||||
innerRadius: 0.5,
|
||||
padAngle: 0.02,
|
||||
pie: {
|
||||
style: {
|
||||
cornerRadius: 4,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.name,
|
||||
value: (datum) => `¥${(datum?.value || 0).toFixed(2)}`,
|
||||
},
|
||||
{
|
||||
key: () => t('笔数'),
|
||||
value: (datum) => `${datum?.count || 0} ${t('笔')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
legends: {
|
||||
visible: true,
|
||||
position: 'bottom',
|
||||
orient: 'horizontal',
|
||||
},
|
||||
label: {
|
||||
visible: true,
|
||||
position: 'outside',
|
||||
content: '{name}: {value:.1%}',
|
||||
},
|
||||
color: colorList,
|
||||
};
|
||||
}, [data, t]);
|
||||
|
||||
// 统计列表
|
||||
const channelList = data || [];
|
||||
const totalAmount = channelList.reduce(
|
||||
(sum, item) => sum + (item.amount || 0),
|
||||
0,
|
||||
);
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
{pieSpec ? (
|
||||
<div>
|
||||
<VChart
|
||||
spec={pieSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 200 }}
|
||||
/>
|
||||
<div className='mt-4 space-y-2'>
|
||||
{channelList.map((item, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className='flex items-center justify-between text-sm py-1 border-b border-gray-100 dark:border-gray-700 last:border-0'
|
||||
>
|
||||
<span className='text-gray-600 dark:text-gray-400'>
|
||||
{item.payment_method}
|
||||
</span>
|
||||
<div className='text-right'>
|
||||
<span className='font-medium'>
|
||||
¥{(item.amount || 0).toFixed(2)}
|
||||
</span>
|
||||
<span className='text-gray-400 text-xs ml-2'>
|
||||
({item.percent?.toFixed(1)}%)
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className='flex items-center justify-between text-sm pt-2 font-semibold'>
|
||||
<span>{t('合计')}</span>
|
||||
<span>¥{totalAmount.toFixed(2)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default TopupChannelChart;
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { Card } from '@douyinfe/semi-ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
|
||||
const TrendCharts = ({ title, icon, data, type, t }) => {
|
||||
const spec = useMemo(() => {
|
||||
if (!data || data.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (type === 'user') {
|
||||
// 用户趋势图
|
||||
const chartData = data.flatMap((item) => [
|
||||
{ date: item.date, type: t('新增用户'), value: item.new_users || 0 },
|
||||
{ date: item.date, type: t('活跃用户'), value: item.active_users || 0 },
|
||||
{ date: item.date, type: t('付费用户'), value: item.paid_users || 0 },
|
||||
]);
|
||||
|
||||
return {
|
||||
type: 'line',
|
||||
data: [{ id: 'userTrend', values: chartData }],
|
||||
xField: 'date',
|
||||
yField: 'value',
|
||||
seriesField: 'type',
|
||||
point: {
|
||||
visible: true,
|
||||
size: 4,
|
||||
},
|
||||
line: {
|
||||
style: {
|
||||
lineWidth: 2,
|
||||
},
|
||||
},
|
||||
legends: {
|
||||
visible: true,
|
||||
orient: 'top',
|
||||
position: 'middle',
|
||||
padding: { top: 0, bottom: 16, left: 0, right: 0 },
|
||||
layoutType: 'normal',
|
||||
},
|
||||
tooltip: {
|
||||
visible: true,
|
||||
mark: {
|
||||
visible: true,
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.type,
|
||||
value: (datum) =>
|
||||
`${(datum?.value || 0).toLocaleString()} ${t('人')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
dimension: {
|
||||
visible: true,
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.type,
|
||||
value: (datum) =>
|
||||
`${(datum?.value || 0).toLocaleString()} ${t('人')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
color: ['#3b82f6', '#10b981', '#f59e0b'],
|
||||
crosshair: {
|
||||
xField: { visible: true, line: { visible: true } },
|
||||
yField: { visible: false },
|
||||
},
|
||||
axes: [
|
||||
{
|
||||
orient: 'bottom',
|
||||
label: {
|
||||
style: {
|
||||
angle: -45,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
orient: 'left',
|
||||
label: {
|
||||
formatMethod: (v) => Math.round(v),
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
} else {
|
||||
// 收支趋势图 - 双轴
|
||||
const topupKey = t('充值金额');
|
||||
const consumeKey = t('消耗额度');
|
||||
const chartData = data.map((item) => ({
|
||||
date: item.date,
|
||||
[topupKey]: item.topup_amount || 0,
|
||||
[consumeKey]: (item.consume_quota || 0) / 500000, // 转换为美元单位
|
||||
rawConsume: item.consume_quota || 0, // 保留原始值用于 tooltip
|
||||
}));
|
||||
|
||||
return {
|
||||
type: 'common',
|
||||
data: [{ id: 'financeTrend', values: chartData }],
|
||||
series: [
|
||||
{
|
||||
type: 'bar',
|
||||
id: 'topup',
|
||||
name: topupKey,
|
||||
dataIndex: 0,
|
||||
xField: 'date',
|
||||
yField: topupKey,
|
||||
bar: {
|
||||
style: {
|
||||
fill: '#3b82f6',
|
||||
cornerRadius: [4, 4, 0, 0],
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
visible: true,
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: () => topupKey,
|
||||
value: (datum) => `¥${(datum?.[topupKey] || 0).toFixed(2)}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'line',
|
||||
id: 'consume',
|
||||
name: consumeKey,
|
||||
dataIndex: 0,
|
||||
xField: 'date',
|
||||
yField: consumeKey,
|
||||
point: {
|
||||
visible: true,
|
||||
size: 4,
|
||||
style: {
|
||||
fill: '#f59e0b',
|
||||
},
|
||||
},
|
||||
line: {
|
||||
style: {
|
||||
stroke: '#f59e0b',
|
||||
lineWidth: 2,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
visible: true,
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: () => consumeKey,
|
||||
value: (datum) =>
|
||||
`¥${(datum?.[consumeKey] || 0).toFixed(2)}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
legends: {
|
||||
visible: true,
|
||||
orient: 'top',
|
||||
position: 'middle',
|
||||
padding: { top: 0, bottom: 16, left: 0, right: 0 },
|
||||
layoutType: 'normal',
|
||||
},
|
||||
tooltip: {
|
||||
visible: true,
|
||||
dimension: {
|
||||
visible: true,
|
||||
},
|
||||
},
|
||||
crosshair: {
|
||||
xField: { visible: true, line: { visible: true } },
|
||||
},
|
||||
axes: [
|
||||
{
|
||||
orient: 'bottom',
|
||||
label: {
|
||||
style: {
|
||||
angle: -45,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
orient: 'left',
|
||||
title: {
|
||||
visible: true,
|
||||
text: t('充值金额 (¥)'),
|
||||
},
|
||||
seriesIndex: [0],
|
||||
},
|
||||
{
|
||||
orient: 'right',
|
||||
title: {
|
||||
visible: true,
|
||||
text: t('消耗额度 ($)'),
|
||||
},
|
||||
seriesIndex: [1],
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}, [data, type, t]);
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
{spec ? (
|
||||
<VChart
|
||||
spec={spec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 300 }}
|
||||
/>
|
||||
) : (
|
||||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default TrendCharts;
|
||||
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card, Avatar, Progress } from '@douyinfe/semi-ui';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const UserRanking = ({ data, title, icon, t }) => {
|
||||
if (!data || data.length === 0) {
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// 计算最大值用于进度条
|
||||
const maxQuota = Math.max(...data.map((item) => item.quota || 0));
|
||||
|
||||
// 排名颜色
|
||||
const getRankStyle = (index) => {
|
||||
if (index === 0)
|
||||
return 'bg-gradient-to-r from-yellow-400 to-yellow-500 text-white';
|
||||
if (index === 1)
|
||||
return 'bg-gradient-to-r from-gray-300 to-gray-400 text-white';
|
||||
if (index === 2)
|
||||
return 'bg-gradient-to-r from-orange-400 to-orange-500 text-white';
|
||||
return 'bg-gray-200 text-gray-600';
|
||||
};
|
||||
|
||||
// 进度条颜色
|
||||
const getProgressColor = (index) => {
|
||||
if (index === 0) return '#f59e0b';
|
||||
if (index === 1) return '#9ca3af';
|
||||
if (index === 2) return '#f97316';
|
||||
return '#3b82f6';
|
||||
};
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
<span className='text-xs text-gray-400 ml-2'>
|
||||
{t('共')} {data.length} {t('人')}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
<div className='space-y-2 max-h-[450px] overflow-y-auto pr-1'>
|
||||
{data.map((item, index) => (
|
||||
<div
|
||||
key={item.user_id}
|
||||
className='flex items-center gap-3 p-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors'
|
||||
>
|
||||
<div
|
||||
className={`w-7 h-7 rounded-full flex items-center justify-center text-xs font-bold flex-shrink-0 ${getRankStyle(
|
||||
index,
|
||||
)}`}
|
||||
>
|
||||
{index + 1}
|
||||
</div>
|
||||
<Avatar size='small' color='blue' className='flex-shrink-0'>
|
||||
{(item.display_name || item.username)?.charAt(0)?.toUpperCase() ||
|
||||
'U'}
|
||||
</Avatar>
|
||||
<div className='flex-1 min-w-0'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<span
|
||||
className='text-sm font-medium truncate'
|
||||
title={`${item.display_name || item.username || 'User'} (ID: ${item.user_id})`}
|
||||
>
|
||||
{item.display_name || item.username || `User ${item.user_id}`}
|
||||
<span className='text-xs text-gray-400 ml-1'>
|
||||
#{item.user_id}
|
||||
</span>
|
||||
</span>
|
||||
<span className='text-sm font-semibold text-gray-700 dark:text-gray-300 ml-2'>
|
||||
{renderQuota(item.quota || 0)}
|
||||
</span>
|
||||
</div>
|
||||
<Progress
|
||||
percent={(item.quota / maxQuota) * 100}
|
||||
showInfo={false}
|
||||
size='small'
|
||||
style={{ height: 4 }}
|
||||
stroke={getProgressColor(index)}
|
||||
/>
|
||||
<div className='flex justify-between text-xs text-gray-400 mt-1'>
|
||||
<span>
|
||||
{item.requests?.toLocaleString()} {t('次请求')}
|
||||
</span>
|
||||
<span>{(item.tokens || 0).toLocaleString()} tokens</span>
|
||||
</div>
|
||||
<div className='flex justify-between text-xs mt-1'>
|
||||
<span className='text-gray-500'>{t('余额')}:</span>
|
||||
<span className='font-medium text-green-600 dark:text-green-400'>
|
||||
{renderQuota(item.balance || 0)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserRanking;
|
||||
@@ -0,0 +1,585 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo, useState, useEffect, useCallback } from 'react';
|
||||
import { Card, Spin, Tag, Progress, Empty } from '@douyinfe/semi-ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { API, showError } from '../../helpers';
|
||||
import {
|
||||
UserCheck,
|
||||
Briefcase,
|
||||
Cpu,
|
||||
Users,
|
||||
TrendingUp,
|
||||
BarChart3,
|
||||
PieChart,
|
||||
ChevronDown,
|
||||
ChevronUp,
|
||||
} from 'lucide-react';
|
||||
|
||||
// 职业类型标签配置
|
||||
const JOB_TYPE_CONFIG = {
|
||||
1: { label: '技术岗位', color: 'blue', icon: '💻', desc: '开发/测试/运维等' },
|
||||
2: {
|
||||
label: '技术周边',
|
||||
color: 'green',
|
||||
icon: '🎨',
|
||||
desc: '产品/设计/运营等',
|
||||
},
|
||||
3: { label: '其他行业', color: 'orange', icon: '🏢', desc: '非IT行业' },
|
||||
};
|
||||
|
||||
// AI工具使用标签配置
|
||||
const AI_TOOL_CONFIG = {
|
||||
1: { label: '正在使用', color: 'green', icon: '🚀', desc: '活跃用户' },
|
||||
2: { label: '了解/尝试过', color: 'blue', icon: '🔍', desc: '潜在用户' },
|
||||
3: { label: '有兴趣', color: 'orange', icon: '✨', desc: '待转化' },
|
||||
4: { label: '暂不需要', color: 'grey', icon: '💤', desc: '观望用户' },
|
||||
};
|
||||
|
||||
const UserSurveyStats = ({ title, icon, t }) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [surveyStats, setSurveyStats] = useState(null);
|
||||
const [surveyTrend, setSurveyTrend] = useState([]);
|
||||
const [collapsed, setCollapsed] = useState(true); // 默认折叠
|
||||
|
||||
// 获取统计数据
|
||||
const fetchSurveyStats = useCallback(async () => {
|
||||
try {
|
||||
const res = await API.get('/api/analytics/survey/stats');
|
||||
if (res.data.success) {
|
||||
setSurveyStats(res.data.data);
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取问卷统计失败:', error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 获取趋势数据
|
||||
const fetchSurveyTrend = useCallback(async () => {
|
||||
try {
|
||||
const res = await API.get('/api/analytics/survey/trend');
|
||||
if (res.data.success) {
|
||||
setSurveyTrend(res.data.data || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取问卷趋势失败:', error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 初始加载
|
||||
useEffect(() => {
|
||||
const loadData = async () => {
|
||||
setLoading(true);
|
||||
await Promise.all([fetchSurveyStats(), fetchSurveyTrend()]);
|
||||
setLoading(false);
|
||||
};
|
||||
loadData();
|
||||
}, [fetchSurveyStats, fetchSurveyTrend]);
|
||||
|
||||
// 职业分布饼图配置
|
||||
const jobTypePieSpec = useMemo(() => {
|
||||
if (!surveyStats?.job_type_stats || surveyStats.job_type_stats.length === 0)
|
||||
return null;
|
||||
|
||||
const chartData = surveyStats.job_type_stats.map((item) => ({
|
||||
name: JOB_TYPE_CONFIG[item.job_type]?.label || t('未知'),
|
||||
value: item.count,
|
||||
percentage: item.percentage,
|
||||
}));
|
||||
|
||||
return {
|
||||
type: 'pie',
|
||||
data: [{ id: 'jobType', values: chartData }],
|
||||
valueField: 'value',
|
||||
categoryField: 'name',
|
||||
outerRadius: 0.8,
|
||||
innerRadius: 0.5,
|
||||
padAngle: 0.02,
|
||||
pie: {
|
||||
style: {
|
||||
cornerRadius: 4,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.name,
|
||||
value: (datum) => `${datum?.value || 0} ${t('人')}`,
|
||||
},
|
||||
{
|
||||
key: () => t('占比'),
|
||||
value: (datum) => `${(datum?.percentage || 0).toFixed(1)}%`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
legends: {
|
||||
visible: true,
|
||||
position: 'bottom',
|
||||
orient: 'horizontal',
|
||||
},
|
||||
label: {
|
||||
visible: true,
|
||||
position: 'outside',
|
||||
content: '{name}',
|
||||
},
|
||||
color: ['#3b82f6', '#10b981', '#f59e0b'],
|
||||
};
|
||||
}, [surveyStats, t]);
|
||||
|
||||
// AI工具使用饼图配置
|
||||
const aiToolPieSpec = useMemo(() => {
|
||||
if (!surveyStats?.ai_tool_stats || surveyStats.ai_tool_stats.length === 0)
|
||||
return null;
|
||||
|
||||
const chartData = surveyStats.ai_tool_stats.map((item) => ({
|
||||
name: AI_TOOL_CONFIG[item.ai_tool_usage]?.label || t('未知'),
|
||||
value: item.count,
|
||||
percentage: item.percentage,
|
||||
}));
|
||||
|
||||
return {
|
||||
type: 'pie',
|
||||
data: [{ id: 'aiTool', values: chartData }],
|
||||
valueField: 'value',
|
||||
categoryField: 'name',
|
||||
outerRadius: 0.8,
|
||||
innerRadius: 0.5,
|
||||
padAngle: 0.02,
|
||||
pie: {
|
||||
style: {
|
||||
cornerRadius: 4,
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: (datum) => datum?.name,
|
||||
value: (datum) => `${datum?.value || 0} ${t('人')}`,
|
||||
},
|
||||
{
|
||||
key: () => t('占比'),
|
||||
value: (datum) => `${(datum?.percentage || 0).toFixed(1)}%`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
legends: {
|
||||
visible: true,
|
||||
position: 'bottom',
|
||||
orient: 'horizontal',
|
||||
},
|
||||
label: {
|
||||
visible: true,
|
||||
position: 'outside',
|
||||
content: '{name}',
|
||||
},
|
||||
color: ['#10b981', '#3b82f6', '#f59e0b', '#9ca3af'],
|
||||
};
|
||||
}, [surveyStats, t]);
|
||||
|
||||
// 趋势图配置
|
||||
const trendSpec = useMemo(() => {
|
||||
if (!surveyTrend || surveyTrend.length === 0) return null;
|
||||
|
||||
const chartData = [...surveyTrend].reverse().map((item) => ({
|
||||
date: item.date,
|
||||
count: item.count,
|
||||
}));
|
||||
|
||||
return {
|
||||
type: 'bar',
|
||||
data: [{ id: 'trend', values: chartData }],
|
||||
xField: 'date',
|
||||
yField: 'count',
|
||||
bar: {
|
||||
style: {
|
||||
cornerRadius: [4, 4, 0, 0],
|
||||
fill: {
|
||||
gradient: 'linear',
|
||||
x0: 0,
|
||||
y0: 0,
|
||||
x1: 0,
|
||||
y1: 1,
|
||||
stops: [
|
||||
{ offset: 0, color: '#8b5cf6' },
|
||||
{ offset: 1, color: '#6366f1' },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
tooltip: {
|
||||
mark: {
|
||||
content: [
|
||||
{
|
||||
key: () => t('日期'),
|
||||
value: (datum) => datum?.date,
|
||||
},
|
||||
{
|
||||
key: () => t('新增'),
|
||||
value: (datum) => `${datum?.count || 0} ${t('人')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
axes: [
|
||||
{
|
||||
orient: 'bottom',
|
||||
label: {
|
||||
autoRotate: true,
|
||||
autoRotateAngle: [0, 45],
|
||||
},
|
||||
},
|
||||
{
|
||||
orient: 'left',
|
||||
label: {
|
||||
formatMethod: (v) => Math.round(v),
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
}, [surveyTrend, t]);
|
||||
|
||||
// 计算统计数据
|
||||
const totalUsers = surveyStats?.total || 0;
|
||||
const techUsers =
|
||||
surveyStats?.job_type_stats?.find((s) => s.job_type === 1)?.count || 0;
|
||||
const activeAIUsers =
|
||||
surveyStats?.ai_tool_stats?.find((s) => s.ai_tool_usage === 1)?.count || 0;
|
||||
const interestedUsers =
|
||||
surveyStats?.ai_tool_stats?.find((s) => s.ai_tool_usage === 3)?.count || 0;
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center justify-between w-full'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
{totalUsers > 0 && (
|
||||
<Tag color='purple' size='small'>
|
||||
{totalUsers} {t('人已填写')}
|
||||
</Tag>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setCollapsed(!collapsed)}
|
||||
className='flex items-center gap-1 px-2 py-1 text-sm text-gray-500 hover:text-brand-deep hover:bg-brand/5 dark:hover:bg-brand-deep/20 rounded transition-colors'
|
||||
>
|
||||
<span className='text-xs'>{collapsed ? t('展开') : t('收起')}</span>
|
||||
{collapsed ? <ChevronDown size={16} /> : <ChevronUp size={16} />}
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: collapsed ? '0' : '16px' }}
|
||||
>
|
||||
{!collapsed && (
|
||||
<Spin spinning={loading}>
|
||||
{totalUsers === 0 ? (
|
||||
<Empty
|
||||
image={<UserCheck className='w-16 h-16 text-gray-300' />}
|
||||
description={t('暂无问卷数据')}
|
||||
style={{ padding: '40px 0' }}
|
||||
/>
|
||||
) : (
|
||||
<div className='space-y-6'>
|
||||
{/* 概览统计卡片 */}
|
||||
<div className='grid grid-cols-2 sm:grid-cols-4 gap-4'>
|
||||
<div className='p-4 bg-gradient-to-br from-brand-from/5 to-brand-to/5 dark:from-brand-from/20 dark:to-brand-to/20 rounded-xl'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<Users className='w-4 h-4 text-brand' />
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('总填写')}
|
||||
</span>
|
||||
</div>
|
||||
<div className='text-2xl font-bold text-brand-deep dark:text-brand-from'>
|
||||
{totalUsers}
|
||||
</div>
|
||||
</div>
|
||||
<div className='p-4 bg-gradient-to-br from-blue-50 to-cyan-50 dark:from-blue-900/20 dark:to-cyan-900/20 rounded-xl'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<Briefcase className='w-4 h-4 text-blue-500' />
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('技术岗位')}
|
||||
</span>
|
||||
</div>
|
||||
<div className='text-2xl font-bold text-blue-600 dark:text-blue-400'>
|
||||
{techUsers}
|
||||
</div>
|
||||
<div className='text-xs text-gray-400 mt-1'>
|
||||
{totalUsers > 0
|
||||
? ((techUsers / totalUsers) * 100).toFixed(1)
|
||||
: 0}
|
||||
%
|
||||
</div>
|
||||
</div>
|
||||
<div className='p-4 bg-gradient-to-br from-green-50 to-emerald-50 dark:from-green-900/20 dark:to-emerald-900/20 rounded-xl'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<Cpu className='w-4 h-4 text-green-500' />
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('正在使用AI')}
|
||||
</span>
|
||||
</div>
|
||||
<div className='text-2xl font-bold text-green-600 dark:text-green-400'>
|
||||
{activeAIUsers}
|
||||
</div>
|
||||
<div className='text-xs text-gray-400 mt-1'>
|
||||
{totalUsers > 0
|
||||
? ((activeAIUsers / totalUsers) * 100).toFixed(1)
|
||||
: 0}
|
||||
%
|
||||
</div>
|
||||
</div>
|
||||
<div className='p-4 bg-gradient-to-br from-orange-50 to-amber-50 dark:from-orange-900/20 dark:to-amber-900/20 rounded-xl'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<TrendingUp className='w-4 h-4 text-orange-500' />
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('有兴趣尝试')}
|
||||
</span>
|
||||
</div>
|
||||
<div className='text-2xl font-bold text-orange-600 dark:text-orange-400'>
|
||||
{interestedUsers}
|
||||
</div>
|
||||
<div className='text-xs text-gray-400 mt-1'>
|
||||
{totalUsers > 0
|
||||
? ((interestedUsers / totalUsers) * 100).toFixed(1)
|
||||
: 0}
|
||||
%
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 图表区域 */}
|
||||
<div className='grid grid-cols-1 lg:grid-cols-2 gap-6'>
|
||||
{/* 职业分布 */}
|
||||
<div className='bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4'>
|
||||
<div className='flex items-center gap-2 mb-4'>
|
||||
<PieChart className='w-4 h-4 text-blue-500' />
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{t('职业分布')}
|
||||
</span>
|
||||
</div>
|
||||
{jobTypePieSpec ? (
|
||||
<>
|
||||
<VChart
|
||||
spec={jobTypePieSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 180 }}
|
||||
/>
|
||||
<div className='mt-3 space-y-2'>
|
||||
{surveyStats?.job_type_stats?.map((item) => {
|
||||
const config = JOB_TYPE_CONFIG[item.job_type];
|
||||
return (
|
||||
<div
|
||||
key={item.job_type}
|
||||
className='flex items-center justify-between'
|
||||
>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-lg'>{config?.icon}</span>
|
||||
<span className='text-sm text-gray-600 dark:text-gray-400'>
|
||||
{config?.label}
|
||||
</span>
|
||||
</div>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Progress
|
||||
percent={item.percentage}
|
||||
size='small'
|
||||
style={{ width: 60 }}
|
||||
showInfo={false}
|
||||
stroke={
|
||||
config?.color === 'blue'
|
||||
? '#3b82f6'
|
||||
: config?.color === 'green'
|
||||
? '#10b981'
|
||||
: '#f59e0b'
|
||||
}
|
||||
/>
|
||||
<span className='text-sm font-medium w-12 text-right'>
|
||||
{item.count}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className='h-[200px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* AI工具使用情况 */}
|
||||
<div className='bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4'>
|
||||
<div className='flex items-center gap-2 mb-4'>
|
||||
<PieChart className='w-4 h-4 text-green-500' />
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{t('AI工具使用情况')}
|
||||
</span>
|
||||
</div>
|
||||
{aiToolPieSpec ? (
|
||||
<>
|
||||
<VChart
|
||||
spec={aiToolPieSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 180 }}
|
||||
/>
|
||||
<div className='mt-3 space-y-2'>
|
||||
{surveyStats?.ai_tool_stats?.map((item) => {
|
||||
const config = AI_TOOL_CONFIG[item.ai_tool_usage];
|
||||
const colors = {
|
||||
green: '#10b981',
|
||||
blue: '#3b82f6',
|
||||
orange: '#f59e0b',
|
||||
grey: '#9ca3af',
|
||||
};
|
||||
return (
|
||||
<div
|
||||
key={item.ai_tool_usage}
|
||||
className='flex items-center justify-between'
|
||||
>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-lg'>{config?.icon}</span>
|
||||
<span className='text-sm text-gray-600 dark:text-gray-400'>
|
||||
{config?.label}
|
||||
</span>
|
||||
</div>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Progress
|
||||
percent={item.percentage}
|
||||
size='small'
|
||||
style={{ width: 60 }}
|
||||
showInfo={false}
|
||||
stroke={colors[config?.color] || '#9ca3af'}
|
||||
/>
|
||||
<span className='text-sm font-medium w-12 text-right'>
|
||||
{item.count}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className='h-[200px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 填写趋势 */}
|
||||
<div className='bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4'>
|
||||
<div className='flex items-center gap-2 mb-4'>
|
||||
<BarChart3 className='w-4 h-4 text-brand' />
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{t('近30天填写趋势')}
|
||||
</span>
|
||||
</div>
|
||||
{trendSpec ? (
|
||||
<VChart
|
||||
spec={trendSpec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
style={{ height: 200 }}
|
||||
/>
|
||||
) : (
|
||||
<div className='h-[200px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 交叉分析表格 */}
|
||||
{surveyStats?.cross_analysis &&
|
||||
surveyStats.cross_analysis.length > 0 && (
|
||||
<div className='bg-gray-50 dark:bg-gray-800/50 rounded-xl p-4'>
|
||||
<div className='flex items-center gap-2 mb-4'>
|
||||
<BarChart3 className='w-4 h-4 text-brand' />
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{t('交叉分析')}
|
||||
</span>
|
||||
</div>
|
||||
<div className='overflow-x-auto'>
|
||||
<table className='w-full text-sm'>
|
||||
<thead>
|
||||
<tr className='border-b border-gray-200 dark:border-gray-700'>
|
||||
<th className='text-left py-2 px-3 font-medium text-gray-600 dark:text-gray-400'>
|
||||
{t('职业类型')}
|
||||
</th>
|
||||
<th className='text-left py-2 px-3 font-medium text-gray-600 dark:text-gray-400'>
|
||||
{t('AI工具使用')}
|
||||
</th>
|
||||
<th className='text-right py-2 px-3 font-medium text-gray-600 dark:text-gray-400'>
|
||||
{t('人数')}
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{surveyStats.cross_analysis.map((item, index) => (
|
||||
<tr
|
||||
key={index}
|
||||
className='border-b border-gray-100 dark:border-gray-700/50 last:border-0'
|
||||
>
|
||||
<td className='py-2 px-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span>
|
||||
{JOB_TYPE_CONFIG[item.job_type]?.icon}
|
||||
</span>
|
||||
<span className='text-gray-700 dark:text-gray-300'>
|
||||
{JOB_TYPE_CONFIG[item.job_type]?.label}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className='py-2 px-3'>
|
||||
<Tag
|
||||
color={
|
||||
AI_TOOL_CONFIG[item.ai_tool_usage]?.color
|
||||
}
|
||||
size='small'
|
||||
>
|
||||
{AI_TOOL_CONFIG[item.ai_tool_usage]?.label}
|
||||
</Tag>
|
||||
</td>
|
||||
<td className='py-2 px-3 text-right font-medium'>
|
||||
{item.count}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserSurveyStats;
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React from 'react';
|
||||
import { Card, Table } from '@douyinfe/semi-ui';
|
||||
import { renderQuota } from '../../helpers';
|
||||
|
||||
const UserTopupRanking = ({ data, title, icon, t }) => {
|
||||
if (!data || data.length === 0) {
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
>
|
||||
<div className='h-[300px] flex items-center justify-center text-gray-400'>
|
||||
{t('暂无数据')}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
// 预计算排名(后端已按充值总额降序排好,直接按顺序编号)
|
||||
const dataWithRank = data.map((item, idx) => ({ ...item, _rank: idx + 1 }));
|
||||
|
||||
// 排名样式
|
||||
const getRankBadge = (rank) => {
|
||||
if (rank === 1)
|
||||
return 'bg-gradient-to-r from-yellow-400 to-yellow-500 text-white';
|
||||
if (rank === 2)
|
||||
return 'bg-gradient-to-r from-gray-300 to-gray-400 text-white';
|
||||
if (rank === 3)
|
||||
return 'bg-gradient-to-r from-orange-400 to-orange-500 text-white';
|
||||
return 'bg-gray-200 text-gray-600';
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('排名'),
|
||||
dataIndex: '_rank',
|
||||
width: 70,
|
||||
render: (rank) => (
|
||||
<div
|
||||
className={`w-7 h-7 rounded-full flex items-center justify-center text-xs font-bold ${getRankBadge(rank)}`}
|
||||
>
|
||||
{rank}
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('用户昵称'),
|
||||
dataIndex: 'display_name',
|
||||
width: 160,
|
||||
render: (text, record) => (
|
||||
<div className='flex flex-col'>
|
||||
<span
|
||||
className='font-medium text-sm truncate'
|
||||
title={text || `User ${record.user_id}`}
|
||||
>
|
||||
{text || `User ${record.user_id}`}
|
||||
</span>
|
||||
<span className='text-xs text-gray-400 truncate'>
|
||||
ID: {record.user_id}
|
||||
</span>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('充值总额'),
|
||||
dataIndex: 'total_topup',
|
||||
width: 130,
|
||||
sorter: (a, b) => a.total_topup - b.total_topup,
|
||||
defaultSortOrder: 'descend',
|
||||
render: (value) => (
|
||||
<span className='font-semibold text-red-500'>
|
||||
¥{(value || 0).toFixed(2)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('历史消耗'),
|
||||
dataIndex: 'used_quota',
|
||||
width: 130,
|
||||
sorter: (a, b) => a.used_quota - b.used_quota,
|
||||
render: (value) => (
|
||||
<span className='text-orange-600 dark:text-orange-400'>
|
||||
{renderQuota(value || 0)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('当前余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 130,
|
||||
sorter: (a, b) => a.balance - b.balance,
|
||||
render: (value) => (
|
||||
<span className='font-medium text-green-600 dark:text-green-400'>
|
||||
{renderQuota(value || 0)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Card
|
||||
className='shadow-sm hover:shadow-md transition-shadow'
|
||||
title={
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-brand'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
<span className='text-xs text-gray-400 ml-2'>
|
||||
{t('共')} {data.length} {t('人')}
|
||||
</span>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '0' }}
|
||||
>
|
||||
<Table
|
||||
// 列宽合计远超窄屏视口;没有 scroll 时表格会压缩到 min-content 硬塞进去,
|
||||
// 末尾的操作列落在视口外,且 iOS 上滚动条不可见、毫无可拖动提示
|
||||
scroll={{ x: 'max-content' }}
|
||||
columns={columns}
|
||||
dataSource={dataWithRank}
|
||||
rowKey='user_id'
|
||||
pagination={
|
||||
data.length > 20 ? { pageSize: 20, showSizeChanger: true } : false
|
||||
}
|
||||
size='small'
|
||||
bordered={false}
|
||||
style={{ borderRadius: 0 }}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserTopupRanking;
|
||||
@@ -0,0 +1,524 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
Empty,
|
||||
Table,
|
||||
TabPane,
|
||||
Tabs,
|
||||
Tag,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { ClipboardList, Download } from 'lucide-react';
|
||||
import { ChangeText, OrgNameCell, ReasonTags, SectionCard } from './shared';
|
||||
import {
|
||||
daysSince,
|
||||
downloadCsv,
|
||||
formatCny,
|
||||
formatCst,
|
||||
orgDisplayName,
|
||||
quotaToCny,
|
||||
REASONS,
|
||||
} from './utils';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
export const ACTION_TABS = ['renewal', 'retention', 'growth', 'activation'];
|
||||
|
||||
const TAB_META = {
|
||||
renewal: {
|
||||
label: '续费跟进',
|
||||
desc: '余额耗尽 / 即将不足 / 低于预警线,以及合同即将到期的企业;按紧急程度排序',
|
||||
},
|
||||
retention: {
|
||||
label: '流失挽回',
|
||||
desc: '本期停用、消耗下滑、近 7 日腰斩,以及 60 天内还在使用的沉睡企业;按消耗减少金额排序',
|
||||
},
|
||||
growth: {
|
||||
label: '增长机会',
|
||||
desc: '高速增长、新客起量、回流,以及成员活跃率低于 30% 的企业;按本期消耗排序',
|
||||
},
|
||||
activation: {
|
||||
label: '激活跟进',
|
||||
desc: '待激活或开通后从未使用的企业;按创建时间倒序',
|
||||
},
|
||||
};
|
||||
|
||||
const money = (cny) => (v) => (
|
||||
<span className='tabular-nums'>{formatCny(v, cny)}</span>
|
||||
);
|
||||
|
||||
const salesRepCol = (t) => ({
|
||||
title: t('跟进人'),
|
||||
dataIndex: 'sales_rep',
|
||||
width: 100,
|
||||
render: (v) =>
|
||||
v ? (
|
||||
<span className='truncate'>{v}</span>
|
||||
) : (
|
||||
<Text type='tertiary'>{t('未分配')}</Text>
|
||||
),
|
||||
});
|
||||
|
||||
const contactCol = (t) => ({
|
||||
title: t('联系人'),
|
||||
dataIndex: 'contact_name',
|
||||
width: 150,
|
||||
render: (v, r) =>
|
||||
v || r.contact_phone ? (
|
||||
<div className='min-w-0'>
|
||||
<div className='truncate'>{v || '—'}</div>
|
||||
{r.contact_phone ? (
|
||||
<div className='text-xs text-gray-400 tabular-nums'>
|
||||
{r.contact_phone}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<Text type='tertiary'>—</Text>
|
||||
),
|
||||
});
|
||||
|
||||
const baseCols = (t) => [
|
||||
{
|
||||
title: t('企业'),
|
||||
dataIndex: 'name',
|
||||
width: 190,
|
||||
fixed: 'left',
|
||||
render: (_, r) => <OrgNameCell org={r} t={t} />,
|
||||
},
|
||||
salesRepCol(t),
|
||||
{
|
||||
title: t('原因'),
|
||||
dataIndex: 'reasons',
|
||||
width: 170,
|
||||
render: (v) => <ReasonTags reasons={v} t={t} />,
|
||||
},
|
||||
];
|
||||
|
||||
const actionCol = (t) => ({
|
||||
title: t('建议动作'),
|
||||
dataIndex: 'action',
|
||||
width: 190,
|
||||
render: (v) => <span className='text-sm'>{t(v)}</span>,
|
||||
});
|
||||
|
||||
const columnsFor = (tab, cny, t, atRisk) => {
|
||||
const m = money(cny);
|
||||
switch (tab) {
|
||||
case 'renewal':
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('当前余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('日均消耗'),
|
||||
dataIndex: 'daily_avg',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: (v) => (v > 0 ? m(v) : <Text type='tertiary'>—</Text>),
|
||||
},
|
||||
{
|
||||
title: t('预计可用'),
|
||||
dataIndex: 'days_left',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (v, r) => {
|
||||
if (v < 0) return <Text type='tertiary'>{t('近期无消耗')}</Text>;
|
||||
return (
|
||||
<span
|
||||
className='tabular-nums font-medium'
|
||||
style={{
|
||||
color:
|
||||
v <= 3
|
||||
? 'var(--semi-color-danger)'
|
||||
: 'var(--semi-color-warning)',
|
||||
}}
|
||||
>
|
||||
{v < 1 ? t('不足 1 天') : `${v.toFixed(1)} ${t('天')}`}
|
||||
</span>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('建议充值'),
|
||||
dataIndex: 'topup_suggest',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (v) =>
|
||||
v > 0 ? (
|
||||
<span className='font-semibold'>{m(v)}</span>
|
||||
) : (
|
||||
<Text type='tertiary'>—</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('到期时间'),
|
||||
dataIndex: 'expired_at',
|
||||
width: 110,
|
||||
render: (v) =>
|
||||
v > 0 ? formatCst(v, false) : <Text type='tertiary'>—</Text>,
|
||||
},
|
||||
contactCol(t),
|
||||
actionCol(t),
|
||||
];
|
||||
case 'retention':
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('对比期消耗'),
|
||||
dataIndex: 'prev_quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('本期消耗'),
|
||||
dataIndex: 'quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('变化'),
|
||||
dataIndex: 'change',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<ChangeText
|
||||
cur={r.quota}
|
||||
prev={r.prev_quota}
|
||||
t={t}
|
||||
showNew={false}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('消耗减少'),
|
||||
dataIndex: 'at_risk',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<span className='tabular-nums font-semibold'>
|
||||
{formatCny(atRisk(r), cny)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('最近使用'),
|
||||
dataIndex: 'last_active',
|
||||
width: 110,
|
||||
render: (v) => {
|
||||
const d = daysSince(v);
|
||||
return d === null ? (
|
||||
<Text type='tertiary'>—</Text>
|
||||
) : d === 0 ? (
|
||||
t('今天')
|
||||
) : (
|
||||
t('{{days}} 天前', { days: d })
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
contactCol(t),
|
||||
actionCol(t),
|
||||
];
|
||||
case 'growth':
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('本期消耗'),
|
||||
dataIndex: 'quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('变化'),
|
||||
dataIndex: 'change',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<ChangeText cur={r.quota} prev={r.prev_quota} t={t} />
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('成员活跃'),
|
||||
dataIndex: 'active_members',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (v, r) => (
|
||||
<span className='tabular-nums'>
|
||||
{v}/{r.member_count}
|
||||
{r.member_count > 0 ? (
|
||||
<span className='text-xs text-gray-400 ml-1'>
|
||||
{Math.min(100, (v / r.member_count) * 100).toFixed(0)}%
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('层级'),
|
||||
dataIndex: 'tier',
|
||||
width: 70,
|
||||
render: (v) =>
|
||||
v ? <Tag size='small'>{v}</Tag> : <Text type='tertiary'>—</Text>,
|
||||
},
|
||||
{
|
||||
title: t('余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
actionCol(t),
|
||||
];
|
||||
default:
|
||||
return [
|
||||
...baseCols(t),
|
||||
{
|
||||
title: t('创建时间'),
|
||||
dataIndex: 'created_at',
|
||||
width: 110,
|
||||
render: (v) => formatCst(v, false),
|
||||
},
|
||||
{
|
||||
title: t('已开通'),
|
||||
dataIndex: 'age',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_, r) => {
|
||||
const d = daysSince(r.created_at);
|
||||
return d === null ? '—' : t('{{days}} 天', { days: d });
|
||||
},
|
||||
},
|
||||
{
|
||||
title: t('成员数'),
|
||||
dataIndex: 'member_count',
|
||||
width: 80,
|
||||
align: 'right',
|
||||
},
|
||||
{
|
||||
title: t('余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
contactCol(t),
|
||||
actionCol(t),
|
||||
];
|
||||
}
|
||||
};
|
||||
|
||||
const exportList = (tab, rows, cny, t, atRisk) => {
|
||||
const yuan = (v) => quotaToCny(v, cny).toFixed(2);
|
||||
const common = (o) => [
|
||||
orgDisplayName(o, t),
|
||||
o.code,
|
||||
o.sales_rep || t('未分配'),
|
||||
o.reasons.map((r) => t(REASONS[r]?.label || r)).join(' / '),
|
||||
];
|
||||
const head = [t('企业'), t('企业代码'), t('跟进人'), t('原因')];
|
||||
let headers;
|
||||
let body;
|
||||
switch (tab) {
|
||||
case 'renewal':
|
||||
headers = [
|
||||
...head,
|
||||
t('当前余额'),
|
||||
t('日均消耗'),
|
||||
t('预计可用天数'),
|
||||
t('建议充值'),
|
||||
t('到期时间'),
|
||||
t('联系人'),
|
||||
t('联系电话'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
yuan(o.balance),
|
||||
yuan(o.daily_avg),
|
||||
o.days_left < 0 ? '' : o.days_left.toFixed(1),
|
||||
yuan(o.topup_suggest),
|
||||
o.expired_at > 0 ? formatCst(o.expired_at, false) : '',
|
||||
o.contact_name,
|
||||
o.contact_phone,
|
||||
t(o.action),
|
||||
]);
|
||||
break;
|
||||
case 'retention':
|
||||
headers = [
|
||||
...head,
|
||||
t('对比期消耗'),
|
||||
t('本期消耗'),
|
||||
t('消耗减少'),
|
||||
t('最近使用'),
|
||||
t('余额'),
|
||||
t('联系人'),
|
||||
t('联系电话'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
yuan(o.prev_quota),
|
||||
yuan(o.quota),
|
||||
yuan(atRisk(o)),
|
||||
formatCst(o.last_active),
|
||||
yuan(o.balance),
|
||||
o.contact_name,
|
||||
o.contact_phone,
|
||||
t(o.action),
|
||||
]);
|
||||
break;
|
||||
case 'growth':
|
||||
headers = [
|
||||
...head,
|
||||
t('本期消耗'),
|
||||
t('对比期消耗'),
|
||||
t('活跃成员'),
|
||||
t('成员数'),
|
||||
t('层级'),
|
||||
t('余额'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
yuan(o.quota),
|
||||
yuan(o.prev_quota),
|
||||
o.active_members,
|
||||
o.member_count,
|
||||
o.tier,
|
||||
yuan(o.balance),
|
||||
t(o.action),
|
||||
]);
|
||||
break;
|
||||
default:
|
||||
headers = [
|
||||
...head,
|
||||
t('创建时间'),
|
||||
t('成员数'),
|
||||
t('余额'),
|
||||
t('联系人'),
|
||||
t('联系电话'),
|
||||
t('建议动作'),
|
||||
];
|
||||
body = rows.map((o) => [
|
||||
...common(o),
|
||||
formatCst(o.created_at, false),
|
||||
o.member_count,
|
||||
yuan(o.balance),
|
||||
o.contact_name,
|
||||
o.contact_phone,
|
||||
t(o.action),
|
||||
]);
|
||||
}
|
||||
downloadCsv(
|
||||
`${t(TAB_META[tab].label)}-${formatCst(Date.now() / 1000, false)}.csv`,
|
||||
headers,
|
||||
body,
|
||||
);
|
||||
};
|
||||
|
||||
export const ActionCenter = ({ lists, activeTab, onTabChange, cny, t }) => (
|
||||
<SectionCard
|
||||
id='org-report-actions'
|
||||
title={t('行动清单')}
|
||||
icon={<ClipboardList className='w-5 h-5' />}
|
||||
extra={
|
||||
<span className='text-xs text-gray-400'>
|
||||
{t('按跟进场景拆分的待办企业,可直接导出分派')}
|
||||
</span>
|
||||
}
|
||||
bodyStyle={{ paddingTop: 4 }}
|
||||
>
|
||||
<Tabs
|
||||
type='line'
|
||||
activeKey={activeTab}
|
||||
onChange={onTabChange}
|
||||
tabBarExtraContent={
|
||||
<Button
|
||||
size='small'
|
||||
icon={<Download className='w-3.5 h-3.5' />}
|
||||
disabled={lists[activeTab].length === 0}
|
||||
onClick={() =>
|
||||
exportList(activeTab, lists[activeTab], cny, t, lists.atRisk)
|
||||
}
|
||||
>
|
||||
{t('导出')}
|
||||
</Button>
|
||||
}
|
||||
>
|
||||
{ACTION_TABS.map((tab) => (
|
||||
<TabPane
|
||||
key={tab}
|
||||
itemKey={tab}
|
||||
tab={
|
||||
<span className='flex items-center gap-1.5'>
|
||||
{t(TAB_META[tab].label)}
|
||||
<Tag
|
||||
size='small'
|
||||
color={
|
||||
lists[tab].length > 0
|
||||
? tab === 'growth'
|
||||
? 'green'
|
||||
: 'red'
|
||||
: 'grey'
|
||||
}
|
||||
>
|
||||
{lists[tab].length}
|
||||
</Tag>
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400 my-2'>
|
||||
{t(TAB_META[tab].desc)}
|
||||
</div>
|
||||
<Table
|
||||
columns={columnsFor(tab, cny, t, lists.atRisk)}
|
||||
dataSource={lists[tab]}
|
||||
rowKey='org_id'
|
||||
size='small'
|
||||
scroll={{ x: 1200 }}
|
||||
pagination={
|
||||
lists[tab].length > 10
|
||||
? { pageSize: 10, showSizeChanger: false }
|
||||
: false
|
||||
}
|
||||
empty={<Empty description={t('暂无需要跟进的企业')} />}
|
||||
/>
|
||||
</TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
</SectionCard>
|
||||
);
|
||||
Binary file not shown.
@@ -0,0 +1,360 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Banner, Button, Card, Tag, Tooltip } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
AlertOctagon,
|
||||
AlertTriangle,
|
||||
CheckCircle2,
|
||||
Download,
|
||||
Info,
|
||||
Lightbulb,
|
||||
} from 'lucide-react';
|
||||
import { ChangeText, KpiCard, SectionCard } from './shared';
|
||||
import { formatCny, formatCst, pct, SEGMENTS } from './utils';
|
||||
|
||||
// ─── 报表抬头:统计口径 + 数据状态 ─────────────────────────────────
|
||||
export const ReportHeader = ({ report, onExport, t }) => {
|
||||
const m = report.meta || {};
|
||||
const now = Date.now() / 1000;
|
||||
const stale = m.rollup_ready && now - m.data_as_of > 2 * 3600;
|
||||
const beyondFloor =
|
||||
m.rollup_ready && m.history_floor > 0 && m.prev_start < m.history_floor;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card className='shadow-sm mb-4' bodyStyle={{ padding: '16px 20px' }}>
|
||||
<div className='flex flex-col md:flex-row md:items-center md:justify-between gap-3'>
|
||||
<div className='min-w-0'>
|
||||
<div className='text-xs font-semibold tracking-wider text-brand mb-1'>
|
||||
{t('企业经营决策报表')}
|
||||
</div>
|
||||
<div className='text-sm text-gray-700 dark:text-gray-200 tabular-nums'>
|
||||
{t('本期')}:{formatCst(m.start)} ~ {formatCst(m.effective_end)}
|
||||
<span className='mx-2 text-gray-300'>|</span>
|
||||
{t('对比期')}:{formatCst(m.prev_start)} ~ {formatCst(m.prev_end)}
|
||||
</div>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400 mt-1'>
|
||||
{t('数据截至 {{time}},按整点统计;对比期与本期按相同时长对齐', {
|
||||
time: formatCst(m.data_as_of),
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<Button
|
||||
icon={<Download className='w-4 h-4' />}
|
||||
onClick={onExport}
|
||||
disabled={!report.orgs?.length}
|
||||
>
|
||||
{t('导出企业明细')}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
{!m.rollup_ready ? (
|
||||
<Banner
|
||||
className='mb-4'
|
||||
type='warning'
|
||||
fullMode={false}
|
||||
closeIcon={null}
|
||||
title={t('报表数据正在初始化')}
|
||||
description={t(
|
||||
'后台正在首次汇总消耗日志,通常 1~2 分钟后可用。若长时间无数据,请确认至少有一个 master 节点(NODE_TYPE 不为 slave),且未设置 ANALYTICS_ROLLUP_ENABLED=false。',
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
{m.rollup_ready && !m.history_ready ? (
|
||||
<Banner
|
||||
className='mb-4'
|
||||
type='info'
|
||||
fullMode={false}
|
||||
closeIcon={null}
|
||||
description={t(
|
||||
'历史数据回填中(已完成至 {{time}}),该时间之前的对比期数据暂不完整,环比与分群仅供参考。',
|
||||
{ time: formatCst(m.backfill_cursor) },
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
{beyondFloor ? (
|
||||
<Banner
|
||||
className='mb-4'
|
||||
type='info'
|
||||
fullMode={false}
|
||||
closeIcon={null}
|
||||
description={t(
|
||||
'对比期早于汇总保留范围({{time}} 起),环比可能偏高。',
|
||||
{
|
||||
time: formatCst(m.history_floor, false),
|
||||
},
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
{stale ? (
|
||||
<Banner
|
||||
className='mb-4'
|
||||
type='warning'
|
||||
fullMode={false}
|
||||
closeIcon={null}
|
||||
description={t(
|
||||
'数据同步延迟:最近一次同步于 {{time}},请检查 master 节点运行状态。',
|
||||
{
|
||||
time: formatCst(m.data_as_of),
|
||||
},
|
||||
)}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
// ─── 本期要点 ─────────────────────────────────────────────────────
|
||||
const FINDING_STYLE = {
|
||||
danger: { icon: AlertOctagon, color: 'var(--semi-color-danger)' },
|
||||
warning: { icon: AlertTriangle, color: 'var(--semi-color-warning)' },
|
||||
success: { icon: CheckCircle2, color: 'var(--semi-color-success)' },
|
||||
info: { icon: Info, color: 'var(--semi-color-primary)' },
|
||||
};
|
||||
|
||||
export const KeyFindings = ({ findings, onJump, t }) => (
|
||||
<SectionCard
|
||||
id='org-report-findings'
|
||||
title={t('本期要点')}
|
||||
icon={<Lightbulb className='w-5 h-5' />}
|
||||
extra={
|
||||
<span className='text-xs text-gray-400'>
|
||||
{t('根据本期数据自动生成,点击可定位到明细')}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
{findings.length === 0 ? (
|
||||
<div className='text-sm text-gray-400 py-4'>
|
||||
{t('本期暂无需要关注的变化')}
|
||||
</div>
|
||||
) : (
|
||||
<ul className='space-y-2'>
|
||||
{findings.map((f, i) => {
|
||||
const style = FINDING_STYLE[f.level] || FINDING_STYLE.info;
|
||||
const Icon = style.icon;
|
||||
return (
|
||||
<li key={i}>
|
||||
<button
|
||||
type='button'
|
||||
onClick={() => onJump(f.target)}
|
||||
className='w-full text-left flex items-start gap-2 p-2 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors focus-visible:outline focus-visible:outline-2'
|
||||
>
|
||||
<Icon
|
||||
className='w-4 h-4 mt-0.5 flex-shrink-0'
|
||||
style={{ color: style.color }}
|
||||
/>
|
||||
<span className='text-sm text-gray-700 dark:text-gray-200 leading-relaxed'>
|
||||
{f.text}
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
</SectionCard>
|
||||
);
|
||||
|
||||
// ─── 核心指标 ─────────────────────────────────────────────────────
|
||||
export const KpiGrid = ({ report, lists, cny, onJump, t }) => {
|
||||
const k = report.kpi || {};
|
||||
const servingOrgs = (k.normal_orgs || 0) + (k.arrears_orgs || 0);
|
||||
const avgPerOrg = k.active_orgs > 0 ? k.org_quota / k.active_orgs : 0;
|
||||
const prevAvgPerOrg =
|
||||
k.prev_active_orgs > 0 ? k.prev_org_quota / k.prev_active_orgs : 0;
|
||||
const platform = (k.org_quota || 0) + (k.personal_quota || 0);
|
||||
const prevPlatform = (k.prev_org_quota || 0) + (k.prev_personal_quota || 0);
|
||||
const share = pct(k.org_quota, platform);
|
||||
const prevShare =
|
||||
prevPlatform > 0 ? pct(k.prev_org_quota, prevPlatform) : null;
|
||||
const shareDelta = prevShare === null ? null : share - prevShare;
|
||||
const coverDays =
|
||||
k.run_rate_daily > 0 ? k.total_balance / k.run_rate_daily : null;
|
||||
|
||||
const cards = [
|
||||
{
|
||||
title: t('企业消耗'),
|
||||
value: formatCny(k.org_quota, cny),
|
||||
sub: `${t('对比期')} ${formatCny(k.prev_org_quota, cny)}`,
|
||||
compare: <ChangeText cur={k.org_quota} prev={k.prev_org_quota} t={t} />,
|
||||
onClick: () => onJump('attribution'),
|
||||
},
|
||||
{
|
||||
title: t('活跃企业'),
|
||||
value: `${(k.active_orgs || 0).toLocaleString()} ${t('家')}`,
|
||||
sub: `${t('活跃率')} ${pct(k.active_orgs, servingOrgs).toFixed(1)}% · ${t('新增')} ${k.new_orgs || 0}`,
|
||||
compare: (
|
||||
<ChangeText cur={k.active_orgs} prev={k.prev_active_orgs} t={t} />
|
||||
),
|
||||
tip: t('本期有调用的企业数;活跃率 = 活跃企业 / 正常与欠费企业'),
|
||||
onClick: () => onJump('segments'),
|
||||
},
|
||||
{
|
||||
title: t('家均消耗'),
|
||||
value: formatCny(avgPerOrg, cny),
|
||||
sub: `${t('人均')} ${formatCny(k.active_members > 0 ? k.org_quota / k.active_members : 0, cny)}`,
|
||||
compare: <ChangeText cur={avgPerOrg} prev={prevAvgPerOrg} t={t} />,
|
||||
tip: t('企业消耗 / 活跃企业数;人均 = 企业消耗 / 活跃成员数'),
|
||||
},
|
||||
{
|
||||
title: t('企业活跃成员'),
|
||||
value: `${(k.active_members || 0).toLocaleString()} ${t('人')}`,
|
||||
sub: `${t('渗透率')} ${Math.min(100, pct(k.active_members, k.total_members)).toFixed(1)}% · ${t('成员')} ${(k.total_members || 0).toLocaleString()}`,
|
||||
tip: t('本期通过企业令牌产生调用的去重成员数(按自然日统计)'),
|
||||
onClick: () => onJump('growth'),
|
||||
},
|
||||
{
|
||||
title: t('本月预计企业消耗'),
|
||||
value: formatCny(k.month_forecast, cny),
|
||||
sub: `${t('本月至今')} ${formatCny(k.month_to_date, cny)}`,
|
||||
compare: (
|
||||
<Tooltip content={`${t('上月')} ${formatCny(k.last_month_quota, cny)}`}>
|
||||
<span>
|
||||
<ChangeText
|
||||
cur={k.month_forecast}
|
||||
prev={k.last_month_quota}
|
||||
t={t}
|
||||
/>
|
||||
</span>
|
||||
</Tooltip>
|
||||
),
|
||||
tip: t('本月至今 + 近 7 个完整日的日均消耗 × 本月剩余天数;对比上月全月'),
|
||||
accent: 'var(--semi-color-tertiary)',
|
||||
},
|
||||
{
|
||||
title: t('未来 30 天充值缺口'),
|
||||
value: formatCny(k.topup_gap_30d, cny),
|
||||
sub: `${lists.renewal.length} ${t('家需续费跟进')}`,
|
||||
tip: t('按各企业近 7 日日均消耗覆盖 30 天所需金额,减去当前余额后累加'),
|
||||
accent:
|
||||
k.topup_gap_30d > 0
|
||||
? 'var(--semi-color-danger)'
|
||||
: 'var(--semi-color-success)',
|
||||
onClick: () => onJump('renewal'),
|
||||
},
|
||||
{
|
||||
title: t('企业总余额'),
|
||||
value: formatCny(k.total_balance, cny),
|
||||
sub:
|
||||
coverDays === null
|
||||
? t('近 7 日无消耗')
|
||||
: t('按当前速度可支撑 {{days}} 天', { days: coverDays.toFixed(0) }),
|
||||
tip: t('全部企业主余额 + 赠送余额'),
|
||||
accent: 'var(--semi-color-success)',
|
||||
},
|
||||
{
|
||||
title: t('企业消耗占平台'),
|
||||
value: `${share.toFixed(1)}%`,
|
||||
sub: `${t('个人消耗')} ${formatCny(k.personal_quota, cny)}`,
|
||||
compare:
|
||||
shareDelta === null ? null : (
|
||||
<span
|
||||
className='text-xs font-medium tabular-nums'
|
||||
style={{
|
||||
color:
|
||||
shareDelta >= 0
|
||||
? 'var(--semi-color-success)'
|
||||
: 'var(--semi-color-danger)',
|
||||
}}
|
||||
>
|
||||
{shareDelta >= 0 ? '+' : ''}
|
||||
{shareDelta.toFixed(1)}pp
|
||||
</span>
|
||||
),
|
||||
tip: t('企业消耗 /(企业 + 个人消耗);pp 为百分点变化'),
|
||||
onClick: () => onJump('trend'),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div
|
||||
id='org-report-kpi'
|
||||
className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3 scroll-mt-24'
|
||||
>
|
||||
{cards.map((c) => (
|
||||
<KpiCard key={c.title} {...c} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ─── 客户健康分群 ─────────────────────────────────────────────────
|
||||
export const HealthSegments = ({ report, cny, activeSegment, onSelect, t }) => {
|
||||
const segs = report.segments || [];
|
||||
const totalCount = segs.reduce((s, x) => s + x.count, 0);
|
||||
return (
|
||||
<div
|
||||
id='org-report-segments'
|
||||
className='grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-3 scroll-mt-24'
|
||||
>
|
||||
{segs.map((s) => {
|
||||
const meta = SEGMENTS[s.key] || { label: s.key, color: 'grey' };
|
||||
const active = activeSegment === s.key;
|
||||
const delta = (s.quota || 0) - (s.prev_quota || 0);
|
||||
return (
|
||||
<Tooltip key={s.key} content={t(meta.desc)}>
|
||||
<button
|
||||
type='button'
|
||||
onClick={() => onSelect(active ? '' : s.key)}
|
||||
className={`text-left rounded-xl border p-3 transition-all focus-visible:outline focus-visible:outline-2 ${
|
||||
active
|
||||
? 'border-brand bg-brand/5 shadow-sm'
|
||||
: 'border-gray-200 dark:border-gray-700 hover:border-brand/50 hover:shadow-sm'
|
||||
} ${s.count === 0 ? 'opacity-60' : ''}`}
|
||||
>
|
||||
<div className='flex items-center justify-between gap-2'>
|
||||
<Tag size='small' color={meta.color}>
|
||||
{t(meta.label)}
|
||||
</Tag>
|
||||
<span className='text-xs text-gray-400 tabular-nums'>
|
||||
{pct(s.count, totalCount).toFixed(0)}%
|
||||
</span>
|
||||
</div>
|
||||
<div className='mt-2 text-lg font-bold text-gray-800 dark:text-gray-100 tabular-nums'>
|
||||
{s.count.toLocaleString()}{' '}
|
||||
<span className='text-xs font-normal text-gray-500'>
|
||||
{t('家')}
|
||||
</span>
|
||||
</div>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400 tabular-nums truncate'>
|
||||
{formatCny(s.quota, cny, 0)}
|
||||
{delta !== 0 ? (
|
||||
<span
|
||||
className='ml-1'
|
||||
style={{
|
||||
color:
|
||||
delta > 0
|
||||
? 'var(--semi-color-success)'
|
||||
: 'var(--semi-color-danger)',
|
||||
}}
|
||||
>
|
||||
{delta > 0 ? '+' : '-'}
|
||||
{formatCny(Math.abs(delta), cny, 0)}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</button>
|
||||
</Tooltip>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,522 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Empty,
|
||||
Input,
|
||||
Select,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { Download, Search, Table2, UserCog } from 'lucide-react';
|
||||
import { ChangeText, OrgNameCell, SectionCard } from './shared';
|
||||
import {
|
||||
ALERT_LEVELS,
|
||||
ORG_STATUS,
|
||||
changeRate,
|
||||
daysSince,
|
||||
downloadCsv,
|
||||
formatCny,
|
||||
formatCst,
|
||||
orgDisplayName,
|
||||
quotaToCny,
|
||||
SEGMENTS,
|
||||
TIERS,
|
||||
} from './utils';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// ─── 跟进人视图 ───────────────────────────────────────────────────
|
||||
export const SalesRepTable = ({ reps, cny, onSelect, t }) => {
|
||||
const m = (v) => <span className='tabular-nums'>{formatCny(v, cny)}</span>;
|
||||
const count = (color) => (v) =>
|
||||
v > 0 ? (
|
||||
<Tag size='small' color={color}>
|
||||
{v}
|
||||
</Tag>
|
||||
) : (
|
||||
<Text type='tertiary'>0</Text>
|
||||
);
|
||||
const columns = [
|
||||
{
|
||||
title: t('跟进人'),
|
||||
dataIndex: 'sales_rep',
|
||||
width: 120,
|
||||
fixed: 'left',
|
||||
render: (v) => (
|
||||
<button
|
||||
type='button'
|
||||
className='text-left font-medium hover:text-brand focus-visible:outline focus-visible:outline-2'
|
||||
onClick={() => onSelect(v || '__none__')}
|
||||
>
|
||||
{v || t('未分配')}
|
||||
</button>
|
||||
),
|
||||
},
|
||||
{ title: t('企业数'), dataIndex: 'orgs', width: 80, align: 'right' },
|
||||
{ title: t('活跃企业'), dataIndex: 'active', width: 90, align: 'right' },
|
||||
{
|
||||
title: t('本期消耗'),
|
||||
dataIndex: 'quota',
|
||||
width: 130,
|
||||
align: 'right',
|
||||
render: m,
|
||||
sorter: (a, b) => a.quota - b.quota,
|
||||
},
|
||||
{
|
||||
title: t('变化'),
|
||||
dataIndex: 'change',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_, r) => <ChangeText cur={r.quota} prev={r.prev_quota} t={t} />,
|
||||
sorter: (a, b) =>
|
||||
(changeRate(a.quota, a.prev_quota) ?? -Infinity) -
|
||||
(changeRate(b.quota, b.prev_quota) ?? -Infinity),
|
||||
},
|
||||
{
|
||||
title: t('企业余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 130,
|
||||
align: 'right',
|
||||
render: m,
|
||||
},
|
||||
{
|
||||
title: t('续费跟进'),
|
||||
dataIndex: 'renewal',
|
||||
width: 90,
|
||||
align: 'center',
|
||||
render: count('red'),
|
||||
sorter: (a, b) => a.renewal - b.renewal,
|
||||
},
|
||||
{
|
||||
title: t('流失挽回'),
|
||||
dataIndex: 'retention',
|
||||
width: 90,
|
||||
align: 'center',
|
||||
render: count('orange'),
|
||||
sorter: (a, b) => a.retention - b.retention,
|
||||
},
|
||||
{
|
||||
title: t('增长机会'),
|
||||
dataIndex: 'growth',
|
||||
width: 90,
|
||||
align: 'center',
|
||||
render: count('green'),
|
||||
sorter: (a, b) => a.growth - b.growth,
|
||||
},
|
||||
];
|
||||
return (
|
||||
<SectionCard
|
||||
title={t('跟进人视图')}
|
||||
icon={<UserCog className='w-5 h-5' />}
|
||||
extra={
|
||||
<span className='text-xs text-gray-400'>
|
||||
{t('点击跟进人筛选下方企业明细')}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={reps}
|
||||
rowKey={(r) => r.sales_rep || '__none__'}
|
||||
size='small'
|
||||
scroll={{ x: 920 }}
|
||||
pagination={
|
||||
reps.length > 8 ? { pageSize: 8, showSizeChanger: false } : false
|
||||
}
|
||||
empty={<Empty description={t('暂无数据')} />}
|
||||
/>
|
||||
</SectionCard>
|
||||
);
|
||||
};
|
||||
|
||||
// ─── 企业明细 ─────────────────────────────────────────────────────
|
||||
export const EMPTY_DETAIL_FILTER = {
|
||||
keyword: '',
|
||||
segment: '',
|
||||
tier: '',
|
||||
alert: '',
|
||||
salesRep: '',
|
||||
};
|
||||
|
||||
const filterOrgs = (orgs, f) => {
|
||||
const kw = f.keyword.trim().toLowerCase();
|
||||
return orgs.filter((o) => {
|
||||
if (kw && !`${o.name || ''} ${o.code || ''}`.toLowerCase().includes(kw))
|
||||
return false;
|
||||
if (f.segment && o.segment !== f.segment) return false;
|
||||
if (f.tier && o.tier !== f.tier) return false;
|
||||
if (
|
||||
f.alert === '__any__'
|
||||
? !o.alert_level
|
||||
: f.alert && o.alert_level !== f.alert
|
||||
)
|
||||
return false;
|
||||
if (f.salesRep && (o.sales_rep || '__none__') !== f.salesRep) return false;
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
export const OrgDetailTable = ({ report, filter, setFilter, cny, t }) => {
|
||||
const orgs = useMemo(() => report.orgs || [], [report]);
|
||||
const rows = useMemo(() => filterOrgs(orgs, filter), [orgs, filter]);
|
||||
const reps = useMemo(
|
||||
() =>
|
||||
Array.from(new Set(orgs.map((o) => o.sales_rep || '__none__'))).sort(),
|
||||
[orgs],
|
||||
);
|
||||
const set = (k) => (v) => setFilter({ ...filter, [k]: v || '' });
|
||||
const filtered = Object.values(filter).some(Boolean);
|
||||
const m = (v) => <span className='tabular-nums'>{formatCny(v, cny)}</span>;
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('企业'),
|
||||
dataIndex: 'name',
|
||||
width: 190,
|
||||
fixed: 'left',
|
||||
render: (_, r) => <OrgNameCell org={r} t={t} />,
|
||||
},
|
||||
{
|
||||
title: t('跟进人'),
|
||||
dataIndex: 'sales_rep',
|
||||
width: 90,
|
||||
render: (v) =>
|
||||
v ? (
|
||||
<span className='truncate'>{v}</span>
|
||||
) : (
|
||||
<Text type='tertiary'>—</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('层级'),
|
||||
dataIndex: 'tier',
|
||||
width: 64,
|
||||
render: (v) =>
|
||||
v ? (
|
||||
<Tag size='small' color={TIERS[v].color}>
|
||||
{v}
|
||||
</Tag>
|
||||
) : (
|
||||
<Text type='tertiary'>—</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('健康'),
|
||||
dataIndex: 'segment',
|
||||
width: 96,
|
||||
render: (v) =>
|
||||
SEGMENTS[v] ? (
|
||||
<Tag size='small' color={SEGMENTS[v].color}>
|
||||
{t(SEGMENTS[v].label)}
|
||||
</Tag>
|
||||
) : null,
|
||||
},
|
||||
{
|
||||
title: t('本期消耗'),
|
||||
dataIndex: 'quota',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
sorter: (a, b) => a.quota - b.quota,
|
||||
defaultSortOrder: 'descend',
|
||||
},
|
||||
{
|
||||
title: t('对比期'),
|
||||
dataIndex: 'prev_quota',
|
||||
width: 110,
|
||||
align: 'right',
|
||||
render: m,
|
||||
sorter: (a, b) => a.prev_quota - b.prev_quota,
|
||||
},
|
||||
{
|
||||
title: t('变化'),
|
||||
dataIndex: 'change',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (_, r) => (
|
||||
<ChangeText cur={r.quota} prev={r.prev_quota} t={t} showNew={false} />
|
||||
),
|
||||
sorter: (a, b) => a.quota - a.prev_quota - (b.quota - b.prev_quota),
|
||||
},
|
||||
{
|
||||
title: t('占比'),
|
||||
dataIndex: 'share',
|
||||
width: 70,
|
||||
align: 'right',
|
||||
render: (v) =>
|
||||
v > 0 ? (
|
||||
<span className='tabular-nums'>{v.toFixed(1)}%</span>
|
||||
) : (
|
||||
<Text type='tertiary'>—</Text>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('请求数'),
|
||||
dataIndex: 'requests',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (v) => (v || 0).toLocaleString(),
|
||||
sorter: (a, b) => a.requests - b.requests,
|
||||
},
|
||||
{
|
||||
title: t('活跃/成员'),
|
||||
dataIndex: 'active_members',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (v, r) => (
|
||||
<span className='tabular-nums'>
|
||||
{v}/{r.member_count}
|
||||
</span>
|
||||
),
|
||||
sorter: (a, b) => a.active_members - b.active_members,
|
||||
},
|
||||
{
|
||||
title: t('余额'),
|
||||
dataIndex: 'balance',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: m,
|
||||
sorter: (a, b) => a.balance - b.balance,
|
||||
},
|
||||
{
|
||||
title: t('预计可用'),
|
||||
dataIndex: 'days_left',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (v) =>
|
||||
v < 0 ? (
|
||||
<Text type='tertiary'>—</Text>
|
||||
) : (
|
||||
<span className='tabular-nums'>
|
||||
{v < 1 ? t('不足 1 天') : `${v.toFixed(0)} ${t('天')}`}
|
||||
</span>
|
||||
),
|
||||
sorter: (a, b) =>
|
||||
(a.days_left < 0 ? Infinity : a.days_left) -
|
||||
(b.days_left < 0 ? Infinity : b.days_left),
|
||||
},
|
||||
{
|
||||
title: t('余额预警'),
|
||||
dataIndex: 'alert_level',
|
||||
width: 110,
|
||||
render: (v) =>
|
||||
ALERT_LEVELS[v] ? (
|
||||
<Tag size='small' color={ALERT_LEVELS[v].color}>
|
||||
{t(ALERT_LEVELS[v].label)}
|
||||
</Tag>
|
||||
) : null,
|
||||
},
|
||||
{
|
||||
title: t('最近使用'),
|
||||
dataIndex: 'last_active',
|
||||
width: 100,
|
||||
render: (v) => {
|
||||
const d = daysSince(v);
|
||||
return d === null ? (
|
||||
<Text type='tertiary'>—</Text>
|
||||
) : d === 0 ? (
|
||||
t('今天')
|
||||
) : (
|
||||
t('{{days}} 天前', { days: d })
|
||||
);
|
||||
},
|
||||
sorter: (a, b) => a.last_active - b.last_active,
|
||||
},
|
||||
];
|
||||
|
||||
const onExport = () => exportOrgDetail(rows, cny, t);
|
||||
|
||||
return (
|
||||
<SectionCard
|
||||
id='org-report-detail'
|
||||
title={t('企业明细')}
|
||||
icon={<Table2 className='w-5 h-5' />}
|
||||
extra={
|
||||
<span className='text-xs text-gray-400 tabular-nums'>
|
||||
{filtered
|
||||
? t('筛选 {{count}} / 共 {{total}} 家', {
|
||||
count: rows.length,
|
||||
total: orgs.length,
|
||||
})
|
||||
: t('共 {{total}} 家', { total: orgs.length })}
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<div className='flex flex-wrap items-center gap-2 mb-3'>
|
||||
<Input
|
||||
prefix={<Search className='w-4 h-4 ml-2 text-gray-400' />}
|
||||
placeholder={t('搜索企业名称或代码')}
|
||||
value={filter.keyword}
|
||||
onChange={set('keyword')}
|
||||
showClear
|
||||
style={{ width: 220 }}
|
||||
/>
|
||||
<Select
|
||||
placeholder={t('健康分群')}
|
||||
value={filter.segment || undefined}
|
||||
onChange={set('segment')}
|
||||
showClear
|
||||
style={{ width: 130 }}
|
||||
optionList={Object.entries(SEGMENTS).map(([k, v]) => ({
|
||||
value: k,
|
||||
label: t(v.label),
|
||||
}))}
|
||||
/>
|
||||
<Select
|
||||
placeholder={t('价值层级')}
|
||||
value={filter.tier || undefined}
|
||||
onChange={set('tier')}
|
||||
showClear
|
||||
style={{ width: 110 }}
|
||||
optionList={Object.entries(TIERS).map(([k, v]) => ({
|
||||
value: k,
|
||||
label: t(v.label),
|
||||
}))}
|
||||
/>
|
||||
<Select
|
||||
placeholder={t('余额预警')}
|
||||
value={filter.alert || undefined}
|
||||
onChange={set('alert')}
|
||||
showClear
|
||||
style={{ width: 130 }}
|
||||
optionList={[
|
||||
{ value: '__any__', label: t('全部预警') },
|
||||
...Object.entries(ALERT_LEVELS).map(([k, v]) => ({
|
||||
value: k,
|
||||
label: t(v.label),
|
||||
})),
|
||||
]}
|
||||
/>
|
||||
<Select
|
||||
placeholder={t('跟进人')}
|
||||
value={filter.salesRep || undefined}
|
||||
onChange={set('salesRep')}
|
||||
showClear
|
||||
filter
|
||||
style={{ width: 130 }}
|
||||
optionList={reps.map((r) => ({
|
||||
value: r,
|
||||
label: r === '__none__' ? t('未分配') : r,
|
||||
}))}
|
||||
/>
|
||||
{filtered ? (
|
||||
<Button
|
||||
type='tertiary'
|
||||
onClick={() => setFilter(EMPTY_DETAIL_FILTER)}
|
||||
>
|
||||
{t('重置')}
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
className='ml-auto'
|
||||
icon={<Download className='w-4 h-4' />}
|
||||
onClick={onExport}
|
||||
disabled={rows.length === 0}
|
||||
>
|
||||
{t('导出')}
|
||||
</Button>
|
||||
</div>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={rows}
|
||||
rowKey='org_id'
|
||||
size='small'
|
||||
scroll={{ x: 1480 }}
|
||||
pagination={{
|
||||
pageSize: 20,
|
||||
showSizeChanger: true,
|
||||
pageSizeOpts: [20, 50, 100],
|
||||
}}
|
||||
empty={
|
||||
<Empty
|
||||
description={filtered ? t('没有符合筛选条件的企业') : t('暂无企业')}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SectionCard>
|
||||
);
|
||||
};
|
||||
|
||||
export const exportOrgDetail = (rows, cny, t) => {
|
||||
const yuan = (v) => quotaToCny(v, cny).toFixed(2);
|
||||
downloadCsv(
|
||||
`${t('企业经营明细')}-${formatCst(Date.now() / 1000, false)}.csv`,
|
||||
[
|
||||
t('企业ID'),
|
||||
t('企业'),
|
||||
t('企业代码'),
|
||||
t('状态'),
|
||||
t('跟进人'),
|
||||
t('层级'),
|
||||
t('健康分群'),
|
||||
t('本期消耗'),
|
||||
t('对比期消耗'),
|
||||
t('变化率'),
|
||||
t('占比'),
|
||||
t('请求数'),
|
||||
t('活跃成员'),
|
||||
t('成员数'),
|
||||
t('余额'),
|
||||
t('赠送余额'),
|
||||
t('近7日日均消耗'),
|
||||
t('预计可用天数'),
|
||||
t('建议充值'),
|
||||
t('余额预警'),
|
||||
t('最近使用'),
|
||||
t('创建时间'),
|
||||
t('到期时间'),
|
||||
t('联系人'),
|
||||
t('联系电话'),
|
||||
],
|
||||
rows.map((o) => {
|
||||
const rate = changeRate(o.quota, o.prev_quota);
|
||||
return [
|
||||
o.org_id,
|
||||
orgDisplayName(o, t),
|
||||
o.code,
|
||||
ORG_STATUS[o.status] ? t(ORG_STATUS[o.status].label) : o.status,
|
||||
o.sales_rep,
|
||||
o.tier,
|
||||
SEGMENTS[o.segment] ? t(SEGMENTS[o.segment].label) : '',
|
||||
yuan(o.quota),
|
||||
yuan(o.prev_quota),
|
||||
rate === null ? '' : `${rate.toFixed(1)}%`,
|
||||
o.share ? `${o.share.toFixed(2)}%` : '',
|
||||
o.requests,
|
||||
o.active_members,
|
||||
o.member_count,
|
||||
yuan(o.balance),
|
||||
yuan(o.gift_quota),
|
||||
yuan(o.daily_avg),
|
||||
o.days_left < 0 ? '' : o.days_left.toFixed(1),
|
||||
yuan(o.topup_suggest),
|
||||
ALERT_LEVELS[o.alert_level] ? t(ALERT_LEVELS[o.alert_level].label) : '',
|
||||
o.last_active ? formatCst(o.last_active) : '',
|
||||
formatCst(o.created_at, false),
|
||||
o.expired_at > 0 ? formatCst(o.expired_at, false) : '',
|
||||
o.contact_name,
|
||||
o.contact_phone,
|
||||
];
|
||||
}),
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
import { Button, Card, Typography } from '@douyinfe/semi-ui';
|
||||
import { ActionCenter, ACTION_TABS } from './ActionCenter';
|
||||
import {
|
||||
ChangeAttribution,
|
||||
TiersAndRankings,
|
||||
TopModels,
|
||||
TrendChart,
|
||||
} from './Analysis';
|
||||
import { HealthSegments, KeyFindings, KpiGrid, ReportHeader } from './Overview';
|
||||
import { SectionTitle } from './shared';
|
||||
import {
|
||||
EMPTY_DETAIL_FILTER,
|
||||
exportOrgDetail,
|
||||
OrgDetailTable,
|
||||
SalesRepTable,
|
||||
} from './Tables';
|
||||
import {
|
||||
deriveActionLists,
|
||||
deriveFindings,
|
||||
deriveSalesReps,
|
||||
getCnyParams,
|
||||
} from './utils';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 页签内锚点跳转:顶栏与跑马灯为 fixed,元素上已加 scroll-mt 让位
|
||||
const scrollToId = (id) => {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
};
|
||||
|
||||
const ReportSkeleton = () => (
|
||||
<div className='space-y-4'>
|
||||
<div className='h-[92px] rounded-xl bg-gray-100 dark:bg-gray-800 animate-pulse' />
|
||||
<div className='h-[160px] rounded-xl bg-gray-100 dark:bg-gray-800 animate-pulse' />
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3'>
|
||||
{Array.from({ length: 8 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className='h-[96px] rounded-xl bg-gray-100 dark:bg-gray-800 animate-pulse'
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
const OrgReportPanel = ({ report, loading, error, onRetry, t }) => {
|
||||
const cny = useMemo(getCnyParams, []);
|
||||
const [actionTab, setActionTab] = useState('renewal');
|
||||
const [detailFilter, setDetailFilter] = useState(EMPTY_DETAIL_FILTER);
|
||||
|
||||
const lists = useMemo(
|
||||
() => deriveActionLists(report?.orgs, report?.meta),
|
||||
[report],
|
||||
);
|
||||
const findings = useMemo(
|
||||
() => deriveFindings(report, lists, cny, t),
|
||||
[report, lists, cny, t],
|
||||
);
|
||||
const reps = useMemo(
|
||||
() => deriveSalesReps(report?.orgs, lists),
|
||||
[report, lists],
|
||||
);
|
||||
|
||||
const jump = useCallback((target) => {
|
||||
if (ACTION_TABS.includes(target)) {
|
||||
setActionTab(target);
|
||||
scrollToId('org-report-actions');
|
||||
return;
|
||||
}
|
||||
scrollToId(`org-report-${target}`);
|
||||
}, []);
|
||||
|
||||
const filterDetail = useCallback((patch) => {
|
||||
setDetailFilter({ ...EMPTY_DETAIL_FILTER, ...patch });
|
||||
scrollToId('org-report-detail');
|
||||
}, []);
|
||||
|
||||
if (!report) {
|
||||
if (error) {
|
||||
return (
|
||||
<Card className='shadow-sm'>
|
||||
<div className='py-12 flex flex-col items-center gap-3'>
|
||||
<Text type='danger'>{t('企业经营报表加载失败,请稍后重试')}</Text>
|
||||
<Button onClick={onRetry} loading={loading}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
return <ReportSkeleton />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={
|
||||
loading
|
||||
? 'opacity-60 transition-opacity pointer-events-none'
|
||||
: 'transition-opacity'
|
||||
}
|
||||
>
|
||||
<ReportHeader
|
||||
report={report}
|
||||
onExport={() => exportOrgDetail(report.orgs || [], cny, t)}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<KeyFindings findings={findings} onJump={jump} t={t} />
|
||||
|
||||
<SectionTitle
|
||||
index={1}
|
||||
title={t('核心指标')}
|
||||
desc={t('本期对比等长对比期;点击卡片定位到相关分析')}
|
||||
/>
|
||||
<KpiGrid report={report} lists={lists} cny={cny} onJump={jump} t={t} />
|
||||
|
||||
<SectionTitle
|
||||
index={2}
|
||||
title={t('客户健康分群')}
|
||||
desc={t('按本期与对比期的使用变化划分,点击分群筛选企业明细')}
|
||||
/>
|
||||
<HealthSegments
|
||||
report={report}
|
||||
cny={cny}
|
||||
activeSegment={detailFilter.segment}
|
||||
onSelect={(segment) =>
|
||||
segment
|
||||
? filterDetail({ segment })
|
||||
: setDetailFilter(EMPTY_DETAIL_FILTER)
|
||||
}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<SectionTitle
|
||||
index={3}
|
||||
title={t('行动清单')}
|
||||
desc={t('续费、挽回、增长、激活四类待办,含建议动作与联系人')}
|
||||
/>
|
||||
<ActionCenter
|
||||
lists={lists}
|
||||
activeTab={actionTab}
|
||||
onTabChange={setActionTab}
|
||||
cny={cny}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<SectionTitle
|
||||
index={4}
|
||||
title={t('变化归因')}
|
||||
desc={t('本期相对对比期的消耗变化由哪些企业、哪些分群贡献')}
|
||||
/>
|
||||
<ChangeAttribution report={report} cny={cny} t={t} />
|
||||
|
||||
<SectionTitle
|
||||
index={5}
|
||||
title={t('客户结构')}
|
||||
desc={t('ABC 价值分层与头部企业')}
|
||||
/>
|
||||
<TiersAndRankings
|
||||
report={report}
|
||||
cny={cny}
|
||||
onSelectTier={(tier) => filterDetail({ tier })}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<SectionTitle index={6} title={t('趋势与模型')} />
|
||||
<div className='grid grid-cols-1 xl:grid-cols-2 gap-4'>
|
||||
<TrendChart report={report} cny={cny} t={t} />
|
||||
<TopModels report={report} cny={cny} t={t} />
|
||||
</div>
|
||||
|
||||
<SectionTitle index={7} title={t('团队与明细')} />
|
||||
<div className='space-y-4 mb-6'>
|
||||
<SalesRepTable
|
||||
reps={reps}
|
||||
cny={cny}
|
||||
onSelect={(salesRep) => filterDetail({ salesRep })}
|
||||
t={t}
|
||||
/>
|
||||
<OrgDetailTable
|
||||
report={report}
|
||||
filter={detailFilter}
|
||||
setFilter={setDetailFilter}
|
||||
cny={cny}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrgReportPanel;
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card, Tag, Tooltip } from '@douyinfe/semi-ui';
|
||||
import { TrendingDown, TrendingUp } from 'lucide-react';
|
||||
import { changeRate, ORG_STATUS, orgDisplayName, REASONS } from './utils';
|
||||
|
||||
export const SectionCard = ({
|
||||
id,
|
||||
title,
|
||||
icon,
|
||||
extra,
|
||||
children,
|
||||
bodyStyle,
|
||||
}) => (
|
||||
<Card
|
||||
id={id}
|
||||
className='shadow-sm h-full scroll-mt-24'
|
||||
title={
|
||||
<div className='flex items-center gap-2 flex-wrap min-w-0'>
|
||||
<span className='text-brand flex-shrink-0'>{icon}</span>
|
||||
<span className='font-semibold'>{title}</span>
|
||||
{extra}
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: '16px', ...bodyStyle }}
|
||||
>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
|
||||
export const SectionTitle = ({ id, index, title, desc }) => (
|
||||
<div
|
||||
id={id}
|
||||
className='flex items-baseline gap-2 mb-3 mt-8 flex-wrap scroll-mt-24'
|
||||
>
|
||||
{index ? (
|
||||
<span className='text-xs font-semibold tracking-wider text-brand tabular-nums'>
|
||||
{String(index).padStart(2, '0')}
|
||||
</span>
|
||||
) : null}
|
||||
<h3 className='text-base font-semibold text-gray-800 dark:text-gray-100'>
|
||||
{title}
|
||||
</h3>
|
||||
{desc ? (
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>{desc}</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
// 变化值:上升绿、下降红;对比期为 0 时无法计算
|
||||
export const ChangeText = ({ cur, prev, t, size = 'xs', showNew = true }) => {
|
||||
const rate = changeRate(cur, prev);
|
||||
const sizeClass = size === 'sm' ? 'text-sm' : 'text-xs';
|
||||
if (rate === null) {
|
||||
return cur > 0 && showNew ? (
|
||||
<span className={`${sizeClass} text-gray-400`}>{t('对比期无数据')}</span>
|
||||
) : (
|
||||
<span className={`${sizeClass} text-gray-400`}>—</span>
|
||||
);
|
||||
}
|
||||
const up = rate >= 0;
|
||||
return (
|
||||
<span
|
||||
className={`inline-flex items-center gap-0.5 ${sizeClass} font-medium tabular-nums`}
|
||||
style={{
|
||||
color: up ? 'var(--semi-color-success)' : 'var(--semi-color-danger)',
|
||||
}}
|
||||
>
|
||||
{up ? (
|
||||
<TrendingUp className='w-3 h-3' />
|
||||
) : (
|
||||
<TrendingDown className='w-3 h-3' />
|
||||
)}
|
||||
{up ? '+' : ''}
|
||||
{rate.toFixed(1)}%
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export const KpiCard = ({
|
||||
title,
|
||||
value,
|
||||
sub,
|
||||
compare,
|
||||
tip,
|
||||
accent,
|
||||
onClick,
|
||||
}) => (
|
||||
<Card
|
||||
className={`shadow-sm border-none transition-shadow ${onClick ? 'cursor-pointer hover:shadow-md' : ''}`}
|
||||
bodyStyle={{ padding: '14px 16px' }}
|
||||
onClick={onClick}
|
||||
style={{
|
||||
borderLeft: `3px solid ${accent || 'var(--semi-color-primary)'}`,
|
||||
}}
|
||||
>
|
||||
<div className='flex items-center gap-1 text-xs text-gray-500 dark:text-gray-400 mb-1'>
|
||||
<span className='truncate'>{title}</span>
|
||||
{tip ? (
|
||||
<Tooltip content={tip}>
|
||||
<span className='cursor-help text-gray-400'>ⓘ</span>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</div>
|
||||
<div className='text-xl font-bold text-gray-800 dark:text-gray-100 tabular-nums truncate'>
|
||||
{value}
|
||||
</div>
|
||||
<div className='flex items-center justify-between gap-2 mt-1 min-h-[18px]'>
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400 truncate'>
|
||||
{sub}
|
||||
</span>
|
||||
{compare}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
export const OrgNameCell = ({ org, t, showCode = true }) => {
|
||||
const name = orgDisplayName(org, t);
|
||||
const status = ORG_STATUS[org.status];
|
||||
return (
|
||||
<div className='min-w-0'>
|
||||
<div className='flex items-center gap-1.5 min-w-0'>
|
||||
<span className='font-medium truncate' title={name}>
|
||||
{name}
|
||||
</span>
|
||||
{!org.deleted && status && org.status !== 1 ? (
|
||||
<Tag size='small' color={status.color} className='flex-shrink-0'>
|
||||
{t(status.label)}
|
||||
</Tag>
|
||||
) : null}
|
||||
</div>
|
||||
{showCode && org.code ? (
|
||||
<div className='text-xs text-gray-400 truncate'>{org.code}</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const ReasonTags = ({ reasons, t }) => (
|
||||
<div className='flex flex-wrap gap-1'>
|
||||
{(reasons || []).map((r) => (
|
||||
<Tag key={r} size='small' color={REASONS[r]?.color || 'grey'}>
|
||||
{t(REASONS[r]?.label || r)}
|
||||
</Tag>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
export const EmptyBlock = ({ height = 240, text }) => (
|
||||
<div
|
||||
className='flex items-center justify-center text-gray-400 text-sm'
|
||||
style={{ height }}
|
||||
>
|
||||
{text}
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
// 企业经营决策报表:口径常量、行动清单派生、要点生成、CSV 导出
|
||||
|
||||
// ─── 金额 ───────────────────────────────────────────────────────
|
||||
// 货币统一显示人民币:额度 → CNY = quota / quota_per_unit × usd_exchange_rate
|
||||
export const getCnyParams = () => {
|
||||
let quotaPerUnit = parseFloat(localStorage.getItem('quota_per_unit'));
|
||||
if (!quotaPerUnit || quotaPerUnit <= 0) quotaPerUnit = 500000;
|
||||
let usdRate = 1;
|
||||
try {
|
||||
const s = JSON.parse(localStorage.getItem('status') || '{}');
|
||||
usdRate = s?.usd_exchange_rate || 1;
|
||||
} catch (e) {
|
||||
usdRate = 1;
|
||||
}
|
||||
return { quotaPerUnit, usdRate };
|
||||
};
|
||||
|
||||
export const quotaToCny = (quota, { quotaPerUnit, usdRate }) =>
|
||||
((quota || 0) / quotaPerUnit) * usdRate;
|
||||
|
||||
export const formatCny = (quota, params, digits = 2) =>
|
||||
`¥${quotaToCny(quota, params).toLocaleString(undefined, {
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: digits,
|
||||
})}`;
|
||||
|
||||
// 环比(%);对比期为 0 时无法计算返回 null
|
||||
export const changeRate = (cur, prev) =>
|
||||
prev > 0 ? (((cur || 0) - prev) / prev) * 100 : null;
|
||||
|
||||
export const formatRate = (rate) =>
|
||||
rate === null || rate === undefined
|
||||
? '—'
|
||||
: `${rate >= 0 ? '+' : ''}${rate.toFixed(1)}%`;
|
||||
|
||||
export const pct = (part, total) => (total > 0 ? (part / total) * 100 : 0);
|
||||
|
||||
// ─── 时间(报表口径统一为 UTC+8,与浏览器时区无关) ─────────────────
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
export const formatCst = (ts, withTime = true) => {
|
||||
if (!ts) return '—';
|
||||
const d = new Date((ts + 8 * 3600) * 1000);
|
||||
const date = `${d.getUTCFullYear()}-${pad(d.getUTCMonth() + 1)}-${pad(d.getUTCDate())}`;
|
||||
return withTime
|
||||
? `${date} ${pad(d.getUTCHours())}:${pad(d.getUTCMinutes())}`
|
||||
: date;
|
||||
};
|
||||
|
||||
export const daysSince = (ts, now = Date.now() / 1000) =>
|
||||
ts > 0 ? Math.max(0, Math.floor((now - ts) / 86400)) : null;
|
||||
|
||||
// ─── 标签字典 ────────────────────────────────────────────────────
|
||||
export const ORG_STATUS = {
|
||||
1: { label: '正常', color: 'green' },
|
||||
2: { label: '冻结', color: 'grey' },
|
||||
3: { label: '欠费', color: 'red' },
|
||||
4: { label: '待激活', color: 'blue' },
|
||||
};
|
||||
|
||||
export const SEGMENTS = {
|
||||
new: { label: '新客起量', color: 'cyan', desc: '本期首次使用' },
|
||||
growing: { label: '增长', color: 'green', desc: '消耗环比增长 ≥ 20%' },
|
||||
stable: { label: '稳定', color: 'blue', desc: '消耗环比波动 < 20%' },
|
||||
recovered: { label: '回流', color: 'teal', desc: '对比期无使用,本期恢复' },
|
||||
declining: { label: '下滑', color: 'orange', desc: '消耗环比下降 ≥ 20%' },
|
||||
stopped: { label: '停用', color: 'red', desc: '对比期有使用,本期无使用' },
|
||||
dormant: { label: '沉睡', color: 'grey', desc: '两期均无使用,历史用过' },
|
||||
never_used: {
|
||||
label: '从未使用',
|
||||
color: 'violet',
|
||||
desc: '开通后从未产生调用',
|
||||
},
|
||||
pending: { label: '待激活', color: 'light-blue', desc: '等待平台激活' },
|
||||
frozen: { label: '冻结', color: 'grey', desc: '已被冻结' },
|
||||
};
|
||||
|
||||
export const ALERT_LEVELS = {
|
||||
exhausted: { label: '余额耗尽', color: 'red', rank: 0 },
|
||||
critical: { label: '3 天内耗尽', color: 'orange', rank: 1 },
|
||||
threshold: { label: '低于预警线', color: 'amber', rank: 2 },
|
||||
warning: { label: '即将不足', color: 'yellow', rank: 3 },
|
||||
};
|
||||
|
||||
export const TIERS = {
|
||||
A: { label: 'A 类', color: 'red', desc: '累计贡献前 80% 消耗' },
|
||||
B: { label: 'B 类', color: 'orange', desc: '累计贡献 80%~95%' },
|
||||
C: { label: 'C 类', color: 'grey', desc: '其余长尾企业' },
|
||||
};
|
||||
|
||||
// 行动原因 → 标签与建议动作(顺序即优先级)
|
||||
export const REASONS = {
|
||||
exhausted: {
|
||||
label: '余额耗尽',
|
||||
color: 'red',
|
||||
action: '立即联系充值,避免业务中断',
|
||||
},
|
||||
critical: { label: '3 天内耗尽', color: 'orange', action: '3 天内跟进续费' },
|
||||
expired: { label: '合同已到期', color: 'red', action: '确认续约方案' },
|
||||
threshold: {
|
||||
label: '低于预警线',
|
||||
color: 'amber',
|
||||
action: '提醒企业补充余额',
|
||||
},
|
||||
warning: { label: '即将不足', color: 'yellow', action: '本周内沟通续费计划' },
|
||||
expiring: { label: '30 天内到期', color: 'orange', action: '推进续约' },
|
||||
stopped: { label: '本期停用', color: 'red', action: '回访了解停用原因' },
|
||||
sharp_decline: {
|
||||
label: '近 7 日腰斩',
|
||||
color: 'red',
|
||||
action: '回访排查使用下降原因',
|
||||
},
|
||||
declining: {
|
||||
label: '消耗下滑',
|
||||
color: 'orange',
|
||||
action: '回访排查使用下降原因',
|
||||
},
|
||||
dormant: {
|
||||
label: '近期沉睡',
|
||||
color: 'grey',
|
||||
action: '唤醒沟通,推送新模型与新功能',
|
||||
},
|
||||
fast_growth: {
|
||||
label: '高速增长',
|
||||
color: 'green',
|
||||
action: '跟进扩容与年度方案',
|
||||
},
|
||||
growing: { label: '稳步增长', color: 'green', action: '跟进扩容与年度方案' },
|
||||
new: { label: '新客起量', color: 'cyan', action: '新客关怀,确认使用顺畅' },
|
||||
recovered: { label: '回流', color: 'teal', action: '回流客户关怀,巩固使用' },
|
||||
low_penetration: {
|
||||
label: '成员渗透低',
|
||||
color: 'violet',
|
||||
action: '推动内部推广、组织培训',
|
||||
},
|
||||
pending: { label: '待激活', color: 'light-blue', action: '协助完成企业激活' },
|
||||
never_used: {
|
||||
label: '开通未使用',
|
||||
color: 'violet',
|
||||
action: '引导创建令牌、完成首次调用',
|
||||
},
|
||||
};
|
||||
|
||||
const isServing = (o) => !o.deleted && (o.status === 1 || o.status === 3);
|
||||
|
||||
// ─── 行动清单 ────────────────────────────────────────────────────
|
||||
const withReasons = (o, reasons) => ({
|
||||
...o,
|
||||
reasons,
|
||||
action: reasons.length ? REASONS[reasons[0]].action : '',
|
||||
});
|
||||
|
||||
export const deriveActionLists = (orgs, meta) => {
|
||||
const renewal = [];
|
||||
const retention = [];
|
||||
const growth = [];
|
||||
const activation = [];
|
||||
// 沉睡只关注「最近 60 天内还用过」的,太久远的不值得逐个跟进
|
||||
const dormantCutoff = (meta?.start || 0) - 60 * 86400;
|
||||
|
||||
(orgs || []).forEach((o) => {
|
||||
if (o.deleted) return;
|
||||
const flags = o.flags || [];
|
||||
|
||||
// 续费跟进
|
||||
if (isServing(o)) {
|
||||
const r = [];
|
||||
if (o.alert_level) r.push(o.alert_level);
|
||||
if (flags.includes('expired')) r.push('expired');
|
||||
if (flags.includes('expiring')) r.push('expiring');
|
||||
if (r.length) {
|
||||
r.sort(
|
||||
(a, b) =>
|
||||
Object.keys(REASONS).indexOf(a) - Object.keys(REASONS).indexOf(b),
|
||||
);
|
||||
renewal.push(withReasons(o, r));
|
||||
}
|
||||
}
|
||||
|
||||
// 流失挽回
|
||||
if (isServing(o)) {
|
||||
const r = [];
|
||||
if (o.segment === 'stopped') r.push('stopped');
|
||||
if (flags.includes('sharp_decline')) r.push('sharp_decline');
|
||||
if (o.segment === 'declining') r.push('declining');
|
||||
if (
|
||||
o.segment === 'dormant' &&
|
||||
o.last_active >= dormantCutoff &&
|
||||
o.last_active > 0
|
||||
)
|
||||
r.push('dormant');
|
||||
if (r.length) retention.push(withReasons(o, r));
|
||||
}
|
||||
|
||||
// 增长机会
|
||||
if (isServing(o)) {
|
||||
const r = [];
|
||||
const rate = changeRate(o.quota, o.prev_quota);
|
||||
if (o.segment === 'growing')
|
||||
r.push(rate !== null && rate >= 50 ? 'fast_growth' : 'growing');
|
||||
if (o.segment === 'new') r.push('new');
|
||||
if (o.segment === 'recovered') r.push('recovered');
|
||||
if (flags.includes('low_penetration')) r.push('low_penetration');
|
||||
if (r.length) growth.push(withReasons(o, r));
|
||||
}
|
||||
|
||||
// 激活跟进
|
||||
if (
|
||||
o.segment === 'pending' ||
|
||||
(o.segment === 'never_used' && isServing(o))
|
||||
) {
|
||||
activation.push(withReasons(o, [o.segment]));
|
||||
}
|
||||
});
|
||||
|
||||
const reasonRank = (o) => Object.keys(REASONS).indexOf(o.reasons[0]);
|
||||
renewal.sort(
|
||||
(a, b) =>
|
||||
reasonRank(a) - reasonRank(b) ||
|
||||
(a.days_left < 0) - (b.days_left < 0) ||
|
||||
a.days_left - b.days_left ||
|
||||
b.daily_avg - a.daily_avg,
|
||||
);
|
||||
const atRisk = (o) =>
|
||||
Math.max(
|
||||
(o.prev_quota || 0) - (o.quota || 0),
|
||||
(o.prior7_quota || 0) - (o.recent7_quota || 0),
|
||||
);
|
||||
retention.sort((a, b) => atRisk(b) - atRisk(a));
|
||||
growth.sort((a, b) => (b.quota || 0) - (a.quota || 0));
|
||||
activation.sort((a, b) => (b.created_at || 0) - (a.created_at || 0));
|
||||
|
||||
return { renewal, retention, growth, activation, atRisk };
|
||||
};
|
||||
|
||||
// ─── 跟进人视图 ──────────────────────────────────────────────────
|
||||
export const deriveSalesReps = (orgs, lists) => {
|
||||
const idsOf = (list) => new Set(list.map((o) => o.org_id));
|
||||
const renewalIds = idsOf(lists.renewal);
|
||||
const retentionIds = idsOf(lists.retention);
|
||||
const growthIds = idsOf(lists.growth);
|
||||
const map = new Map();
|
||||
(orgs || []).forEach((o) => {
|
||||
if (o.deleted) return;
|
||||
const key = o.sales_rep || '';
|
||||
if (!map.has(key)) {
|
||||
map.set(key, {
|
||||
sales_rep: key,
|
||||
orgs: 0,
|
||||
active: 0,
|
||||
quota: 0,
|
||||
prev_quota: 0,
|
||||
renewal: 0,
|
||||
retention: 0,
|
||||
growth: 0,
|
||||
balance: 0,
|
||||
});
|
||||
}
|
||||
const r = map.get(key);
|
||||
r.orgs += 1;
|
||||
if (o.requests > 0) r.active += 1;
|
||||
r.quota += o.quota || 0;
|
||||
r.prev_quota += o.prev_quota || 0;
|
||||
r.balance += o.balance || 0;
|
||||
if (renewalIds.has(o.org_id)) r.renewal += 1;
|
||||
if (retentionIds.has(o.org_id)) r.retention += 1;
|
||||
if (growthIds.has(o.org_id)) r.growth += 1;
|
||||
});
|
||||
return Array.from(map.values()).sort((a, b) => b.quota - a.quota);
|
||||
};
|
||||
|
||||
// ─── 本期要点(结论先行) ────────────────────────────────────────
|
||||
// 返回 [{ level: 'danger'|'warning'|'success'|'info', text, target }],text 已翻译
|
||||
export const deriveFindings = (report, lists, cny, t) => {
|
||||
if (!report) return [];
|
||||
const k = report.kpi || {};
|
||||
const orgs = report.orgs || [];
|
||||
const out = [];
|
||||
const money = (q) => formatCny(q, cny, 0);
|
||||
|
||||
// 1. 消耗变化与主要贡献者
|
||||
const rate = changeRate(k.org_quota, k.prev_org_quota);
|
||||
const deltas = orgs
|
||||
.filter((o) => !o.deleted)
|
||||
.map((o) => ({ name: o.name, d: (o.quota || 0) - (o.prev_quota || 0) }));
|
||||
const up = deltas
|
||||
.filter((x) => x.d > 0)
|
||||
.sort((a, b) => b.d - a.d)
|
||||
.slice(0, 2);
|
||||
const down = deltas
|
||||
.filter((x) => x.d < 0)
|
||||
.sort((a, b) => a.d - b.d)
|
||||
.slice(0, 2);
|
||||
if (rate !== null) {
|
||||
const drivers = (rate >= 0 ? up : down)
|
||||
.map((x) => `${x.name} (${x.d > 0 ? '+' : '-'}${money(Math.abs(x.d))})`)
|
||||
.join(', ');
|
||||
const params = {
|
||||
amount: money(k.org_quota),
|
||||
rate: formatRate(rate),
|
||||
drivers,
|
||||
};
|
||||
let text;
|
||||
if (!drivers) {
|
||||
text = t('企业消耗 {{amount}},较对比期 {{rate}}', params);
|
||||
} else if (rate >= 0) {
|
||||
text = t(
|
||||
'企业消耗 {{amount}},较对比期 {{rate}},增长主要来自 {{drivers}}',
|
||||
params,
|
||||
);
|
||||
} else {
|
||||
text = t(
|
||||
'企业消耗 {{amount}},较对比期 {{rate}},下滑主要来自 {{drivers}}',
|
||||
params,
|
||||
);
|
||||
}
|
||||
out.push({
|
||||
level: rate >= 0 ? 'success' : 'warning',
|
||||
text,
|
||||
target: 'attribution',
|
||||
});
|
||||
} else if (k.org_quota > 0) {
|
||||
out.push({
|
||||
level: 'info',
|
||||
text: t('企业消耗 {{amount}},对比期无消耗数据', {
|
||||
amount: money(k.org_quota),
|
||||
}),
|
||||
target: 'attribution',
|
||||
});
|
||||
}
|
||||
|
||||
// 2. 续费风险
|
||||
const urgent = lists.renewal.filter((o) =>
|
||||
['exhausted', 'critical'].includes(o.alert_level),
|
||||
).length;
|
||||
if (lists.renewal.length > 0) {
|
||||
out.push({
|
||||
level: urgent > 0 ? 'danger' : 'warning',
|
||||
text: t(
|
||||
'{{count}} 家企业需续费跟进({{urgent}} 家已耗尽或 3 天内耗尽),未来 30 天充值缺口约 {{gap}}',
|
||||
{ count: lists.renewal.length, urgent, gap: money(k.topup_gap_30d) },
|
||||
),
|
||||
target: 'renewal',
|
||||
});
|
||||
}
|
||||
|
||||
// 3. 流失风险
|
||||
if (lists.retention.length > 0) {
|
||||
const exposure = lists.retention.reduce((s, o) => s + lists.atRisk(o), 0);
|
||||
out.push({
|
||||
level: 'warning',
|
||||
text: t(
|
||||
'{{count}} 家企业存在流失风险(停用 / 下滑 / 沉睡),涉及消耗减少约 {{amount}}',
|
||||
{
|
||||
count: lists.retention.length,
|
||||
amount: money(exposure),
|
||||
},
|
||||
),
|
||||
target: 'retention',
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 本月预测
|
||||
if (k.month_to_date > 0 || k.last_month_quota > 0) {
|
||||
const mRate = changeRate(k.month_forecast, k.last_month_quota);
|
||||
out.push({
|
||||
level: mRate !== null && mRate < 0 ? 'warning' : 'info',
|
||||
text: t(
|
||||
'按近 7 日日均 {{runRate}} 推算,本月企业消耗预计 {{forecast}},上月 {{last}}({{rate}})',
|
||||
{
|
||||
runRate: money(k.run_rate_daily),
|
||||
forecast: money(k.month_forecast),
|
||||
last: money(k.last_month_quota),
|
||||
rate: formatRate(mRate),
|
||||
},
|
||||
),
|
||||
target: 'kpi',
|
||||
});
|
||||
}
|
||||
|
||||
// 5. 集中度
|
||||
if (k.org_quota > 0 && k.active_orgs >= 5) {
|
||||
out.push({
|
||||
level: k.top5_share >= 60 ? 'warning' : 'info',
|
||||
text:
|
||||
k.top5_share >= 60
|
||||
? t(
|
||||
'头部依赖较高:Top5 企业贡献 {{share}} 的企业消耗,需关注大客户稳定性',
|
||||
{
|
||||
share: `${k.top5_share.toFixed(1)}%`,
|
||||
},
|
||||
)
|
||||
: t('客户结构较分散:Top5 企业贡献 {{share}} 的企业消耗', {
|
||||
share: `${k.top5_share.toFixed(1)}%`,
|
||||
}),
|
||||
target: 'tiers',
|
||||
});
|
||||
}
|
||||
|
||||
// 6. 渗透与激活
|
||||
const lowPen = lists.growth.filter((o) =>
|
||||
o.reasons.includes('low_penetration'),
|
||||
).length;
|
||||
const penetration = pct(k.active_members, k.total_members);
|
||||
if (k.total_members > 0 && (penetration < 50 || lowPen > 0)) {
|
||||
out.push({
|
||||
level: 'info',
|
||||
text: t(
|
||||
'企业成员渗透率 {{rate}},{{count}} 家企业成员活跃率低于 30%,存在增量空间',
|
||||
{
|
||||
rate: `${Math.min(100, penetration).toFixed(1)}%`,
|
||||
count: lowPen,
|
||||
},
|
||||
),
|
||||
target: 'growth',
|
||||
});
|
||||
}
|
||||
if (lists.activation.length > 0) {
|
||||
out.push({
|
||||
level: 'info',
|
||||
text: t('{{count}} 家企业待激活或开通后从未使用,建议安排激活跟进', {
|
||||
count: lists.activation.length,
|
||||
}),
|
||||
target: 'activation',
|
||||
});
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
// ─── CSV 导出(带 BOM,Excel 直接打开不乱码) ─────────────────────
|
||||
export const downloadCsv = (filename, headers, rows) => {
|
||||
const escape = (v) => {
|
||||
const s = v === null || v === undefined ? '' : String(v);
|
||||
return /[",\n\r]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
|
||||
};
|
||||
const lines = [headers.map(escape).join(',')];
|
||||
rows.forEach((r) => lines.push(r.map(escape).join(',')));
|
||||
const blob = new Blob(['' + lines.join('\r\n')], {
|
||||
type: 'text/csv;charset=utf-8;',
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
export const orgDisplayName = (o, t) =>
|
||||
o.deleted ? `${t('已删除企业')} #${o.org_id}` : o.name || `#${o.org_id}`;
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Sparkles } from 'lucide-react';
|
||||
|
||||
/**
|
||||
* 登录/注册/企业登录页卡片顶部的「品牌 Logo + 标题 + 副标题」头部。
|
||||
*
|
||||
* 这一段(Logo 光环 + 白底圆角 + 右上角 Sparkles + h4 标题 + p 副标题)原本在
|
||||
* LoginForm / RegisterForm / OrgLogin 中重复了 5 份,抽到这里统一维护,避免日后样式漂移。
|
||||
*
|
||||
* - logoNode:自定义 Logo 节点(如企业 Avatar);不传则用 logo(src) 渲染平台 <img>。
|
||||
* - wrapperClassName / logoWrapperClassName:保留各页面原有的间距微调(mb-*)。
|
||||
* - Sparkles 统一用 motion-safe:animate-pulse,遵循 prefers-reduced-motion。
|
||||
*/
|
||||
const AuthCardHeader = ({
|
||||
title,
|
||||
subtitle,
|
||||
logo,
|
||||
logoNode,
|
||||
wrapperClassName = 'mb-5',
|
||||
logoWrapperClassName = 'mb-3',
|
||||
}) => (
|
||||
<div
|
||||
className={`flex flex-col items-center justify-center ${wrapperClassName}`}
|
||||
>
|
||||
<div className={`relative ${logoWrapperClassName}`}>
|
||||
{/* Logo 光环 */}
|
||||
<div className='absolute -inset-1.5 bg-gradient-to-r from-brand-from/30 to-brand-to/30 rounded-xl blur-md opacity-60' />
|
||||
<div className='relative p-2 bg-white dark:bg-neutral-800 rounded-xl shadow-md'>
|
||||
{logoNode || (
|
||||
<img
|
||||
src={logo}
|
||||
alt='Logo'
|
||||
className='h-10 w-10 rounded-lg object-cover'
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<Sparkles
|
||||
size={14}
|
||||
className='absolute -top-0.5 -right-0.5 text-amber-400 motion-safe:animate-pulse'
|
||||
/>
|
||||
</div>
|
||||
<h4 className='text-xl font-bold text-gray-800 dark:text-white tracking-tight mb-0.5'>
|
||||
{title}
|
||||
</h4>
|
||||
<p className='text-gray-500 dark:text-gray-400 text-xs'>{subtitle}</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default AuthCardHeader;
|
||||
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Avatar } from '@douyinfe/semi-ui';
|
||||
import { MessageCircle, ScanLine } from 'lucide-react';
|
||||
import { API } from '../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/**
|
||||
* 登录/注册页面的客服浮窗
|
||||
* 右上角固定展示客服二维码,始终可见
|
||||
*/
|
||||
const AuthCustomerServiceFloat = () => {
|
||||
const { t } = useTranslation();
|
||||
const [agent, setAgent] = useState(null);
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [qrcodeError, setQrcodeError] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchAgent = async () => {
|
||||
try {
|
||||
const configRes = await API.get('/api/customer-service/config');
|
||||
if (!configRes.data.success || !configRes.data.data?.enabled) return;
|
||||
|
||||
const agentRes = await API.get('/api/customer-service/display');
|
||||
if (agentRes.data.success && agentRes.data.data) {
|
||||
const data = agentRes.data.data;
|
||||
if (data.qrcode_url || data.wecom_url) {
|
||||
setAgent(data);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// 静默处理,不影响登录页
|
||||
}
|
||||
};
|
||||
fetchAgent();
|
||||
}, []);
|
||||
|
||||
if (!visible || !agent) return null;
|
||||
|
||||
const hasQrcode = agent.qrcode_url && !qrcodeError;
|
||||
|
||||
return (
|
||||
<div className='fixed top-28 right-5 z-[200] w-52'>
|
||||
<style>{`
|
||||
.auth-cs-glass-card {
|
||||
box-shadow:
|
||||
0 20px 45px -15px rgba(15, 42, 80, 0.25),
|
||||
0 8px 20px -8px rgb(var(--brand-primary-rgb) / 0.18),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7),
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
.dark .auth-cs-glass-card {
|
||||
box-shadow:
|
||||
0 20px 45px -15px rgba(0, 0, 0, 0.6),
|
||||
0 10px 24px -8px rgb(var(--brand-primary-rgb) / 0.22),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.1),
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
.auth-cs-aurora {
|
||||
top: -30%;
|
||||
left: -20%;
|
||||
width: 90%;
|
||||
height: 90%;
|
||||
background: radial-gradient(ellipse at center, rgb(var(--brand-primary-rgb) / 0.18) 0%, transparent 70%);
|
||||
animation: authCsAurora 18s ease-in-out infinite;
|
||||
}
|
||||
.dark .auth-cs-aurora {
|
||||
background: radial-gradient(ellipse at center, rgb(var(--brand-primary-rgb) / 0.22) 0%, transparent 70%);
|
||||
}
|
||||
@keyframes authCsAurora {
|
||||
0%, 100% { transform: translate(0%, 0%); }
|
||||
50% { transform: translate(20%, 18%); }
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.auth-cs-glass-card {
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.auth-cs-aurora,
|
||||
.auth-cs-glass-card { animation: none; transition: none; }
|
||||
}
|
||||
`}</style>
|
||||
{/* 外层柔光晕 - 增强浮空立体感 */}
|
||||
<div className='absolute -inset-3 bg-gradient-to-br from-brand-from/15 via-brand-via/10 to-brand-to/15 rounded-3xl blur-xl opacity-80 pointer-events-none' />
|
||||
|
||||
{/* 展示面板 - 玻璃拟态立体效果 */}
|
||||
<div
|
||||
className='
|
||||
auth-cs-glass-card relative isolate
|
||||
backdrop-blur-2xl rounded-xl overflow-hidden
|
||||
ring-1 ring-white/50 dark:ring-white/[0.06]
|
||||
border border-white/30 dark:border-white/[0.05]
|
||||
bg-white/55 dark:bg-neutral-900/55
|
||||
transition-[transform,box-shadow] duration-500 ease-out
|
||||
hover:scale-[1.01]
|
||||
'
|
||||
>
|
||||
{/* 内层 aurora - 缓慢漂移品牌色辉光 */}
|
||||
<div className='auth-cs-aurora absolute -z-10 pointer-events-none' />
|
||||
|
||||
{/* 顶部渐变装饰线 */}
|
||||
<div className='h-0.5 bg-gradient-to-r from-brand-from via-brand-via to-brand-to' />
|
||||
|
||||
{/* 顶部高光反射 - 位于装饰线下方,模拟玻璃反光 */}
|
||||
<div className='absolute top-0.5 left-[15%] right-[15%] h-px bg-gradient-to-r from-transparent via-white/90 dark:via-white/40 to-transparent pointer-events-none' />
|
||||
|
||||
<div className='p-3'>
|
||||
{/* 客服信息 */}
|
||||
<div className='flex items-center gap-2 mb-2.5'>
|
||||
{agent.avatar ? (
|
||||
<Avatar
|
||||
src={agent.avatar}
|
||||
size='extra-small'
|
||||
className='!w-7 !h-7 flex-shrink-0'
|
||||
/>
|
||||
) : (
|
||||
<div className='w-7 h-7 rounded-full bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center flex-shrink-0'>
|
||||
<MessageCircle size={13} className='text-white' />
|
||||
</div>
|
||||
)}
|
||||
<div className='flex-1 min-w-0'>
|
||||
<div className='flex items-center gap-1'>
|
||||
<span className='text-xs font-semibold text-gray-800 dark:text-white truncate'>
|
||||
{agent.name || t('在线客服')}
|
||||
</span>
|
||||
<span className='inline-flex items-center gap-0.5 px-1 py-px bg-emerald-50 dark:bg-emerald-900/30 rounded-full flex-shrink-0'>
|
||||
<span className='w-1 h-1 bg-emerald-500 rounded-full animate-pulse' />
|
||||
<span className='text-[9px] text-emerald-600 dark:text-emerald-400 font-medium'>
|
||||
{t('在线')}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 提示文案 */}
|
||||
<p className='text-[11px] text-gray-500 dark:text-gray-400 mb-2.5 leading-relaxed'>
|
||||
{t('登录遇到问题?扫码咨询客服解决')}
|
||||
</p>
|
||||
|
||||
{/* 二维码 - 始终展示 */}
|
||||
{hasQrcode ? (
|
||||
<div className='flex flex-col items-center'>
|
||||
<div className='w-full p-2 bg-white dark:bg-neutral-800/60 rounded-lg border border-gray-100 dark:border-neutral-700/50'>
|
||||
<img
|
||||
src={agent.qrcode_url}
|
||||
alt={t('客服二维码')}
|
||||
className='w-full aspect-square object-contain rounded'
|
||||
onError={() => setQrcodeError(true)}
|
||||
/>
|
||||
</div>
|
||||
<div className='mt-2 flex items-center gap-1 text-[10px] text-brand-deep dark:text-brand-from font-medium'>
|
||||
<ScanLine size={10} />
|
||||
<span>{t('微信扫码添加客服')}</span>
|
||||
</div>
|
||||
</div>
|
||||
) : agent.wecom_url ? (
|
||||
<button
|
||||
onClick={() => window.open(agent.wecom_url, '_blank')}
|
||||
className='w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-gradient-to-r from-brand-from to-brand-to hover:from-brand-from hover:to-brand-to text-white text-xs font-medium rounded-lg transition-colors'
|
||||
>
|
||||
<MessageCircle size={12} />
|
||||
{t('联系客服')}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuthCustomerServiceFloat;
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/**
|
||||
* 认证页「个人 / 企业」分段切换控件(登录与注册两种模式)。
|
||||
* 跨页跳转:mode='login' 在 /login 与 /org/login 间切换;
|
||||
* mode='register' 在 /register 与 /org/register 间切换。四页共用,保持对称的信息架构。
|
||||
* active:当前页归属('personal' | 'enterprise'),高亮且不重复跳转。
|
||||
*
|
||||
* 浮于玻璃卡片之外、之上:自带玻璃壳(backdrop-blur + 半透白底 + ring/border),
|
||||
* 在背景上保持可读并与下方卡片呼应;激活态用品牌渐变强化「当前入口」的辨识度。
|
||||
*/
|
||||
const AuthLoginTabs = ({ active = 'personal', mode = 'login' }) => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
// 企业入口置于左侧首位:本产品主推企业用户,企业登录/注册是默认入口
|
||||
const tabs =
|
||||
mode === 'register'
|
||||
? [
|
||||
{ key: 'enterprise', label: t('企业注册'), to: '/org/register' },
|
||||
{ key: 'personal', label: t('个人注册'), to: '/register' },
|
||||
]
|
||||
: [
|
||||
{ key: 'enterprise', label: t('企业登录'), to: '/org/login' },
|
||||
{ key: 'personal', label: t('个人登录'), to: '/login' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='relative z-20 flex p-1 gap-1 rounded-2xl backdrop-blur-2xl bg-white/45 dark:bg-neutral-900/55 ring-1 ring-white/50 dark:ring-white/[0.06] border border-white/30 dark:border-white/[0.05] shadow-[0_12px_32px_-16px_rgb(var(--brand-primary-rgb)/0.45)]'>
|
||||
{tabs.map((tab) => {
|
||||
const isActive = tab.key === active;
|
||||
return (
|
||||
<button
|
||||
key={tab.key}
|
||||
type='button'
|
||||
aria-pressed={isActive}
|
||||
onClick={() => {
|
||||
if (!isActive) navigate(tab.to);
|
||||
}}
|
||||
className={`flex-1 h-10 rounded-xl text-sm font-medium transition-all duration-200 ${
|
||||
isActive
|
||||
? 'bg-gradient-to-r from-brand-from to-brand-to text-white shadow-md shadow-brand/25'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-white/40 dark:hover:bg-white/[0.05]'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuthLoginTabs;
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
/**
|
||||
* 玻璃卡片所需的动画与阴影样式(浮动 / 角落脉动 / aurora / 多层阴影)。
|
||||
* 内置于 GlassCard,任何使用本卡片的页面(登录、注册、企业登录…)都会自动获得,
|
||||
* 无需各自再注入一份 <style>。类名全局唯一,多处渲染重复定义亦无副作用。
|
||||
*/
|
||||
export const GlassCardStyles = () => (
|
||||
<style>{`
|
||||
@keyframes loginHaloPulse {
|
||||
0%, 100% { opacity: 0.55; transform: scale(1); }
|
||||
50% { opacity: 0.9; transform: scale(1.08); }
|
||||
}
|
||||
@keyframes loginCardFloat {
|
||||
0%, 100% { transform: translateY(0); }
|
||||
50% { transform: translateY(-4px); }
|
||||
}
|
||||
@keyframes loginAurora {
|
||||
0%, 100% { transform: translate(0%, 0%); }
|
||||
50% { transform: translate(18%, 12%); }
|
||||
}
|
||||
.login-card-float { animation: loginCardFloat 7s ease-in-out infinite; will-change: transform; }
|
||||
.login-halo-pulse { animation: loginHaloPulse 6s ease-in-out infinite; }
|
||||
.login-halo-pulse-delayed { animation: loginHaloPulse 6s ease-in-out infinite; animation-delay: 3s; }
|
||||
.login-glass-aurora {
|
||||
top: -25%;
|
||||
left: -15%;
|
||||
width: 80%;
|
||||
height: 85%;
|
||||
background: radial-gradient(ellipse at center, rgb(var(--brand-primary-rgb) / 0.16) 0%, transparent 70%);
|
||||
animation: loginAurora 22s ease-in-out infinite;
|
||||
}
|
||||
.dark .login-glass-aurora {
|
||||
background: radial-gradient(ellipse at center, rgb(var(--brand-primary-rgb) / 0.22) 0%, transparent 70%);
|
||||
}
|
||||
.login-glass-card {
|
||||
box-shadow:
|
||||
0 30px 70px -20px rgba(15, 42, 80, 0.28),
|
||||
0 12px 28px -10px rgb(var(--brand-primary-rgb) / 0.20),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.65),
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.18);
|
||||
}
|
||||
.dark .login-glass-card {
|
||||
box-shadow:
|
||||
0 30px 70px -18px rgba(0, 0, 0, 0.65),
|
||||
0 14px 32px -10px rgb(var(--brand-primary-rgb) / 0.25),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.12),
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.04);
|
||||
}
|
||||
/* 卡片 hover 与内部按钮 hover 联动时,避免抖动 */
|
||||
.login-glass-card:hover { box-shadow:
|
||||
0 36px 80px -18px rgba(15, 42, 80, 0.32),
|
||||
0 14px 32px -10px rgb(var(--brand-primary-rgb) / 0.26),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.7),
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
.dark .login-glass-card:hover { box-shadow:
|
||||
0 36px 80px -16px rgba(0, 0, 0, 0.7),
|
||||
0 16px 36px -10px rgb(var(--brand-primary-rgb) / 0.3),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.14),
|
||||
inset 0 -1px 0 rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
/* 认证页 Semi 输入框玻璃风格:容器挂 .auth-glass-form 后,四个认证页
|
||||
(登录/注册/企业登录/企业注册)的输入框共享同一套观感 ——
|
||||
半透白玻璃底 + 圆角、hover 提亮、聚焦品牌色边框 + 柔和光环、错误态沿用语义色 */
|
||||
.auth-glass-form .semi-input-wrapper {
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
border: 1px solid rgba(229, 231, 235, 0.8);
|
||||
border-radius: 0.75rem;
|
||||
backdrop-filter: blur(4px);
|
||||
-webkit-backdrop-filter: blur(4px);
|
||||
transition:
|
||||
border-color 0.2s ease,
|
||||
background-color 0.2s ease,
|
||||
box-shadow 0.2s ease;
|
||||
}
|
||||
.auth-glass-form .semi-input-wrapper:hover {
|
||||
background: rgba(255, 255, 255, 0.78);
|
||||
border-color: rgba(209, 213, 219, 1);
|
||||
}
|
||||
.auth-glass-form .semi-input-wrapper-focus,
|
||||
.auth-glass-form .semi-input-wrapper-focus:hover {
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
border-color: rgb(var(--brand-primary-rgb));
|
||||
box-shadow: 0 0 0 3px rgb(var(--brand-primary-rgb) / 0.14);
|
||||
}
|
||||
.dark .auth-glass-form .semi-input-wrapper {
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border-color: rgba(255, 255, 255, 0.12);
|
||||
}
|
||||
.dark .auth-glass-form .semi-input-wrapper:hover {
|
||||
background: rgba(255, 255, 255, 0.09);
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
.dark .auth-glass-form .semi-input-wrapper-focus,
|
||||
.dark .auth-glass-form .semi-input-wrapper-focus:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-color: rgb(var(--brand-primary-rgb));
|
||||
box-shadow: 0 0 0 3px rgb(var(--brand-primary-rgb) / 0.22);
|
||||
}
|
||||
/* 校验失败:边框与光环改用语义 danger 色,保持玻璃底不变 */
|
||||
.auth-glass-form .semi-input-wrapper-error,
|
||||
.auth-glass-form .semi-input-wrapper-error:hover,
|
||||
.auth-glass-form .semi-input-wrapper-error.semi-input-wrapper-focus {
|
||||
border-color: var(--semi-color-danger);
|
||||
box-shadow: none;
|
||||
}
|
||||
/* 前缀图标与内建功能钮(密码眼睛/清除)默认弱化;
|
||||
只针对这三处染色,避免误染 suffix 里自定义按钮(如「获取验证码」)的 loading 图标 */
|
||||
.auth-glass-form .semi-input-wrapper .semi-input-prefix .semi-icon,
|
||||
.auth-glass-form .semi-input-wrapper .semi-input-clearbtn .semi-icon,
|
||||
.auth-glass-form .semi-input-wrapper .semi-input-modebtn .semi-icon {
|
||||
color: rgba(156, 163, 175, 1);
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
.dark .auth-glass-form .semi-input-wrapper .semi-input-prefix .semi-icon,
|
||||
.dark .auth-glass-form .semi-input-wrapper .semi-input-clearbtn .semi-icon,
|
||||
.dark .auth-glass-form .semi-input-wrapper .semi-input-modebtn .semi-icon {
|
||||
color: rgba(107, 114, 128, 1);
|
||||
}
|
||||
/* 密码眼睛/清除按钮 hover 加深,给出可点击反馈 */
|
||||
.auth-glass-form .semi-input-wrapper .semi-input-clearbtn:hover .semi-icon,
|
||||
.auth-glass-form .semi-input-wrapper .semi-input-modebtn:hover .semi-icon {
|
||||
color: rgba(75, 85, 99, 1);
|
||||
}
|
||||
.dark .auth-glass-form .semi-input-wrapper .semi-input-clearbtn:hover .semi-icon,
|
||||
.dark .auth-glass-form .semi-input-wrapper .semi-input-modebtn:hover .semi-icon {
|
||||
color: rgba(209, 213, 219, 1);
|
||||
}
|
||||
/* 聚焦时前缀图标点亮为品牌色,给出清晰的焦点反馈 */
|
||||
.auth-glass-form .semi-input-wrapper-focus .semi-input-prefix .semi-icon {
|
||||
color: rgb(var(--brand-primary-rgb));
|
||||
}
|
||||
.dark .auth-glass-form .semi-input::placeholder {
|
||||
color: rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
/* 移动端降级 backdrop-filter,减轻 GPU 负担 */
|
||||
@media (max-width: 640px) {
|
||||
.login-glass-card {
|
||||
backdrop-filter: blur(24px);
|
||||
-webkit-backdrop-filter: blur(24px);
|
||||
}
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.login-card-float,
|
||||
.login-halo-pulse,
|
||||
.login-halo-pulse-delayed,
|
||||
.login-glass-aurora { animation: none; }
|
||||
.login-glass-card { transition: none; }
|
||||
}
|
||||
`}</style>
|
||||
);
|
||||
|
||||
/**
|
||||
* 登录/注册页通用的玻璃拟态卡片壳
|
||||
*
|
||||
* 视觉层(由后到前):
|
||||
* 1. 外环柔光晕(品牌渐变 + 模糊)
|
||||
* 2. 左上 / 右下角脉动光晕(可选,withCornerHalos)
|
||||
* 3. 内层 aurora(缓慢漂移的品牌色径向辉光)
|
||||
* 4. 卡片主体(高透白 + 强 backdrop-blur + ring/border 双层玻璃边)
|
||||
* 5. 顶部品牌渐变线 + 1px 白色反光(玻璃顶面反光)
|
||||
* 6. 用户传入的 children
|
||||
*
|
||||
* 交互:
|
||||
* - 整卡浮动动画(translateY,7s 缓慢呼吸)
|
||||
* - 角落光晕轻微缩放脉动(6s)
|
||||
* - 卡片 hover 微抬升(scale 1.008,500ms 缓动)
|
||||
*
|
||||
* 性能:
|
||||
* - 移动端自动降级 backdrop-filter 模糊半径(@media (max-width: 640px))
|
||||
* - aurora 单层 GPU 合成
|
||||
* - 全部动画在 prefers-reduced-motion 下关闭
|
||||
* - 阴影、aurora 颜色均使用 var(--brand-primary-rgb),跟随主题预设
|
||||
*/
|
||||
const GlassCard = ({
|
||||
children,
|
||||
withCornerHalos = true,
|
||||
withAurora = true,
|
||||
className = '',
|
||||
}) => {
|
||||
return (
|
||||
<div className={`w-full max-w-sm relative login-card-float ${className}`}>
|
||||
<GlassCardStyles />
|
||||
{/* 外环柔光晕 */}
|
||||
<div className='absolute -inset-6 bg-gradient-to-br from-brand-from/15 via-brand-via/10 to-brand-to/15 rounded-[2rem] blur-2xl opacity-80 pointer-events-none' />
|
||||
|
||||
{/* 左上 / 右下脉动光晕 */}
|
||||
{withCornerHalos && (
|
||||
<>
|
||||
<div className='absolute -top-20 -left-20 w-44 h-44 bg-brand-from/25 dark:bg-brand-from/20 rounded-full blur-3xl pointer-events-none login-halo-pulse' />
|
||||
<div className='absolute -bottom-20 -right-20 w-44 h-44 bg-brand-to/25 dark:bg-brand-to/15 rounded-full blur-3xl pointer-events-none login-halo-pulse-delayed' />
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 卡片主体 */}
|
||||
<div className='login-glass-card relative isolate backdrop-blur-2xl bg-white/45 dark:bg-neutral-900/55 rounded-2xl ring-1 ring-white/50 dark:ring-white/[0.06] border border-white/30 dark:border-white/[0.05] px-6 py-5 overflow-hidden transition-[transform,box-shadow] duration-500 ease-out hover:scale-[1.008]'>
|
||||
{/* 内层 aurora - 缓慢漂移,z-index 负值避免遮挡内容 */}
|
||||
{withAurora && (
|
||||
<div className='login-glass-aurora absolute -z-10 pointer-events-none' />
|
||||
)}
|
||||
|
||||
{/* 顶部品牌渐变线 */}
|
||||
<div className='absolute top-0 left-0 right-0 h-0.5 bg-gradient-to-r from-brand-from via-brand-via to-brand-to opacity-90' />
|
||||
|
||||
{/* 顶部 1px 白色反光 - 紧贴品牌线下方 */}
|
||||
<div className='absolute top-0.5 left-[15%] right-[15%] h-px bg-gradient-to-r from-transparent via-white/90 dark:via-white/40 to-transparent pointer-events-none' />
|
||||
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlassCard;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
API,
|
||||
showError,
|
||||
showSuccess,
|
||||
updateAPI,
|
||||
clearUserData,
|
||||
finishLogin as runLoginFlow,
|
||||
} from '../../helpers';
|
||||
import { UserContext } from '../../context/User';
|
||||
import Loading from '../common/ui/Loading';
|
||||
|
||||
const OAuth2Callback = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const [, userDispatch] = useContext(UserContext);
|
||||
const navigate = useNavigate();
|
||||
|
||||
// 最大重试次数
|
||||
const MAX_RETRIES = 3;
|
||||
|
||||
const sendCode = async (code, state, retry = 0) => {
|
||||
try {
|
||||
const { data: resData } = await API.get(
|
||||
`/api/oauth/${props.type}?code=${code}&state=${state}`,
|
||||
);
|
||||
|
||||
const { success, message, data } = resData;
|
||||
|
||||
if (!success) {
|
||||
throw new Error(message || 'OAuth2 callback error');
|
||||
}
|
||||
|
||||
if (message === 'bind') {
|
||||
showSuccess(t('绑定成功!'));
|
||||
navigate('/console/personal');
|
||||
return;
|
||||
}
|
||||
|
||||
// OAuth code is single-use; if finishLogin reports the session cookie
|
||||
// wasn't persisted, retrying the same code can't fix it — fall through
|
||||
// to the login page (finishLogin already surfaced the error toast).
|
||||
const loggedIn = await runLoginFlow({
|
||||
data,
|
||||
userDispatch,
|
||||
navigate,
|
||||
t,
|
||||
});
|
||||
if (!loggedIn) {
|
||||
navigate('/login');
|
||||
}
|
||||
} catch (error) {
|
||||
if (retry < MAX_RETRIES) {
|
||||
// 递增的退避等待
|
||||
await new Promise((resolve) => setTimeout(resolve, (retry + 1) * 2000));
|
||||
return sendCode(code, state, retry + 1);
|
||||
}
|
||||
|
||||
// 重试次数耗尽,提示错误并返回登录页面
|
||||
clearUserData();
|
||||
updateAPI();
|
||||
showError(error.message || t('授权失败'));
|
||||
navigate('/login');
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const code = searchParams.get('code');
|
||||
const state = searchParams.get('state');
|
||||
|
||||
// 参数缺失直接返回
|
||||
if (!code) {
|
||||
showError(t('未获取到授权码'));
|
||||
navigate('/console/personal');
|
||||
return;
|
||||
}
|
||||
|
||||
sendCode(code, state);
|
||||
}, []);
|
||||
|
||||
return <Loading />;
|
||||
};
|
||||
|
||||
export default OAuth2Callback;
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, Toast, Banner } from '@douyinfe/semi-ui';
|
||||
import { Copy } from 'lucide-react';
|
||||
|
||||
/**
|
||||
* 企业建号一次性凭证展示面板(注册自助建号 / 管理员建号复用)。
|
||||
* props:
|
||||
* creds: { status?, org_code, org_name, owner_login_name, initial_password }
|
||||
* onLogin?: () => void 存在时展示「立即登录」按钮
|
||||
*/
|
||||
const OrgCredentialResult = ({ creds, onLogin }) => {
|
||||
const { t } = useTranslation();
|
||||
if (!creds) return null;
|
||||
|
||||
const isPending = creds.status === 'pending';
|
||||
|
||||
const copy = (val) => {
|
||||
navigator.clipboard
|
||||
.writeText(val)
|
||||
.then(() => Toast.success(t('已复制到剪贴板')))
|
||||
.catch(() => Toast.error(t('复制失败,请手动复制')));
|
||||
};
|
||||
|
||||
// 四项凭证拼成带标签的文本块一次复制,避免逐项复制的遗漏(如只记了密码没记企业代码)
|
||||
const copyAll = () => {
|
||||
copy(
|
||||
[
|
||||
`${t('企业代码')}: ${creds.org_code}`,
|
||||
`${t('企业名称')}: ${creds.org_name}`,
|
||||
`${t('登录名')}: ${creds.owner_login_name}`,
|
||||
`${t('初始密码')}: ${creds.initial_password}`,
|
||||
].join('\n'),
|
||||
);
|
||||
};
|
||||
|
||||
const Row = ({ label, value, mono }) => (
|
||||
<div className='flex items-center justify-between gap-2 py-2 border-b border-gray-100 dark:border-white/[0.06] last:border-0'>
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400 shrink-0'>
|
||||
{label}
|
||||
</span>
|
||||
<div className='flex items-center gap-1.5 min-w-0'>
|
||||
<span
|
||||
className={`truncate text-sm text-gray-800 dark:text-gray-100 ${mono ? 'font-mono' : ''}`}
|
||||
>
|
||||
{value}
|
||||
</span>
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
icon={<Copy size={14} />}
|
||||
onClick={() => copy(value)}
|
||||
aria-label={t('复制')}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-3'>
|
||||
<Banner
|
||||
type={isPending ? 'info' : 'warning'}
|
||||
closeIcon={null}
|
||||
description={
|
||||
isPending
|
||||
? t(
|
||||
'企业已提交,待平台审核通过后即可用以下凭证登录。请立即保存初始密码,此信息仅显示一次。',
|
||||
)
|
||||
: t(
|
||||
'请立即保存以下凭证并交付管理员。初始密码仅显示一次,关闭后无法再次查看。',
|
||||
)
|
||||
}
|
||||
/>
|
||||
<div className='rounded-xl border border-gray-200/80 dark:border-white/[0.1] bg-white/60 dark:bg-white/[0.04] px-4'>
|
||||
<Row label={t('企业代码')} value={creds.org_code} mono />
|
||||
<Row label={t('企业名称')} value={creds.org_name} />
|
||||
<Row label={t('登录名')} value={creds.owner_login_name} mono />
|
||||
<Row label={t('初始密码')} value={creds.initial_password} mono />
|
||||
</div>
|
||||
<Button
|
||||
size='large'
|
||||
block
|
||||
icon={<Copy size={14} />}
|
||||
onClick={copyAll}
|
||||
>
|
||||
{t('复制全部凭证')}
|
||||
</Button>
|
||||
{onLogin && (
|
||||
<Button
|
||||
theme='solid'
|
||||
size='large'
|
||||
block
|
||||
onClick={onLogin}
|
||||
disabled={isPending}
|
||||
>
|
||||
{isPending ? t('待审核通过后可登录') : t('立即登录')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default OrgCredentialResult;
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
API,
|
||||
copy,
|
||||
showError,
|
||||
showNotice,
|
||||
getLogo,
|
||||
getSystemName,
|
||||
} from '../../helpers';
|
||||
import { useSearchParams, Link } from 'react-router-dom';
|
||||
import { Button, Card, Form, Typography, Banner } from '@douyinfe/semi-ui';
|
||||
import { IconMail, IconLock, IconCopy } from '@douyinfe/semi-icons';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
|
||||
const PasswordResetConfirm = () => {
|
||||
const { t } = useTranslation();
|
||||
const [inputs, setInputs] = useState({
|
||||
email: '',
|
||||
token: '',
|
||||
});
|
||||
const { email, token } = inputs;
|
||||
const isValidResetLink = email && token;
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [disableButton, setDisableButton] = useState(false);
|
||||
const [countdown, setCountdown] = useState(30);
|
||||
const [newPassword, setNewPassword] = useState('');
|
||||
const [searchParams] = useSearchParams();
|
||||
const [formApi, setFormApi] = useState(null);
|
||||
|
||||
const logo = getLogo();
|
||||
const systemName = getSystemName();
|
||||
|
||||
useEffect(() => {
|
||||
let token = searchParams.get('token');
|
||||
let email = searchParams.get('email');
|
||||
setInputs({
|
||||
token: token || '',
|
||||
email: email || '',
|
||||
});
|
||||
if (formApi) {
|
||||
formApi.setValues({
|
||||
email: email || '',
|
||||
newPassword: newPassword || '',
|
||||
});
|
||||
}
|
||||
}, [searchParams, newPassword, formApi]);
|
||||
|
||||
useEffect(() => {
|
||||
let countdownInterval = null;
|
||||
if (disableButton && countdown > 0) {
|
||||
countdownInterval = setInterval(() => {
|
||||
setCountdown(countdown - 1);
|
||||
}, 1000);
|
||||
} else if (countdown === 0) {
|
||||
setDisableButton(false);
|
||||
setCountdown(30);
|
||||
}
|
||||
return () => clearInterval(countdownInterval);
|
||||
}, [disableButton, countdown]);
|
||||
|
||||
async function handleSubmit(e) {
|
||||
if (!email || !token) {
|
||||
showError(t('无效的重置链接,请重新发起密码重置请求'));
|
||||
return;
|
||||
}
|
||||
setDisableButton(true);
|
||||
setLoading(true);
|
||||
const res = await API.post(`/api/user/reset`, {
|
||||
email,
|
||||
token,
|
||||
});
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
let password = res.data.data;
|
||||
setNewPassword(password);
|
||||
await copy(password);
|
||||
showNotice(`${t('密码已重置并已复制到剪贴板:')} ${password}`);
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='relative overflow-hidden bg-gray-100 flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8'>
|
||||
{/* 背景模糊晕染球 */}
|
||||
<div
|
||||
className='blur-ball blur-ball-indigo'
|
||||
style={{ top: '-80px', right: '-80px', transform: 'none' }}
|
||||
/>
|
||||
<div
|
||||
className='blur-ball blur-ball-teal'
|
||||
style={{ top: '50%', left: '-120px' }}
|
||||
/>
|
||||
<div className='w-full max-w-sm mt-[60px]'>
|
||||
<div className='flex flex-col items-center'>
|
||||
<div className='w-full max-w-md'>
|
||||
<div className='flex items-center justify-center mb-6 gap-2'>
|
||||
<img src={logo} alt='Logo' className='h-10 rounded-full' />
|
||||
<Title heading={3} className='!text-gray-800'>
|
||||
{systemName}
|
||||
</Title>
|
||||
</div>
|
||||
|
||||
<Card className='border-0 !rounded-2xl overflow-hidden'>
|
||||
<div className='flex justify-center pt-6 pb-2'>
|
||||
<Title heading={3} className='text-gray-800 dark:text-gray-200'>
|
||||
{t('密码重置确认')}
|
||||
</Title>
|
||||
</div>
|
||||
<div className='px-2 py-8'>
|
||||
{!isValidResetLink && (
|
||||
<Banner
|
||||
type='danger'
|
||||
description={t('无效的重置链接,请重新发起密码重置请求')}
|
||||
className='mb-4 !rounded-lg'
|
||||
closeIcon={null}
|
||||
/>
|
||||
)}
|
||||
<Form
|
||||
getFormApi={(api) => setFormApi(api)}
|
||||
initValues={{
|
||||
email: email || '',
|
||||
newPassword: newPassword || '',
|
||||
}}
|
||||
className='space-y-4'
|
||||
>
|
||||
<Form.Input
|
||||
field='email'
|
||||
label={t('邮箱')}
|
||||
name='email'
|
||||
disabled={true}
|
||||
prefix={<IconMail />}
|
||||
placeholder={email ? '' : t('等待获取邮箱信息...')}
|
||||
/>
|
||||
|
||||
{newPassword && (
|
||||
<Form.Input
|
||||
field='newPassword'
|
||||
label={t('新密码')}
|
||||
name='newPassword'
|
||||
disabled={true}
|
||||
prefix={<IconLock />}
|
||||
suffix={
|
||||
<Button
|
||||
icon={<IconCopy />}
|
||||
type='tertiary'
|
||||
theme='borderless'
|
||||
onClick={async () => {
|
||||
await copy(newPassword);
|
||||
showNotice(`${t('密码已复制到剪贴板:')} ${newPassword}`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
{t('复制')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className='space-y-2 pt-2'>
|
||||
<Button
|
||||
theme='solid'
|
||||
className='w-full !rounded-full'
|
||||
type='primary'
|
||||
htmlType='submit'
|
||||
onClick={handleSubmit}
|
||||
loading={loading}
|
||||
disabled={
|
||||
disableButton || newPassword || !isValidResetLink
|
||||
}
|
||||
>
|
||||
{newPassword ? t('密码重置完成') : t('确认重置密码')}
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
<div className='mt-6 text-center text-sm'>
|
||||
<Text>
|
||||
<Link
|
||||
to='/login'
|
||||
className='!text-brand-deep dark:!text-brand-from hover:!text-brand dark:hover:!text-brand-from font-medium transition-colors'
|
||||
>
|
||||
{t('返回登录')}
|
||||
</Link>
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PasswordResetConfirm;
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import {
|
||||
API,
|
||||
getLogo,
|
||||
showError,
|
||||
showInfo,
|
||||
showSuccess,
|
||||
getSystemName,
|
||||
} from '../../helpers';
|
||||
import Turnstile from 'react-turnstile';
|
||||
import { Button, Card, Form, Typography } from '@douyinfe/semi-ui';
|
||||
import { IconMail } from '@douyinfe/semi-icons';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
|
||||
const PasswordResetForm = () => {
|
||||
const { t } = useTranslation();
|
||||
const [inputs, setInputs] = useState({
|
||||
email: '',
|
||||
});
|
||||
const { email } = inputs;
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [turnstileEnabled, setTurnstileEnabled] = useState(false);
|
||||
const [turnstileSiteKey, setTurnstileSiteKey] = useState('');
|
||||
const [turnstileToken, setTurnstileToken] = useState('');
|
||||
const [disableButton, setDisableButton] = useState(false);
|
||||
const [countdown, setCountdown] = useState(30);
|
||||
|
||||
const logo = getLogo();
|
||||
const systemName = getSystemName();
|
||||
|
||||
useEffect(() => {
|
||||
let status = localStorage.getItem('status');
|
||||
if (status) {
|
||||
status = JSON.parse(status);
|
||||
if (status.turnstile_check) {
|
||||
setTurnstileEnabled(true);
|
||||
setTurnstileSiteKey(status.turnstile_site_key);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
let countdownInterval = null;
|
||||
if (disableButton && countdown > 0) {
|
||||
countdownInterval = setInterval(() => {
|
||||
setCountdown(countdown - 1);
|
||||
}, 1000);
|
||||
} else if (countdown === 0) {
|
||||
setDisableButton(false);
|
||||
setCountdown(30);
|
||||
}
|
||||
return () => clearInterval(countdownInterval);
|
||||
}, [disableButton, countdown]);
|
||||
|
||||
function handleChange(value) {
|
||||
setInputs((inputs) => ({ ...inputs, email: value }));
|
||||
}
|
||||
|
||||
async function handleSubmit(e) {
|
||||
if (!email) {
|
||||
showError(t('请输入邮箱地址'));
|
||||
return;
|
||||
}
|
||||
if (turnstileEnabled && turnstileToken === '') {
|
||||
showInfo(t('请稍后几秒重试,Turnstile 正在检查用户环境!'));
|
||||
return;
|
||||
}
|
||||
setDisableButton(true);
|
||||
setLoading(true);
|
||||
const res = await API.get(
|
||||
`/api/reset_password?email=${encodeURIComponent(email)}&turnstile=${turnstileToken}`,
|
||||
);
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('重置邮件发送成功,请检查邮箱!'));
|
||||
setInputs({ ...inputs, email: '' });
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='relative overflow-hidden bg-gray-100 flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8'>
|
||||
{/* 背景模糊晕染球 */}
|
||||
<div
|
||||
className='blur-ball blur-ball-indigo'
|
||||
style={{ top: '-80px', right: '-80px', transform: 'none' }}
|
||||
/>
|
||||
<div
|
||||
className='blur-ball blur-ball-teal'
|
||||
style={{ top: '50%', left: '-120px' }}
|
||||
/>
|
||||
<div className='w-full max-w-sm mt-[60px]'>
|
||||
<div className='flex flex-col items-center'>
|
||||
<div className='w-full max-w-md'>
|
||||
<div className='flex items-center justify-center mb-6 gap-2'>
|
||||
<img src={logo} alt='Logo' className='h-10 rounded-full' />
|
||||
<Title heading={3} className='!text-gray-800'>
|
||||
{systemName}
|
||||
</Title>
|
||||
</div>
|
||||
|
||||
<Card className='border-0 !rounded-2xl overflow-hidden'>
|
||||
<div className='flex justify-center pt-6 pb-2'>
|
||||
<Title heading={3} className='text-gray-800 dark:text-gray-200'>
|
||||
{t('密码重置')}
|
||||
</Title>
|
||||
</div>
|
||||
<div className='px-2 py-8'>
|
||||
<Form className='space-y-3'>
|
||||
<Form.Input
|
||||
field='email'
|
||||
label={t('邮箱')}
|
||||
placeholder={t('请输入您的邮箱地址')}
|
||||
name='email'
|
||||
value={email}
|
||||
onChange={handleChange}
|
||||
prefix={<IconMail />}
|
||||
/>
|
||||
|
||||
<div className='space-y-2 pt-2'>
|
||||
<Button
|
||||
theme='solid'
|
||||
className='w-full !rounded-full'
|
||||
type='primary'
|
||||
htmlType='submit'
|
||||
onClick={handleSubmit}
|
||||
loading={loading}
|
||||
disabled={disableButton}
|
||||
>
|
||||
{disableButton
|
||||
? `${t('重试')} (${countdown})`
|
||||
: t('提交')}
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
<div className='mt-6 text-center text-sm'>
|
||||
<Text>
|
||||
{t('想起来了?')}{' '}
|
||||
<Link
|
||||
to='/login'
|
||||
className='!text-brand-deep dark:!text-brand-from hover:!text-brand dark:hover:!text-brand-from font-medium transition-colors'
|
||||
>
|
||||
{t('登录')}
|
||||
</Link>
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{turnstileEnabled && (
|
||||
<div className='flex justify-center mt-6'>
|
||||
<Turnstile
|
||||
sitekey={turnstileSiteKey}
|
||||
onVerify={(token) => {
|
||||
setTurnstileToken(token);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PasswordResetForm;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React from 'react';
|
||||
import TelegramLoginButton from 'react-telegram-login';
|
||||
|
||||
const TelegramLogin = ({ botName, onAuth }) => {
|
||||
return (
|
||||
<div className='flex justify-center my-2'>
|
||||
<TelegramLoginButton dataOnauth={onAuth} botName={botName} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TelegramLogin;
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import { API, showError, showSuccess } from '../../helpers';
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Divider,
|
||||
Form,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { Title, Text, Paragraph } = Typography;
|
||||
|
||||
const TwoFAVerification = ({ onSuccess, onBack, isModal = false }) => {
|
||||
const { t } = useTranslation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [useBackupCode, setUseBackupCode] = useState(false);
|
||||
const [verificationCode, setVerificationCode] = useState('');
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!verificationCode) {
|
||||
showError(t('请输入验证码'));
|
||||
return;
|
||||
}
|
||||
// Validate code format
|
||||
if (useBackupCode && verificationCode.length !== 8) {
|
||||
showError(t('备用码必须是8位'));
|
||||
return;
|
||||
} else if (!useBackupCode && !/^\d{6}$/.test(verificationCode)) {
|
||||
showError(t('验证码必须是6位数字'));
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await API.post('/api/user/login/2fa', {
|
||||
code: verificationCode,
|
||||
});
|
||||
|
||||
if (res.data.success) {
|
||||
showSuccess(t('登录成功'));
|
||||
if (onSuccess) {
|
||||
onSuccess(res.data.data);
|
||||
}
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('验证失败,请重试'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleKeyPress = (e) => {
|
||||
if (e.key === 'Enter') {
|
||||
handleSubmit();
|
||||
}
|
||||
};
|
||||
|
||||
if (isModal) {
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
<Paragraph className='text-gray-600 dark:text-gray-300'>
|
||||
{t('请输入认证器应用显示的验证码完成登录')}
|
||||
</Paragraph>
|
||||
|
||||
<Form onSubmit={handleSubmit}>
|
||||
<Form.Input
|
||||
field='code'
|
||||
label={useBackupCode ? t('备用码') : t('验证码')}
|
||||
placeholder={
|
||||
useBackupCode ? t('请输入8位备用码') : t('请输入6位验证码')
|
||||
}
|
||||
value={verificationCode}
|
||||
onChange={setVerificationCode}
|
||||
onKeyPress={handleKeyPress}
|
||||
size='large'
|
||||
style={{ marginBottom: 16 }}
|
||||
autoFocus
|
||||
/>
|
||||
|
||||
<Button
|
||||
htmlType='submit'
|
||||
type='primary'
|
||||
loading={loading}
|
||||
block
|
||||
size='large'
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
{t('验证并登录')}
|
||||
</Button>
|
||||
</Form>
|
||||
|
||||
<Divider />
|
||||
|
||||
<div style={{ textAlign: 'center' }}>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
onClick={() => {
|
||||
setUseBackupCode(!useBackupCode);
|
||||
setVerificationCode('');
|
||||
}}
|
||||
style={{ marginRight: 16, color: '#1890ff', padding: 0 }}
|
||||
>
|
||||
{useBackupCode ? t('使用认证器验证码') : t('使用备用码')}
|
||||
</Button>
|
||||
|
||||
{onBack && (
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
onClick={onBack}
|
||||
style={{ color: '#1890ff', padding: 0 }}
|
||||
>
|
||||
{t('返回登录')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className='bg-gray-50 dark:bg-gray-800 rounded-lg p-3'>
|
||||
<Text size='small' type='secondary'>
|
||||
<strong>{t('提示:')}</strong>
|
||||
<br />• {t('验证码每30秒更新一次')}
|
||||
<br />• {t('如果无法获取验证码,请使用备用码')}
|
||||
<br />• {t('每个备用码只能使用一次')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
minHeight: '60vh',
|
||||
}}
|
||||
>
|
||||
<Card style={{ width: 400, padding: 24 }}>
|
||||
<div style={{ textAlign: 'center', marginBottom: 24 }}>
|
||||
<Title heading={3}>{t('两步验证')}</Title>
|
||||
<Paragraph type='secondary'>
|
||||
{t('请输入认证器应用显示的验证码完成登录')}
|
||||
</Paragraph>
|
||||
</div>
|
||||
|
||||
<Form onSubmit={handleSubmit}>
|
||||
<Form.Input
|
||||
field='code'
|
||||
label={useBackupCode ? t('备用码') : t('验证码')}
|
||||
placeholder={
|
||||
useBackupCode ? t('请输入8位备用码') : t('请输入6位验证码')
|
||||
}
|
||||
value={verificationCode}
|
||||
onChange={setVerificationCode}
|
||||
onKeyPress={handleKeyPress}
|
||||
size='large'
|
||||
style={{ marginBottom: 16 }}
|
||||
autoFocus
|
||||
/>
|
||||
|
||||
<Button
|
||||
htmlType='submit'
|
||||
type='primary'
|
||||
loading={loading}
|
||||
block
|
||||
size='large'
|
||||
style={{ marginBottom: 16 }}
|
||||
>
|
||||
{t('验证并登录')}
|
||||
</Button>
|
||||
</Form>
|
||||
|
||||
<Divider />
|
||||
|
||||
<div style={{ textAlign: 'center' }}>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
onClick={() => {
|
||||
setUseBackupCode(!useBackupCode);
|
||||
setVerificationCode('');
|
||||
}}
|
||||
style={{ marginRight: 16, color: '#1890ff', padding: 0 }}
|
||||
>
|
||||
{useBackupCode ? t('使用认证器验证码') : t('使用备用码')}
|
||||
</Button>
|
||||
|
||||
{onBack && (
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
onClick={onBack}
|
||||
style={{ color: '#1890ff', padding: 0 }}
|
||||
>
|
||||
{t('返回登录')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
marginTop: 24,
|
||||
padding: 16,
|
||||
background: '#f6f8fa',
|
||||
borderRadius: 6,
|
||||
}}
|
||||
>
|
||||
<Text size='small' type='secondary'>
|
||||
<strong>{t('提示:')}</strong>
|
||||
<br />• {t('验证码每30秒更新一次')}
|
||||
<br />• {t('如果无法获取验证码,请使用备用码')}
|
||||
<br />• {t('每个备用码只能使用一次')}
|
||||
</Text>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TwoFAVerification;
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { Suspense, lazy, useContext } from 'react';
|
||||
import { StatusContext } from '../../../context/Status';
|
||||
|
||||
/**
|
||||
* 登录/注册页背景动画 —— 主题注册表
|
||||
*
|
||||
* 主题由后端 option「AuthBackgroundTheme」控制,经 /api/status 的
|
||||
* auth_background_theme 字段下发。未配置 / 配置非法时兜底 ocean,
|
||||
* 保证老部署行为不变。每个主题懒加载,未选中的不进首屏 bundle。
|
||||
*/
|
||||
const THEMES = {
|
||||
ocean: lazy(() => import('../OceanBackground')),
|
||||
'token-factory': lazy(() => import('./themes/TokenFactory')),
|
||||
'token-factory-cinematic': lazy(
|
||||
() => import('./themes/CinematicTokenFactory'),
|
||||
),
|
||||
};
|
||||
|
||||
// status 尚未拉取完成时,用 localStorage 缓存的上一次 status 兜底,
|
||||
// 避免回头客先黑屏再闪入动画。
|
||||
const readCachedTheme = () => {
|
||||
try {
|
||||
const s = JSON.parse(localStorage.getItem('status') || '{}');
|
||||
return s?.auth_background_theme;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
const AuthBackground = () => {
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const theme =
|
||||
statusState?.status?.auth_background_theme ?? readCachedTheme() ?? 'ocean';
|
||||
|
||||
if (theme === 'none') return null;
|
||||
// hasOwnProperty 守卫:防止 "constructor" 之类的原型链键名取出非组件值导致渲染崩溃
|
||||
const ThemeComponent = Object.prototype.hasOwnProperty.call(THEMES, theme)
|
||||
? THEMES[theme]
|
||||
: THEMES.ocean;
|
||||
|
||||
return (
|
||||
<Suspense fallback={null}>
|
||||
<ThemeComponent />
|
||||
</Suspense>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuthBackground;
|
||||
@@ -0,0 +1,246 @@
|
||||
/* Cinematic image layer and lightweight motion effects. */
|
||||
.token-factory-scene {
|
||||
--factory-parallax-x: 0px;
|
||||
--factory-parallax-y: 0px;
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: -1;
|
||||
overflow: hidden;
|
||||
pointer-events: none;
|
||||
background: #020611;
|
||||
isolation: isolate;
|
||||
}
|
||||
|
||||
.token-factory-scene__image {
|
||||
position: absolute;
|
||||
inset: -3.5%;
|
||||
background-image: url('/assets/token-factory-cinematic-v2-web.webp');
|
||||
background-position: center center;
|
||||
background-size: cover;
|
||||
filter: saturate(1.08) contrast(1.08) brightness(0.88);
|
||||
transform: translate3d(
|
||||
var(--factory-parallax-x),
|
||||
var(--factory-parallax-y),
|
||||
0
|
||||
)
|
||||
scale(1.055);
|
||||
animation: factory-camera-breathe 18s ease-in-out infinite alternate;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
.token-factory-scene__grade {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background:
|
||||
radial-gradient(
|
||||
ellipse 28% 62% at 50% 49%,
|
||||
rgba(0, 4, 12, 0.62) 0%,
|
||||
rgba(1, 7, 18, 0.36) 48%,
|
||||
transparent 100%
|
||||
),
|
||||
linear-gradient(
|
||||
90deg,
|
||||
rgba(1, 5, 13, 0.06),
|
||||
transparent 30%,
|
||||
transparent 68%,
|
||||
rgba(0, 4, 12, 0.18)
|
||||
),
|
||||
linear-gradient(
|
||||
180deg,
|
||||
rgba(1, 5, 14, 0.2),
|
||||
transparent 38%,
|
||||
rgba(0, 3, 10, 0.4)
|
||||
);
|
||||
mix-blend-mode: multiply;
|
||||
}
|
||||
|
||||
.token-factory-scene__beam {
|
||||
position: absolute;
|
||||
width: 52vw;
|
||||
height: 9vh;
|
||||
top: 59%;
|
||||
left: -18vw;
|
||||
opacity: 0.42;
|
||||
filter: blur(16px);
|
||||
transform: rotate(-3deg);
|
||||
animation: factory-energy-sweep 8.5s cubic-bezier(0.42, 0, 0.2, 1) infinite;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
rgba(255, 184, 78, 0.8),
|
||||
rgba(255, 238, 191, 0.92),
|
||||
transparent
|
||||
);
|
||||
mix-blend-mode: screen;
|
||||
}
|
||||
|
||||
.token-factory-scene__beam--cool {
|
||||
top: 66%;
|
||||
left: -32vw;
|
||||
width: 68vw;
|
||||
height: 7vh;
|
||||
opacity: 0.38;
|
||||
animation-delay: -4.2s;
|
||||
animation-duration: 10.5s;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
rgba(28, 178, 255, 0.8),
|
||||
rgba(124, 239, 255, 0.92),
|
||||
transparent
|
||||
);
|
||||
}
|
||||
|
||||
.token-factory-scene__haze {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background:
|
||||
radial-gradient(
|
||||
circle at 50% 46%,
|
||||
rgba(63, 196, 255, 0.15),
|
||||
transparent 20%
|
||||
),
|
||||
radial-gradient(
|
||||
circle at 12% 48%,
|
||||
rgba(255, 181, 78, 0.1),
|
||||
transparent 26%
|
||||
),
|
||||
linear-gradient(
|
||||
112deg,
|
||||
transparent 42%,
|
||||
rgba(93, 211, 255, 0.06) 51%,
|
||||
transparent 59%
|
||||
);
|
||||
animation: factory-haze-pulse 7s ease-in-out infinite alternate;
|
||||
mix-blend-mode: screen;
|
||||
}
|
||||
|
||||
.token-factory-scene__particles {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
mix-blend-mode: screen;
|
||||
}
|
||||
|
||||
.token-factory-scene__vignette {
|
||||
position: absolute;
|
||||
inset: -1px;
|
||||
box-shadow:
|
||||
inset 0 0 17vw 3vw rgba(0, 2, 8, 0.72),
|
||||
inset 0 -16vh 18vh rgba(0, 3, 10, 0.52);
|
||||
}
|
||||
|
||||
.token-factory-scene__grain {
|
||||
position: absolute;
|
||||
inset: -50%;
|
||||
opacity: 0.055;
|
||||
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.85'/%3E%3C/svg%3E");
|
||||
animation: factory-film-grain 0.35s steps(2) infinite;
|
||||
mix-blend-mode: soft-light;
|
||||
}
|
||||
|
||||
@keyframes factory-camera-breathe {
|
||||
from {
|
||||
transform: translate3d(
|
||||
var(--factory-parallax-x),
|
||||
var(--factory-parallax-y),
|
||||
0
|
||||
)
|
||||
scale(1.055);
|
||||
}
|
||||
to {
|
||||
transform: translate3d(
|
||||
var(--factory-parallax-x),
|
||||
var(--factory-parallax-y),
|
||||
0
|
||||
)
|
||||
scale(1.075);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes factory-energy-sweep {
|
||||
0% {
|
||||
transform: translate3d(-8vw, 0, 0) rotate(-3deg) scaleX(0.7);
|
||||
opacity: 0;
|
||||
}
|
||||
18% {
|
||||
opacity: 0.42;
|
||||
}
|
||||
72% {
|
||||
opacity: 0.3;
|
||||
}
|
||||
100% {
|
||||
transform: translate3d(148vw, -3vh, 0) rotate(-3deg) scaleX(1.1);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes factory-haze-pulse {
|
||||
from {
|
||||
opacity: 0.62;
|
||||
transform: scale(1);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: scale(1.035);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes factory-film-grain {
|
||||
0% {
|
||||
transform: translate3d(-2%, 1%, 0);
|
||||
}
|
||||
25% {
|
||||
transform: translate3d(1%, -2%, 0);
|
||||
}
|
||||
50% {
|
||||
transform: translate3d(2%, 2%, 0);
|
||||
}
|
||||
75% {
|
||||
transform: translate3d(-1%, -1%, 0);
|
||||
}
|
||||
100% {
|
||||
transform: translate3d(0, 2%, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.token-factory-scene__image {
|
||||
inset: -2%;
|
||||
background-position: 51% center;
|
||||
transform: scale(1.04);
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.token-factory-scene__grade {
|
||||
background:
|
||||
radial-gradient(
|
||||
ellipse 72% 50% at 50% 48%,
|
||||
rgba(1, 5, 14, 0.58),
|
||||
transparent 100%
|
||||
),
|
||||
linear-gradient(
|
||||
180deg,
|
||||
rgba(1, 5, 14, 0.24),
|
||||
transparent 35%,
|
||||
rgba(0, 3, 10, 0.5)
|
||||
);
|
||||
}
|
||||
|
||||
.token-factory-scene__beam {
|
||||
opacity: 0.25;
|
||||
}
|
||||
.token-factory-scene__grain {
|
||||
opacity: 0.035;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.token-factory-scene__image,
|
||||
.token-factory-scene__beam,
|
||||
.token-factory-scene__haze,
|
||||
.token-factory-scene__grain {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import './CinematicTokenFactory.css';
|
||||
|
||||
const mulberry32 = (seed) => {
|
||||
let value = seed >>> 0;
|
||||
return () => {
|
||||
value += 0x6d2b79f5;
|
||||
let result = value;
|
||||
result = Math.imul(result ^ (result >>> 15), result | 1);
|
||||
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
|
||||
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
};
|
||||
|
||||
const CinematicTokenFactory = () => {
|
||||
const sceneRef = useRef(null);
|
||||
const canvasRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const scene = sceneRef.current;
|
||||
const canvas = canvasRef.current;
|
||||
if (!scene || !canvas) return undefined;
|
||||
|
||||
const context = canvas.getContext('2d');
|
||||
const motionQuery = window.matchMedia('(prefers-reduced-motion: reduce)');
|
||||
let reducedMotion = motionQuery.matches;
|
||||
const random = mulberry32(0x746f6b65);
|
||||
const particles = Array.from({ length: 48 }, (_, index) => ({
|
||||
x: random(),
|
||||
y: random(),
|
||||
depth: 0.35 + random() * 0.9,
|
||||
radius: index % 8 === 0 ? 3 + random() * 2.4 : 0.6 + random() * 1.5,
|
||||
speed: 0.000018 + random() * 0.000035,
|
||||
phase: random() * Math.PI * 2,
|
||||
token: index % 8 === 0,
|
||||
}));
|
||||
|
||||
let width = 0;
|
||||
let height = 0;
|
||||
let dpr = 1;
|
||||
let frameId = 0;
|
||||
let visible = !document.hidden;
|
||||
let pointerX = 0;
|
||||
let pointerY = 0;
|
||||
let smoothX = 0;
|
||||
let smoothY = 0;
|
||||
let lastFrameTime = 0;
|
||||
|
||||
const resize = () => {
|
||||
width = window.innerWidth;
|
||||
height = window.innerHeight;
|
||||
dpr = Math.min(window.devicePixelRatio || 1, 1.5);
|
||||
canvas.width = Math.round(width * dpr);
|
||||
canvas.height = Math.round(height * dpr);
|
||||
canvas.style.width = `${width}px`;
|
||||
canvas.style.height = `${height}px`;
|
||||
context.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
};
|
||||
|
||||
const onPointerMove = (event) => {
|
||||
pointerX = event.clientX / Math.max(width, 1) - 0.5;
|
||||
pointerY = event.clientY / Math.max(height, 1) - 0.5;
|
||||
};
|
||||
|
||||
const drawEnergyStream = (time, y, color, speed, amplitude) => {
|
||||
context.save();
|
||||
context.globalCompositeOperation = 'screen';
|
||||
context.lineWidth = 1.15;
|
||||
context.strokeStyle = color;
|
||||
context.shadowColor = color;
|
||||
context.shadowBlur = 10;
|
||||
context.beginPath();
|
||||
for (let x = -40; x <= width + 40; x += 18) {
|
||||
const progress = x / Math.max(width, 1);
|
||||
const wave = Math.sin(progress * 8 + time * speed) * amplitude;
|
||||
const perspective = (progress - 0.52) ** 2 * height * 0.08;
|
||||
const py = height * y + wave + perspective;
|
||||
if (x === -40) context.moveTo(x, py);
|
||||
else context.lineTo(x, py);
|
||||
}
|
||||
context.stroke();
|
||||
|
||||
for (let i = 0; i < 6; i += 1) {
|
||||
const progress = (time * speed * 0.13 + i / 6) % 1;
|
||||
const x = progress * width;
|
||||
const wave = Math.sin(progress * 8 + time * speed) * amplitude;
|
||||
const py = height * y + wave + (progress - 0.52) ** 2 * height * 0.08;
|
||||
const glow = context.createRadialGradient(x, py, 0, x, py, 13);
|
||||
glow.addColorStop(0, 'rgba(255,255,255,.95)');
|
||||
glow.addColorStop(0.25, color);
|
||||
glow.addColorStop(1, 'rgba(0,0,0,0)');
|
||||
context.fillStyle = glow;
|
||||
context.beginPath();
|
||||
context.arc(x, py, 13, 0, Math.PI * 2);
|
||||
context.fill();
|
||||
}
|
||||
context.restore();
|
||||
};
|
||||
|
||||
const drawParticle = (particle, time, deltaMs) => {
|
||||
if (!reducedMotion) {
|
||||
particle.x += particle.speed * particle.depth * deltaMs;
|
||||
particle.y +=
|
||||
Math.sin(time * 0.00045 + particle.phase) *
|
||||
0.000025 *
|
||||
(deltaMs / 16.67);
|
||||
if (particle.x > 1.08) particle.x = -0.08;
|
||||
}
|
||||
|
||||
const x = particle.x * width + smoothX * 24 * particle.depth;
|
||||
const y = particle.y * height + smoothY * 14 * particle.depth;
|
||||
const pulse = 0.65 + Math.sin(time * 0.0012 + particle.phase) * 0.35;
|
||||
context.save();
|
||||
context.globalCompositeOperation = 'screen';
|
||||
|
||||
if (particle.token) {
|
||||
const radius = particle.radius * (0.85 + pulse * 0.2);
|
||||
context.translate(x, y);
|
||||
context.rotate(Math.sin(time * 0.00035 + particle.phase) * 0.35);
|
||||
context.shadowColor = '#ffc861';
|
||||
context.shadowBlur = 14;
|
||||
context.strokeStyle = `rgba(255, 202, 98, ${0.45 + pulse * 0.4})`;
|
||||
context.lineWidth = 1.1;
|
||||
context.beginPath();
|
||||
context.arc(0, 0, radius * 1.65, 0, Math.PI * 2);
|
||||
context.stroke();
|
||||
context.beginPath();
|
||||
context.moveTo(-radius * 0.65, -radius * 0.15);
|
||||
context.lineTo(radius * 0.65, -radius * 0.15);
|
||||
context.moveTo(-radius * 0.65, radius * 0.35);
|
||||
context.lineTo(radius * 0.65, radius * 0.35);
|
||||
context.stroke();
|
||||
} else {
|
||||
context.shadowColor = '#72e8ff';
|
||||
context.shadowBlur = 9;
|
||||
context.fillStyle = `rgba(125, 231, 255, ${0.18 + pulse * 0.5})`;
|
||||
context.beginPath();
|
||||
context.arc(x, y, particle.radius * pulse, 0, Math.PI * 2);
|
||||
context.fill();
|
||||
}
|
||||
context.restore();
|
||||
};
|
||||
|
||||
const render = (time = 0) => {
|
||||
const deltaMs = lastFrameTime
|
||||
? Math.min(Math.max(time - lastFrameTime, 0), 50)
|
||||
: 16.67;
|
||||
lastFrameTime = time;
|
||||
context.clearRect(0, 0, width, height);
|
||||
smoothX += (pointerX - smoothX) * 0.035;
|
||||
smoothY += (pointerY - smoothY) * 0.035;
|
||||
scene.style.setProperty('--factory-parallax-x', `${smoothX * -18}px`);
|
||||
scene.style.setProperty('--factory-parallax-y', `${smoothY * -10}px`);
|
||||
|
||||
drawEnergyStream(time * 0.001, 0.68, 'rgba(255, 181, 73, .58)', 1.2, 4);
|
||||
drawEnergyStream(time * 0.001, 0.73, 'rgba(47, 211, 255, .62)', 1.65, 6);
|
||||
particles.forEach((particle) => drawParticle(particle, time, deltaMs));
|
||||
|
||||
if (!reducedMotion && visible) frameId = requestAnimationFrame(render);
|
||||
};
|
||||
|
||||
const onVisibilityChange = () => {
|
||||
visible = !document.hidden;
|
||||
if (visible && !reducedMotion) {
|
||||
cancelAnimationFrame(frameId);
|
||||
lastFrameTime = 0;
|
||||
frameId = requestAnimationFrame(render);
|
||||
}
|
||||
};
|
||||
|
||||
const onResize = () => {
|
||||
resize();
|
||||
if (reducedMotion) {
|
||||
lastFrameTime = 0;
|
||||
render(performance.now());
|
||||
}
|
||||
};
|
||||
|
||||
const onMotionPreferenceChange = (event) => {
|
||||
reducedMotion = event.matches;
|
||||
cancelAnimationFrame(frameId);
|
||||
lastFrameTime = 0;
|
||||
render(performance.now());
|
||||
};
|
||||
|
||||
resize();
|
||||
render();
|
||||
window.addEventListener('resize', onResize);
|
||||
window.addEventListener('pointermove', onPointerMove, { passive: true });
|
||||
document.addEventListener('visibilitychange', onVisibilityChange);
|
||||
motionQuery.addEventListener('change', onMotionPreferenceChange);
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(frameId);
|
||||
window.removeEventListener('resize', onResize);
|
||||
window.removeEventListener('pointermove', onPointerMove);
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||
motionQuery.removeEventListener('change', onMotionPreferenceChange);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div ref={sceneRef} className='token-factory-scene' aria-hidden='true'>
|
||||
<div className='token-factory-scene__image' />
|
||||
<div className='token-factory-scene__grade' />
|
||||
<div className='token-factory-scene__beam token-factory-scene__beam--warm' />
|
||||
<div className='token-factory-scene__beam token-factory-scene__beam--cool' />
|
||||
<div className='token-factory-scene__haze' />
|
||||
<canvas ref={canvasRef} className='token-factory-scene__particles' />
|
||||
<div className='token-factory-scene__vignette' />
|
||||
<div className='token-factory-scene__grain' />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CinematicTokenFactory;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React from 'react';
|
||||
import Loading from './ui/Loading';
|
||||
import {
|
||||
isChunkLoadError,
|
||||
reloadForChunkError,
|
||||
} from '../../helpers/chunkReload';
|
||||
|
||||
class ChunkErrorBoundary extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { error: null, reloading: false };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(error) {
|
||||
return { error, reloading: false };
|
||||
}
|
||||
|
||||
componentDidCatch(error) {
|
||||
if (reloadForChunkError(error)) {
|
||||
this.setState({ reloading: true });
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { error } = this.state;
|
||||
|
||||
if (!error) {
|
||||
return this.props.children;
|
||||
}
|
||||
|
||||
const chunkLoadError = isChunkLoadError(error);
|
||||
|
||||
if (chunkLoadError && this.state.reloading) {
|
||||
return <Loading />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
minHeight: '100vh',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
padding: 24,
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<div>
|
||||
<h2 style={{ marginBottom: 12 }}>
|
||||
{chunkLoadError ? 'Page update required' : 'Something went wrong'}
|
||||
</h2>
|
||||
<p style={{ marginBottom: 16 }}>
|
||||
{chunkLoadError
|
||||
? 'The app was updated while this page was open. Refresh to load the latest files.'
|
||||
: 'Please refresh the page and try again.'}
|
||||
</p>
|
||||
<button type='button' onClick={() => window.location.reload()}>
|
||||
Refresh
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default ChunkErrorBoundary;
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useCallback } from 'react';
|
||||
import { Modal } from '@douyinfe/semi-ui';
|
||||
import { X, Shield, Scale, ScrollText, ExternalLink } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import DocumentRenderer from './index';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
|
||||
const getIconByType = (type) => {
|
||||
if (type === 'privacy') return Shield;
|
||||
if (type === 'agreement') return Scale;
|
||||
return ScrollText;
|
||||
};
|
||||
|
||||
const AGREEMENT_CONFIGS = {
|
||||
agreement: {
|
||||
apiEndpoint: '/api/user-agreement',
|
||||
cacheKey: 'user_agreement',
|
||||
fullPagePath: '/user-agreement',
|
||||
titleKey: '服务协议',
|
||||
emptyKey: '加载服务协议内容失败...',
|
||||
},
|
||||
privacy: {
|
||||
apiEndpoint: '/api/privacy-policy',
|
||||
cacheKey: 'privacy_policy',
|
||||
fullPagePath: '/privacy-policy',
|
||||
titleKey: '隐私政策',
|
||||
emptyKey: '加载隐私政策内容失败...',
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 协议预览弹窗(用于登录/注册页内嵌预览)
|
||||
* @param {boolean} visible
|
||||
* @param {'agreement'|'privacy'} type
|
||||
* @param {function} onClose
|
||||
*/
|
||||
const AgreementModal = ({ visible, type, onClose }) => {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const [progress, setProgress] = useState(0);
|
||||
|
||||
const handleProgressChange = useCallback((p) => setProgress(p), []);
|
||||
|
||||
const config = type ? AGREEMENT_CONFIGS[type] : null;
|
||||
if (!config) return null;
|
||||
|
||||
const IconComponent = getIconByType(type);
|
||||
const title = t(config.titleKey);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={null}
|
||||
header={null}
|
||||
footer={null}
|
||||
visible={visible}
|
||||
onCancel={onClose}
|
||||
closeIcon={null}
|
||||
maskClosable={true}
|
||||
centered
|
||||
width={isMobile ? '94%' : 720}
|
||||
bodyStyle={{
|
||||
padding: 0,
|
||||
borderRadius: 16,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
className='agreement-preview-modal'
|
||||
maskStyle={{
|
||||
backgroundColor: 'rgba(15, 18, 28, 0.55)',
|
||||
backdropFilter: 'blur(8px)',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className='flex flex-col bg-white dark:bg-gray-900 ring-1 ring-gray-200/60 dark:ring-gray-800/60 rounded-2xl overflow-hidden'
|
||||
style={{ height: isMobile ? '85vh' : '78vh' }}
|
||||
>
|
||||
{/* 阅读进度条 */}
|
||||
<div
|
||||
className='h-[2px] bg-gradient-to-r from-brand-from via-brand to-brand-to origin-left transition-transform duration-150 ease-out'
|
||||
style={{ transform: `scaleX(${progress / 100})` }}
|
||||
aria-hidden
|
||||
/>
|
||||
|
||||
{/* 头部 */}
|
||||
<div className='relative flex items-center justify-between px-5 sm:px-6 h-14 border-b border-gray-200/80 dark:border-gray-800/80 flex-shrink-0 bg-white/95 dark:bg-gray-900/95 backdrop-blur-md'>
|
||||
{/* 头部环境光 */}
|
||||
<div className='pointer-events-none absolute inset-0 overflow-hidden' aria-hidden>
|
||||
<div className='absolute -top-12 left-8 w-48 h-24 bg-gradient-to-br from-brand-from/15 to-brand-to/10 dark:from-brand-from/15 dark:to-brand-to/10 blur-3xl rounded-full' />
|
||||
</div>
|
||||
|
||||
<div className='relative flex items-center gap-2.5'>
|
||||
<div className='relative'>
|
||||
<div className='absolute inset-0 bg-gradient-to-br from-brand-from to-brand-to blur-md opacity-50 dark:opacity-40 rounded-lg' />
|
||||
<div className='relative w-7 h-7 rounded-lg bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center shadow-sm'>
|
||||
<IconComponent size={14} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<h2 className='text-sm font-semibold text-gray-900 dark:text-gray-50 tracking-tight'>
|
||||
{title}
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div className='relative flex items-center gap-1'>
|
||||
<a
|
||||
href={config.fullPagePath}
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
className='group inline-flex items-center gap-1 px-2 py-1.5 text-xs font-medium text-gray-500 dark:text-gray-400 hover:text-brand-deep dark:hover:text-brand-from hover:bg-gray-100/80 dark:hover:bg-gray-800/80 rounded-md transition-colors'
|
||||
title={t('在新标签页打开')}
|
||||
>
|
||||
<ExternalLink size={12} className='transition-transform group-hover:translate-x-0.5 group-hover:-translate-y-0.5' />
|
||||
<span className='hidden sm:inline'>{t('完整页面')}</span>
|
||||
</a>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className='p-1.5 rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-gray-100/80 dark:hover:bg-gray-800/80 transition-colors'
|
||||
aria-label={t('关闭')}
|
||||
>
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 内容区 */}
|
||||
<div className='flex-1 min-h-0 bg-gray-50/30 dark:bg-gray-950/20'>
|
||||
<DocumentRenderer
|
||||
apiEndpoint={config.apiEndpoint}
|
||||
title={title}
|
||||
cacheKey={config.cacheKey}
|
||||
emptyMessage={t(config.emptyKey)}
|
||||
mode='embedded'
|
||||
docType={type}
|
||||
onProgressChange={handleProgressChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AgreementModal;
|
||||
@@ -0,0 +1,637 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { API, showError } from '../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import MarkdownRenderer from '../markdown/MarkdownRenderer';
|
||||
import {
|
||||
Shield,
|
||||
ScrollText,
|
||||
ExternalLink,
|
||||
ChevronUp,
|
||||
ArrowLeft,
|
||||
BookOpen,
|
||||
Scale,
|
||||
Printer,
|
||||
} from 'lucide-react';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
|
||||
// 检查是否为 URL
|
||||
const isUrl = (content) => {
|
||||
try {
|
||||
new URL(content.trim());
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// 检查是否为 HTML 内容
|
||||
const isHtmlContent = (content) => {
|
||||
if (!content || typeof content !== 'string') return false;
|
||||
const htmlTagRegex = /<\/?[a-z][\s\S]*>/i;
|
||||
return htmlTagRegex.test(content);
|
||||
};
|
||||
|
||||
/**
|
||||
* 抽取 HTML body 内容与 style 标签。
|
||||
* 注意:此函数 NOT 是真正的 XSS 消毒,仅做结构整理;
|
||||
* 信任来源:内容由后台管理员设置(需登录管理后台),如需在不受信场景使用应替换为 DOMPurify。
|
||||
*/
|
||||
const extractHtml = (html) => {
|
||||
const tempDiv = document.createElement('div');
|
||||
tempDiv.innerHTML = html;
|
||||
const styles = Array.from(tempDiv.querySelectorAll('style'))
|
||||
.map((style) => style.innerHTML)
|
||||
.join('\n');
|
||||
// 主动剔除 script 标签,降低风险
|
||||
tempDiv.querySelectorAll('script').forEach((el) => el.remove());
|
||||
const bodyContent = tempDiv.querySelector('body');
|
||||
const content = bodyContent ? bodyContent.innerHTML : tempDiv.innerHTML;
|
||||
return { content, styles };
|
||||
};
|
||||
|
||||
// 根据 type / 标题获取对应的图标
|
||||
const getIcon = ({ type, title }) => {
|
||||
if (type === 'privacy') return Shield;
|
||||
if (type === 'agreement') return Scale;
|
||||
// 兜底(i18n 友好度有限):按标题关键字推断
|
||||
if (title?.includes('隐私') || title?.toLowerCase().includes('privacy')) {
|
||||
return Shield;
|
||||
}
|
||||
if (
|
||||
title?.includes('服务') ||
|
||||
title?.includes('用户') ||
|
||||
title?.toLowerCase().includes('terms') ||
|
||||
title?.toLowerCase().includes('service')
|
||||
) {
|
||||
return Scale;
|
||||
}
|
||||
return ScrollText;
|
||||
};
|
||||
|
||||
/**
|
||||
* 智能返回:
|
||||
* 1) 有真实历史(length>1)→ navigate(-1)
|
||||
* 2) 尝试 window.close()(脚本打开的标签页会成功,否则被忽略)
|
||||
* 3) 兜底跳首页
|
||||
*
|
||||
* 说明:因 LoginForm 的协议链接使用了 rel="noopener noreferrer",
|
||||
* 新标签里的 window.opener 为 null、document.referrer 为空,无法用 referrer 判同源。
|
||||
*/
|
||||
const useSmartBack = () => {
|
||||
const navigate = useNavigate();
|
||||
return useCallback(() => {
|
||||
if (window.history.length > 1) {
|
||||
navigate(-1);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
window.close();
|
||||
} catch (e) {
|
||||
// 浏览器拒绝则继续走兜底
|
||||
}
|
||||
// 短延时给 close() 一个机会
|
||||
setTimeout(() => {
|
||||
if (!window.closed) navigate('/');
|
||||
}, 50);
|
||||
}, [navigate]);
|
||||
};
|
||||
|
||||
/**
|
||||
* 通用文档渲染组件
|
||||
* @param {string} apiEndpoint API 接口地址
|
||||
* @param {string} title 文档标题
|
||||
* @param {string} cacheKey 本地存储缓存键
|
||||
* @param {string} emptyMessage 空内容时的提示消息
|
||||
* @param {'page'|'embedded'} mode page=独立页面(默认),embedded=嵌入式(无背景/头部)
|
||||
* @param {'agreement'|'privacy'} [docType] 文档类型(用于图标识别,比标题更可靠)
|
||||
* @param {function} [onProgressChange] 进度变化回调(嵌入模式用于宿主显示进度条)
|
||||
*/
|
||||
const DocumentRenderer = ({
|
||||
apiEndpoint,
|
||||
title,
|
||||
cacheKey,
|
||||
emptyMessage,
|
||||
mode = 'page',
|
||||
docType,
|
||||
onProgressChange,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const smartBack = useSmartBack();
|
||||
const location = useLocation();
|
||||
const [content, setContent] = useState('');
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [htmlStyles, setHtmlStyles] = useState('');
|
||||
const [processedHtmlContent, setProcessedHtmlContent] = useState('');
|
||||
const [showBackToTop, setShowBackToTop] = useState(false);
|
||||
const [readProgress, setReadProgress] = useState(0);
|
||||
const scrollContainerRef = useRef(null);
|
||||
const rootRef = useRef(null);
|
||||
const isMountedRef = useRef(true);
|
||||
const abortControllerRef = useRef(null);
|
||||
|
||||
const isEmbedded = mode === 'embedded';
|
||||
const IconComponent = getIcon({ type: docType, title });
|
||||
|
||||
const processContent = useCallback((rawContent) => {
|
||||
if (isHtmlContent(rawContent)) {
|
||||
const { content: htmlContent, styles } = extractHtml(rawContent);
|
||||
setProcessedHtmlContent(htmlContent);
|
||||
setHtmlStyles(styles);
|
||||
} else {
|
||||
setProcessedHtmlContent('');
|
||||
setHtmlStyles('');
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 加载内容(含取消保护,避免在卸载后 setState)
|
||||
useEffect(() => {
|
||||
isMountedRef.current = true;
|
||||
const controller = new AbortController();
|
||||
abortControllerRef.current = controller;
|
||||
|
||||
const load = async () => {
|
||||
const cachedContent = localStorage.getItem(cacheKey) || '';
|
||||
if (cachedContent) {
|
||||
setContent(cachedContent);
|
||||
processContent(cachedContent);
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await API.get(apiEndpoint, { signal: controller.signal });
|
||||
if (!isMountedRef.current) return;
|
||||
const { success, message, data } = res.data;
|
||||
if (success && data) {
|
||||
setContent(data);
|
||||
processContent(data);
|
||||
localStorage.setItem(cacheKey, data);
|
||||
} else if (!cachedContent) {
|
||||
showError(message || emptyMessage);
|
||||
setContent('');
|
||||
}
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted) return; // 用户离开页面
|
||||
if (!isMountedRef.current) return;
|
||||
const cached = localStorage.getItem(cacheKey) || '';
|
||||
if (!cached) {
|
||||
showError(emptyMessage);
|
||||
setContent('');
|
||||
}
|
||||
} finally {
|
||||
if (isMountedRef.current) setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
load();
|
||||
|
||||
return () => {
|
||||
isMountedRef.current = false;
|
||||
controller.abort();
|
||||
};
|
||||
}, [apiEndpoint, cacheKey, emptyMessage, processContent]);
|
||||
|
||||
// 滚动监听 + 阅读进度计算(page 模式监听 window,embedded 模式监听容器)
|
||||
const handleScroll = useCallback(
|
||||
(e) => {
|
||||
let scrollTop;
|
||||
let scrollHeight;
|
||||
let clientHeight;
|
||||
|
||||
if (
|
||||
e?.target &&
|
||||
e.target !== window &&
|
||||
e.target.scrollHeight !== undefined
|
||||
) {
|
||||
scrollTop = e.target.scrollTop;
|
||||
scrollHeight = e.target.scrollHeight;
|
||||
clientHeight = e.target.clientHeight;
|
||||
} else {
|
||||
scrollTop = window.scrollY;
|
||||
scrollHeight = document.documentElement.scrollHeight;
|
||||
clientHeight = window.innerHeight;
|
||||
}
|
||||
|
||||
setShowBackToTop(scrollTop > 300);
|
||||
|
||||
const denom = scrollHeight - clientHeight;
|
||||
const progress =
|
||||
denom > 0 ? Math.min(100, Math.max(0, (scrollTop / denom) * 100)) : 0;
|
||||
setReadProgress(progress);
|
||||
if (isEmbedded && onProgressChange) {
|
||||
onProgressChange(progress);
|
||||
}
|
||||
},
|
||||
[isEmbedded, onProgressChange],
|
||||
);
|
||||
|
||||
const scrollToTop = () => {
|
||||
const target =
|
||||
(isEmbedded && scrollContainerRef.current) || pageScrollElRef.current;
|
||||
if (target) {
|
||||
target.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
} else {
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
};
|
||||
|
||||
// page 模式的实际滚动容器不是 window:PageLayout 外层是 height:100vh + overflow:hidden,
|
||||
// 真正滚动的是内层 Semi Layout(一个普通 div)。元素的 scroll 事件不冒泡到 window,
|
||||
// 所以原来只监听 window 时 showBackToTop 永远为 false、阅读进度条恒为 0。
|
||||
// 这里向上找到真正可滚动的祖先来监听;找不到再回退 window(独立页/未来结构变化)。
|
||||
const pageScrollElRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (isEmbedded) return;
|
||||
|
||||
const findScrollParent = (node) => {
|
||||
let el = node?.parentElement;
|
||||
while (el && el !== document.body) {
|
||||
const overflowY = window.getComputedStyle(el).overflowY;
|
||||
if (
|
||||
(overflowY === 'auto' || overflowY === 'scroll') &&
|
||||
el.scrollHeight > el.clientHeight
|
||||
) {
|
||||
return el;
|
||||
}
|
||||
el = el.parentElement;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
const target = findScrollParent(rootRef.current) || window;
|
||||
pageScrollElRef.current = target === window ? null : target;
|
||||
|
||||
const onScroll = (e) => {
|
||||
if (target === window) {
|
||||
handleScroll();
|
||||
return;
|
||||
}
|
||||
handleScroll({ target });
|
||||
};
|
||||
|
||||
target.addEventListener('scroll', onScroll, { passive: true });
|
||||
return () => target.removeEventListener('scroll', onScroll);
|
||||
}, [isEmbedded, handleScroll]);
|
||||
|
||||
// 处理 HTML 样式注入
|
||||
useEffect(() => {
|
||||
const styleId = `document-renderer-styles-${cacheKey}-${mode}`;
|
||||
|
||||
if (htmlStyles) {
|
||||
let styleEl = document.getElementById(styleId);
|
||||
if (!styleEl) {
|
||||
styleEl = document.createElement('style');
|
||||
styleEl.id = styleId;
|
||||
styleEl.type = 'text/css';
|
||||
document.head.appendChild(styleEl);
|
||||
}
|
||||
styleEl.innerHTML = htmlStyles;
|
||||
} else {
|
||||
const el = document.getElementById(styleId);
|
||||
if (el) el.remove();
|
||||
}
|
||||
|
||||
return () => {
|
||||
const el = document.getElementById(styleId);
|
||||
if (el) el.remove();
|
||||
};
|
||||
}, [htmlStyles, cacheKey, mode]);
|
||||
|
||||
// URL hash 自动滚动到对应 h2/h3 anchor(仅 page 模式 + 内容加载完成后)
|
||||
useEffect(() => {
|
||||
if (isEmbedded || loading || !content || !location.hash) return;
|
||||
const id = decodeURIComponent(location.hash.slice(1));
|
||||
if (!id) return;
|
||||
const t = setTimeout(() => {
|
||||
const el = document.getElementById(id);
|
||||
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}, 200);
|
||||
return () => clearTimeout(t);
|
||||
}, [isEmbedded, loading, content, location.hash]);
|
||||
|
||||
// 为 h2/h3 注入 id + 锚点链接(page 模式 + Markdown 已渲染 DOM 后)
|
||||
const contentRef = useRef(null);
|
||||
useEffect(() => {
|
||||
if (isEmbedded || loading || !contentRef.current) return;
|
||||
const root = contentRef.current;
|
||||
const slugify = (text) =>
|
||||
String(text || '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/[^\w\-一-龥]+/g, '')
|
||||
.slice(0, 80);
|
||||
|
||||
const seen = new Map();
|
||||
const headings = root.querySelectorAll('h2, h3');
|
||||
headings.forEach((h) => {
|
||||
if (h.querySelector('.doc-anchor')) return; // 已处理
|
||||
let base = h.id || slugify(h.textContent);
|
||||
if (!base) return;
|
||||
let id = base;
|
||||
const n = seen.get(base) || 0;
|
||||
if (n > 0) id = `${base}-${n}`;
|
||||
seen.set(base, n + 1);
|
||||
h.id = id;
|
||||
|
||||
const a = document.createElement('a');
|
||||
a.href = `#${id}`;
|
||||
a.className = 'doc-anchor';
|
||||
a.setAttribute('aria-label', '复制段落链接');
|
||||
a.textContent = '#';
|
||||
a.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
const url = `${window.location.origin}${window.location.pathname}#${id}`;
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(url).catch(() => {});
|
||||
}
|
||||
history.replaceState(null, '', `#${id}`);
|
||||
});
|
||||
h.prepend(a);
|
||||
});
|
||||
}, [isEmbedded, loading, content, processedHtmlContent]);
|
||||
|
||||
// 文档内容样式(prose)—— 同时兼顾浅色与深色
|
||||
const proseClass = `prose prose-base dark:prose-invert max-w-none
|
||||
prose-headings:font-semibold prose-headings:text-gray-900 dark:prose-headings:text-gray-50 prose-headings:scroll-mt-24 prose-headings:tracking-tight
|
||||
prose-h1:text-2xl prose-h1:mb-4 prose-h1:mt-0
|
||||
prose-h2:text-lg prose-h2:mt-8 prose-h2:mb-3 prose-h2:pb-2 prose-h2:border-b prose-h2:border-gray-200 dark:prose-h2:border-gray-800
|
||||
prose-h3:text-base prose-h3:mt-5 prose-h3:mb-2
|
||||
prose-p:text-gray-700 dark:prose-p:text-gray-300 prose-p:leading-[1.75] prose-p:my-3
|
||||
prose-a:text-brand-deep dark:prose-a:text-brand-from prose-a:no-underline prose-a:font-medium hover:prose-a:underline hover:prose-a:underline-offset-4
|
||||
prose-strong:text-gray-900 dark:prose-strong:text-white prose-strong:font-semibold
|
||||
prose-code:bg-brand/10 dark:prose-code:bg-brand/15 prose-code:text-brand-deep dark:prose-code:text-brand-from prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-[0.875em] prose-code:font-mono prose-code:before:content-none prose-code:after:content-none prose-code:border prose-code:border-brand/15 dark:prose-code:border-brand/20
|
||||
prose-pre:bg-gray-50 dark:prose-pre:bg-gray-900/60 prose-pre:border prose-pre:border-gray-200 dark:prose-pre:border-gray-800 prose-pre:rounded-lg
|
||||
prose-ul:my-3 prose-ol:my-3 prose-ul:space-y-1 prose-ol:space-y-1
|
||||
prose-li:text-gray-700 dark:prose-li:text-gray-300 prose-li:my-0.5 prose-li:marker:text-brand
|
||||
prose-blockquote:border-l-4 prose-blockquote:border-brand prose-blockquote:bg-brand/5 dark:prose-blockquote:bg-brand/10 prose-blockquote:py-2 prose-blockquote:px-4 prose-blockquote:rounded-r prose-blockquote:not-italic prose-blockquote:text-gray-700 dark:prose-blockquote:text-gray-300
|
||||
prose-hr:border-gray-200 dark:prose-hr:border-gray-800 prose-hr:my-6
|
||||
prose-table:rounded-lg prose-table:overflow-hidden
|
||||
prose-th:bg-gray-50 dark:prose-th:bg-gray-800/50 prose-th:text-gray-900 dark:prose-th:text-gray-100
|
||||
prose-td:border-gray-200 dark:prose-td:border-gray-800
|
||||
prose-img:rounded-lg prose-img:border prose-img:border-gray-200 dark:prose-img:border-gray-800`;
|
||||
|
||||
// ============ Skeleton(短暂加载也更稳) ============
|
||||
const renderLoading = () => (
|
||||
<div className='doc-fade-in' aria-busy='true' aria-live='polite'>
|
||||
<div className='space-y-3 max-w-2xl'>
|
||||
<div className='h-7 w-2/3 rounded-md bg-gray-200/70 dark:bg-gray-800/70 animate-pulse' />
|
||||
<div className='h-4 w-1/3 rounded-md bg-gray-200/60 dark:bg-gray-800/60 animate-pulse' />
|
||||
<div className='h-px bg-gray-200 dark:bg-gray-800 my-5' />
|
||||
<div className='space-y-2.5'>
|
||||
<div className='h-4 w-full rounded bg-gray-200/60 dark:bg-gray-800/60 animate-pulse' />
|
||||
<div className='h-4 w-[92%] rounded bg-gray-200/60 dark:bg-gray-800/60 animate-pulse' />
|
||||
<div className='h-4 w-[85%] rounded bg-gray-200/60 dark:bg-gray-800/60 animate-pulse' />
|
||||
</div>
|
||||
<div className='h-6 w-1/2 rounded bg-gray-200/70 dark:bg-gray-800/70 animate-pulse mt-6' />
|
||||
<div className='space-y-2.5'>
|
||||
<div className='h-4 w-full rounded bg-gray-200/60 dark:bg-gray-800/60 animate-pulse' />
|
||||
<div className='h-4 w-[88%] rounded bg-gray-200/60 dark:bg-gray-800/60 animate-pulse' />
|
||||
</div>
|
||||
</div>
|
||||
<span className='sr-only'>{t('加载中...')}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
// ============ 空状态 ============
|
||||
const renderEmpty = () => (
|
||||
<div className='flex flex-col items-center justify-center py-20 px-6 text-center doc-fade-in'>
|
||||
<div className='relative mb-5'>
|
||||
<div className='absolute inset-0 bg-gradient-to-br from-brand-from/20 to-brand-to/20 dark:from-brand-from/10 dark:to-brand-to/10 blur-2xl rounded-full' />
|
||||
<div className='relative w-16 h-16 bg-gray-100 dark:bg-gray-800/80 border border-gray-200 dark:border-gray-700/60 rounded-2xl flex items-center justify-center'>
|
||||
<IconComponent
|
||||
size={28}
|
||||
className='text-gray-400 dark:text-gray-500'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<h3 className='text-base font-semibold text-gray-800 dark:text-gray-100 mb-1.5'>
|
||||
{t('内容正在准备中')}
|
||||
</h3>
|
||||
<p className='text-sm text-gray-500 dark:text-gray-400'>
|
||||
{t('管理员尚未设置') + title + t('内容')}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
// ============ URL 卡片 ============
|
||||
const renderUrlCard = () => (
|
||||
<div className='flex flex-col items-center justify-center py-16 px-6 text-center doc-fade-in'>
|
||||
<div className='relative mb-5'>
|
||||
<div className='absolute -inset-4 bg-gradient-to-br from-brand-from/30 to-brand-to/30 dark:from-brand-from/20 dark:to-brand-to/20 blur-2xl rounded-full' />
|
||||
<div className='relative w-16 h-16 bg-gradient-to-br from-brand-from to-brand-to rounded-2xl flex items-center justify-center shadow-lg shadow-brand/30 dark:shadow-brand/20'>
|
||||
<IconComponent size={28} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<h3 className='text-lg font-semibold text-gray-900 dark:text-white mb-2'>
|
||||
{title}
|
||||
</h3>
|
||||
<p className='text-sm text-gray-500 dark:text-gray-400 mb-6 max-w-md'>
|
||||
{t('管理员设置了外部链接,点击下方按钮访问完整文档')}
|
||||
</p>
|
||||
<a
|
||||
href={content.trim()}
|
||||
target='_blank'
|
||||
rel='noopener noreferrer'
|
||||
title={content.trim()}
|
||||
className='group inline-flex items-center gap-2 px-6 py-2.5 bg-gradient-to-r from-brand-from to-brand-to hover:shadow-lg hover:shadow-brand/30 dark:hover:shadow-brand/20 text-white text-sm font-medium rounded-lg shadow-sm transition-all hover:-translate-y-0.5'
|
||||
>
|
||||
<BookOpen size={16} />
|
||||
{t('访问') + title}
|
||||
<ExternalLink
|
||||
size={14}
|
||||
className='transition-transform group-hover:translate-x-0.5'
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
|
||||
// ============ HTML / Markdown 主体 ============
|
||||
const renderDocumentBody = () => {
|
||||
if (isHtmlContent(content)) {
|
||||
return (
|
||||
<div
|
||||
ref={contentRef}
|
||||
className={`${proseClass} doc-content`}
|
||||
dangerouslySetInnerHTML={{ __html: processedHtmlContent }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div ref={contentRef} className={`${proseClass} doc-content`}>
|
||||
<MarkdownRenderer content={content} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ============ 主体决策 ============
|
||||
const renderBody = () => {
|
||||
if (loading) return renderLoading();
|
||||
if (!content || content.trim() === '') return renderEmpty();
|
||||
if (isUrl(content)) return renderUrlCard();
|
||||
return renderDocumentBody();
|
||||
};
|
||||
|
||||
// ============ 嵌入模式 ============
|
||||
if (isEmbedded) {
|
||||
return (
|
||||
<div
|
||||
ref={scrollContainerRef}
|
||||
onScroll={handleScroll}
|
||||
className='relative h-full overflow-y-auto px-5 sm:px-8 py-6 doc-fade-in scroll-smooth doc-scrollbar'
|
||||
>
|
||||
{renderBody()}
|
||||
|
||||
<button
|
||||
onClick={scrollToTop}
|
||||
className={`sticky bottom-3 ml-auto block p-2 bg-white/95 dark:bg-gray-800/95 backdrop-blur-md rounded-full shadow-lg border border-gray-200 dark:border-gray-700 hover:shadow-xl hover:-translate-y-0.5 hover:bg-white dark:hover:bg-gray-800 transition-all duration-200 ${
|
||||
showBackToTop ? 'opacity-100' : 'opacity-0 pointer-events-none'
|
||||
}`}
|
||||
aria-label={t('返回顶部')}
|
||||
>
|
||||
<ChevronUp size={16} className='text-gray-600 dark:text-gray-300' />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ============ 页面模式 ============
|
||||
const hasRealContent =
|
||||
!loading && content && content.trim() !== '' && !isUrl(content);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={rootRef}
|
||||
className='relative min-h-screen bg-gray-50 dark:bg-gray-950 doc-fade-in doc-page-root'
|
||||
>
|
||||
{/* 阅读进度条 */}
|
||||
<div
|
||||
className='fixed top-0 left-0 right-0 z-50 h-[2px] bg-gradient-to-r from-brand-from via-brand to-brand-to origin-left transition-transform duration-150 ease-out doc-no-print'
|
||||
style={{ transform: `scaleX(${readProgress / 100})` }}
|
||||
aria-hidden
|
||||
/>
|
||||
|
||||
{/* 顶部环境光 */}
|
||||
<div
|
||||
className='pointer-events-none absolute inset-x-0 top-0 h-[420px] overflow-hidden doc-no-print'
|
||||
aria-hidden
|
||||
>
|
||||
<div className='absolute -top-40 left-1/2 -translate-x-1/2 w-[900px] h-[500px] bg-gradient-to-b from-brand-from/[0.08] via-brand-via/[0.04] to-transparent dark:from-brand-from/[0.12] dark:via-brand-via/[0.06] blur-3xl rounded-full' />
|
||||
</div>
|
||||
|
||||
{/* Sticky Header */}
|
||||
<header className='sticky top-0 z-40 bg-white/85 dark:bg-gray-950/85 backdrop-blur-xl border-b border-gray-200/70 dark:border-gray-800/70 doc-no-print'>
|
||||
<div className='max-w-3xl mx-auto px-4 sm:px-6 h-14 flex items-center justify-between gap-2'>
|
||||
<button
|
||||
onClick={smartBack}
|
||||
className='group inline-flex items-center gap-1.5 px-2.5 py-1.5 -ml-2 text-sm font-medium text-gray-600 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white hover:bg-gray-100 dark:hover:bg-gray-800/80 rounded-md transition-colors shrink-0'
|
||||
>
|
||||
<ArrowLeft
|
||||
size={15}
|
||||
className='transition-transform group-hover:-translate-x-0.5'
|
||||
/>
|
||||
<span>{t('返回')}</span>
|
||||
</button>
|
||||
|
||||
<div className='flex items-center gap-2 text-gray-700 dark:text-gray-200 min-w-0'>
|
||||
<div className='w-6 h-6 rounded-md bg-brand/10 dark:bg-brand/20 flex items-center justify-center shrink-0'>
|
||||
<IconComponent
|
||||
size={13}
|
||||
className='text-brand-deep dark:text-brand-from'
|
||||
/>
|
||||
</div>
|
||||
<span className='text-sm font-semibold tracking-tight truncate'>
|
||||
{title}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 打印按钮 */}
|
||||
<button
|
||||
onClick={() => window.print()}
|
||||
className='inline-flex items-center justify-center w-8 h-8 text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white hover:bg-gray-100 dark:hover:bg-gray-800/80 rounded-md transition-colors shrink-0'
|
||||
aria-label={t('打印')}
|
||||
title={t('打印')}
|
||||
>
|
||||
<Printer size={15} />
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* 文档主体 */}
|
||||
<main className='relative max-w-3xl mx-auto px-4 sm:px-6 py-8 sm:py-12'>
|
||||
{/* 文档标题区 */}
|
||||
{hasRealContent && (
|
||||
<div className='mb-6 doc-slide-up'>
|
||||
<div className='flex items-center gap-2 mb-3 doc-no-print'>
|
||||
<div className='w-1 h-5 bg-gradient-to-b from-brand-from to-brand-to rounded-full' />
|
||||
<span className='text-xs font-medium text-brand-deep dark:text-brand-from uppercase tracking-wider'>
|
||||
{t('法律文档')}
|
||||
</span>
|
||||
</div>
|
||||
<h1 className='text-2xl sm:text-3xl font-bold text-gray-900 dark:text-white mb-2 tracking-tight'>
|
||||
{title}
|
||||
</h1>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{t('最后更新')}:{new Date().toLocaleDateString()}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 文档卡片 */}
|
||||
<article className='doc-card relative bg-white dark:bg-gray-900 rounded-xl border border-gray-200/80 dark:border-gray-800/80 shadow-[0_1px_2px_rgba(0,0,0,0.04),0_4px_24px_-12px_rgba(0,0,0,0.08)] dark:shadow-[0_1px_2px_rgba(0,0,0,0.3),0_8px_32px_-12px_rgba(0,0,0,0.4)] p-6 sm:p-10 doc-slide-up'>
|
||||
{renderBody()}
|
||||
</article>
|
||||
|
||||
{/* 底部返回入口 */}
|
||||
{!loading && (
|
||||
<div className='mt-8 flex justify-center doc-no-print'>
|
||||
<button
|
||||
onClick={smartBack}
|
||||
className='group inline-flex items-center gap-2 px-5 py-2 text-sm bg-white dark:bg-gray-900 hover:bg-gray-50 dark:hover:bg-gray-800/80 border border-gray-200 dark:border-gray-800 hover:border-gray-300 dark:hover:border-gray-700 rounded-lg text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white shadow-sm transition-all'
|
||||
>
|
||||
<ArrowLeft
|
||||
size={14}
|
||||
className='transition-transform group-hover:-translate-x-0.5'
|
||||
/>
|
||||
{t('返回')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
|
||||
{/* 返回顶部 FAB */}
|
||||
<button
|
||||
onClick={scrollToTop}
|
||||
className={`fixed bottom-6 right-6 z-50 p-2.5 bg-white/95 dark:bg-gray-800/95 backdrop-blur-md rounded-full shadow-lg border border-gray-200 dark:border-gray-700 hover:shadow-xl hover:-translate-y-0.5 hover:bg-white dark:hover:bg-gray-800 transition-all duration-200 doc-no-print ${
|
||||
showBackToTop
|
||||
? 'opacity-100 translate-y-0'
|
||||
: 'opacity-0 translate-y-2 pointer-events-none'
|
||||
}`}
|
||||
aria-label={t('返回顶部')}
|
||||
>
|
||||
<ChevronUp size={18} className='text-gray-600 dark:text-gray-300' />
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DocumentRenderer;
|
||||
@@ -0,0 +1,282 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
|
||||
const MapleBackground = () => {
|
||||
const canvasRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
const ctx = canvas.getContext('2d');
|
||||
let animationFrameId;
|
||||
let width, height;
|
||||
|
||||
// Realistic Maple Leaf Path Data (SVG path)
|
||||
const leafPathData =
|
||||
'M150.6,90.8c-5.8,1.6-11.3-1.6-14.9-5.3c-3.6-3.7-5.5-8.5-4.8-13.6c-0.6-2.6-1.5-5.1-2.9-7.4c-3.2-5.4-8.8-8.8-14.8-9.5 c-3.8-0.5-7.6,0.3-11.1,2.1c-0.8,0.4-1.6,0.9-2.5,1.5c-0.1-0.1-0.2-0.3-0.3-0.4c-3-5.2-7.8-9.1-13.4-10.9c-2.3-0.7-4.7-1.1-7-1.1 c-0.8,0-1.6,0-2.3,0.1c0.1-1.3,0.1-2.7-0.1-4c-0.4-3.4-1.7-6.5-3.6-9.1c-4.3-5.7-11.2-8.5-18.1-7.4c-6.8,1.1-12.2,6-14.3,12.7 c-0.6,1.9-0.8,3.9-0.7,5.9c-2.6-0.3-5.3-0.2-7.8,0.5c-6.2,1.5-11.2,6.1-13.6,12.1c-0.7,1.8-1.2,3.7-1.3,5.6c-0.8-0.6-1.7-1.1-2.6-1.6 c-3.5-1.8-7.3-2.6-11.1-2.1c-6.1,0.7-11.6,4.1-14.8,9.5c-1.4,2.3-2.3,4.8-2.9,7.4c0.7,5.1-1.2,9.9-4.8,13.6 c-3.6,3.7-9.1,6.9-14.9,5.3c-2.6-0.7-5.1-1.9-7.2-3.5c-1.3-1-2.3-2.3-3.1-3.7c-0.6,3.1-0.1,6.4,1.4,9.2c2.6,4.9,7.6,8.2,13,8.7 c3.5,0.3,6.9-0.5,9.9-2.1c0.4,2.5,1.2,4.8,2.5,6.9c2.6,4.3,6.8,7.3,11.6,8.4c0.8,0.2,1.6,0.3,2.4,0.3c0.7,0,1.3-0.1,2-0.2 c-0.1,1.1-0.1,2.3,0,3.4c0.6,5,3.6,9.2,8.1,11.5c4.5,2.3,9.8,2.3,14.3,0c1.7-0.9,3.2-2.1,4.4-3.5c0.8,3.1,2.6,5.8,5.1,7.8 c4.4,3.4,10.2,4.3,15.3,2.4c1.1-0.4,2.2-0.9,3.2-1.6l0.5,21.7c0.1,2.5,2.2,4.5,4.7,4.4c2.5-0.1,4.5-2.2,4.4-4.7l-0.5-22.6 c1.1,0.5,2.2,0.9,3.4,1.2c1.7,0.4,3.4,0.6,5.1,0.6c3.9,0,7.6-1.2,10.7-3.6c2.5-1.9,4.4-4.6,5.2-7.6c1.3,1.4,2.8,2.6,4.5,3.5 c4.5,2.3,9.8,2.3,14.3,0c4.5-2.3,7.5-6.5,8.1-11.5c0.1-1.1,0.1-2.3,0-3.4c0.7,0.1,1.3,0.2,2,0.2c0.8,0,1.6-0.1,2.4-0.3 c4.8-1.1,9-4.1,11.6-8.4c1.2-2.1,2.1-4.4,2.5-6.9c3.1,1.7,6.4,2.4,9.9,2.1c5.5-0.5,10.4-3.8,13-8.7c1.5-2.8,2-6.1,1.4-9.2 C157.9,87,156.9,88.3,155.6,89.3C153.5,90.9,153.2,90.1,150.6,90.8z';
|
||||
|
||||
const leafPath = new Path2D(leafPathData);
|
||||
|
||||
// 检测是否为移动设备
|
||||
const isMobile =
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent,
|
||||
);
|
||||
|
||||
// 简化的云朵类(性能优化版)
|
||||
class Cloud {
|
||||
constructor() {
|
||||
this.reset();
|
||||
this.x = Math.random() * width; // 随机初始位置
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.x = -150;
|
||||
this.y = Math.random() * (height * 0.3); // 屏幕上方 30%
|
||||
this.speed = Math.random() * 0.15 + 0.08;
|
||||
this.scale = Math.random() * 0.4 + 0.4;
|
||||
this.opacity = Math.random() * 0.2 + 0.3;
|
||||
}
|
||||
|
||||
update() {
|
||||
this.x += this.speed;
|
||||
if (this.x > width + 150) {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
|
||||
draw(ctx) {
|
||||
ctx.save();
|
||||
ctx.translate(this.x, this.y);
|
||||
ctx.scale(this.scale, this.scale);
|
||||
ctx.globalAlpha = this.opacity;
|
||||
ctx.fillStyle = '#FFFFFF';
|
||||
|
||||
// 简化云朵:只用 3 个圆形(原版 4 个)
|
||||
ctx.beginPath();
|
||||
ctx.arc(0, 0, 25, 0, Math.PI * 2);
|
||||
ctx.arc(30, -8, 30, 0, Math.PI * 2);
|
||||
ctx.arc(55, 0, 25, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
class Leaf {
|
||||
constructor() {
|
||||
this.init(true);
|
||||
}
|
||||
|
||||
init(randomY = false) {
|
||||
this.x = Math.random() * width;
|
||||
this.y = randomY ? Math.random() * height : -50;
|
||||
this.size = (Math.random() * 0.5 + 0.3) * 0.4; // Scaled down for the path size
|
||||
this.speed = Math.random() * 1.5 + 0.5;
|
||||
this.sway = Math.random() * 0.02 + 0.005;
|
||||
this.swayOffset = Math.random() * Math.PI * 2;
|
||||
this.rotation = Math.random() * Math.PI * 2;
|
||||
this.rotationSpeed = (Math.random() - 0.5) * 0.02;
|
||||
|
||||
// Realistic Autumn Colors
|
||||
const colors = [
|
||||
'#C0392B', // Dark Red
|
||||
'#E74C3C', // Red
|
||||
'#D35400', // Pumpkin
|
||||
'#E67E22', // Carrot
|
||||
'#F39C12', // Orange
|
||||
'#F1C40F', // Yellow
|
||||
'#A0522D', // Sienna (Brown)
|
||||
'#8B4513', // SaddleBrown
|
||||
];
|
||||
this.color = colors[Math.floor(Math.random() * colors.length)];
|
||||
}
|
||||
|
||||
update() {
|
||||
this.y += this.speed;
|
||||
this.x += Math.sin(this.swayOffset) * 0.8; // More gentle sway
|
||||
this.swayOffset += this.sway;
|
||||
this.rotation += this.rotationSpeed;
|
||||
|
||||
if (this.y > height + 50) {
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
|
||||
draw(ctx) {
|
||||
ctx.save();
|
||||
ctx.translate(this.x, this.y);
|
||||
ctx.rotate(this.rotation);
|
||||
ctx.scale(this.size, this.size);
|
||||
|
||||
// Offset to center the path rotation
|
||||
ctx.translate(-75, -75);
|
||||
|
||||
// 添加轻微阴影以保留立体感(性能影响小)
|
||||
ctx.shadowColor = 'rgba(0,0,0,0.15)';
|
||||
ctx.shadowBlur = 3;
|
||||
ctx.shadowOffsetX = 1;
|
||||
ctx.shadowOffsetY = 1;
|
||||
|
||||
ctx.fillStyle = this.color;
|
||||
ctx.fill(leafPath);
|
||||
|
||||
// 移除阴影以避免影响叶脉
|
||||
ctx.shadowColor = 'transparent';
|
||||
|
||||
// 只在桌面端绘制叶脉,移动端跳过以提升性能
|
||||
if (!isMobile) {
|
||||
ctx.strokeStyle = 'rgba(0, 0, 0, 0.2)';
|
||||
ctx.lineWidth = 1.5;
|
||||
ctx.lineCap = 'round';
|
||||
|
||||
// 简化叶脉:绘制主脉和 2 条侧脉
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(78, 115);
|
||||
ctx.lineTo(78, 20);
|
||||
ctx.stroke();
|
||||
|
||||
// 上侧脉
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(78, 100);
|
||||
ctx.quadraticCurveTo(60, 80, 30, 45);
|
||||
ctx.stroke();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(78, 100);
|
||||
ctx.quadraticCurveTo(96, 80, 125, 45);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
let leaves = [];
|
||||
let clouds = [];
|
||||
// 根据设备性能自适应调整元素数量
|
||||
const LEAF_COUNT = isMobile ? 10 : 20;
|
||||
const CLOUD_COUNT = isMobile ? 2 : 3; // 简化版:移动端 2 朵,桌面端 3 朵
|
||||
|
||||
const initElements = () => {
|
||||
leaves = [];
|
||||
clouds = [];
|
||||
for (let i = 0; i < LEAF_COUNT; i++) {
|
||||
leaves.push(new Leaf());
|
||||
}
|
||||
for (let i = 0; i < CLOUD_COUNT; i++) {
|
||||
clouds.push(new Cloud());
|
||||
}
|
||||
};
|
||||
|
||||
const drawSkyAndField = () => {
|
||||
// 保留天空渐变(性能影响小,视觉提升大)
|
||||
const skyGrad = ctx.createLinearGradient(0, 0, 0, height);
|
||||
skyGrad.addColorStop(0, '#5CACEE');
|
||||
skyGrad.addColorStop(0.6, '#B0E0E6');
|
||||
skyGrad.addColorStop(1, '#E0F7FA');
|
||||
ctx.fillStyle = skyGrad;
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
|
||||
// 绘制云朵(在山丘后面)
|
||||
clouds.forEach((cloud) => {
|
||||
cloud.update();
|
||||
cloud.draw(ctx);
|
||||
});
|
||||
|
||||
// 简化山丘:只保留 2 层以保持层次感
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, height * 0.85);
|
||||
ctx.bezierCurveTo(
|
||||
width * 0.4,
|
||||
height * 0.75,
|
||||
width * 0.6,
|
||||
height * 0.9,
|
||||
width,
|
||||
height * 0.82,
|
||||
);
|
||||
ctx.lineTo(width, height);
|
||||
ctx.lineTo(0, height);
|
||||
ctx.fillStyle = '#8FBC8F';
|
||||
ctx.fill();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(0, height);
|
||||
ctx.lineTo(0, height * 0.95);
|
||||
ctx.bezierCurveTo(
|
||||
width * 0.5,
|
||||
height * 1.05,
|
||||
width * 0.8,
|
||||
height * 0.92,
|
||||
width,
|
||||
height * 0.96,
|
||||
);
|
||||
ctx.lineTo(width, height);
|
||||
ctx.fillStyle = '#556B2F';
|
||||
ctx.fill();
|
||||
};
|
||||
|
||||
const animate = () => {
|
||||
ctx.clearRect(0, 0, width, height);
|
||||
|
||||
drawSkyAndField();
|
||||
|
||||
leaves.forEach((leaf) => {
|
||||
leaf.update();
|
||||
leaf.draw(ctx);
|
||||
});
|
||||
|
||||
animationFrameId = requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
const resize = () => {
|
||||
width = window.innerWidth;
|
||||
height = window.innerHeight;
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
};
|
||||
|
||||
window.addEventListener('resize', resize);
|
||||
resize();
|
||||
initElements();
|
||||
animate();
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', resize);
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
zIndex: -1,
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default MapleBackground;
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import {
|
||||
Select,
|
||||
Spin,
|
||||
Typography,
|
||||
Empty,
|
||||
Tag,
|
||||
Tooltip,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { Lock } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useModelSelector } from '../../hooks/models/useModelSelector';
|
||||
import { MODEL_CATEGORY_NAMES } from '../../constants';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
/**
|
||||
* 模型选择器组件
|
||||
* @param {string} category - 模型分类(可选)
|
||||
* @param {string} value - 当前选中的模型ID或名称
|
||||
* @param {function} onChange - 模型变化回调
|
||||
* @param {string} placeholder - 占位文本
|
||||
* @param {boolean} disabled - 是否禁用
|
||||
* @param {string} size - 尺寸
|
||||
*/
|
||||
const ModelSelector = ({
|
||||
category = null,
|
||||
value,
|
||||
onChange,
|
||||
placeholder,
|
||||
disabled = false,
|
||||
size = 'default',
|
||||
showCategoryLabel = false,
|
||||
// 加载完成后向父组件回传模型列表(用于父组件按 name 反查 model 对象,避免重复 fetch)
|
||||
onModelsLoaded,
|
||||
// 是否在初次加载完成后自动选中第一个模型(外部需要"先回填再生成"时可关闭)
|
||||
autoSelectFirst = true,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { models, loading, selectedModel, setSelectedModel } =
|
||||
useModelSelector(category);
|
||||
const isInitializedRef = useRef(false);
|
||||
|
||||
// 当模型加载完成时,自动选择第一个「可调用」模型(避免默认选中锁定模型)
|
||||
useEffect(() => {
|
||||
if (!loading && models.length > 0 && !isInitializedRef.current) {
|
||||
if (autoSelectFirst) {
|
||||
const firstModel = models.find((m) => !m.level_locked);
|
||||
setSelectedModel(firstModel || null);
|
||||
if (firstModel && onChange) {
|
||||
onChange(firstModel);
|
||||
}
|
||||
}
|
||||
isInitializedRef.current = true;
|
||||
}
|
||||
}, [loading, models, setSelectedModel, onChange, autoSelectFirst]);
|
||||
|
||||
// 把加载好的模型列表传给父组件
|
||||
useEffect(() => {
|
||||
if (!onModelsLoaded) return;
|
||||
if (loading) return;
|
||||
onModelsLoaded(models);
|
||||
}, [models, loading, onModelsLoaded]);
|
||||
|
||||
// 处理模型选择:锁定(仅可见)模型不可选中
|
||||
const handleChange = (selectedValue) => {
|
||||
const model = models.find(
|
||||
(m) => m.id === selectedValue || m.model_name === selectedValue,
|
||||
);
|
||||
if (model && !model.level_locked) {
|
||||
setSelectedModel(model);
|
||||
if (onChange) {
|
||||
onChange(model);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 渲染模型选项:level_state=visible 展示锁态并禁用
|
||||
const renderOption = (model) => {
|
||||
const locked = model.level_locked;
|
||||
return (
|
||||
<Select.Option
|
||||
key={model.id}
|
||||
value={model.id}
|
||||
disabled={locked}
|
||||
showTick={!locked}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<Text strong type={locked ? 'tertiary' : undefined}>
|
||||
{model.model_name}
|
||||
</Text>
|
||||
{model.vendor && (
|
||||
<Text type='secondary' size='small' style={{ marginLeft: '8px' }}>
|
||||
({model.vendor})
|
||||
</Text>
|
||||
)}
|
||||
{locked && (
|
||||
<Tooltip content={t('当前等级无权调用此模型,升级等级后可用')}>
|
||||
<Tag
|
||||
size='small'
|
||||
color='grey'
|
||||
prefixIcon={<Lock size={12} />}
|
||||
style={{ marginLeft: '8px' }}
|
||||
>
|
||||
{t('仅可见')}
|
||||
</Tag>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</Select.Option>
|
||||
);
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div style={{ textAlign: 'center', padding: '20px' }}>
|
||||
<Spin />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (models.length === 0) {
|
||||
return (
|
||||
<Empty
|
||||
title={t('暂无可用模型')}
|
||||
description={
|
||||
category
|
||||
? `${MODEL_CATEGORY_NAMES[category]}类模型暂无可用`
|
||||
: t('请先添加模型')
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{showCategoryLabel && category && (
|
||||
<Text
|
||||
type='secondary'
|
||||
size='small'
|
||||
style={{ display: 'block', marginBottom: '4px' }}
|
||||
>
|
||||
{MODEL_CATEGORY_NAMES[category]}
|
||||
</Text>
|
||||
)}
|
||||
<Select
|
||||
value={value || selectedModel?.id}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder || t('请选择模型')}
|
||||
disabled={disabled}
|
||||
size={size}
|
||||
style={{ width: '100%' }}
|
||||
filter
|
||||
showClear
|
||||
>
|
||||
{models.map(renderOption)}
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ModelSelector;
|
||||
@@ -0,0 +1,532 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
|
||||
/**
|
||||
* 深海八爪 · 幽光 —— 登录页背景动画
|
||||
*
|
||||
* 七层景深(由后到前):
|
||||
* 1. 景深渐变背景(浅→深,带 vignette)
|
||||
* 2. 顶部光柱(brand-primary,缓 breathing)
|
||||
* 3. 中层浮游粒子(brand-primary 微辉光)
|
||||
* 4. 触手剪影 + 吸盘 Mexican wave 发光(右下角)
|
||||
* 5. 上升气泡(白色,正弦摆动)
|
||||
* 6. 前景闪烁粒子(brand-gradient-to,快移视差)
|
||||
* 7. 生命脉冲(每 6-10s 一次环形扩散)
|
||||
*
|
||||
* 立体感来源:
|
||||
* - 鼠标视差(各层不同步移动,后层慢、前层快)
|
||||
* - 触手 sucker 波浪式呼吸(像 Mexican wave)
|
||||
* - 偶发生命脉冲(节奏惊喜)
|
||||
*
|
||||
* 主题适配:
|
||||
* - 所有发光层用 --brand-primary / --brand-gradient-to(CSS 变量实时读取)
|
||||
* - 暗色模式背景换为午夜蓝→墨黑
|
||||
* - prefers-reduced-motion:关闭脉冲 / breathing / 视差,只留缓慢气泡
|
||||
*
|
||||
* 性能:
|
||||
* - 单 canvas + 单 rAF 循环
|
||||
* - 设备自适应粒子数(移动端减半)
|
||||
* - 主题色每 500ms 读一次(不是每帧)
|
||||
*/
|
||||
|
||||
// ─── 工具函数 ─────────────────────────────────────────────────
|
||||
const hexToRgb = (hex) => {
|
||||
if (!hex) return { r: 99, g: 102, b: 241 }; // brand-primary 兜底
|
||||
let h = hex.replace('#', '').trim();
|
||||
if (h.length === 3) h = h.split('').map((c) => c + c).join('');
|
||||
if (h.length === 8) h = h.slice(0, 6); // 忽略 alpha
|
||||
if (!/^[0-9a-fA-F]{6}$/.test(h)) return { r: 99, g: 102, b: 241 };
|
||||
const num = parseInt(h, 16);
|
||||
return { r: (num >> 16) & 255, g: (num >> 8) & 255, b: num & 255 };
|
||||
};
|
||||
const rgba = (c, a) => `rgba(${c.r}, ${c.g}, ${c.b}, ${a})`;
|
||||
const lerp = (a, b, t) => a + (b - a) * t;
|
||||
const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
||||
// 三阶 Bezier 求 t 处坐标(给触手沿曲线放置吸盘用)
|
||||
const bezierPoint = (p0, p1, p2, p3, t) => {
|
||||
const mt = 1 - t;
|
||||
return mt * mt * mt * p0 + 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t * p3;
|
||||
};
|
||||
|
||||
// ─── 粒子类 ──────────────────────────────────────────────────
|
||||
class Plankton {
|
||||
constructor(width, height) {
|
||||
this.w = width;
|
||||
this.h = height;
|
||||
this.reset(true);
|
||||
}
|
||||
reset(randomY = false) {
|
||||
this.x = Math.random() * this.w;
|
||||
this.y = randomY ? Math.random() * this.h : Math.random() < 0.5 ? -10 : this.h + 10;
|
||||
this.size = Math.random() * 1.5 + 0.5;
|
||||
this.vx = (Math.random() - 0.5) * 0.2;
|
||||
this.vy = (Math.random() - 0.5) * 0.15;
|
||||
this.alpha = Math.random() * 0.35 + 0.2;
|
||||
this.phase = Math.random() * Math.PI * 2;
|
||||
}
|
||||
update() {
|
||||
this.x += this.vx;
|
||||
this.y += this.vy + Math.sin(this.phase) * 0.15;
|
||||
this.phase += 0.015;
|
||||
if (this.x < -20 || this.x > this.w + 20 || this.y < -20 || this.y > this.h + 20) this.reset();
|
||||
}
|
||||
resize(w, h) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
draw(ctx, ox, oy, color) {
|
||||
const x = this.x + ox;
|
||||
const y = this.y + oy;
|
||||
const r = this.size * 4;
|
||||
const grad = ctx.createRadialGradient(x, y, 0, x, y, r);
|
||||
grad.addColorStop(0, rgba(color, this.alpha));
|
||||
grad.addColorStop(1, rgba(color, 0));
|
||||
ctx.fillStyle = grad;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, r, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${this.alpha * 0.5})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, this.size, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
class Sparkle extends Plankton {
|
||||
reset(randomY = false) {
|
||||
super.reset(randomY);
|
||||
this.size = Math.random() * 2.2 + 0.8;
|
||||
this.vx *= 2.5;
|
||||
this.vy *= 2.5;
|
||||
this.alpha = Math.random() * 0.5 + 0.35;
|
||||
}
|
||||
}
|
||||
|
||||
class Bubble {
|
||||
constructor(width, height) {
|
||||
this.w = width;
|
||||
this.h = height;
|
||||
this.reset(true);
|
||||
}
|
||||
reset(randomY = false) {
|
||||
this.x = Math.random() * this.w;
|
||||
this.y = randomY ? Math.random() * this.h : this.h + 30;
|
||||
this.size = Math.random() * 8 + 3;
|
||||
this.vy = -(Math.random() * 0.7 + 0.3);
|
||||
this.swayPhase = Math.random() * Math.PI * 2;
|
||||
this.alpha = Math.random() * 0.4 + 0.3;
|
||||
}
|
||||
update() {
|
||||
this.y += this.vy;
|
||||
this.x += Math.sin(this.swayPhase) * 0.5;
|
||||
this.swayPhase += 0.03;
|
||||
if (this.y < -30) this.reset(false);
|
||||
}
|
||||
resize(w, h) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
draw(ctx, ox, oy) {
|
||||
const x = this.x + ox;
|
||||
const y = this.y + oy;
|
||||
ctx.strokeStyle = `rgba(255, 255, 255, ${this.alpha * 0.6})`;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, this.size, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${this.alpha * 0.5})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x - this.size * 0.3, y - this.size * 0.3, this.size * 0.28, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
|
||||
class LightPillar {
|
||||
constructor(width, index, total) {
|
||||
this.idx = index;
|
||||
this.total = total;
|
||||
// 这些参数只在构造时随机一次,resize 时不能重抽,
|
||||
// 否则窗口拖拽时光柱会"跳"位置和宽度。
|
||||
this.offset = (Math.random() - 0.5) * 80;
|
||||
this.width = 120 + Math.random() * 100;
|
||||
this.angle = -0.18 + Math.random() * 0.36;
|
||||
this.intensity = 0.05 + Math.random() * 0.05;
|
||||
this.breathPhase = Math.random() * Math.PI * 2;
|
||||
this.resize(width);
|
||||
}
|
||||
resize(width) {
|
||||
// 只更新跟 width 相关的 baseX 基准,固定 offset 保持不变
|
||||
this.baseX = ((this.idx + 0.5) / this.total) * width + this.offset;
|
||||
}
|
||||
update(breathOn) {
|
||||
if (breathOn) this.breathPhase += 0.003;
|
||||
}
|
||||
draw(ctx, ox, height, color) {
|
||||
const breath = 0.6 + Math.sin(this.breathPhase) * 0.4;
|
||||
const x = this.baseX + ox * 0.3;
|
||||
ctx.save();
|
||||
ctx.translate(x, 0);
|
||||
ctx.rotate(this.angle);
|
||||
const grad = ctx.createLinearGradient(0, 0, 0, height * 1.3);
|
||||
grad.addColorStop(0, rgba(color, this.intensity * breath));
|
||||
grad.addColorStop(1, rgba(color, 0));
|
||||
ctx.fillStyle = grad;
|
||||
ctx.fillRect(-this.width / 2, -50, this.width, height * 1.4);
|
||||
ctx.restore();
|
||||
}
|
||||
}
|
||||
|
||||
class Tentacle {
|
||||
constructor(width, height, suckerCount) {
|
||||
this.w = width;
|
||||
this.h = height;
|
||||
this.suckerCount = suckerCount;
|
||||
this.suckerPhases = Array.from({ length: suckerCount }, (_, i) => i * 0.6);
|
||||
this.swayPhase = 0;
|
||||
}
|
||||
resize(w, h) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
update() {
|
||||
this.swayPhase += 0.004;
|
||||
for (let i = 0; i < this.suckerCount; i++) this.suckerPhases[i] += 0.045;
|
||||
}
|
||||
draw(ctx, ox, oy, color, isDark) {
|
||||
const baseX = this.w;
|
||||
const baseY = this.h;
|
||||
const length = Math.min(this.w, this.h) * 0.7;
|
||||
const sway = Math.sin(this.swayPhase) * 40;
|
||||
// tip 跟随鼠标视差;base 锚定在角落
|
||||
const endX = baseX - length * 0.5 + sway + ox;
|
||||
const endY = baseY - length * 0.7 + oy;
|
||||
const c2X = baseX - length * 0.4 + sway * 1.4 + ox * 0.7;
|
||||
const c2Y = baseY - length * 0.55 + oy * 0.7;
|
||||
const c1X = baseX - length * 0.1 + ox * 0.3;
|
||||
const c1Y = baseY - length * 0.3 + oy * 0.3;
|
||||
|
||||
// 分段绘制以做出尖端渐细的效果
|
||||
const segs = 32;
|
||||
const taperFrom = 38;
|
||||
const taperTo = 8;
|
||||
ctx.strokeStyle = isDark ? 'rgba(0, 5, 15, 0.55)' : 'rgba(0, 25, 40, 0.45)';
|
||||
ctx.lineCap = 'round';
|
||||
let prevX = baseX;
|
||||
let prevY = baseY;
|
||||
for (let i = 1; i <= segs; i++) {
|
||||
const t = i / segs;
|
||||
const x = bezierPoint(baseX, c1X, c2X, endX, t);
|
||||
const y = bezierPoint(baseY, c1Y, c2Y, endY, t);
|
||||
ctx.lineWidth = lerp(taperFrom, taperTo, t);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(prevX, prevY);
|
||||
ctx.lineTo(x, y);
|
||||
ctx.stroke();
|
||||
prevX = x;
|
||||
prevY = y;
|
||||
}
|
||||
|
||||
// 吸盘:沿曲线均匀分布,各自相位错开形成 Mexican wave
|
||||
for (let i = 0; i < this.suckerCount; i++) {
|
||||
const t = 0.18 + (i / (this.suckerCount - 1)) * 0.78;
|
||||
const x = bezierPoint(baseX, c1X, c2X, endX, t);
|
||||
const y = bezierPoint(baseY, c1Y, c2Y, endY, t);
|
||||
const breath = 0.5 + Math.sin(this.suckerPhases[i]) * 0.5;
|
||||
const glow = 5 + breath * 8;
|
||||
// 外层光晕
|
||||
const grad = ctx.createRadialGradient(x, y, 0, x, y, glow * 3);
|
||||
grad.addColorStop(0, rgba(color, 0.6 + breath * 0.3));
|
||||
grad.addColorStop(0.4, rgba(color, 0.3 + breath * 0.2));
|
||||
grad.addColorStop(1, rgba(color, 0));
|
||||
ctx.fillStyle = grad;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, glow * 3, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
// 内核亮点
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${0.7 + breath * 0.3})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(x, y, glow * 0.45, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LifePulse {
|
||||
constructor(width, height) {
|
||||
this.w = width;
|
||||
this.h = height;
|
||||
this.active = false;
|
||||
this.startT = 0;
|
||||
this.nextT = performance.now() + 4000 + Math.random() * 3000;
|
||||
this.duration = 3200;
|
||||
}
|
||||
resize(w, h) {
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
update(now, enabled) {
|
||||
if (!enabled) return;
|
||||
if (!this.active && now >= this.nextT) {
|
||||
// 从屏幕外随机一侧触发
|
||||
const side = Math.floor(Math.random() * 4);
|
||||
const m = 100;
|
||||
if (side === 0) { this.ox = Math.random() * this.w; this.oy = -m; }
|
||||
else if (side === 1) { this.ox = this.w + m; this.oy = Math.random() * this.h; }
|
||||
else if (side === 2) { this.ox = Math.random() * this.w; this.oy = this.h + m; }
|
||||
else { this.ox = -m; this.oy = Math.random() * this.h; }
|
||||
this.active = true;
|
||||
this.startT = now;
|
||||
this.maxR = Math.hypot(this.w, this.h) * 0.7;
|
||||
}
|
||||
if (this.active && now - this.startT >= this.duration) {
|
||||
this.active = false;
|
||||
this.nextT = now + 6000 + Math.random() * 4000;
|
||||
}
|
||||
}
|
||||
draw(ctx, now, color) {
|
||||
if (!this.active) return;
|
||||
const p = (now - this.startT) / this.duration;
|
||||
const radius = this.maxR * easeOutCubic(p);
|
||||
const alpha = p < 0.5 ? p * 2 * 0.35 : (1 - p) * 2 * 0.35;
|
||||
const inner = Math.max(0, radius - 50);
|
||||
const outer = radius + 50;
|
||||
const grad = ctx.createRadialGradient(this.ox, this.oy, inner, this.ox, this.oy, outer);
|
||||
grad.addColorStop(0, rgba(color, 0));
|
||||
grad.addColorStop(0.5, rgba(color, alpha));
|
||||
grad.addColorStop(1, rgba(color, 0));
|
||||
ctx.fillStyle = grad;
|
||||
ctx.fillRect(0, 0, this.w, this.h);
|
||||
}
|
||||
}
|
||||
|
||||
// ─── 主题 / 模式读取 ────────────────────────────────────────
|
||||
const readTheme = () => {
|
||||
const cs = getComputedStyle(document.documentElement);
|
||||
const get = (k, fallback) => {
|
||||
const v = cs.getPropertyValue(k).trim();
|
||||
return v || fallback;
|
||||
};
|
||||
return {
|
||||
primary: hexToRgb(get('--brand-primary', '#1668dc')),
|
||||
accent: hexToRgb(get('--brand-gradient-to', '#0958d9')),
|
||||
};
|
||||
};
|
||||
const detectDark = () => {
|
||||
if (document.documentElement.classList.contains('dark')) return true;
|
||||
if (document.body && document.body.getAttribute('theme-mode') === 'dark') return true;
|
||||
// ThemeContext 在浅色模式会移除上面两个标记,此时必须先看用户显式选择,
|
||||
// 否则"强制浅色 + 系统深色"会被 prefers-color-scheme 兜底误判成暗色
|
||||
try {
|
||||
const stored = localStorage.getItem('theme-mode');
|
||||
if (stored === 'dark') return true;
|
||||
if (stored === 'light') return false;
|
||||
} catch {
|
||||
// localStorage 不可用(隐私模式等)时继续走系统偏好
|
||||
}
|
||||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
};
|
||||
|
||||
// ─── 组件 ─────────────────────────────────────────────────
|
||||
const OceanBackground = () => {
|
||||
const canvasRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
const ctx = canvas.getContext('2d');
|
||||
let frameId = 0;
|
||||
let themeTickId = 0;
|
||||
|
||||
let width = window.innerWidth;
|
||||
let height = window.innerHeight;
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, 1.5); // 上限避免移动端开销
|
||||
|
||||
// 设备 / 偏好检测
|
||||
const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
|
||||
navigator.userAgent,
|
||||
);
|
||||
const reducedMotion =
|
||||
window.matchMedia &&
|
||||
window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
// 元素数量自适应。宽矩形光柱左右边缘无法自然羽化,会形成明显条带,统一关闭。
|
||||
const COUNT = reducedMotion
|
||||
? { plankton: 25, sparkle: 0, bubble: 6, pillar: 0 }
|
||||
: isMobile
|
||||
? { plankton: 40, sparkle: 12, bubble: 10, pillar: 0 }
|
||||
: { plankton: 80, sparkle: 28, bubble: 16, pillar: 0 };
|
||||
|
||||
// 主题色 + 暗色,500ms 一更新(getComputedStyle 不算贵,但没必要每帧)
|
||||
let theme = readTheme();
|
||||
let isDark = detectDark();
|
||||
themeTickId = setInterval(() => {
|
||||
theme = readTheme();
|
||||
isDark = detectDark();
|
||||
}, 500);
|
||||
|
||||
// 鼠标视差状态
|
||||
let mouseTargetX = 0;
|
||||
let mouseTargetY = 0;
|
||||
let mouseX = 0;
|
||||
let mouseY = 0;
|
||||
const onMouseMove = (e) => {
|
||||
if (reducedMotion) return;
|
||||
mouseTargetX = (e.clientX / width - 0.5) * 2;
|
||||
mouseTargetY = (e.clientY / height - 0.5) * 2;
|
||||
};
|
||||
|
||||
// 实例化
|
||||
const plankton = Array.from({ length: COUNT.plankton }, () => new Plankton(width, height));
|
||||
const sparkles = Array.from({ length: COUNT.sparkle }, () => new Sparkle(width, height));
|
||||
const bubbles = Array.from({ length: COUNT.bubble }, () => new Bubble(width, height));
|
||||
const pillars = Array.from(
|
||||
{ length: COUNT.pillar },
|
||||
(_, i) => new LightPillar(width, i, COUNT.pillar || 1),
|
||||
);
|
||||
const tentacle = reducedMotion
|
||||
? null
|
||||
: new Tentacle(width, height, isMobile ? 6 : 8);
|
||||
const pulse = new LifePulse(width, height);
|
||||
|
||||
// ─ resize ─────────────────────────
|
||||
const resize = () => {
|
||||
width = window.innerWidth;
|
||||
height = window.innerHeight;
|
||||
canvas.width = width * dpr;
|
||||
canvas.height = height * dpr;
|
||||
canvas.style.width = width + 'px';
|
||||
canvas.style.height = height + 'px';
|
||||
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||
plankton.forEach((p) => p.resize(width, height));
|
||||
sparkles.forEach((p) => p.resize(width, height));
|
||||
bubbles.forEach((b) => b.resize(width, height));
|
||||
pillars.forEach((p) => p.resize(width));
|
||||
if (tentacle) tentacle.resize(width, height);
|
||||
pulse.resize(width, height);
|
||||
};
|
||||
|
||||
// ─ 景深渐变背景 ───────────────────────
|
||||
const drawBackground = () => {
|
||||
// 主渐变:浅色 = 水青→深 teal,暗色 = 午夜蓝→墨黑
|
||||
const grad = ctx.createLinearGradient(0, 0, 0, height);
|
||||
if (isDark) {
|
||||
grad.addColorStop(0, '#0d1f33');
|
||||
grad.addColorStop(0.5, '#0a1525');
|
||||
grad.addColorStop(1, '#02060d');
|
||||
} else {
|
||||
grad.addColorStop(0, '#b8e0e8');
|
||||
grad.addColorStop(0.45, '#4a8fa8');
|
||||
grad.addColorStop(1, '#0d3854');
|
||||
}
|
||||
ctx.fillStyle = grad;
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
|
||||
// 四角 vignette,加强深度感
|
||||
const cx = width / 2;
|
||||
const cy = height / 2;
|
||||
const r0 = Math.min(width, height) * 0.35;
|
||||
const r1 = Math.max(width, height) * 0.75;
|
||||
const vig = ctx.createRadialGradient(cx, cy, r0, cx, cy, r1);
|
||||
vig.addColorStop(0, 'rgba(0, 0, 0, 0)');
|
||||
vig.addColorStop(1, isDark ? 'rgba(0, 0, 0, 0.55)' : 'rgba(0, 10, 25, 0.35)');
|
||||
ctx.fillStyle = vig;
|
||||
ctx.fillRect(0, 0, width, height);
|
||||
};
|
||||
|
||||
// ─ 主循环 ────────────────────────────
|
||||
const animate = () => {
|
||||
const now = performance.now();
|
||||
|
||||
// 鼠标视差 lerp(reducedMotion 时跳过)
|
||||
if (!reducedMotion) {
|
||||
mouseX = lerp(mouseX, mouseTargetX, 0.05);
|
||||
mouseY = lerp(mouseY, mouseTargetY, 0.05);
|
||||
}
|
||||
|
||||
drawBackground();
|
||||
|
||||
// Layer 2: 光柱(后景,视差最少)
|
||||
pillars.forEach((p) => {
|
||||
p.update(!reducedMotion);
|
||||
p.draw(ctx, mouseX * 10, height, theme.primary);
|
||||
});
|
||||
|
||||
// Layer 3: 中层浮游(视差中等)
|
||||
plankton.forEach((p) => {
|
||||
p.update();
|
||||
p.draw(ctx, mouseX * 18, mouseY * 12, theme.primary);
|
||||
});
|
||||
|
||||
// Layer 4: 触手(视差中前)
|
||||
if (tentacle) {
|
||||
tentacle.update();
|
||||
tentacle.draw(ctx, mouseX * 25, mouseY * 18, theme.primary, isDark);
|
||||
}
|
||||
|
||||
// Layer 5: 气泡(视差中前)
|
||||
bubbles.forEach((b) => {
|
||||
b.update();
|
||||
b.draw(ctx, mouseX * 30, mouseY * 20);
|
||||
});
|
||||
|
||||
// Layer 6: 前景闪烁粒子(视差最大,给"动感")
|
||||
sparkles.forEach((s) => {
|
||||
s.update();
|
||||
s.draw(ctx, mouseX * 40, mouseY * 28, theme.accent);
|
||||
});
|
||||
|
||||
// Layer 7: 生命脉冲(reducedMotion 时不启用)
|
||||
pulse.update(now, !reducedMotion);
|
||||
pulse.draw(ctx, now, theme.primary);
|
||||
|
||||
frameId = requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
window.addEventListener('resize', resize);
|
||||
window.addEventListener('mousemove', onMouseMove);
|
||||
resize();
|
||||
animate();
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('resize', resize);
|
||||
window.removeEventListener('mousemove', onMouseMove);
|
||||
cancelAnimationFrame(frameId);
|
||||
clearInterval(themeTickId);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<canvas
|
||||
ref={canvasRef}
|
||||
style={{
|
||||
position: 'fixed',
|
||||
top: 0,
|
||||
left: 0,
|
||||
zIndex: -1,
|
||||
width: '100vw',
|
||||
height: '100vh',
|
||||
pointerEvents: 'none',
|
||||
}}
|
||||
aria-hidden='true'
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default OceanBackground;
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
/**
|
||||
* 统一页面背景层 —— 所有路由级页面 shell 的唯一背景来源。
|
||||
*
|
||||
* 设计目标(详见 docs/11-前端与体验中心/03-主题色配置化改造方案.md):
|
||||
* 1. 可管理:颜色全部走 bg-glow-* CSS 变量,管理员在
|
||||
* 系统设置 → 主题设置 → 背景晕染 调一处,全场所有页面同步生效。
|
||||
* 2. 单层:每个可视页面只有一层背景。父 shell 渲染本组件,
|
||||
* 嵌套子页面用 embedded 开关跳过自身背景,避免双层叠加。
|
||||
* 3. 一致:from/to 两 stop,强度统一刻度。
|
||||
*
|
||||
* 两种强度:
|
||||
* subtle(默认)—— 后台 / 管理 / 列表类页面:2 个角落光斑 blur-3xl,克制。
|
||||
* rich —— 沉浸式页面(对话 / 生成):3 个大光球 blur-[100px],更强。
|
||||
*
|
||||
* 暗色无需 dark: 前缀切换颜色 —— bg-glow-*-rgb 变量本身随浅/暗级联,
|
||||
* 仅在需要"暗色更克制"时用 dark: 降低 alpha。
|
||||
*
|
||||
* 用法:放在一个 `relative` 容器内作为第一个子元素,内容用 `relative z-10` 叠其上。
|
||||
* <div className='relative ...'>
|
||||
* <PageBackground grid animate />
|
||||
* <div className='relative z-10'>{children}</div>
|
||||
* </div>
|
||||
*/
|
||||
export default function PageBackground({
|
||||
variant = 'subtle',
|
||||
grid = false,
|
||||
animate = false,
|
||||
className = '',
|
||||
}) {
|
||||
const pulse = animate ? 'animate-pulse motion-reduce:animate-none' : '';
|
||||
return (
|
||||
<div
|
||||
className={`absolute inset-0 overflow-hidden pointer-events-none ${className}`}
|
||||
aria-hidden='true'
|
||||
>
|
||||
{variant === 'rich' ? (
|
||||
<>
|
||||
{/* 基础渐变 —— 顶部→底部晕染(顶起色、底止色、中段通透) */}
|
||||
<div className='absolute inset-0 bg-gradient-to-b from-bg-glow-from/15 via-transparent to-bg-glow-to/20 dark:from-bg-glow-from/10 dark:via-transparent dark:to-bg-glow-to/15' />
|
||||
{/* 3 个沉浸式大光球 */}
|
||||
<div
|
||||
className={`absolute top-[5%] right-[10%] w-[400px] h-[400px] rounded-full bg-gradient-to-br from-bg-glow-from/15 to-bg-glow-to/15 dark:from-bg-glow-from/10 dark:to-bg-glow-to/10 blur-[100px] ${pulse}`}
|
||||
/>
|
||||
<div
|
||||
className={`absolute bottom-[10%] left-[5%] w-[350px] h-[350px] rounded-full bg-gradient-to-br from-bg-glow-from/15 to-bg-glow-to/15 dark:from-bg-glow-from/10 dark:to-bg-glow-to/10 blur-[100px] ${pulse}`}
|
||||
style={animate ? { animationDelay: '1.5s' } : undefined}
|
||||
/>
|
||||
<div
|
||||
className={`absolute top-[40%] left-[35%] w-[250px] h-[250px] rounded-full bg-gradient-to-br from-bg-glow-from/10 to-bg-glow-to/10 dark:from-bg-glow-from/5 dark:to-bg-glow-to/5 blur-[80px] ${pulse}`}
|
||||
style={animate ? { animationDelay: '3s' } : undefined}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{/* 基础渐变 —— 顶部→底部晕染(顶起色、底止色、中段通透) */}
|
||||
<div className='absolute inset-0 bg-gradient-to-b from-bg-glow-from/10 via-transparent to-bg-glow-to/20 dark:from-bg-glow-from/10 dark:via-transparent dark:to-bg-glow-to/15' />
|
||||
{/* 2 个角落光斑 */}
|
||||
<div
|
||||
className={`absolute top-20 right-20 w-64 h-64 rounded-full bg-bg-glow-from/10 blur-3xl ${pulse}`}
|
||||
/>
|
||||
<div
|
||||
className={`absolute bottom-20 left-20 w-80 h-80 rounded-full bg-bg-glow-to/10 blur-3xl ${pulse}`}
|
||||
style={animate ? { animationDelay: '1s' } : undefined}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{grid && (
|
||||
<div
|
||||
className='absolute inset-0 opacity-[0.02] dark:opacity-[0.04]'
|
||||
style={{
|
||||
backgroundImage:
|
||||
'radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)',
|
||||
backgroundSize: '32px 32px',
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
/*
|
||||
* PageGuide —— 企业控制台页面级「使用指引」三层体系的可复用实现。
|
||||
*
|
||||
* 三层结构(详见 docs 设计提案「页面功能指引」):
|
||||
* 1. 常驻入口 <PageGuideTrigger>:放在页面 hero 动作区,随时唤起抽屉;
|
||||
* 2. 进度胶囊 <PageGuidePill>:有上手流程的页面放在 hero 下方,
|
||||
* 展示数据驱动的完成度与「下一步」,全部完成后自动隐藏;
|
||||
* 3. 侧滑抽屉 <PageGuideDrawer>:承载定位一句话、分步操作、FAQ 与直达 CTA,
|
||||
* 首次访问自动展开一次(localStorage 按 guideKey 记忆)。
|
||||
*
|
||||
* 页面只需 usePageGuide({...配置}) 后把三个组件放到对应位置;
|
||||
* steps[].done 传布尔值即启用进度跟踪,不传则渲染为纯阅读步骤。
|
||||
*/
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Button, SideSheet } from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
BookOpenText,
|
||||
CheckCircle2,
|
||||
ChevronDown,
|
||||
Compass,
|
||||
Loader2,
|
||||
} from 'lucide-react';
|
||||
import './page-guide.css';
|
||||
|
||||
const seenKey = (guideKey) => `page-guide-seen-${guideKey}`;
|
||||
|
||||
// localStorage 在隐私模式/配额耗尽时会抛异常(知识页 verified-key 处已有同款
|
||||
// 防御)。指引记忆是增强功能,绝不能反过来弄坏「使用指引」入口:写失败静默
|
||||
// 放弃;读失败按「已看过」处理,避免每次进页都重复自动弹出。
|
||||
// sessionSeen 兜"读正常、写抛异常"(配额耗尽)的场景:持久化失败时至少
|
||||
// 本会话内不重复自动弹出——否则每次路由进页都会弹一次,比不弹更糟。
|
||||
const sessionSeen = new Set();
|
||||
const readSeen = (guideKey) => {
|
||||
if (sessionSeen.has(guideKey)) return true;
|
||||
try {
|
||||
return window.localStorage.getItem(seenKey(guideKey)) === '1';
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
const markSeen = (guideKey) => {
|
||||
sessionSeen.add(guideKey);
|
||||
try {
|
||||
window.localStorage.setItem(seenKey(guideKey), '1');
|
||||
} catch {
|
||||
// 忽略:仅损失跨会话记忆(本会话由 sessionSeen 兜底)
|
||||
}
|
||||
};
|
||||
|
||||
const prefersReducedMotion = () =>
|
||||
window.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches ?? false;
|
||||
|
||||
// 指引 CTA 通用落点:滚动到目标区块并短暂高亮。延迟一拍等抽屉先关闭——
|
||||
// SideSheet 关闭动画约 300ms,早于它执行 scrollIntoView 会被遮罩滚动锁吞掉。
|
||||
export const flashGuideTarget = (selector, focusSelector) => {
|
||||
window.setTimeout(() => {
|
||||
const node = document.querySelector(selector);
|
||||
if (!node) return;
|
||||
node.scrollIntoView({
|
||||
behavior: prefersReducedMotion() ? 'auto' : 'smooth',
|
||||
block: 'center',
|
||||
});
|
||||
node.classList.add('page-guide-flash');
|
||||
window.setTimeout(() => node.classList.remove('page-guide-flash'), 1700);
|
||||
if (focusSelector) {
|
||||
window.setTimeout(
|
||||
() =>
|
||||
document.querySelector(focusSelector)?.focus({ preventScroll: true }),
|
||||
450,
|
||||
);
|
||||
}
|
||||
}, 350);
|
||||
};
|
||||
|
||||
export const usePageGuide = ({
|
||||
guideKey,
|
||||
title,
|
||||
intro,
|
||||
steps = [],
|
||||
faq = [],
|
||||
footer,
|
||||
autoOpen = true,
|
||||
// ready=false 时进度胶囊不渲染:页面数据未就绪前 done 全为 false,
|
||||
// 会对老用户闪现一个错误的「0/N」胶囊。
|
||||
ready = true,
|
||||
}) => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
// focusStep:从胶囊进入时定位展开的步骤;null 表示按「下一步」默认展开。
|
||||
const [focusStep, setFocusStep] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoOpen || !guideKey) return undefined;
|
||||
if (readSeen(guideKey)) return undefined;
|
||||
// 延迟一拍再展开,等页面首屏渲染完成,避免抽屉与骨架屏同时抢焦点。
|
||||
const timer = window.setTimeout(() => {
|
||||
// 二次核对:800ms 窗口内用户手动打开过(open() 已 markSeen)就不再
|
||||
// 重弹——否则"快速开又关"后抽屉会自行复活一次。
|
||||
if (readSeen(guideKey)) return;
|
||||
markSeen(guideKey);
|
||||
setVisible(true);
|
||||
}, 800);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [autoOpen, guideKey]);
|
||||
|
||||
const progress = useMemo(() => {
|
||||
const trackable = steps.some((step) => typeof step.done === 'boolean');
|
||||
const doneCount = steps.filter((step) => step.done).length;
|
||||
const nextIndex = trackable ? steps.findIndex((step) => !step.done) : -1;
|
||||
return {
|
||||
trackable,
|
||||
doneCount,
|
||||
total: steps.length,
|
||||
nextIndex,
|
||||
allDone: trackable && nextIndex === -1,
|
||||
};
|
||||
}, [steps]);
|
||||
|
||||
const open = useCallback(
|
||||
(stepIndex = null) => {
|
||||
if (guideKey) markSeen(guideKey);
|
||||
setFocusStep(stepIndex);
|
||||
setVisible(true);
|
||||
},
|
||||
[guideKey],
|
||||
);
|
||||
const close = useCallback(() => setVisible(false), []);
|
||||
|
||||
return {
|
||||
visible,
|
||||
open,
|
||||
close,
|
||||
focusStep,
|
||||
progress,
|
||||
ready,
|
||||
config: { guideKey, title, intro, steps, faq, footer },
|
||||
};
|
||||
};
|
||||
|
||||
export const PageGuideTrigger = ({ guide, className = '' }) => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Button
|
||||
theme='borderless'
|
||||
className={`page-guide-trigger ${className}`}
|
||||
icon={<BookOpenText size={16} />}
|
||||
onClick={() => guide.open()}
|
||||
>
|
||||
{t('使用指引')}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
export const PageGuidePill = ({ guide, className = '' }) => {
|
||||
const { t } = useTranslation();
|
||||
const { progress, config } = guide;
|
||||
if (!guide.ready || !progress.trackable || progress.allDone) return null;
|
||||
const nextStep = config.steps[progress.nextIndex];
|
||||
return (
|
||||
<button
|
||||
type='button'
|
||||
className={`page-guide-pill ${className}`}
|
||||
onClick={() => guide.open(progress.nextIndex)}
|
||||
>
|
||||
<Compass size={14} className='page-guide-pill-icon' />
|
||||
<span className='page-guide-pill-dots' aria-hidden='true'>
|
||||
{config.steps.map((step, index) => (
|
||||
<i
|
||||
key={step.title}
|
||||
className={
|
||||
step.done
|
||||
? 'is-done'
|
||||
: index === progress.nextIndex
|
||||
? 'is-next'
|
||||
: ''
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</span>
|
||||
<span className='page-guide-pill-text'>
|
||||
{t('快速上手')} {progress.doneCount}/{progress.total}
|
||||
{' · '}
|
||||
<strong>
|
||||
{t('下一步')}
|
||||
{t(':')}
|
||||
{nextStep?.working ? t('进行中') : nextStep?.title}
|
||||
</strong>
|
||||
</span>
|
||||
<span className='page-guide-pill-go'>{t('继续')} →</span>
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
const StepIcon = ({ step, index, isNext }) => {
|
||||
if (step.done) return <CheckCircle2 size={14} />;
|
||||
if (!step.done && step.working)
|
||||
return <Loader2 size={13} className='page-guide-spin' />;
|
||||
return <span className={isNext ? 'is-next' : ''}>{index + 1}</span>;
|
||||
};
|
||||
|
||||
export const PageGuideDrawer = ({ guide }) => {
|
||||
const { t } = useTranslation();
|
||||
const { config, progress, visible, focusStep } = guide;
|
||||
// 展开哪一步:胶囊点进来的目标步 > 数据驱动的下一步 > 第一步。
|
||||
const defaultExpanded =
|
||||
focusStep ?? (progress.nextIndex >= 0 ? progress.nextIndex : 0);
|
||||
const [expanded, setExpanded] = useState(defaultExpanded);
|
||||
useEffect(() => {
|
||||
if (visible) setExpanded(defaultExpanded);
|
||||
// 抽屉每次打开时重新对齐展开项;关闭期间不响应数据变化。
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [visible, focusStep]);
|
||||
|
||||
const runAction = (step) => {
|
||||
guide.close();
|
||||
if (typeof step.onAction === 'function') step.onAction();
|
||||
};
|
||||
|
||||
return (
|
||||
<SideSheet
|
||||
className='page-guide-drawer'
|
||||
closeOnEsc
|
||||
title={
|
||||
<div className='page-guide-head'>
|
||||
<strong>{config.title}</strong>
|
||||
{config.intro && <span>{config.intro}</span>}
|
||||
</div>
|
||||
}
|
||||
visible={visible}
|
||||
onCancel={guide.close}
|
||||
width={420}
|
||||
footer={
|
||||
<div className='page-guide-foot'>
|
||||
{config.footer || t('可随时从页面右上角「使用指引」再次打开')}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className='page-guide-body'>
|
||||
{progress.trackable && (
|
||||
<p className='page-guide-progress'>
|
||||
{t('上手进度')}{' '}
|
||||
<b>
|
||||
{progress.doneCount}/{progress.total}
|
||||
</b>
|
||||
{' · '}
|
||||
{progress.allDone
|
||||
? t('已完成全部入门步骤')
|
||||
: t('完成态由页面真实数据驱动,无需手动勾选')}
|
||||
</p>
|
||||
)}
|
||||
<ol className='page-guide-steps'>
|
||||
{config.steps.map((step, index) => {
|
||||
const isNext = index === progress.nextIndex;
|
||||
const isOpen = index === expanded;
|
||||
const detailId = `page-guide-step-${config.guideKey}-${index}`;
|
||||
const stateClass = step.done
|
||||
? 'is-done'
|
||||
: step.working
|
||||
? 'is-working'
|
||||
: isNext
|
||||
? 'is-next'
|
||||
: '';
|
||||
return (
|
||||
<li
|
||||
key={step.title}
|
||||
className={`page-guide-step ${stateClass} ${isOpen ? 'is-open' : ''}`}
|
||||
>
|
||||
<button
|
||||
type='button'
|
||||
className='page-guide-step-head'
|
||||
aria-expanded={isOpen}
|
||||
aria-controls={isOpen ? detailId : undefined}
|
||||
onClick={() => setExpanded(isOpen ? -1 : index)}
|
||||
>
|
||||
<span className='page-guide-step-ic'>
|
||||
<StepIcon step={step} index={index} isNext={isNext} />
|
||||
</span>
|
||||
<span className='page-guide-step-copy'>
|
||||
<strong>
|
||||
{step.title}
|
||||
{step.done && (
|
||||
<em className='page-guide-badge is-done'>
|
||||
{t('已完成')}
|
||||
</em>
|
||||
)}
|
||||
{!step.done && step.working && (
|
||||
<em className='page-guide-badge is-working'>
|
||||
{t('进行中')}
|
||||
</em>
|
||||
)}
|
||||
{!step.done && !step.working && isNext && (
|
||||
<em className='page-guide-badge'>{t('下一步')}</em>
|
||||
)}
|
||||
</strong>
|
||||
{step.detail && <small>{step.detail}</small>}
|
||||
</span>
|
||||
<ChevronDown size={15} className='page-guide-step-arrow' />
|
||||
</button>
|
||||
{isOpen && (
|
||||
<div className='page-guide-step-detail' id={detailId}>
|
||||
{Array.isArray(step.points) && step.points.length > 0 && (
|
||||
<ul>
|
||||
{step.points.map((point) => (
|
||||
<li key={point}>{point}</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
{step.cta && step.onAction && (
|
||||
<button
|
||||
type='button'
|
||||
className='page-guide-step-cta'
|
||||
onClick={() => runAction(step)}
|
||||
>
|
||||
{step.cta} →
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
{guide.config.faq.length > 0 && (
|
||||
<>
|
||||
<p className='page-guide-section-title'>{t('常见问题')}</p>
|
||||
{config.faq.map((item) => (
|
||||
<div className='page-guide-faq' key={item.q}>
|
||||
<b>{item.q}</b>
|
||||
<span>{item.a}</span>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</SideSheet>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,396 @@
|
||||
/* PageGuide —— 页面级使用指引(触发按钮 / 进度胶囊 / 侧滑抽屉)
|
||||
* 配色全部从主题 token 派生,随亮暗色与品牌预设自动适配。 */
|
||||
|
||||
.page-guide-pill,
|
||||
.page-guide-drawer {
|
||||
--pg-ink: var(--text-primary);
|
||||
--pg-muted: var(--text-secondary);
|
||||
--pg-line: var(--border-subtle);
|
||||
--pg-accent: var(--semi-color-primary);
|
||||
--pg-accent-deep: var(--semi-color-primary-active, var(--semi-color-primary));
|
||||
--pg-tint: color-mix(in srgb, var(--semi-color-primary) 8%, transparent);
|
||||
--pg-tint-strong: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-primary) 14%,
|
||||
transparent
|
||||
);
|
||||
--pg-tint-line: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-primary) 28%,
|
||||
transparent
|
||||
);
|
||||
--pg-ok: var(--semi-color-success);
|
||||
--pg-ok-tint: color-mix(in srgb, var(--semi-color-success) 14%, transparent);
|
||||
}
|
||||
|
||||
/* ===== 进度胶囊 ===== */
|
||||
.page-guide-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
max-width: 100%;
|
||||
padding: 6px 8px 6px 14px;
|
||||
border: 1px solid var(--pg-tint-line);
|
||||
border-radius: 999px;
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-primary) 4%,
|
||||
var(--surface-card)
|
||||
);
|
||||
color: var(--pg-ink);
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
border-color 0.15s ease,
|
||||
box-shadow 0.15s ease;
|
||||
}
|
||||
|
||||
.page-guide-pill:hover {
|
||||
border-color: var(--pg-accent);
|
||||
box-shadow: 0 2px 10px var(--pg-tint);
|
||||
}
|
||||
|
||||
.page-guide-pill:focus-visible,
|
||||
.page-guide-trigger:focus-visible,
|
||||
.page-guide-step-head:focus-visible,
|
||||
.page-guide-step-cta:focus-visible {
|
||||
outline: 2px solid
|
||||
color-mix(in srgb, var(--semi-color-primary) 55%, transparent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.page-guide-pill-icon {
|
||||
flex: none;
|
||||
color: var(--pg-accent);
|
||||
}
|
||||
|
||||
.page-guide-pill-dots {
|
||||
display: inline-flex;
|
||||
gap: 4px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.page-guide-pill-dots i {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: var(--pg-line);
|
||||
}
|
||||
|
||||
.page-guide-pill-dots i.is-done {
|
||||
background: var(--pg-ok);
|
||||
}
|
||||
|
||||
.page-guide-pill-dots i.is-next {
|
||||
background: var(--pg-accent);
|
||||
}
|
||||
|
||||
.page-guide-pill-text {
|
||||
color: var(--pg-muted);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.page-guide-pill-text strong {
|
||||
color: var(--pg-accent);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.page-guide-pill-go {
|
||||
flex: none;
|
||||
padding: 2px 10px;
|
||||
border-radius: 999px;
|
||||
background: var(--pg-tint);
|
||||
color: var(--pg-accent);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* ===== 抽屉 ===== */
|
||||
.page-guide-drawer .semi-sidesheet-inner {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.page-guide-drawer .semi-sidesheet-body {
|
||||
padding: 14px 22px 20px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
/* 抽屉滚动条:复用品牌滚动条 token(同 app-scrollbar 的取色来源) */
|
||||
.page-guide-drawer .semi-sidesheet-body::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.page-guide-drawer .semi-sidesheet-body::-webkit-scrollbar-thumb {
|
||||
border-radius: 999px;
|
||||
background: var(--brand-scroll);
|
||||
}
|
||||
|
||||
.page-guide-drawer .semi-sidesheet-body::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--brand-scroll-hover);
|
||||
}
|
||||
|
||||
.page-guide-head {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.page-guide-head strong {
|
||||
font-size: 16px;
|
||||
color: var(--pg-ink);
|
||||
letter-spacing: -0.01em;
|
||||
}
|
||||
|
||||
.page-guide-head span {
|
||||
font-size: 12.5px;
|
||||
font-weight: 400;
|
||||
color: var(--pg-muted);
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.page-guide-progress {
|
||||
margin: 0 0 12px;
|
||||
font-size: 12px;
|
||||
color: var(--pg-muted);
|
||||
}
|
||||
|
||||
.page-guide-progress b {
|
||||
color: var(--pg-ok);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
/* ===== 步骤 ===== */
|
||||
.page-guide-steps {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.page-guide-step {
|
||||
border: 1px solid var(--pg-line);
|
||||
border-radius: 10px;
|
||||
overflow: hidden;
|
||||
background: var(--surface-card);
|
||||
}
|
||||
|
||||
.page-guide-step.is-next {
|
||||
border-color: var(--pg-tint-line);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-primary) 5%,
|
||||
var(--surface-card)
|
||||
);
|
||||
}
|
||||
|
||||
.page-guide-step-head {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
padding: 12px 14px;
|
||||
border: 0;
|
||||
background: none;
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.page-guide-step-ic {
|
||||
flex: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
margin-top: 1px;
|
||||
border: 1px solid var(--pg-line);
|
||||
border-radius: 50%;
|
||||
font-size: 12px;
|
||||
color: var(--pg-muted);
|
||||
}
|
||||
|
||||
.page-guide-step.is-done .page-guide-step-ic {
|
||||
border-color: transparent;
|
||||
background: var(--pg-ok-tint);
|
||||
color: var(--pg-ok);
|
||||
}
|
||||
|
||||
.page-guide-step.is-next .page-guide-step-ic {
|
||||
border-color: transparent;
|
||||
background: var(--pg-accent);
|
||||
color: var(--semi-color-white, var(--surface-card));
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.page-guide-step.is-working .page-guide-step-ic {
|
||||
border-color: var(--pg-tint-line);
|
||||
color: var(--pg-accent);
|
||||
}
|
||||
|
||||
.page-guide-step-copy {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.page-guide-step-copy strong {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
font-size: 13.5px;
|
||||
color: var(--pg-ink);
|
||||
}
|
||||
|
||||
.page-guide-step-copy small {
|
||||
display: block;
|
||||
margin-top: 2px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.6;
|
||||
color: var(--pg-muted);
|
||||
}
|
||||
|
||||
.page-guide-badge {
|
||||
flex: none;
|
||||
padding: 1px 8px;
|
||||
border: 1px solid var(--pg-tint-line);
|
||||
border-radius: 999px;
|
||||
background: var(--surface-card);
|
||||
color: var(--pg-accent);
|
||||
font-size: 11px;
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.page-guide-badge.is-done {
|
||||
border-color: transparent;
|
||||
background: var(--pg-ok-tint);
|
||||
color: var(--pg-ok);
|
||||
}
|
||||
|
||||
.page-guide-badge.is-working {
|
||||
border-color: transparent;
|
||||
background: var(--pg-tint);
|
||||
}
|
||||
|
||||
.page-guide-step-arrow {
|
||||
flex: none;
|
||||
margin-top: 3px;
|
||||
color: var(--pg-muted);
|
||||
transition: transform 0.15s ease;
|
||||
}
|
||||
|
||||
.page-guide-step.is-open .page-guide-step-arrow {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.page-guide-step-detail {
|
||||
padding: 0 14px 12px 46px;
|
||||
}
|
||||
|
||||
.page-guide-step-detail ul {
|
||||
margin: 0;
|
||||
padding-left: 16px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
color: var(--pg-muted);
|
||||
}
|
||||
|
||||
.page-guide-step-detail li + li {
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.page-guide-step-cta {
|
||||
margin-top: 10px;
|
||||
padding: 5px 12px;
|
||||
border: 1px solid var(--pg-tint-line);
|
||||
border-radius: 8px;
|
||||
background: var(--surface-card);
|
||||
color: var(--pg-accent);
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: background 0.15s ease;
|
||||
}
|
||||
|
||||
.page-guide-step-cta:hover {
|
||||
background: var(--pg-tint);
|
||||
}
|
||||
|
||||
/* ===== FAQ ===== */
|
||||
.page-guide-section-title {
|
||||
margin: 20px 0 10px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.08em;
|
||||
color: var(--pg-muted);
|
||||
}
|
||||
|
||||
.page-guide-faq {
|
||||
margin-bottom: 10px;
|
||||
padding-left: 12px;
|
||||
border-left: 2px solid var(--pg-tint-line);
|
||||
font-size: 12.5px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.page-guide-faq b {
|
||||
display: block;
|
||||
color: var(--pg-ink);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.page-guide-faq span {
|
||||
color: var(--pg-muted);
|
||||
}
|
||||
|
||||
.page-guide-foot {
|
||||
font-size: 12px;
|
||||
color: var(--pg-muted);
|
||||
}
|
||||
|
||||
/* 指引 CTA 落点的短暂高亮(flashGuideTarget) */
|
||||
.page-guide-flash {
|
||||
animation: page-guide-flash-pulse 1.6s ease;
|
||||
}
|
||||
|
||||
@keyframes page-guide-flash-pulse {
|
||||
0%,
|
||||
100% {
|
||||
box-shadow: none;
|
||||
}
|
||||
30% {
|
||||
box-shadow: 0 0 0 4px
|
||||
color-mix(in srgb, var(--semi-color-primary) 45%, transparent);
|
||||
}
|
||||
}
|
||||
|
||||
.page-guide-spin {
|
||||
animation: page-guide-spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes page-guide-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.page-guide-pill,
|
||||
.page-guide-step-arrow,
|
||||
.page-guide-step-cta {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.page-guide-spin,
|
||||
.page-guide-flash {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, Modal } from '@douyinfe/semi-ui';
|
||||
import { useSecureVerification } from '../../../hooks/common/useSecureVerification';
|
||||
import { createApiCalls } from '../../../services/secureVerification';
|
||||
import SecureVerificationModal from '../modals/SecureVerificationModal';
|
||||
import ChannelKeyDisplay from '../ui/ChannelKeyDisplay';
|
||||
|
||||
/**
|
||||
* 渠道密钥查看组件使用示例
|
||||
* 展示如何使用通用安全验证系统
|
||||
*/
|
||||
const ChannelKeyViewExample = ({ channelId }) => {
|
||||
const { t } = useTranslation();
|
||||
const [keyData, setKeyData] = useState('');
|
||||
const [showKeyModal, setShowKeyModal] = useState(false);
|
||||
|
||||
// 使用通用安全验证 Hook
|
||||
const {
|
||||
isModalVisible,
|
||||
verificationMethods,
|
||||
verificationState,
|
||||
startVerification,
|
||||
executeVerification,
|
||||
cancelVerification,
|
||||
setVerificationCode,
|
||||
switchVerificationMethod,
|
||||
} = useSecureVerification({
|
||||
onSuccess: (result) => {
|
||||
// 验证成功后处理结果
|
||||
if (result.success && result.data?.key) {
|
||||
setKeyData(result.data.key);
|
||||
setShowKeyModal(true);
|
||||
}
|
||||
},
|
||||
successMessage: t('密钥获取成功'),
|
||||
});
|
||||
|
||||
// 开始查看密钥流程
|
||||
const handleViewKey = async () => {
|
||||
const apiCall = createApiCalls.viewChannelKey(channelId);
|
||||
|
||||
await startVerification(apiCall, {
|
||||
title: t('查看渠道密钥'),
|
||||
description: t('为了保护账户安全,请验证您的身份。'),
|
||||
preferredMethod: 'passkey', // 可以指定首选验证方式
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* 查看密钥按钮 */}
|
||||
<Button type='primary' theme='outline' onClick={handleViewKey}>
|
||||
{t('查看密钥')}
|
||||
</Button>
|
||||
|
||||
{/* 安全验证模态框 */}
|
||||
<SecureVerificationModal
|
||||
visible={isModalVisible}
|
||||
verificationMethods={verificationMethods}
|
||||
verificationState={verificationState}
|
||||
onVerify={executeVerification}
|
||||
onCancel={cancelVerification}
|
||||
onCodeChange={setVerificationCode}
|
||||
onMethodSwitch={switchVerificationMethod}
|
||||
title={verificationState.title}
|
||||
description={verificationState.description}
|
||||
/>
|
||||
|
||||
{/* 密钥显示模态框 */}
|
||||
<Modal
|
||||
title={t('渠道密钥信息')}
|
||||
visible={showKeyModal}
|
||||
onCancel={() => setShowKeyModal(false)}
|
||||
footer={
|
||||
<Button type='primary' onClick={() => setShowKeyModal(false)}>
|
||||
{t('完成')}
|
||||
</Button>
|
||||
}
|
||||
width={700}
|
||||
style={{ maxWidth: '90vw' }}
|
||||
>
|
||||
<ChannelKeyDisplay
|
||||
keyData={keyData}
|
||||
showSuccessIcon={true}
|
||||
successText={t('密钥获取成功')}
|
||||
showWarning={true}
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChannelKeyViewExample;
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
// 微信图标 (已经存在于 WeChatIcon.jsx,但为了统一导入,这里也提供)
|
||||
export const WechatBrandIcon = ({
|
||||
size = 24,
|
||||
color = '#07C160',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill={color}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<path d='M8.691 2.188C3.891 2.188 0 5.476 0 9.53c0 2.212 1.17 4.203 3.002 5.55a.59.59 0 0 1 .213.665l-.39 1.48c-.019.07-.048.141-.048.213 0 .163.13.295.29.295a.326.326 0 0 0 .167-.054l1.903-1.114a.864.864 0 0 1 .717-.098 10.16 10.16 0 0 0 2.837.403c.276 0 .543-.027.811-.05-.857-2.578.157-4.972 1.932-6.446 1.703-1.415 3.882-1.98 5.853-1.838-.576-3.583-4.196-6.348-8.596-6.348zM5.785 5.991c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178A1.17 1.17 0 0 1 4.623 7.17c0-.651.52-1.18 1.162-1.18zm5.813 0c.642 0 1.162.529 1.162 1.18a1.17 1.17 0 0 1-1.162 1.178 1.17 1.17 0 0 1-1.162-1.178c0-.651.52-1.18 1.162-1.18zm5.34 2.867c-1.797-.052-3.746.512-5.28 1.786-1.72 1.428-2.687 3.72-1.78 6.22.942 2.453 3.666 4.229 6.884 4.229.826 0 1.622-.12 2.361-.336a.722.722 0 0 1 .598.082l1.584.926a.272.272 0 0 0 .14.047c.134 0 .24-.111.24-.247 0-.06-.023-.12-.038-.177l-.327-1.233a.582.582 0 0 1 .123-.51c1.531-1.186 2.498-2.913 2.498-4.879 0-3.583-3.256-6.468-7.11-6.468l.107-.44zm-2.68 2.58c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982zm4.844 0c.535 0 .969.44.969.982a.976.976 0 0 1-.969.983.976.976 0 0 1-.969-.983c0-.542.434-.982.969-.982z' />
|
||||
</svg>
|
||||
);
|
||||
|
||||
// 支付宝图标
|
||||
export const AlipayBrandIcon = ({
|
||||
size = 24,
|
||||
color = '#1677FF',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill={color}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<path d='M18.423 8.467c-.012-.02-4.54-8.467-4.54-8.467h-13.883l8 14.889-8 9.111h5l2.973-3.378s1.522 1.378 3.527 1.378c3 0 6.5-2.5 6.5-6.5 0-2.653-1.714-4.941-4.119-5.755zm-8.423 9.533l-4-7.432 4-4.568zm8.5 1c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5z' />
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Stripe 图标
|
||||
export const StripeBrandIcon = ({
|
||||
size = 24,
|
||||
color = '#635BFF',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill={color}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<path d='M13.976 9.15c-2.172-.806-3.356-1.426-3.356-2.409 0-.831.683-1.305 1.901-1.305 2.227 0 4.515.858 6.09 1.631l.89-5.494C18.252.975 15.697 0 12.165 0 9.667 0 7.589.654 6.104 1.872 4.56 3.147 3.757 4.992 3.757 7.218c0 4.039 2.467 5.76 6.476 7.219 2.585.92 3.445 1.574 3.445 2.583 0 .98-.84 1.545-2.354 1.545-1.875 0-4.965-.921-6.99-2.109l-.9 5.555C5.175 22.99 8.385 24 11.714 24c2.641 0 4.843-.624 6.328-1.813 1.664-1.305 2.525-3.236 2.525-5.732 0-4.128-2.524-5.851-6.591-7.305z' />
|
||||
</svg>
|
||||
);
|
||||
|
||||
// PayPal brand mark
|
||||
export const PayPalBrandIcon = ({
|
||||
size = 24,
|
||||
color = '#0070BA',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill={color}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<path d='M7.08 20.5H3.5a.75.75 0 0 1-.74-.87L5.74 1.1A1.3 1.3 0 0 1 7.02 0h6.53c4.15 0 6.58 2.2 6.11 5.76-.54 4.08-3.37 6.34-7.4 6.34H10.4a1.3 1.3 0 0 0-1.28 1.1L8.3 18.36A1.3 1.3 0 0 1 7.08 20.5Zm3.65-15.93-.55 3.47h1.57c1.72 0 2.8-.78 3.02-2.16.18-1.13-.64-1.31-2.05-1.31h-1.99Z' />
|
||||
<path
|
||||
d='M19.63 7.04c-.63 4.75-4.08 7.68-8.94 7.68h-.64l-.7 4.46-.2 1.27A1.3 1.3 0 0 0 10.44 22h3.1a1.3 1.3 0 0 0 1.28-1.1l.5-3.17a1.3 1.3 0 0 1 1.28-1.1h.81c3.57 0 6.02-2.08 6.48-5.52.33-2.48-.8-4.16-2.75-4.89-.45-.17-.94-.3-1.47-.38 0 .4-.01.8-.04 1.2Z'
|
||||
fill='#003087'
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Telegram 图标
|
||||
export const TelegramBrandIcon = ({
|
||||
size = 24,
|
||||
color = '#26A5E4',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill={color}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<path d='M11.944 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0a12 12 0 0 0-.056 0zm4.962 7.224c.1-.002.321.023.465.14a.506.506 0 0 1 .171.325c.016.093.036.306.02.472-.18 1.898-.962 6.502-1.36 8.627-.168.9-.499 1.201-.82 1.23-.696.065-1.225-.46-1.9-.902-1.056-.693-1.653-1.124-2.678-1.8-1.185-.78-.417-1.21.258-1.91.177-.184 3.247-2.977 3.307-3.23.007-.032.014-.15-.056-.212s-.174-.041-.249-.024c-.106.024-1.793 1.14-5.061 3.345-.48.33-.913.49-1.302.48-.428-.008-1.252-.241-1.865-.44-.752-.245-1.349-.374-1.297-.789.027-.216.325-.437.893-.663 3.498-1.524 5.83-2.529 6.998-3.014 3.332-1.386 4.025-1.627 4.476-1.635z' />
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Discord 图标
|
||||
export const DiscordBrandIcon = ({
|
||||
size = 24,
|
||||
color = '#5865F2',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill={color}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<path d='M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z' />
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Linux 图标 (用于 LinuxDO)
|
||||
export const LinuxBrandIcon = ({
|
||||
size = 24,
|
||||
color = '#FCC624',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill={color}
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<path d='M12.504 0c-.155 0-.315.008-.48.021-4.226.333-3.105 4.807-3.17 6.298-.076 1.092-.3 1.953-1.05 3.02-.885 1.051-2.127 2.75-2.716 4.521-.278.832-.41 1.684-.287 2.489a.424.424 0 00-.011.078c0 .072.011.142.033.21.179-.78.46-1.474.846-2.078l.53.07c-.145.49-.194.977-.148 1.449.04.42.15.82.43 1.131.711.77 1.89 1.032 2.902 1.032 1.02 0 1.902-.26 2.61-1.03.28-.31.39-.71.43-1.13.046-.473-.003-.96-.148-1.45l.53-.07c.386.605.668 1.299.847 2.078.022-.068.033-.139.033-.21a.424.424 0 00-.011-.078c.123-.805-.009-1.657-.287-2.489-.59-1.77-1.831-3.47-2.716-4.52-.75-1.068-.974-1.929-1.05-3.021-.066-1.491 1.055-5.965-3.17-6.298-.165-.013-.325-.021-.48-.021zm-.751 4.143c.357 0 .646.287.646.643a.645.645 0 01-.646.644.645.645 0 01-.645-.644c0-.356.288-.643.645-.643zm-5.116.641c.356 0 .645.287.645.644a.645.645 0 01-.645.643.645.645 0 01-.644-.643c0-.357.288-.644.644-.644zM12 8.941c.528 0 .956.428.956.955 0 .527-.428.955-.956.955-.527 0-.955-.428-.955-.955 0-.527.428-.955.955-.955zM4.668 11.19c.42 0 .76.34.76.76 0 .42-.34.76-.76.76a.76.76 0 01-.76-.76c0-.42.34-.76.76-.76zm14.664 0c.42 0 .76.34.76.76 0 .42-.34.76-.76.76a.76.76 0 01-.76-.76c0-.42.34-.76.76-.76z' />
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Shuffle 图标 (用于替换 FaRandom)
|
||||
export const ShuffleBrandIcon = ({
|
||||
size = 16,
|
||||
color = 'currentColor',
|
||||
className = '',
|
||||
...props
|
||||
}) => (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
width={size}
|
||||
height={size}
|
||||
fill='none'
|
||||
stroke={color}
|
||||
strokeWidth='2'
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
className={className}
|
||||
{...props}
|
||||
>
|
||||
<polyline points='16 3 21 3 21 8'></polyline>
|
||||
<line x1='4' y1='20' x2='21' y2='3'></line>
|
||||
<polyline points='21 16 21 21 16 21'></polyline>
|
||||
<line x1='15' y1='15' x2='21' y2='21'></line>
|
||||
<line x1='4' y1='4' x2='9' y2='9'></line>
|
||||
</svg>
|
||||
);
|
||||
@@ -0,0 +1,953 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
|
||||
// ========== 无结果插图 ==========
|
||||
export const IllustrationNoResult = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='noResultGrad1' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='var(--brand-primary)' />
|
||||
<stop offset='100%' stopColor='var(--brand-gradient-via)' />
|
||||
</linearGradient>
|
||||
<linearGradient id='noResultGrad2' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--brand-primary) 12%, #fff)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--brand-primary) 20%, #fff)' />
|
||||
</linearGradient>
|
||||
<filter id='noResultShadow' x='-20%' y='-20%' width='140%' height='140%'>
|
||||
<feDropShadow
|
||||
dx='0'
|
||||
dy='4'
|
||||
stdDeviation='8'
|
||||
floodColor='var(--brand-primary)'
|
||||
floodOpacity='0.15'
|
||||
/>
|
||||
</filter>
|
||||
</defs>
|
||||
{/* 背景装饰圆 */}
|
||||
<circle cx='100' cy='100' r='80' fill='url(#noResultGrad2)' opacity='0.3' />
|
||||
<circle cx='100' cy='100' r='60' fill='url(#noResultGrad2)' opacity='0.5' />
|
||||
{/* 搜索放大镜 */}
|
||||
<g filter='url(#noResultShadow)'>
|
||||
<circle
|
||||
cx='90'
|
||||
cy='85'
|
||||
r='35'
|
||||
stroke='url(#noResultGrad1)'
|
||||
strokeWidth='6'
|
||||
fill='white'
|
||||
/>
|
||||
<line
|
||||
x1='115'
|
||||
y1='110'
|
||||
x2='140'
|
||||
y2='135'
|
||||
stroke='url(#noResultGrad1)'
|
||||
strokeWidth='8'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
</g>
|
||||
{/* X 标记 */}
|
||||
<g opacity='0.8'>
|
||||
<line
|
||||
x1='75'
|
||||
y1='70'
|
||||
x2='105'
|
||||
y2='100'
|
||||
stroke='var(--semi-color-danger)'
|
||||
strokeWidth='4'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='105'
|
||||
y1='70'
|
||||
x2='75'
|
||||
y2='100'
|
||||
stroke='var(--semi-color-danger)'
|
||||
strokeWidth='4'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
</g>
|
||||
{/* 装饰点 */}
|
||||
<circle cx='45' cy='60' r='4' fill='var(--brand-primary)' opacity='0.4'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.4;0.8;0.4'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='160' cy='50' r='3' fill='var(--brand-gradient-via)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;1;0.5'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='155' cy='140' r='5' fill='var(--brand-gradient-to)' opacity='0.3'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.3;0.7;0.3'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const IllustrationNoResultDark = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id='noResultGradDark1'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='var(--brand-gradient-from)' />
|
||||
<stop offset='100%' stopColor='var(--brand-gradient-to)' />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id='noResultGradDark2'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--brand-primary) 25%, #000)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--brand-gradient-via) 25%, #000)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='80'
|
||||
fill='url(#noResultGradDark2)'
|
||||
opacity='0.3'
|
||||
/>
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='60'
|
||||
fill='url(#noResultGradDark2)'
|
||||
opacity='0.5'
|
||||
/>
|
||||
<g>
|
||||
<circle
|
||||
cx='90'
|
||||
cy='85'
|
||||
r='35'
|
||||
stroke='url(#noResultGradDark1)'
|
||||
strokeWidth='6'
|
||||
fill='color-mix(in srgb, var(--brand-primary) 15%, #000)'
|
||||
/>
|
||||
<line
|
||||
x1='115'
|
||||
y1='110'
|
||||
x2='140'
|
||||
y2='135'
|
||||
stroke='url(#noResultGradDark1)'
|
||||
strokeWidth='8'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
</g>
|
||||
<g opacity='0.8'>
|
||||
<line
|
||||
x1='75'
|
||||
y1='70'
|
||||
x2='105'
|
||||
y2='100'
|
||||
stroke='var(--semi-color-danger)'
|
||||
strokeWidth='4'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<line
|
||||
x1='105'
|
||||
y1='70'
|
||||
x2='75'
|
||||
y2='100'
|
||||
stroke='var(--semi-color-danger)'
|
||||
strokeWidth='4'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
</g>
|
||||
<circle cx='45' cy='60' r='4' fill='var(--brand-gradient-from)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;1;0.5'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='160' cy='50' r='3' fill='var(--brand-gradient-to)' opacity='0.6'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='155' cy='140' r='5' fill='var(--brand-primary-hover)' opacity='0.4'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.4;0.8;0.4'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// ========== 页面未找到插图 ==========
|
||||
export const IllustrationNotFound = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='notFoundGrad1' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='var(--semi-color-warning)' />
|
||||
<stop offset='100%' stopColor='var(--semi-color-danger)' />
|
||||
</linearGradient>
|
||||
<linearGradient id='notFoundGrad2' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--semi-color-warning) 15%, #fff)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--semi-color-danger) 25%, #fff)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
{/* 背景 */}
|
||||
<circle cx='100' cy='100' r='75' fill='url(#notFoundGrad2)' opacity='0.4' />
|
||||
{/* 404 文字 */}
|
||||
<text
|
||||
x='100'
|
||||
y='90'
|
||||
textAnchor='middle'
|
||||
fontSize='48'
|
||||
fontWeight='bold'
|
||||
fill='url(#notFoundGrad1)'
|
||||
>
|
||||
404
|
||||
</text>
|
||||
{/* 底部线条 */}
|
||||
<path
|
||||
d='M50 120 Q100 140 150 120'
|
||||
stroke='url(#notFoundGrad1)'
|
||||
strokeWidth='3'
|
||||
fill='none'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
{/* 问号 */}
|
||||
<text
|
||||
x='100'
|
||||
y='160'
|
||||
textAnchor='middle'
|
||||
fontSize='24'
|
||||
fill='url(#notFoundGrad1)'
|
||||
opacity='0.6'
|
||||
>
|
||||
?
|
||||
</text>
|
||||
{/* 装饰星星 */}
|
||||
<path
|
||||
d='M40 40 L42 48 L50 50 L42 52 L40 60 L38 52 L30 50 L38 48 Z'
|
||||
fill='var(--semi-color-warning)'
|
||||
opacity='0.6'
|
||||
>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='1.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</path>
|
||||
<path
|
||||
d='M160 60 L161.5 66 L168 68 L161.5 70 L160 76 L158.5 70 L152 68 L158.5 66 Z'
|
||||
fill='var(--semi-color-danger)'
|
||||
opacity='0.5'
|
||||
>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;0.9;0.5'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</path>
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const IllustrationNotFoundDark = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id='notFoundGradDark1'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='var(--semi-color-warning)' />
|
||||
<stop offset='100%' stopColor='var(--semi-color-danger)' />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id='notFoundGradDark2'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--semi-color-warning) 30%, #000)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--semi-color-danger) 30%, #000)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='75'
|
||||
fill='url(#notFoundGradDark2)'
|
||||
opacity='0.4'
|
||||
/>
|
||||
<text
|
||||
x='100'
|
||||
y='90'
|
||||
textAnchor='middle'
|
||||
fontSize='48'
|
||||
fontWeight='bold'
|
||||
fill='url(#notFoundGradDark1)'
|
||||
>
|
||||
404
|
||||
</text>
|
||||
<path
|
||||
d='M50 120 Q100 140 150 120'
|
||||
stroke='url(#notFoundGradDark1)'
|
||||
strokeWidth='3'
|
||||
fill='none'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<text
|
||||
x='100'
|
||||
y='160'
|
||||
textAnchor='middle'
|
||||
fontSize='24'
|
||||
fill='url(#notFoundGradDark1)'
|
||||
opacity='0.6'
|
||||
>
|
||||
?
|
||||
</text>
|
||||
<path
|
||||
d='M40 40 L42 48 L50 50 L42 52 L40 60 L38 52 L30 50 L38 48 Z'
|
||||
fill='var(--semi-color-warning)'
|
||||
opacity='0.7'
|
||||
>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.7;1;0.7'
|
||||
dur='1.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</path>
|
||||
<path
|
||||
d='M160 60 L161.5 66 L168 68 L161.5 70 L160 76 L158.5 70 L152 68 L158.5 66 Z'
|
||||
fill='var(--semi-color-danger)'
|
||||
opacity='0.6'
|
||||
>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</path>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// ========== 无权限插图 ==========
|
||||
export const IllustrationNoAccess = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='noAccessGrad1' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='var(--semi-color-danger)' />
|
||||
<stop offset='100%' stopColor='var(--brand-gradient-via)' />
|
||||
</linearGradient>
|
||||
<linearGradient id='noAccessGrad2' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='#fce7f3' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--brand-gradient-via) 10%, #fff)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
{/* 背景 */}
|
||||
<circle cx='100' cy='100' r='75' fill='url(#noAccessGrad2)' opacity='0.5' />
|
||||
{/* 锁身 */}
|
||||
<rect
|
||||
x='65'
|
||||
y='90'
|
||||
width='70'
|
||||
height='55'
|
||||
rx='8'
|
||||
fill='url(#noAccessGrad1)'
|
||||
/>
|
||||
{/* 锁孔 */}
|
||||
<circle cx='100' cy='112' r='8' fill='white' />
|
||||
<rect x='96' y='112' width='8' height='18' rx='2' fill='white' />
|
||||
{/* 锁钩 */}
|
||||
<path
|
||||
d='M75 90 V70 C75 55 85 45 100 45 C115 45 125 55 125 70 V90'
|
||||
stroke='url(#noAccessGrad1)'
|
||||
strokeWidth='8'
|
||||
fill='none'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
{/* 装饰 */}
|
||||
<circle cx='45' cy='70' r='4' fill='var(--semi-color-danger)' opacity='0.4'>
|
||||
<animate
|
||||
attributeName='r'
|
||||
values='4;6;4'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='160' cy='130' r='5' fill='var(--brand-gradient-via)' opacity='0.4'>
|
||||
<animate
|
||||
attributeName='r'
|
||||
values='5;7;5'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const IllustrationNoAccessDark = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id='noAccessGradDark1'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='var(--semi-color-danger)' />
|
||||
<stop offset='100%' stopColor='var(--brand-gradient-to)' />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id='noAccessGradDark2'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--semi-color-danger) 30%, #000)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--brand-gradient-via) 25%, #000)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='75'
|
||||
fill='url(#noAccessGradDark2)'
|
||||
opacity='0.4'
|
||||
/>
|
||||
<rect
|
||||
x='65'
|
||||
y='90'
|
||||
width='70'
|
||||
height='55'
|
||||
rx='8'
|
||||
fill='url(#noAccessGradDark1)'
|
||||
/>
|
||||
<circle cx='100' cy='112' r='8' fill='color-mix(in srgb, var(--brand-primary) 15%, #000)' />
|
||||
<rect x='96' y='112' width='8' height='18' rx='2' fill='color-mix(in srgb, var(--brand-primary) 15%, #000)' />
|
||||
<path
|
||||
d='M75 90 V70 C75 55 85 45 100 45 C115 45 125 55 125 70 V90'
|
||||
stroke='url(#noAccessGradDark1)'
|
||||
strokeWidth='8'
|
||||
fill='none'
|
||||
strokeLinecap='round'
|
||||
/>
|
||||
<circle cx='45' cy='70' r='4' fill='var(--semi-color-danger)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='r'
|
||||
values='4;6;4'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='160' cy='130' r='5' fill='var(--brand-gradient-to)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='r'
|
||||
values='5;7;5'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// ========== 建设中插图 ==========
|
||||
export const IllustrationConstruction = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='constructGrad1' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='var(--semi-color-success)' />
|
||||
<stop offset='100%' stopColor='var(--accent-teal)' />
|
||||
</linearGradient>
|
||||
<linearGradient id='constructGrad2' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--semi-color-success) 15%, #fff)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--accent-teal) 15%, #fff)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
{/* 背景 */}
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='75'
|
||||
fill='url(#constructGrad2)'
|
||||
opacity='0.4'
|
||||
/>
|
||||
{/* 齿轮1 */}
|
||||
<g transform='translate(70, 80)'>
|
||||
<circle
|
||||
cx='20'
|
||||
cy='20'
|
||||
r='15'
|
||||
stroke='url(#constructGrad1)'
|
||||
strokeWidth='4'
|
||||
fill='white'
|
||||
/>
|
||||
<circle cx='20' cy='20' r='6' fill='url(#constructGrad1)' />
|
||||
{[0, 45, 90, 135, 180, 225, 270, 315].map((angle, i) => (
|
||||
<rect
|
||||
key={i}
|
||||
x='17'
|
||||
y='0'
|
||||
width='6'
|
||||
height='8'
|
||||
rx='2'
|
||||
fill='url(#constructGrad1)'
|
||||
transform={`rotate(${angle} 20 20)`}
|
||||
/>
|
||||
))}
|
||||
<animateTransform
|
||||
attributeName='transform'
|
||||
type='rotate'
|
||||
from='0 90 100'
|
||||
to='360 90 100'
|
||||
dur='8s'
|
||||
repeatCount='indefinite'
|
||||
additive='sum'
|
||||
/>
|
||||
</g>
|
||||
{/* 齿轮2 */}
|
||||
<g transform='translate(105, 95)'>
|
||||
<circle
|
||||
cx='15'
|
||||
cy='15'
|
||||
r='12'
|
||||
stroke='url(#constructGrad1)'
|
||||
strokeWidth='3'
|
||||
fill='white'
|
||||
/>
|
||||
<circle cx='15' cy='15' r='5' fill='url(#constructGrad1)' />
|
||||
{[0, 60, 120, 180, 240, 300].map((angle, i) => (
|
||||
<rect
|
||||
key={i}
|
||||
x='13'
|
||||
y='0'
|
||||
width='4'
|
||||
height='6'
|
||||
rx='1'
|
||||
fill='url(#constructGrad1)'
|
||||
transform={`rotate(${angle} 15 15)`}
|
||||
/>
|
||||
))}
|
||||
<animateTransform
|
||||
attributeName='transform'
|
||||
type='rotate'
|
||||
from='360 120 110'
|
||||
to='0 120 110'
|
||||
dur='6s'
|
||||
repeatCount='indefinite'
|
||||
additive='sum'
|
||||
/>
|
||||
</g>
|
||||
{/* 扳手 */}
|
||||
<path
|
||||
d='M55 55 L65 65 L60 70 L50 60 Z'
|
||||
fill='url(#constructGrad1)'
|
||||
opacity='0.7'
|
||||
/>
|
||||
{/* 装饰 */}
|
||||
<circle cx='150' cy='50' r='4' fill='var(--semi-color-success)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;1;0.5'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='50' cy='150' r='3' fill='var(--accent-teal)' opacity='0.4'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.4;0.8;0.4'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const IllustrationConstructionDark = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id='constructGradDark1'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='var(--semi-color-success)' />
|
||||
<stop offset='100%' stopColor='var(--accent-teal)' />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id='constructGradDark2'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--semi-color-success) 25%, #000)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--accent-teal) 25%, #000)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='75'
|
||||
fill='url(#constructGradDark2)'
|
||||
opacity='0.4'
|
||||
/>
|
||||
<g transform='translate(70, 80)'>
|
||||
<circle
|
||||
cx='20'
|
||||
cy='20'
|
||||
r='15'
|
||||
stroke='url(#constructGradDark1)'
|
||||
strokeWidth='4'
|
||||
fill='#0f172a'
|
||||
/>
|
||||
<circle cx='20' cy='20' r='6' fill='url(#constructGradDark1)' />
|
||||
{[0, 45, 90, 135, 180, 225, 270, 315].map((angle, i) => (
|
||||
<rect
|
||||
key={i}
|
||||
x='17'
|
||||
y='0'
|
||||
width='6'
|
||||
height='8'
|
||||
rx='2'
|
||||
fill='url(#constructGradDark1)'
|
||||
transform={`rotate(${angle} 20 20)`}
|
||||
/>
|
||||
))}
|
||||
<animateTransform
|
||||
attributeName='transform'
|
||||
type='rotate'
|
||||
from='0 90 100'
|
||||
to='360 90 100'
|
||||
dur='8s'
|
||||
repeatCount='indefinite'
|
||||
additive='sum'
|
||||
/>
|
||||
</g>
|
||||
<g transform='translate(105, 95)'>
|
||||
<circle
|
||||
cx='15'
|
||||
cy='15'
|
||||
r='12'
|
||||
stroke='url(#constructGradDark1)'
|
||||
strokeWidth='3'
|
||||
fill='#0f172a'
|
||||
/>
|
||||
<circle cx='15' cy='15' r='5' fill='url(#constructGradDark1)' />
|
||||
{[0, 60, 120, 180, 240, 300].map((angle, i) => (
|
||||
<rect
|
||||
key={i}
|
||||
x='13'
|
||||
y='0'
|
||||
width='4'
|
||||
height='6'
|
||||
rx='1'
|
||||
fill='url(#constructGradDark1)'
|
||||
transform={`rotate(${angle} 15 15)`}
|
||||
/>
|
||||
))}
|
||||
<animateTransform
|
||||
attributeName='transform'
|
||||
type='rotate'
|
||||
from='360 120 110'
|
||||
to='0 120 110'
|
||||
dur='6s'
|
||||
repeatCount='indefinite'
|
||||
additive='sum'
|
||||
/>
|
||||
</g>
|
||||
<path
|
||||
d='M55 55 L65 65 L60 70 L50 60 Z'
|
||||
fill='url(#constructGradDark1)'
|
||||
opacity='0.7'
|
||||
/>
|
||||
<circle cx='150' cy='50' r='4' fill='var(--semi-color-success)' opacity='0.6'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='50' cy='150' r='3' fill='var(--accent-teal)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;0.9;0.5'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// ========== 无内容插图 ==========
|
||||
export const IllustrationNoContent = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='noContentGrad1' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='var(--accent-blue)' />
|
||||
<stop offset='100%' stopColor='var(--brand-gradient-via)' />
|
||||
</linearGradient>
|
||||
<linearGradient id='noContentGrad2' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--accent-blue) 12%, #fff)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--brand-gradient-via) 10%, #fff)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
{/* 背景 */}
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='75'
|
||||
fill='url(#noContentGrad2)'
|
||||
opacity='0.4'
|
||||
/>
|
||||
{/* 文件夹 */}
|
||||
<path
|
||||
d='M50 70 L50 140 C50 145 55 150 60 150 L140 150 C145 150 150 145 150 140 L150 85 C150 80 145 75 140 75 L100 75 L90 65 L60 65 C55 65 50 70 50 75 Z'
|
||||
fill='url(#noContentGrad1)'
|
||||
opacity='0.9'
|
||||
/>
|
||||
<path
|
||||
d='M50 85 L150 85 L150 140 C150 145 145 150 140 150 L60 150 C55 150 50 145 50 140 Z'
|
||||
fill='white'
|
||||
opacity='0.9'
|
||||
/>
|
||||
{/* 虚线 */}
|
||||
<line
|
||||
x1='70'
|
||||
y1='105'
|
||||
x2='130'
|
||||
y2='105'
|
||||
stroke='url(#noContentGrad1)'
|
||||
strokeWidth='3'
|
||||
strokeDasharray='8,4'
|
||||
opacity='0.5'
|
||||
/>
|
||||
<line
|
||||
x1='70'
|
||||
y1='120'
|
||||
x2='110'
|
||||
y2='120'
|
||||
stroke='url(#noContentGrad1)'
|
||||
strokeWidth='3'
|
||||
strokeDasharray='8,4'
|
||||
opacity='0.3'
|
||||
/>
|
||||
<line
|
||||
x1='70'
|
||||
y1='135'
|
||||
x2='90'
|
||||
y2='135'
|
||||
stroke='url(#noContentGrad1)'
|
||||
strokeWidth='3'
|
||||
strokeDasharray='8,4'
|
||||
opacity='0.2'
|
||||
/>
|
||||
{/* 装饰 */}
|
||||
<circle cx='160' cy='55' r='4' fill='var(--accent-blue)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;1;0.5'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='40' cy='145' r='3' fill='var(--brand-gradient-via)' opacity='0.4'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.4;0.8;0.4'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
export const IllustrationNoContentDark = ({ style = {} }) => (
|
||||
<svg
|
||||
viewBox='0 0 200 200'
|
||||
fill='none'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
style={{ width: 150, height: 150, ...style }}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient
|
||||
id='noContentGradDark1'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='var(--accent-blue)' />
|
||||
<stop offset='100%' stopColor='var(--brand-gradient-to)' />
|
||||
</linearGradient>
|
||||
<linearGradient
|
||||
id='noContentGradDark2'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='color-mix(in srgb, var(--accent-blue) 25%, #000)' />
|
||||
<stop offset='100%' stopColor='color-mix(in srgb, var(--brand-gradient-via) 25%, #000)' />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<circle
|
||||
cx='100'
|
||||
cy='100'
|
||||
r='75'
|
||||
fill='url(#noContentGradDark2)'
|
||||
opacity='0.3'
|
||||
/>
|
||||
<path
|
||||
d='M50 70 L50 140 C50 145 55 150 60 150 L140 150 C145 150 150 145 150 140 L150 85 C150 80 145 75 140 75 L100 75 L90 65 L60 65 C55 65 50 70 50 75 Z'
|
||||
fill='url(#noContentGradDark1)'
|
||||
opacity='0.9'
|
||||
/>
|
||||
<path
|
||||
d='M50 85 L150 85 L150 140 C150 145 145 150 140 150 L60 150 C55 150 50 145 50 140 Z'
|
||||
fill='color-mix(in srgb, var(--brand-primary) 15%, #000)'
|
||||
opacity='0.9'
|
||||
/>
|
||||
<line
|
||||
x1='70'
|
||||
y1='105'
|
||||
x2='130'
|
||||
y2='105'
|
||||
stroke='url(#noContentGradDark1)'
|
||||
strokeWidth='3'
|
||||
strokeDasharray='8,4'
|
||||
opacity='0.5'
|
||||
/>
|
||||
<line
|
||||
x1='70'
|
||||
y1='120'
|
||||
x2='110'
|
||||
y2='120'
|
||||
stroke='url(#noContentGradDark1)'
|
||||
strokeWidth='3'
|
||||
strokeDasharray='8,4'
|
||||
opacity='0.3'
|
||||
/>
|
||||
<line
|
||||
x1='70'
|
||||
y1='135'
|
||||
x2='90'
|
||||
y2='135'
|
||||
stroke='url(#noContentGradDark1)'
|
||||
strokeWidth='3'
|
||||
strokeDasharray='8,4'
|
||||
opacity='0.2'
|
||||
/>
|
||||
<circle cx='160' cy='55' r='4' fill='var(--accent-blue)' opacity='0.6'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='40' cy='145' r='3' fill='var(--brand-gradient-to)' opacity='0.5'>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;0.9;0.5'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React from 'react';
|
||||
|
||||
const DiscordIcon = ({ style = {}, ...props }) => {
|
||||
return (
|
||||
<svg
|
||||
viewBox='0 0 24 24'
|
||||
fill='currentColor'
|
||||
style={{ width: '20px', height: '20px', ...style }}
|
||||
{...props}
|
||||
>
|
||||
<path d='M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z' />
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export default DiscordIcon;
|
||||
@@ -0,0 +1,169 @@
|
||||
/* Dolphin Logo Styles - 海豚图标动画样式 */
|
||||
|
||||
.dolphin-logo {
|
||||
display: inline-block;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
/* 整体游泳动画 */
|
||||
.dolphin-animated .dolphin-body {
|
||||
animation: dolphinSwim 3s ease-in-out infinite;
|
||||
transform-origin: center center;
|
||||
}
|
||||
|
||||
@keyframes dolphinSwim {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0) rotate(0deg);
|
||||
}
|
||||
25% {
|
||||
transform: translateY(-3px) rotate(-2deg);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(0) rotate(0deg);
|
||||
}
|
||||
75% {
|
||||
transform: translateY(2px) rotate(2deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* 尾巴摆动 */
|
||||
.dolphin-animated .dolphin-tail {
|
||||
animation: tailWag 0.8s ease-in-out infinite;
|
||||
transform-origin: 20px 48px;
|
||||
}
|
||||
|
||||
@keyframes tailWag {
|
||||
0%,
|
||||
100% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
50% {
|
||||
transform: rotate(-8deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* 背鳍微动 */
|
||||
.dolphin-animated .dolphin-fin {
|
||||
animation: finMove 2s ease-in-out infinite;
|
||||
transform-origin: 45px 25px;
|
||||
}
|
||||
|
||||
@keyframes finMove {
|
||||
0%,
|
||||
100% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
50% {
|
||||
transform: rotate(-3deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* 胸鳍划水 */
|
||||
.dolphin-animated .dolphin-pectoral {
|
||||
animation: pectoralMove 1.5s ease-in-out infinite;
|
||||
transform-origin: 38px 55px;
|
||||
}
|
||||
|
||||
@keyframes pectoralMove {
|
||||
0%,
|
||||
100% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
50% {
|
||||
transform: rotate(5deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* 眼睛眨眼 */
|
||||
.dolphin-animated .dolphin-eye {
|
||||
animation: blink 4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
0%,
|
||||
45%,
|
||||
55%,
|
||||
100% {
|
||||
transform: scaleY(1);
|
||||
}
|
||||
50% {
|
||||
transform: scaleY(0.1);
|
||||
}
|
||||
}
|
||||
|
||||
/* 眼睛高光闪烁 */
|
||||
.dolphin-animated .dolphin-eye-highlight {
|
||||
animation: eyeSparkle 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes eyeSparkle {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
/* 光泽流动 */
|
||||
.dolphin-animated .dolphin-shine {
|
||||
animation: shineMove 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes shineMove {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 0.8;
|
||||
transform: translateX(0);
|
||||
}
|
||||
50% {
|
||||
opacity: 0.4;
|
||||
transform: translateX(2px);
|
||||
}
|
||||
}
|
||||
|
||||
/* 气泡上浮已在 SVG 中定义 */
|
||||
|
||||
/* 悬停效果 */
|
||||
.dolphin-logo:hover .dolphin-body {
|
||||
animation: dolphinJump 0.6s ease-out;
|
||||
}
|
||||
|
||||
@keyframes dolphinJump {
|
||||
0% {
|
||||
transform: translateY(0) rotate(0deg);
|
||||
}
|
||||
30% {
|
||||
transform: translateY(-8px) rotate(-5deg);
|
||||
}
|
||||
60% {
|
||||
transform: translateY(-4px) rotate(3deg);
|
||||
}
|
||||
100% {
|
||||
transform: translateY(0) rotate(0deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* 暗色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.dolphin-logo {
|
||||
filter: brightness(1.1);
|
||||
}
|
||||
}
|
||||
|
||||
/* 禁用动画时的静态样式 */
|
||||
.dolphin-logo:not(.dolphin-animated) .dolphin-body,
|
||||
.dolphin-logo:not(.dolphin-animated) .dolphin-tail,
|
||||
.dolphin-logo:not(.dolphin-animated) .dolphin-fin,
|
||||
.dolphin-logo:not(.dolphin-animated) .dolphin-pectoral,
|
||||
.dolphin-logo:not(.dolphin-animated) .dolphin-eye,
|
||||
.dolphin-logo:not(.dolphin-animated) .dolphin-eye-highlight,
|
||||
.dolphin-logo:not(.dolphin-animated) .dolphin-shine {
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.dolphin-logo:not(.dolphin-animated) .bubbles {
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import './DolphinLogo.css';
|
||||
|
||||
/**
|
||||
* Dolphin Logo Component - 海豚动画图标
|
||||
* @param {number} size - Logo 大小(像素),默认 32
|
||||
* @param {string} className - 额外的 CSS 类名
|
||||
* @param {boolean} animated - 是否启用动画,默认 true
|
||||
*/
|
||||
const DolphinLogo = ({ size = 32, className = '', animated = true }) => {
|
||||
return (
|
||||
<svg
|
||||
viewBox='0 0 100 100'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
width={size}
|
||||
height={size}
|
||||
className={`dolphin-logo ${animated ? 'dolphin-animated' : ''} ${className}`}
|
||||
>
|
||||
<defs>
|
||||
{/* 主渐变 - 海洋蓝 */}
|
||||
<linearGradient
|
||||
id='dolphinGradient'
|
||||
x1='0%'
|
||||
y1='0%'
|
||||
x2='100%'
|
||||
y2='100%'
|
||||
>
|
||||
<stop offset='0%' stopColor='#4facfe'>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#4facfe;#00f2fe;#38bdf8;#4facfe'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='50%' stopColor='#00c6fb'>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#00c6fb;#4facfe;#00f2fe;#00c6fb'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='100%' stopColor='#005bea'>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#005bea;#0083b0;#4facfe;#005bea'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
|
||||
{/* 腹部渐变 - 浅色 */}
|
||||
<linearGradient id='bellyGradient' x1='0%' y1='0%' x2='0%' y2='100%'>
|
||||
<stop offset='0%' stopColor='#e0f7ff' />
|
||||
<stop offset='100%' stopColor='#b8e8fc' />
|
||||
</linearGradient>
|
||||
|
||||
{/* 光泽效果 */}
|
||||
<linearGradient id='shineGradient' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' stopColor='#ffffff' stopOpacity='0.6' />
|
||||
<stop offset='50%' stopColor='#ffffff' stopOpacity='0.2' />
|
||||
<stop offset='100%' stopColor='#ffffff' stopOpacity='0' />
|
||||
</linearGradient>
|
||||
|
||||
{/* 阴影滤镜 */}
|
||||
<filter id='dolphinShadow' x='-20%' y='-20%' width='140%' height='140%'>
|
||||
<feDropShadow
|
||||
dx='0'
|
||||
dy='2'
|
||||
stdDeviation='2'
|
||||
floodColor='#0066cc'
|
||||
floodOpacity='0.3'
|
||||
/>
|
||||
</filter>
|
||||
|
||||
{/* 水波纹效果 */}
|
||||
<filter id='waterRipple'>
|
||||
<feTurbulence
|
||||
type='fractalNoise'
|
||||
baseFrequency='0.02'
|
||||
numOctaves='2'
|
||||
result='turbulence'
|
||||
>
|
||||
<animate
|
||||
attributeName='baseFrequency'
|
||||
values='0.02;0.025;0.02'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</feTurbulence>
|
||||
<feDisplacementMap
|
||||
in='SourceGraphic'
|
||||
in2='turbulence'
|
||||
scale='1'
|
||||
xChannelSelector='R'
|
||||
yChannelSelector='G'
|
||||
/>
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
{/* 海豚主体 */}
|
||||
<g className='dolphin-body' filter='url(#dolphinShadow)'>
|
||||
{/* 身体 */}
|
||||
<path
|
||||
className='dolphin-main'
|
||||
d='M 75 45
|
||||
C 80 35, 78 25, 70 22
|
||||
C 62 19, 50 20, 42 25
|
||||
C 34 30, 25 38, 20 48
|
||||
C 15 58, 18 68, 28 72
|
||||
C 38 76, 55 74, 68 65
|
||||
C 78 58, 82 50, 75 45
|
||||
Z'
|
||||
fill='url(#dolphinGradient)'
|
||||
/>
|
||||
|
||||
{/* 腹部 */}
|
||||
<path
|
||||
className='dolphin-belly'
|
||||
d='M 68 52
|
||||
C 65 58, 55 65, 42 66
|
||||
C 32 67, 25 63, 24 56
|
||||
C 23 50, 28 44, 38 42
|
||||
C 50 40, 62 44, 68 52
|
||||
Z'
|
||||
fill='url(#bellyGradient)'
|
||||
opacity='0.9'
|
||||
/>
|
||||
|
||||
{/* 嘴巴/吻部 */}
|
||||
<path
|
||||
className='dolphin-snout'
|
||||
d='M 70 22
|
||||
C 75 20, 82 22, 88 28
|
||||
C 85 30, 78 30, 72 28
|
||||
C 70 26, 70 24, 70 22
|
||||
Z'
|
||||
fill='url(#dolphinGradient)'
|
||||
/>
|
||||
|
||||
{/* 背鳍 */}
|
||||
<path
|
||||
className='dolphin-fin'
|
||||
d='M 45 25
|
||||
C 48 18, 52 12, 50 8
|
||||
C 48 12, 44 18, 42 25
|
||||
Z'
|
||||
fill='url(#dolphinGradient)'
|
||||
/>
|
||||
|
||||
{/* 胸鳍 */}
|
||||
<path
|
||||
className='dolphin-pectoral'
|
||||
d='M 38 55
|
||||
C 32 58, 25 65, 20 70
|
||||
C 22 68, 28 62, 35 58
|
||||
C 36 56, 37 55, 38 55
|
||||
Z'
|
||||
fill='url(#dolphinGradient)'
|
||||
/>
|
||||
|
||||
{/* 尾鳍 */}
|
||||
<path
|
||||
className='dolphin-tail'
|
||||
d='M 20 48
|
||||
C 14 42, 8 38, 5 42
|
||||
C 8 45, 12 48, 15 52
|
||||
M 20 48
|
||||
C 14 54, 8 58, 5 54
|
||||
C 8 52, 12 50, 15 48
|
||||
Z'
|
||||
fill='url(#dolphinGradient)'
|
||||
/>
|
||||
|
||||
{/* 眼睛 */}
|
||||
<ellipse
|
||||
className='dolphin-eye'
|
||||
cx='62'
|
||||
cy='32'
|
||||
rx='3'
|
||||
ry='3.5'
|
||||
fill='#1a365d'
|
||||
/>
|
||||
|
||||
{/* 眼睛高光 */}
|
||||
<ellipse
|
||||
className='dolphin-eye-highlight'
|
||||
cx='63'
|
||||
cy='31'
|
||||
rx='1'
|
||||
ry='1.2'
|
||||
fill='#ffffff'
|
||||
/>
|
||||
|
||||
{/* 身体光泽 */}
|
||||
<path
|
||||
className='dolphin-shine'
|
||||
d='M 55 28
|
||||
C 60 26, 65 28, 68 32
|
||||
C 65 30, 58 28, 52 30
|
||||
C 50 31, 52 29, 55 28
|
||||
Z'
|
||||
fill='url(#shineGradient)'
|
||||
/>
|
||||
|
||||
{/* 微笑线条 */}
|
||||
<path
|
||||
className='dolphin-smile'
|
||||
d='M 75 28 Q 80 30, 84 28'
|
||||
fill='none'
|
||||
stroke='#1a365d'
|
||||
strokeWidth='1'
|
||||
strokeLinecap='round'
|
||||
opacity='0.5'
|
||||
/>
|
||||
</g>
|
||||
|
||||
{/* 水花气泡 */}
|
||||
<g className='bubbles'>
|
||||
<circle
|
||||
className='bubble bubble-1'
|
||||
cx='15'
|
||||
cy='75'
|
||||
r='2'
|
||||
fill='#4facfe'
|
||||
opacity='0.6'
|
||||
>
|
||||
<animate
|
||||
attributeName='cy'
|
||||
values='75;65;55'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;0.3;0'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='r'
|
||||
values='2;3;2'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle
|
||||
className='bubble bubble-2'
|
||||
cx='22'
|
||||
cy='80'
|
||||
r='1.5'
|
||||
fill='#00c6fb'
|
||||
opacity='0.5'
|
||||
>
|
||||
<animate
|
||||
attributeName='cy'
|
||||
values='80;68;56'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.5;0.2;0'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='r'
|
||||
values='1.5;2.5;1.5'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle
|
||||
className='bubble bubble-3'
|
||||
cx='10'
|
||||
cy='82'
|
||||
r='1'
|
||||
fill='#38bdf8'
|
||||
opacity='0.4'
|
||||
>
|
||||
<animate
|
||||
attributeName='cy'
|
||||
values='82;72;62'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.4;0.2;0'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='r'
|
||||
values='1;2;1'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export default DolphinLogo;
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Icon } from '@douyinfe/semi-ui';
|
||||
|
||||
const LinuxDoIcon = (props) => {
|
||||
function CustomIcon() {
|
||||
return (
|
||||
<svg
|
||||
className='icon'
|
||||
viewBox='0 0 16 16'
|
||||
version='1.1'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
width='1em'
|
||||
height='1em'
|
||||
{...props}
|
||||
>
|
||||
<g id='linuxdo_icon' data-name='linuxdo_icon'>
|
||||
<path
|
||||
d='m7.44,0s.09,0,.13,0c.09,0,.19,0,.28,0,.14,0,.29,0,.43,0,.09,0,.18,0,.27,0q.12,0,.25,0t.26.08c.15.03.29.06.44.08,1.97.38,3.78,1.47,4.95,3.11.04.06.09.12.13.18.67.96,1.15,2.11,1.3,3.28q0,.19.09.26c0,.15,0,.29,0,.44,0,.04,0,.09,0,.13,0,.09,0,.19,0,.28,0,.14,0,.29,0,.43,0,.09,0,.18,0,.27,0,.08,0,.17,0,.25q0,.19-.08.26c-.03.15-.06.29-.08.44-.38,1.97-1.47,3.78-3.11,4.95-.06.04-.12.09-.18.13-.96.67-2.11,1.15-3.28,1.3q-.19,0-.26.09c-.15,0-.29,0-.44,0-.04,0-.09,0-.13,0-.09,0-.19,0-.28,0-.14,0-.29,0-.43,0-.09,0-.18,0-.27,0-.08,0-.17,0-.25,0q-.19,0-.26-.08c-.15-.03-.29-.06-.44-.08-1.97-.38-3.78-1.47-4.95-3.11q-.07-.09-.13-.18c-.67-.96-1.15-2.11-1.3-3.28q0-.19-.09-.26c0-.15,0-.29,0-.44,0-.04,0-.09,0-.13,0-.09,0-.19,0-.28,0-.14,0-.29,0-.43,0-.09,0-.18,0-.27,0-.08,0-.17,0-.25q0-.19.08-.26c.03-.15.06-.29.08-.44.38-1.97,1.47-3.78,3.11-4.95.06-.04.12-.09.18-.13C4.42.73,5.57.26,6.74.1,7,.07,7.15,0,7.44,0Z'
|
||||
fill='#EFEFEF'
|
||||
/>
|
||||
<path
|
||||
d='m1.27,11.33h13.45c-.94,1.89-2.51,3.21-4.51,3.88-1.99.59-3.96.37-5.8-.57-1.25-.7-2.67-1.9-3.14-3.3Z'
|
||||
fill='#FEB005'
|
||||
/>
|
||||
<path
|
||||
d='m12.54,1.99c.87.7,1.82,1.59,2.18,2.68H1.27c.87-1.74,2.33-3.13,4.2-3.78,2.44-.79,5-.47,7.07,1.1Z'
|
||||
fill='#1D1D1F'
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
return <Icon svg={<CustomIcon />} />;
|
||||
};
|
||||
|
||||
export default LinuxDoIcon;
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Icon } from '@douyinfe/semi-ui';
|
||||
|
||||
const OIDCIcon = (props) => {
|
||||
function CustomIcon() {
|
||||
return (
|
||||
<svg
|
||||
t='1723135116886'
|
||||
className='icon'
|
||||
viewBox='0 0 1024 1024'
|
||||
version='1.1'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
p-id='10969'
|
||||
width='20'
|
||||
height='20'
|
||||
>
|
||||
<path
|
||||
d='M512 960C265 960 64 759 64 512S265 64 512 64s448 201 448 448-201 448-448 448z m0-882.6c-239.7 0-434.6 195-434.6 434.6s195 434.6 434.6 434.6 434.6-195 434.6-434.6S751.7 77.4 512 77.4z'
|
||||
p-id='10970'
|
||||
fill='#2c2c2c'
|
||||
stroke='#2c2c2c'
|
||||
stroke-width='60'
|
||||
></path>
|
||||
<path
|
||||
d='M197.7 512c0-78.3 31.6-98.8 87.2-98.8 56.2 0 87.2 20.5 87.2 98.8s-31 98.8-87.2 98.8c-55.7 0-87.2-20.5-87.2-98.8z m130.4 0c0-46.8-7.8-64.5-43.2-64.5-35.2 0-42.9 17.7-42.9 64.5 0 47.1 7.8 63.7 42.9 63.7 35.4 0 43.2-16.6 43.2-63.7zM409.7 415.9h42.1V608h-42.1V415.9zM653.9 512c0 74.2-37.1 96.1-93.6 96.1h-65.9V415.9h65.9c56.5 0 93.6 16.1 93.6 96.1z m-43.5 0c0-49.3-17.7-60.6-52.3-60.6h-21.6v120.7h21.6c35.4 0 52.3-13.3 52.3-60.1zM686.5 512c0-74.2 36.3-98.8 92.7-98.8 18.3 0 33.2 2.2 44.8 6.4v36.3c-11.9-4.2-26-6.6-42.1-6.6-34.6 0-49.8 15.5-49.8 62.6 0 50.1 15.2 62.6 49.3 62.6 15.8 0 30.2-2.2 44.8-7.5v36c-11.3 4.7-28.5 8-46.8 8-56.1-0.2-92.9-18.7-92.9-99z'
|
||||
p-id='10971'
|
||||
fill='#2c2c2c'
|
||||
stroke='#2c2c2c'
|
||||
stroke-width='20'
|
||||
></path>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
return <Icon svg={<CustomIcon />} />;
|
||||
};
|
||||
|
||||
export default OIDCIcon;
|
||||
@@ -0,0 +1,246 @@
|
||||
# WeeLogo 组件使用说明
|
||||
|
||||
## 简介
|
||||
|
||||
WeeLogo 是一个基于 SVG 的动画 Logo 组件,提供 4 种不同的视觉风格。这个组件从原始的 HTML logo 文件中提取并转换为 React 组件。
|
||||
|
||||
## 可用风格
|
||||
|
||||
1. **minimalist** - 极简线条风格(默认)
|
||||
- 简洁的线条设计
|
||||
- 柔和的渐变动画
|
||||
- 适合现代简约的界面
|
||||
|
||||
2. **modern** - 现代圆润风格
|
||||
- 圆润的形状设计
|
||||
- 浮动动画效果
|
||||
- 适合友好、亲和的界面
|
||||
|
||||
3. **tech** - 科技未来风格
|
||||
- 科技感强烈的发光效果
|
||||
- 扫描线动画
|
||||
- 适合科技、创新主题
|
||||
|
||||
4. **wave** - 波浪流动风格
|
||||
- 流畅的波浪效果
|
||||
- 液态动画
|
||||
- 适合创意、动态的界面
|
||||
|
||||
## 基本使用
|
||||
|
||||
### 导入组件
|
||||
|
||||
```jsx
|
||||
import WeeLogo from '../../components/common/logo/WeeLogo';
|
||||
```
|
||||
|
||||
### 使用示例
|
||||
|
||||
#### 1. 默认使用(极简风格,32px)
|
||||
|
||||
```jsx
|
||||
<WeeLogo />
|
||||
```
|
||||
|
||||
#### 2. 指定风格
|
||||
|
||||
```jsx
|
||||
<WeeLogo style="modern" />
|
||||
<WeeLogo style="tech" />
|
||||
<WeeLogo style="wave" />
|
||||
```
|
||||
|
||||
#### 3. 自定义大小
|
||||
|
||||
```jsx
|
||||
{
|
||||
/* 64px 高度 */
|
||||
}
|
||||
<WeeLogo size={64} />;
|
||||
|
||||
{
|
||||
/* 48px 高度 */
|
||||
}
|
||||
<WeeLogo style='tech' size={48} />;
|
||||
```
|
||||
|
||||
#### 4. 添加自定义样式
|
||||
|
||||
```jsx
|
||||
<WeeLogo style='modern' size={40} className='my-custom-class' />
|
||||
```
|
||||
|
||||
## 在 HeaderLogo 中使用
|
||||
|
||||
HeaderLogo 组件已经集成了 WeeLogo 支持:
|
||||
|
||||
```jsx
|
||||
<HeaderLogo
|
||||
useSvgLogo={true} // 启用 SVG logo
|
||||
logoStyle='minimalist' // 选择风格
|
||||
// ... 其他 props
|
||||
/>
|
||||
```
|
||||
|
||||
### 完整示例
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import HeaderLogo from './components/layout/headerbar/HeaderLogo';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<HeaderLogo
|
||||
isMobile={false}
|
||||
isConsoleRoute={false}
|
||||
logo='/path/to/fallback-logo.png'
|
||||
logoLoaded={true}
|
||||
isLoading={false}
|
||||
systemName='My System'
|
||||
isSelfUseMode={false}
|
||||
isDemoSiteMode={false}
|
||||
t={(key) => key}
|
||||
useSvgLogo={true} // 使用 SVG logo
|
||||
logoStyle='tech' // 科技风格
|
||||
/>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Props 说明
|
||||
|
||||
### WeeLogo
|
||||
|
||||
| Prop | 类型 | 默认值 | 说明 |
|
||||
| --------- | ------ | ------------ | ------------------------------------------------------- |
|
||||
| style | string | 'minimalist' | Logo 风格: 'minimalist' \| 'modern' \| 'tech' \| 'wave' |
|
||||
| size | number | 32 | Logo 高度(像素),宽度自动按 2:1 比例计算 |
|
||||
| className | string | '' | 自定义 CSS 类名 |
|
||||
|
||||
### HeaderLogo (新增 Props)
|
||||
|
||||
| Prop | 类型 | 默认值 | 说明 |
|
||||
| ---------- | ------- | ------------ | -------------------------- |
|
||||
| useSvgLogo | boolean | false | 是否使用 SVG logo 而非图片 |
|
||||
| logoStyle | string | 'minimalist' | SVG logo 风格 |
|
||||
|
||||
## 样式自定义
|
||||
|
||||
可以通过 CSS 覆盖默认样式:
|
||||
|
||||
```css
|
||||
/* 修改动画速度 */
|
||||
.wee-logo-minimalist .letter {
|
||||
animation-duration: 5s !important;
|
||||
}
|
||||
|
||||
/* 修改颜色(需要修改 SVG gradient) */
|
||||
.my-custom-logo {
|
||||
filter: hue-rotate(45deg);
|
||||
}
|
||||
|
||||
/* 修改大小(也可以用 size prop) */
|
||||
.wee-logo {
|
||||
transform: scale(1.5);
|
||||
}
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **性能**: SVG 动画比图片稍微占用更多 CPU,但在现代浏览器中性能表现良好
|
||||
2. **兼容性**: 所有现代浏览器都支持 SVG 动画,包括移动端
|
||||
3. **尺寸**: Logo 的宽高比固定为 2:1,只需设置高度即可
|
||||
4. **主题**: Logo 动画颜色是硬编码的,如需适配深色/浅色主题,可能需要添加额外的 CSS
|
||||
|
||||
## 迁移指南
|
||||
|
||||
### 从图片 Logo 迁移到 SVG Logo
|
||||
|
||||
**之前:**
|
||||
|
||||
```jsx
|
||||
<HeaderLogo
|
||||
logo='/logo.png'
|
||||
logoLoaded={true}
|
||||
// ...
|
||||
/>
|
||||
```
|
||||
|
||||
**之后:**
|
||||
|
||||
```jsx
|
||||
<HeaderLogo
|
||||
logo='/logo.png' // 保留作为后备
|
||||
logoLoaded={true}
|
||||
useSvgLogo={true} // 启用 SVG
|
||||
logoStyle='minimalist' // 选择风格
|
||||
// ...
|
||||
/>
|
||||
```
|
||||
|
||||
## 文件位置
|
||||
|
||||
- 组件: `web/src/components/common/logo/WeeLogo.jsx`
|
||||
- 样式: `web/src/components/common/logo/WeeLogo.css`
|
||||
- 原始设计: `web/src/components/common/logo/wee-logo-style*.html`
|
||||
|
||||
## 示例页面
|
||||
|
||||
可以创建一个专门的页面来展示所有 Logo 风格:
|
||||
|
||||
```jsx
|
||||
import React from 'react';
|
||||
import WeeLogo from './components/common/logo/WeeLogo';
|
||||
|
||||
function LogoShowcase() {
|
||||
const styles = ['minimalist', 'modern', 'tech', 'wave'];
|
||||
|
||||
return (
|
||||
<div style={{ padding: '40px' }}>
|
||||
<h1>WeeLogo 风格展示</h1>
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(2, 1fr)',
|
||||
gap: '40px',
|
||||
}}
|
||||
>
|
||||
{styles.map((style) => (
|
||||
<div
|
||||
key={style}
|
||||
style={{
|
||||
padding: '20px',
|
||||
background: style === 'tech' ? '#0a0e27' : '#f5f5f5',
|
||||
borderRadius: '10px',
|
||||
textAlign: 'center',
|
||||
}}
|
||||
>
|
||||
<h3>{style}</h3>
|
||||
<WeeLogo style={style} size={48} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default LogoShowcase;
|
||||
```
|
||||
|
||||
## 故障排除
|
||||
|
||||
### Logo 不显示
|
||||
|
||||
- 检查 WeeLogo.css 是否正确导入
|
||||
- 检查浏览器控制台是否有错误
|
||||
- 确认 style prop 的值是有效的
|
||||
|
||||
### 动画不流畅
|
||||
|
||||
- 检查是否同时显示了太多动画元素
|
||||
- 考虑在移动设备上禁用复杂动画
|
||||
|
||||
### 大小不正确
|
||||
|
||||
- 确认 size prop 是数字类型,不是字符串
|
||||
- 检查父容器是否有限制大小的样式
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Icon } from '@douyinfe/semi-ui';
|
||||
|
||||
const WeChatIcon = () => {
|
||||
function CustomIcon() {
|
||||
return (
|
||||
<svg
|
||||
t='1709714447384'
|
||||
className='icon'
|
||||
viewBox='0 0 1024 1024'
|
||||
version='1.1'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
p-id='5091'
|
||||
width='20'
|
||||
height='20'
|
||||
>
|
||||
<path
|
||||
d='M690.1 377.4c5.9 0 11.8 0.2 17.6 0.5-24.4-128.7-158.3-227.1-319.9-227.1C209 150.8 64 271.4 64 420.2c0 81.1 43.6 154.2 111.9 203.6 5.5 3.9 9.1 10.3 9.1 17.6 0 2.4-0.5 4.6-1.1 6.9-5.5 20.3-14.2 52.8-14.6 54.3-0.7 2.6-1.7 5.2-1.7 7.9 0 5.9 4.8 10.8 10.8 10.8 2.3 0 4.2-0.9 6.2-2l70.9-40.9c5.3-3.1 11-5 17.2-5 3.2 0 6.4 0.5 9.5 1.4 33.1 9.5 68.8 14.8 105.7 14.8 6 0 11.9-0.1 17.8-0.4-7.1-21-10.9-43.1-10.9-66 0-135.8 132.2-245.8 295.3-245.8z m-194.3-86.5c23.8 0 43.2 19.3 43.2 43.1s-19.3 43.1-43.2 43.1c-23.8 0-43.2-19.3-43.2-43.1s19.4-43.1 43.2-43.1z m-215.9 86.2c-23.8 0-43.2-19.3-43.2-43.1s19.3-43.1 43.2-43.1 43.2 19.3 43.2 43.1-19.4 43.1-43.2 43.1z'
|
||||
p-id='5092'
|
||||
></path>
|
||||
<path
|
||||
d='M866.7 792.7c56.9-41.2 93.2-102 93.2-169.7 0-124-120.8-224.5-269.9-224.5-149 0-269.9 100.5-269.9 224.5S540.9 847.5 690 847.5c30.8 0 60.6-4.4 88.1-12.3 2.6-0.8 5.2-1.2 7.9-1.2 5.2 0 9.9 1.6 14.3 4.1l59.1 34c1.7 1 3.3 1.7 5.2 1.7 2.4 0 4.7-0.9 6.4-2.6 1.7-1.7 2.6-4 2.6-6.4 0-2.2-0.9-4.4-1.4-6.6-0.3-1.2-7.6-28.3-12.2-45.3-0.5-1.9-0.9-3.8-0.9-5.7 0.1-5.9 3.1-11.2 7.6-14.5zM600.2 587.2c-19.9 0-36-16.1-36-35.9 0-19.8 16.1-35.9 36-35.9s36 16.1 36 35.9c0 19.8-16.2 35.9-36 35.9z m179.9 0c-19.9 0-36-16.1-36-35.9 0-19.8 16.1-35.9 36-35.9s36 16.1 36 35.9c-0.1 19.8-16.2 35.9-36 35.9z'
|
||||
p-id='5093'
|
||||
></path>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Icon svg={<CustomIcon />} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default WeChatIcon;
|
||||
@@ -0,0 +1,144 @@
|
||||
/* Wee Logo Styles */
|
||||
|
||||
.wee-logo {
|
||||
display: inline-block;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
/* Minimalist Style */
|
||||
.wee-logo-minimalist .letter {
|
||||
animation: pulse 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.wee-logo-minimalist .w1 {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
||||
.wee-logo-minimalist .e1 {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
|
||||
.wee-logo-minimalist .e2 {
|
||||
animation-delay: 0.6s;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
/* Modern Style */
|
||||
.wee-logo-modern .w-letter,
|
||||
.wee-logo-modern .e1-letter,
|
||||
.wee-logo-modern .e2-letter {
|
||||
animation: float 2s ease-in-out infinite;
|
||||
transform-origin: center;
|
||||
}
|
||||
|
||||
.wee-logo-modern .e1-letter {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
|
||||
.wee-logo-modern .e2-letter {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0px);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
}
|
||||
|
||||
/* Tech Style */
|
||||
.wee-logo-tech .letter-group {
|
||||
animation: glow 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.wee-logo-tech .w-tech {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
||||
.wee-logo-tech .e1-tech {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
|
||||
.wee-logo-tech .e2-tech {
|
||||
animation-delay: 0.6s;
|
||||
}
|
||||
|
||||
.wee-logo-tech .scan-line {
|
||||
animation: scan 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes glow {
|
||||
0%,
|
||||
100% {
|
||||
filter: drop-shadow(0 0 2px rgba(74, 144, 226, 0.4))
|
||||
drop-shadow(0 0 4px rgba(74, 144, 226, 0.3));
|
||||
}
|
||||
50% {
|
||||
filter: drop-shadow(0 0 4px rgba(74, 144, 226, 0.6))
|
||||
drop-shadow(0 0 8px rgba(74, 144, 226, 0.4));
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes scan {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
transform: translateX(500%);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Wave Style */
|
||||
.wee-logo-wave .liquid-bg {
|
||||
animation: liquidMove 8s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.wee-logo-wave .flow-w,
|
||||
.wee-logo-wave .flow-e1,
|
||||
.wee-logo-wave .flow-e2 {
|
||||
animation: flowText 2s ease-in-out infinite alternate;
|
||||
}
|
||||
|
||||
.wee-logo-wave .flow-e1 {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
|
||||
.wee-logo-wave .flow-e2 {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
|
||||
@keyframes liquidMove {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-2px) scale(1.01);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes flowText {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(2px);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,502 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import './WeeLogo.css';
|
||||
|
||||
/**
|
||||
* Wee Logo Component
|
||||
* @param {string} style - Logo style: 'minimalist' | 'modern' | 'tech' | 'wave' (default: 'minimalist')
|
||||
* @param {number} size - Logo size in pixels (default: 32)
|
||||
* @param {string} className - Additional CSS classes
|
||||
*/
|
||||
const WeeLogo = ({ style = 'minimalist', size = 32, className = '' }) => {
|
||||
const aspectRatio = 2; // width/height ratio
|
||||
const width = size * aspectRatio;
|
||||
const height = size;
|
||||
|
||||
// Style 1: Minimalist Lines
|
||||
const MinimalistLogo = () => (
|
||||
<svg
|
||||
viewBox='0 0 400 200'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
width={width}
|
||||
height={height}
|
||||
className={`wee-logo wee-logo-minimalist ${className}`}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='blueGradient' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' style={{ stopColor: '#4A90E2', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#4A90E2;#2E5C8A;#4A90E2'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='100%' style={{ stopColor: '#1E3A5F', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#1E3A5F;#4A90E2;#1E3A5F'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
{/* W */}
|
||||
<path
|
||||
className='letter w1'
|
||||
d='M 20 60 L 40 140 L 60 100 L 80 140 L 100 60'
|
||||
strokeWidth='8'
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
fill='none'
|
||||
stroke='url(#blueGradient)'
|
||||
/>
|
||||
|
||||
{/* E */}
|
||||
<path
|
||||
className='letter e1'
|
||||
d='M 150 60 L 150 140 M 150 60 L 230 60 M 150 100 L 210 100 M 150 140 L 230 140'
|
||||
strokeWidth='8'
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
fill='none'
|
||||
stroke='url(#blueGradient)'
|
||||
/>
|
||||
|
||||
{/* E */}
|
||||
<path
|
||||
className='letter e2'
|
||||
d='M 270 60 L 270 140 M 270 60 L 350 60 M 270 100 L 330 100 M 270 140 L 350 140'
|
||||
strokeWidth='8'
|
||||
strokeLinecap='round'
|
||||
strokeLinejoin='round'
|
||||
fill='none'
|
||||
stroke='url(#blueGradient)'
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Style 2: Modern Rounded
|
||||
const ModernLogo = () => (
|
||||
<svg
|
||||
viewBox='0 0 420 200'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
width={width}
|
||||
height={height}
|
||||
className={`wee-logo wee-logo-modern ${className}`}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='blueGradient2' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' style={{ stopColor: '#5DADE2', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#5DADE2;#3498DB;#2E86C1;#5DADE2'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='50%' style={{ stopColor: '#3498DB', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#3498DB;#2E86C1;#5DADE2;#3498DB'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='100%' style={{ stopColor: '#2874A6', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#2874A6;#5DADE2;#3498DB;#2874A6'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
{/* W */}
|
||||
<g className='w-letter'>
|
||||
<path
|
||||
className='letter'
|
||||
fill='url(#blueGradient2)'
|
||||
d='M 10,50 Q 20,40 30,50 L 35,120 Q 37,130 45,130 Q 53,130 55,120 L 60,80 Q 62,70 70,70 Q 78,70 80,80 L 85,120 Q 87,130 95,130 Q 103,130 105,120 L 110,50 Q 120,40 130,50 L 135,60 L 115,130 Q 110,145 95,145 Q 85,145 80,135 L 70,105 L 60,135 Q 55,145 45,145 Q 30,145 25,130 L 5,60 Z'
|
||||
/>
|
||||
</g>
|
||||
|
||||
{/* First E */}
|
||||
<g className='e1-letter'>
|
||||
<path
|
||||
className='letter'
|
||||
fill='url(#blueGradient2)'
|
||||
d='M 170,50 Q 180,40 200,45 L 240,50 Q 250,52 248,62 Q 246,72 236,70 L 200,65 L 200,90 L 225,92 Q 235,93 233,103 Q 231,113 221,112 L 200,110 L 200,130 L 240,135 Q 250,136 248,146 Q 246,156 236,155 L 200,150 Q 180,148 170,138 Z'
|
||||
/>
|
||||
</g>
|
||||
|
||||
{/* Second E */}
|
||||
<g className='e2-letter'>
|
||||
<path
|
||||
className='letter'
|
||||
fill='url(#blueGradient2)'
|
||||
d='M 280,50 Q 290,40 310,45 L 350,50 Q 360,52 358,62 Q 356,72 346,70 L 310,65 L 310,90 L 335,92 Q 345,93 343,103 Q 341,113 331,112 L 310,110 L 310,130 L 350,135 Q 360,136 358,146 Q 356,156 346,155 L 310,150 Q 290,148 280,138 Z'
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Style 3: Tech Futuristic
|
||||
const TechLogo = () => (
|
||||
<svg
|
||||
viewBox='0 0 400 200'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
width={width}
|
||||
height={height}
|
||||
className={`wee-logo wee-logo-tech ${className}`}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='techGradient' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' style={{ stopColor: '#00D9FF', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#00D9FF;#0099FF;#0066FF;#00D9FF'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='100%' style={{ stopColor: '#0066FF', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#0066FF;#00D9FF;#0099FF;#0066FF'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
|
||||
<linearGradient id='glowGradient' x1='0%' y1='0%' x2='100%' y2='0%'>
|
||||
<stop
|
||||
offset='0%'
|
||||
style={{ stopColor: '#4A90E2', stopOpacity: 0.5 }}
|
||||
/>
|
||||
<stop offset='50%' style={{ stopColor: '#00D9FF', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='offset'
|
||||
values='0;1;0'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop
|
||||
offset='100%'
|
||||
style={{ stopColor: '#4A90E2', stopOpacity: 0.5 }}
|
||||
/>
|
||||
</linearGradient>
|
||||
|
||||
<filter id='glow'>
|
||||
<feGaussianBlur stdDeviation='3' result='coloredBlur' />
|
||||
<feMerge>
|
||||
<feMergeNode in='coloredBlur' />
|
||||
<feMergeNode in='SourceGraphic' />
|
||||
</feMerge>
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
{/* Scan line effect */}
|
||||
<rect
|
||||
className='scan-line'
|
||||
x='0'
|
||||
y='0'
|
||||
width='20'
|
||||
height='200'
|
||||
fill='url(#glowGradient)'
|
||||
opacity='0.3'
|
||||
/>
|
||||
|
||||
{/* W */}
|
||||
<g className='letter-group w-tech'>
|
||||
<text
|
||||
className='letter'
|
||||
x='10'
|
||||
y='140'
|
||||
fontFamily="'Arial Black', sans-serif"
|
||||
fontSize='120'
|
||||
fontWeight='900'
|
||||
fill='url(#techGradient)'
|
||||
stroke='url(#glowGradient)'
|
||||
strokeWidth='2'
|
||||
filter='url(#glow)'
|
||||
>
|
||||
W
|
||||
</text>
|
||||
</g>
|
||||
|
||||
{/* E */}
|
||||
<g className='letter-group e1-tech'>
|
||||
<text
|
||||
className='letter'
|
||||
x='140'
|
||||
y='140'
|
||||
fontFamily="'Arial Black', sans-serif"
|
||||
fontSize='120'
|
||||
fontWeight='900'
|
||||
fill='url(#techGradient)'
|
||||
stroke='url(#glowGradient)'
|
||||
strokeWidth='2'
|
||||
filter='url(#glow)'
|
||||
>
|
||||
E
|
||||
</text>
|
||||
</g>
|
||||
|
||||
{/* E */}
|
||||
<g className='letter-group e2-tech'>
|
||||
<text
|
||||
className='letter'
|
||||
x='260'
|
||||
y='140'
|
||||
fontFamily="'Arial Black', sans-serif"
|
||||
fontSize='120'
|
||||
fontWeight='900'
|
||||
fill='url(#techGradient)'
|
||||
stroke='url(#glowGradient)'
|
||||
strokeWidth='2'
|
||||
filter='url(#glow)'
|
||||
>
|
||||
E
|
||||
</text>
|
||||
</g>
|
||||
|
||||
{/* Grid lines for tech effect */}
|
||||
<line
|
||||
x1='0'
|
||||
y1='180'
|
||||
x2='400'
|
||||
y2='180'
|
||||
stroke='#0099FF'
|
||||
strokeWidth='0.5'
|
||||
opacity='0.3'
|
||||
>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.3;0.6;0.3'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</line>
|
||||
<line
|
||||
x1='0'
|
||||
y1='190'
|
||||
x2='400'
|
||||
y2='190'
|
||||
stroke='#00D9FF'
|
||||
strokeWidth='0.5'
|
||||
opacity='0.2'
|
||||
>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.2;0.5;0.2'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</line>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Style 4: Wave Flow
|
||||
const WaveLogo = () => (
|
||||
<svg
|
||||
viewBox='0 0 500 220'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
width={width}
|
||||
height={height}
|
||||
className={`wee-logo wee-logo-wave ${className}`}
|
||||
>
|
||||
<defs>
|
||||
<linearGradient id='waveGradient' x1='0%' y1='0%' x2='100%' y2='100%'>
|
||||
<stop offset='0%' style={{ stopColor: '#2193b0', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#2193b0;#6dd5ed;#4facfe;#2193b0'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='50%' style={{ stopColor: '#4facfe', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#4facfe;#00f2fe;#2193b0;#4facfe'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
<stop offset='100%' style={{ stopColor: '#00f2fe', stopOpacity: 1 }}>
|
||||
<animate
|
||||
attributeName='stop-color'
|
||||
values='#00f2fe;#4facfe;#6dd5ed;#00f2fe'
|
||||
dur='4s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
|
||||
<filter id='liquid'>
|
||||
<feTurbulence
|
||||
type='fractalNoise'
|
||||
baseFrequency='0.01'
|
||||
numOctaves='3'
|
||||
result='turbulence'
|
||||
>
|
||||
<animate
|
||||
attributeName='baseFrequency'
|
||||
values='0.01;0.02;0.01'
|
||||
dur='10s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</feTurbulence>
|
||||
<feDisplacementMap
|
||||
in='SourceGraphic'
|
||||
in2='turbulence'
|
||||
scale='5'
|
||||
xChannelSelector='R'
|
||||
yChannelSelector='G'
|
||||
/>
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
{/* Background liquid shapes */}
|
||||
<ellipse
|
||||
className='liquid-bg'
|
||||
cx='100'
|
||||
cy='150'
|
||||
rx='80'
|
||||
ry='60'
|
||||
fill='url(#waveGradient)'
|
||||
opacity='0.1'
|
||||
filter='url(#liquid)'
|
||||
/>
|
||||
<ellipse
|
||||
className='liquid-bg'
|
||||
cx='250'
|
||||
cy='140'
|
||||
rx='90'
|
||||
ry='70'
|
||||
fill='url(#waveGradient)'
|
||||
opacity='0.1'
|
||||
filter='url(#liquid)'
|
||||
style={{ animationDelay: '1s' }}
|
||||
/>
|
||||
<ellipse
|
||||
className='liquid-bg'
|
||||
cx='400'
|
||||
cy='145'
|
||||
rx='85'
|
||||
ry='65'
|
||||
fill='url(#waveGradient)'
|
||||
opacity='0.1'
|
||||
filter='url(#liquid)'
|
||||
style={{ animationDelay: '2s' }}
|
||||
/>
|
||||
|
||||
{/* Wave path for baseline */}
|
||||
<path id='wavePath' d='M 0,140 Q 125,120 250,140 T 500,140' fill='none' />
|
||||
|
||||
{/* Text on wave path */}
|
||||
<text
|
||||
className='wave-text'
|
||||
fontSize='120'
|
||||
fontWeight='900'
|
||||
fill='url(#waveGradient)'
|
||||
fontFamily="'Arial Rounded MT Bold', 'Helvetica Rounded', Arial, sans-serif"
|
||||
>
|
||||
<textPath href='#wavePath' startOffset='8%'>
|
||||
<tspan className='flow-w'>w</tspan>
|
||||
<tspan className='flow-e1'>e</tspan>
|
||||
<tspan className='flow-e2'>e</tspan>
|
||||
<animate
|
||||
attributeName='startOffset'
|
||||
values='8%;10%;8%'
|
||||
dur='3s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</textPath>
|
||||
</text>
|
||||
|
||||
{/* Decorative dots */}
|
||||
<circle cx='50' cy='100' r='3' fill='#4facfe' opacity='0.6'>
|
||||
<animate
|
||||
attributeName='cy'
|
||||
values='100;95;100'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='450' cy='110' r='3' fill='#2193b0' opacity='0.6'>
|
||||
<animate
|
||||
attributeName='cy'
|
||||
values='110;105;110'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='2.5s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
<circle cx='250' cy='95' r='3' fill='#00f2fe' opacity='0.6'>
|
||||
<animate
|
||||
attributeName='cy'
|
||||
values='95;90;95'
|
||||
dur='2.2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
<animate
|
||||
attributeName='opacity'
|
||||
values='0.6;1;0.6'
|
||||
dur='2.2s'
|
||||
repeatCount='indefinite'
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
);
|
||||
|
||||
// Select logo style
|
||||
const logos = {
|
||||
minimalist: MinimalistLogo,
|
||||
modern: ModernLogo,
|
||||
tech: TechLogo,
|
||||
wave: WaveLogo,
|
||||
};
|
||||
|
||||
const LogoComponent = logos[style] || MinimalistLogo;
|
||||
|
||||
return <LogoComponent />;
|
||||
};
|
||||
|
||||
export default WeeLogo;
|
||||
@@ -0,0 +1,160 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Wee Logo - Style 1: Minimalist Lines</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo-container {
|
||||
background: white;
|
||||
padding: 60px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 400px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.letter {
|
||||
fill: url(#blueGradient);
|
||||
stroke-width: 0;
|
||||
}
|
||||
|
||||
.w1 {
|
||||
animation: slideIn 1s ease-out forwards;
|
||||
}
|
||||
.e1 {
|
||||
animation: slideIn 1s ease-out 0.2s forwards;
|
||||
}
|
||||
.e2 {
|
||||
animation: slideIn 1s ease-out 0.4s forwards;
|
||||
}
|
||||
|
||||
@keyframes slideIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-20px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.letter {
|
||||
animation: pulse 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.w1 {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
.e1 {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
.e2 {
|
||||
animation-delay: 0.6s;
|
||||
}
|
||||
|
||||
@keyframes pulse {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #333;
|
||||
margin-top: 20px;
|
||||
font-weight: 300;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="logo-container">
|
||||
<svg viewBox="0 0 400 200" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="blueGradient"
|
||||
x1="0%"
|
||||
y1="0%"
|
||||
x2="100%"
|
||||
y2="100%"
|
||||
>
|
||||
<stop offset="0%" style="stop-color: #4a90e2; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#4A90E2;#2E5C8A;#4A90E2"
|
||||
dur="4s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
<stop offset="100%" style="stop-color: #1e3a5f; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#1E3A5F;#4A90E2;#1E3A5F"
|
||||
dur="4s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<!-- W -->
|
||||
<path
|
||||
class="letter w1"
|
||||
d="M 20 60 L 40 140 L 60 100 L 80 140 L 100 60"
|
||||
stroke-width="8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
fill="none"
|
||||
stroke="url(#blueGradient)"
|
||||
/>
|
||||
|
||||
<!-- E -->
|
||||
<path
|
||||
class="letter e1"
|
||||
d="M 150 60 L 150 140 M 150 60 L 230 60 M 150 100 L 210 100 M 150 140 L 230 140"
|
||||
stroke-width="8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
fill="none"
|
||||
stroke="url(#blueGradient)"
|
||||
/>
|
||||
|
||||
<!-- E -->
|
||||
<path
|
||||
class="letter e2"
|
||||
d="M 270 60 L 270 140 M 270 60 L 350 60 M 270 100 L 330 100 M 270 140 L 350 140"
|
||||
stroke-width="8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
fill="none"
|
||||
stroke="url(#blueGradient)"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<h2>Style 1: Minimalist Lines</h2>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,149 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Wee Logo - Style 2: Modern Rounded</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background: #f5f5f5;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo-container {
|
||||
background: white;
|
||||
padding: 60px;
|
||||
border-radius: 20px;
|
||||
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 400px;
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.letter {
|
||||
fill: url(#blueGradient2);
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0px);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes rotate {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.w-letter {
|
||||
animation: float 2s ease-in-out infinite;
|
||||
transform-origin: center;
|
||||
}
|
||||
|
||||
.e1-letter {
|
||||
animation: float 2s ease-in-out infinite;
|
||||
animation-delay: 0.2s;
|
||||
transform-origin: center;
|
||||
}
|
||||
|
||||
.e2-letter {
|
||||
animation: float 2s ease-in-out infinite;
|
||||
animation-delay: 0.4s;
|
||||
transform-origin: center;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #333;
|
||||
margin-top: 20px;
|
||||
font-weight: 300;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="logo-container">
|
||||
<svg viewBox="0 0 420 200" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="blueGradient2"
|
||||
x1="0%"
|
||||
y1="0%"
|
||||
x2="100%"
|
||||
y2="100%"
|
||||
>
|
||||
<stop offset="0%" style="stop-color: #5dade2; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#5DADE2;#3498DB;#2E86C1;#5DADE2"
|
||||
dur="3s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
<stop offset="50%" style="stop-color: #3498db; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#3498DB;#2E86C1;#5DADE2;#3498DB"
|
||||
dur="3s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
<stop offset="100%" style="stop-color: #2874a6; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#2874A6;#5DADE2;#3498DB;#2874A6"
|
||||
dur="3s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
|
||||
<!-- W -->
|
||||
<g class="w-letter">
|
||||
<path
|
||||
class="letter"
|
||||
d="M 10,50 Q 20,40 30,50 L 35,120 Q 37,130 45,130 Q 53,130 55,120 L 60,80 Q 62,70 70,70 Q 78,70 80,80 L 85,120 Q 87,130 95,130 Q 103,130 105,120 L 110,50 Q 120,40 130,50 L 135,60 L 115,130 Q 110,145 95,145 Q 85,145 80,135 L 70,105 L 60,135 Q 55,145 45,145 Q 30,145 25,130 L 5,60 Z"
|
||||
/>
|
||||
</g>
|
||||
|
||||
<!-- First E -->
|
||||
<g class="e1-letter">
|
||||
<path
|
||||
class="letter"
|
||||
d="M 170,50 Q 180,40 200,45 L 240,50 Q 250,52 248,62 Q 246,72 236,70 L 200,65 L 200,90 L 225,92 Q 235,93 233,103 Q 231,113 221,112 L 200,110 L 200,130 L 240,135 Q 250,136 248,146 Q 246,156 236,155 L 200,150 Q 180,148 170,138 Z"
|
||||
/>
|
||||
</g>
|
||||
|
||||
<!-- Second E -->
|
||||
<g class="e2-letter">
|
||||
<path
|
||||
class="letter"
|
||||
d="M 280,50 Q 290,40 310,45 L 350,50 Q 360,52 358,62 Q 356,72 346,70 L 310,65 L 310,90 L 335,92 Q 345,93 343,103 Q 341,113 331,112 L 310,110 L 310,130 L 350,135 Q 360,136 358,146 Q 356,156 346,155 L 310,150 Q 290,148 280,138 Z"
|
||||
/>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
<h2>Style 2: Modern Rounded</h2>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,293 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Wee Logo - Style 3: Tech Futuristic</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background: #0a0e27;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo-container {
|
||||
background: linear-gradient(135deg, #1a1f3a 0%, #0f1229 100%);
|
||||
padding: 60px;
|
||||
border-radius: 20px;
|
||||
box-shadow:
|
||||
0 10px 40px rgba(0, 0, 0, 0.5),
|
||||
0 0 60px rgba(74, 144, 226, 0.3);
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 400px;
|
||||
height: 200px;
|
||||
filter: drop-shadow(0 0 20px rgba(74, 144, 226, 0.5));
|
||||
}
|
||||
|
||||
.letter {
|
||||
fill: url(#techGradient);
|
||||
stroke: url(#glowGradient);
|
||||
stroke-width: 2;
|
||||
}
|
||||
|
||||
@keyframes glow {
|
||||
0%,
|
||||
100% {
|
||||
filter: drop-shadow(0 0 5px rgba(74, 144, 226, 0.8))
|
||||
drop-shadow(0 0 10px rgba(74, 144, 226, 0.6))
|
||||
drop-shadow(0 0 15px rgba(74, 144, 226, 0.4));
|
||||
}
|
||||
50% {
|
||||
filter: drop-shadow(0 0 10px rgba(74, 144, 226, 1))
|
||||
drop-shadow(0 0 20px rgba(74, 144, 226, 0.8))
|
||||
drop-shadow(0 0 30px rgba(74, 144, 226, 0.6));
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes scan {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
transform: translateX(500%);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.scan-line {
|
||||
animation: scan 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.letter-group {
|
||||
animation: glow 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.w-tech {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
.e1-tech {
|
||||
animation-delay: 0.3s;
|
||||
}
|
||||
.e2-tech {
|
||||
animation-delay: 0.6s;
|
||||
}
|
||||
|
||||
@keyframes flicker {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.95;
|
||||
}
|
||||
75% {
|
||||
opacity: 0.98;
|
||||
}
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #5dade2;
|
||||
margin-top: 20px;
|
||||
font-weight: 300;
|
||||
text-shadow: 0 0 10px rgba(93, 173, 226, 0.5);
|
||||
}
|
||||
|
||||
.particles {
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.particle {
|
||||
position: absolute;
|
||||
width: 2px;
|
||||
height: 2px;
|
||||
background: #5dade2;
|
||||
border-radius: 50%;
|
||||
animation: particle-float 4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes particle-float {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0) translateX(0);
|
||||
opacity: 0;
|
||||
}
|
||||
50% {
|
||||
opacity: 1;
|
||||
}
|
||||
100% {
|
||||
transform: translateY(-100px) translateX(20px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="logo-container">
|
||||
<svg viewBox="0 0 400 200" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="techGradient"
|
||||
x1="0%"
|
||||
y1="0%"
|
||||
x2="100%"
|
||||
y2="100%"
|
||||
>
|
||||
<stop offset="0%" style="stop-color: #00d9ff; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#00D9FF;#0099FF;#0066FF;#00D9FF"
|
||||
dur="2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
<stop offset="100%" style="stop-color: #0066ff; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#0066FF;#00D9FF;#0099FF;#0066FF"
|
||||
dur="2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
|
||||
<linearGradient id="glowGradient" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop
|
||||
offset="0%"
|
||||
style="stop-color: #4a90e2; stop-opacity: 0.5"
|
||||
/>
|
||||
<stop offset="50%" style="stop-color: #00d9ff; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="offset"
|
||||
values="0;1;0"
|
||||
dur="2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
<stop
|
||||
offset="100%"
|
||||
style="stop-color: #4a90e2; stop-opacity: 0.5"
|
||||
/>
|
||||
</linearGradient>
|
||||
|
||||
<filter id="glow">
|
||||
<feGaussianBlur stdDeviation="3" result="coloredBlur" />
|
||||
<feMerge>
|
||||
<feMergeNode in="coloredBlur" />
|
||||
<feMergeNode in="SourceGraphic" />
|
||||
</feMerge>
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
<!-- Scan line effect -->
|
||||
<rect
|
||||
class="scan-line"
|
||||
x="0"
|
||||
y="0"
|
||||
width="20"
|
||||
height="200"
|
||||
fill="url(#glowGradient)"
|
||||
opacity="0.3"
|
||||
/>
|
||||
|
||||
<!-- W -->
|
||||
<g class="letter-group w-tech">
|
||||
<text
|
||||
class="letter"
|
||||
x="10"
|
||||
y="140"
|
||||
font-family="'Arial Black', sans-serif"
|
||||
font-size="120"
|
||||
font-weight="900"
|
||||
filter="url(#glow)"
|
||||
>
|
||||
W
|
||||
</text>
|
||||
</g>
|
||||
|
||||
<!-- E -->
|
||||
<g class="letter-group e1-tech">
|
||||
<text
|
||||
class="letter"
|
||||
x="140"
|
||||
y="140"
|
||||
font-family="'Arial Black', sans-serif"
|
||||
font-size="120"
|
||||
font-weight="900"
|
||||
filter="url(#glow)"
|
||||
>
|
||||
E
|
||||
</text>
|
||||
</g>
|
||||
|
||||
<!-- E -->
|
||||
<g class="letter-group e2-tech">
|
||||
<text
|
||||
class="letter"
|
||||
x="260"
|
||||
y="140"
|
||||
font-family="'Arial Black', sans-serif"
|
||||
font-size="120"
|
||||
font-weight="900"
|
||||
filter="url(#glow)"
|
||||
>
|
||||
E
|
||||
</text>
|
||||
</g>
|
||||
|
||||
<!-- Grid lines for tech effect -->
|
||||
<line
|
||||
x1="0"
|
||||
y1="180"
|
||||
x2="400"
|
||||
y2="180"
|
||||
stroke="#0099FF"
|
||||
stroke-width="0.5"
|
||||
opacity="0.3"
|
||||
>
|
||||
<animate
|
||||
attributeName="opacity"
|
||||
values="0.3;0.6;0.3"
|
||||
dur="2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</line>
|
||||
<line
|
||||
x1="0"
|
||||
y1="190"
|
||||
x2="400"
|
||||
y2="190"
|
||||
stroke="#00D9FF"
|
||||
stroke-width="0.5"
|
||||
opacity="0.2"
|
||||
>
|
||||
<animate
|
||||
attributeName="opacity"
|
||||
values="0.2;0.5;0.2"
|
||||
dur="2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</line>
|
||||
</svg>
|
||||
</div>
|
||||
<h2>Style 3: Tech Futuristic</h2>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,293 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Wee Logo - Style 4: Wave Flow</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
||||
}
|
||||
|
||||
.container {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo-container {
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
padding: 60px;
|
||||
border-radius: 30px;
|
||||
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
svg {
|
||||
width: 500px;
|
||||
height: 200px;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.wave-text {
|
||||
fill: url(#waveGradient);
|
||||
font-family:
|
||||
'Arial Rounded MT Bold', 'Helvetica Rounded', Arial, sans-serif;
|
||||
font-size: 140px;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
@keyframes wave {
|
||||
0%,
|
||||
100% {
|
||||
d: path('M0,100 Q25,80 50,100 T100,100');
|
||||
}
|
||||
50% {
|
||||
d: path('M0,100 Q25,120 50,100 T100,100');
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes morphW {
|
||||
0%,
|
||||
100% {
|
||||
d: path(
|
||||
'M 20,60 L 35,130 Q 37,140 45,140 Q 53,140 55,130 L 65,85 L 75,130 Q 77,140 85,140 Q 93,140 95,130 L 110,60'
|
||||
);
|
||||
}
|
||||
50% {
|
||||
d: path(
|
||||
'M 20,65 L 35,125 Q 37,135 45,135 Q 53,135 55,125 L 65,90 L 75,125 Q 77,135 85,135 Q 93,135 95,125 L 110,65'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
.liquid-bg {
|
||||
animation: liquidMove 8s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes liquidMove {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
50% {
|
||||
transform: translateY(-5px) scale(1.02);
|
||||
}
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #fff;
|
||||
margin-top: 20px;
|
||||
font-weight: 300;
|
||||
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
@keyframes flowText {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(5px);
|
||||
}
|
||||
}
|
||||
|
||||
.flow-w {
|
||||
animation: flowText 2s ease-in-out infinite alternate;
|
||||
}
|
||||
|
||||
.flow-e1 {
|
||||
animation: flowText 2s ease-in-out infinite alternate;
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
|
||||
.flow-e2 {
|
||||
animation: flowText 2s ease-in-out infinite alternate;
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="logo-container">
|
||||
<svg viewBox="0 0 500 220" xmlns="http://www.w3.org/2000/svg">
|
||||
<defs>
|
||||
<linearGradient
|
||||
id="waveGradient"
|
||||
x1="0%"
|
||||
y1="0%"
|
||||
x2="100%"
|
||||
y2="100%"
|
||||
>
|
||||
<stop offset="0%" style="stop-color: #2193b0; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#2193b0;#6dd5ed;#4facfe;#2193b0"
|
||||
dur="4s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
<stop offset="50%" style="stop-color: #4facfe; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#4facfe;#00f2fe;#2193b0;#4facfe"
|
||||
dur="4s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
<stop offset="100%" style="stop-color: #00f2fe; stop-opacity: 1">
|
||||
<animate
|
||||
attributeName="stop-color"
|
||||
values="#00f2fe;#4facfe;#6dd5ed;#00f2fe"
|
||||
dur="4s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</stop>
|
||||
</linearGradient>
|
||||
|
||||
<filter id="wave-blur">
|
||||
<feGaussianBlur in="SourceGraphic" stdDeviation="1" />
|
||||
</filter>
|
||||
|
||||
<filter id="liquid">
|
||||
<feTurbulence
|
||||
type="fractalNoise"
|
||||
baseFrequency="0.01"
|
||||
numOctaves="3"
|
||||
result="turbulence"
|
||||
>
|
||||
<animate
|
||||
attributeName="baseFrequency"
|
||||
values="0.01;0.02;0.01"
|
||||
dur="10s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</feTurbulence>
|
||||
<feDisplacementMap
|
||||
in="SourceGraphic"
|
||||
in2="turbulence"
|
||||
scale="5"
|
||||
xChannelSelector="R"
|
||||
yChannelSelector="G"
|
||||
/>
|
||||
</filter>
|
||||
</defs>
|
||||
|
||||
<!-- Background liquid shapes -->
|
||||
<ellipse
|
||||
class="liquid-bg"
|
||||
cx="100"
|
||||
cy="150"
|
||||
rx="80"
|
||||
ry="60"
|
||||
fill="url(#waveGradient)"
|
||||
opacity="0.1"
|
||||
filter="url(#liquid)"
|
||||
/>
|
||||
<ellipse
|
||||
class="liquid-bg"
|
||||
cx="250"
|
||||
cy="140"
|
||||
rx="90"
|
||||
ry="70"
|
||||
fill="url(#waveGradient)"
|
||||
opacity="0.1"
|
||||
filter="url(#liquid)"
|
||||
style="animation-delay: 1s"
|
||||
/>
|
||||
<ellipse
|
||||
class="liquid-bg"
|
||||
cx="400"
|
||||
cy="145"
|
||||
rx="85"
|
||||
ry="65"
|
||||
fill="url(#waveGradient)"
|
||||
opacity="0.1"
|
||||
filter="url(#liquid)"
|
||||
style="animation-delay: 2s"
|
||||
/>
|
||||
|
||||
<!-- Wave path for baseline -->
|
||||
<path
|
||||
id="wavePath"
|
||||
d="M 0,140 Q 125,120 250,140 T 500,140"
|
||||
fill="none"
|
||||
/>
|
||||
|
||||
<!-- Text on wave path -->
|
||||
<text class="wave-text" font-size="120" font-weight="900">
|
||||
<textPath href="#wavePath" startOffset="8%">
|
||||
<tspan class="flow-w">w</tspan>
|
||||
<tspan class="flow-e1">e</tspan>
|
||||
<tspan class="flow-e2">e</tspan>
|
||||
<animate
|
||||
attributeName="startOffset"
|
||||
values="8%;10%;8%"
|
||||
dur="3s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</textPath>
|
||||
</text>
|
||||
|
||||
<!-- Animated wave path -->
|
||||
<animateTransform
|
||||
attributeName="transform"
|
||||
type="translate"
|
||||
values="0,0; 0,-3; 0,0"
|
||||
dur="3s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
|
||||
<!-- Decorative dots -->
|
||||
<circle cx="50" cy="100" r="3" fill="#4facfe" opacity="0.6">
|
||||
<animate
|
||||
attributeName="cy"
|
||||
values="100;95;100"
|
||||
dur="2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
<animate
|
||||
attributeName="opacity"
|
||||
values="0.6;1;0.6"
|
||||
dur="2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</circle>
|
||||
<circle cx="450" cy="110" r="3" fill="#2193b0" opacity="0.6">
|
||||
<animate
|
||||
attributeName="cy"
|
||||
values="110;105;110"
|
||||
dur="2.5s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
<animate
|
||||
attributeName="opacity"
|
||||
values="0.6;1;0.6"
|
||||
dur="2.5s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</circle>
|
||||
<circle cx="250" cy="95" r="3" fill="#00f2fe" opacity="0.6">
|
||||
<animate
|
||||
attributeName="cy"
|
||||
values="95;90;95"
|
||||
dur="2.2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
<animate
|
||||
attributeName="opacity"
|
||||
values="0.6;1;0.6"
|
||||
dur="2.2s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</circle>
|
||||
</svg>
|
||||
</div>
|
||||
<h2>Style 4: Wave Flow</h2>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,770 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import ReactMarkdown from 'react-markdown';
|
||||
import 'katex/dist/katex.min.css';
|
||||
import 'highlight.js/styles/github.css';
|
||||
import './markdown.css';
|
||||
import RemarkMath from 'remark-math';
|
||||
import RemarkBreaks from 'remark-breaks';
|
||||
import RehypeKatex from 'rehype-katex';
|
||||
import RemarkGfm from 'remark-gfm';
|
||||
import RehypeHighlight from 'rehype-highlight';
|
||||
import {
|
||||
useRef,
|
||||
useState,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useId,
|
||||
} from 'react';
|
||||
import React from 'react';
|
||||
import { useDebouncedCallback } from 'use-debounce';
|
||||
import clsx from 'clsx';
|
||||
import { Button, Tooltip, Toast } from '@douyinfe/semi-ui';
|
||||
import { copy, rehypeSplitWordsIntoSpans } from '../../../helpers';
|
||||
import { IconCopy } from '@douyinfe/semi-icons';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import ImagePreviewModal from '../../playground/ImagePreviewModal';
|
||||
|
||||
// 懒加载 mermaid 库 - 只在需要时才加载这个大型依赖
|
||||
let mermaidInstance = null;
|
||||
let mermaidLoading = null;
|
||||
|
||||
const loadMermaid = async () => {
|
||||
if (mermaidInstance) return mermaidInstance;
|
||||
if (mermaidLoading) return mermaidLoading;
|
||||
|
||||
mermaidLoading = import('mermaid').then((module) => {
|
||||
mermaidInstance = module.default;
|
||||
mermaidInstance.initialize({
|
||||
startOnLoad: false,
|
||||
theme: 'default',
|
||||
securityLevel: 'loose',
|
||||
});
|
||||
return mermaidInstance;
|
||||
});
|
||||
|
||||
return mermaidLoading;
|
||||
};
|
||||
|
||||
export function Mermaid(props) {
|
||||
// svgRef 指向一个「React 视角里永远为空」的子节点,我们用 innerHTML 手动塞 SVG。
|
||||
// 关键:绝不能让 mermaid 去改写 React 正在管理子节点的元素 —— 之前用
|
||||
// mermaid.run({nodes:[ref.current]}) 直接抹掉了容器里 React 渲染的 loading/文本节点,
|
||||
// 等 setIsLoading(false) 触发重渲染时,React 找不到那些被 mermaid 删掉的节点,
|
||||
// 就抛 removeChild "NotFoundError"。改用 mermaid.render() 拿 svg 字符串后写进 svgRef,
|
||||
// React 始终认为 svgRef 这个 div 是空的,便不会与 mermaid 的 DOM 改动冲突。
|
||||
const svgRef = useRef(null);
|
||||
const [hasError, setHasError] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const rawId = useId();
|
||||
// useId 产出形如 ":r0:",含非法字符;清洗后作为 mermaid.render 的 id 基底(会进 querySelector)
|
||||
const idBase = `mermaid-${rawId.replace(/[^a-zA-Z0-9_-]/g, '')}`;
|
||||
// 每次 render 取递增后缀,确保 id 唯一。关键:StrictMode 开发模式下 mount effect 会跑两次,
|
||||
// 若两次用同一 id 并发调用 mermaid.render,会因其内部临时节点 #d{id} 冲突而报错/画不出图。
|
||||
const renderSeqRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!props.code) return;
|
||||
let cancelled = false;
|
||||
const renderId = `${idBase}-${renderSeqRef.current++}`;
|
||||
setIsLoading(true);
|
||||
setHasError(false);
|
||||
loadMermaid()
|
||||
.then((mermaid) => mermaid.render(renderId, props.code))
|
||||
.then(({ svg, bindFunctions }) => {
|
||||
if (cancelled || !svgRef.current) return;
|
||||
svgRef.current.innerHTML = svg;
|
||||
// 交互式图表(点击/tooltip)需要 mermaid 绑定事件;静态图表则是空操作
|
||||
if (typeof bindFunctions === 'function') {
|
||||
bindFunctions(svgRef.current);
|
||||
}
|
||||
setIsLoading(false);
|
||||
})
|
||||
.catch((e) => {
|
||||
if (cancelled) return;
|
||||
setHasError(true);
|
||||
setIsLoading(false);
|
||||
console.error('[Mermaid] ', e.message);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [props.code, idBase]);
|
||||
|
||||
function viewSvgInNewWindow() {
|
||||
const svg = svgRef.current?.querySelector('svg');
|
||||
if (!svg) return;
|
||||
const text = new XMLSerializer().serializeToString(svg);
|
||||
const blob = new Blob([text], { type: 'image/svg+xml' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
|
||||
// 解析失败(含流式中途语法不完整)时整体隐藏,不渲染半截图表。
|
||||
// 调用方是 <Mermaid key={mermaidCode}/>:代码一变即全新实例重挂载并重画,
|
||||
// 不依赖同实例内重试,所以这里直接卸载是安全的。
|
||||
if (hasError) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={clsx('mermaid-container')}
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
overflow: 'auto',
|
||||
padding: '12px',
|
||||
border: '1px solid var(--semi-color-border)',
|
||||
borderRadius: '8px',
|
||||
backgroundColor: 'var(--semi-color-bg-1)',
|
||||
margin: '12px 0',
|
||||
position: 'relative',
|
||||
minHeight: isLoading ? '100px' : 'auto',
|
||||
}}
|
||||
onClick={() => viewSvgInNewWindow()}
|
||||
>
|
||||
{isLoading && (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '50%',
|
||||
left: '50%',
|
||||
transform: 'translate(-50%, -50%)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '8px',
|
||||
color: 'var(--semi-color-text-2)',
|
||||
fontSize: '12px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: '14px',
|
||||
height: '14px',
|
||||
border: '2px solid var(--semi-color-border)',
|
||||
borderTop: '2px solid var(--semi-color-primary)',
|
||||
borderRadius: '50%',
|
||||
animation: 'spin 1s linear infinite',
|
||||
}}
|
||||
/>
|
||||
加载图表中...
|
||||
</div>
|
||||
)}
|
||||
{/* React 视角下这个 div 恒为空,SVG 由 effect 通过 innerHTML 注入,互不干涉 */}
|
||||
<div ref={svgRef} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function PreCode(props) {
|
||||
const ref = useRef(null);
|
||||
const [mermaidCode, setMermaidCode] = useState('');
|
||||
const [htmlCode, setHtmlCode] = useState('');
|
||||
const { t } = useTranslation();
|
||||
|
||||
const renderArtifacts = useDebouncedCallback(() => {
|
||||
if (!ref.current) return;
|
||||
const mermaidDom = ref.current.querySelector('code.language-mermaid');
|
||||
if (mermaidDom) {
|
||||
setMermaidCode(mermaidDom.innerText);
|
||||
}
|
||||
const htmlDom = ref.current.querySelector('code.language-html');
|
||||
const refText = ref.current.querySelector('code')?.innerText;
|
||||
if (htmlDom) {
|
||||
setHtmlCode(htmlDom.innerText);
|
||||
} else if (
|
||||
refText?.startsWith('<!DOCTYPE') ||
|
||||
refText?.startsWith('<svg') ||
|
||||
refText?.startsWith('<?xml')
|
||||
) {
|
||||
setHtmlCode(refText);
|
||||
}
|
||||
}, 600);
|
||||
|
||||
// 处理代码块的换行
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
const codeElements = ref.current.querySelectorAll('code');
|
||||
const wrapLanguages = [
|
||||
'',
|
||||
'md',
|
||||
'markdown',
|
||||
'text',
|
||||
'txt',
|
||||
'plaintext',
|
||||
'tex',
|
||||
'latex',
|
||||
];
|
||||
codeElements.forEach((codeElement) => {
|
||||
let languageClass = codeElement.className.match(/language-(\w+)/);
|
||||
let name = languageClass ? languageClass[1] : '';
|
||||
if (wrapLanguages.includes(name)) {
|
||||
codeElement.style.whiteSpace = 'pre-wrap';
|
||||
}
|
||||
});
|
||||
setTimeout(renderArtifacts, 1);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<pre
|
||||
ref={ref}
|
||||
style={{
|
||||
position: 'relative',
|
||||
backgroundColor: 'var(--semi-color-fill-0)',
|
||||
border: '1px solid var(--semi-color-border)',
|
||||
borderRadius: '6px',
|
||||
padding: '12px',
|
||||
margin: '12px 0',
|
||||
overflow: 'auto',
|
||||
fontSize: '14px',
|
||||
lineHeight: '1.4',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className='copy-code-button'
|
||||
style={{
|
||||
position: 'absolute',
|
||||
top: '8px',
|
||||
right: '8px',
|
||||
display: 'flex',
|
||||
gap: '4px',
|
||||
zIndex: 10,
|
||||
opacity: 0,
|
||||
transition: 'opacity 0.2s ease',
|
||||
}}
|
||||
>
|
||||
<Tooltip content={t('复制代码')}>
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
icon={<IconCopy />}
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (ref.current) {
|
||||
const codeElement = ref.current.querySelector('code');
|
||||
const code = codeElement?.textContent ?? '';
|
||||
copy(code).then((success) => {
|
||||
if (success) {
|
||||
Toast.success(t('代码已复制到剪贴板'));
|
||||
} else {
|
||||
Toast.error(t('复制失败,请手动复制'));
|
||||
}
|
||||
});
|
||||
}
|
||||
}}
|
||||
style={{
|
||||
padding: '4px',
|
||||
backgroundColor: 'var(--semi-color-bg-2)',
|
||||
borderRadius: '4px',
|
||||
cursor: 'pointer',
|
||||
border: '1px solid var(--semi-color-border)',
|
||||
boxShadow: '0 1px 2px rgba(0, 0, 0, 0.1)',
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
{props.children}
|
||||
</pre>
|
||||
{mermaidCode.length > 0 && (
|
||||
<Mermaid code={mermaidCode} key={mermaidCode} />
|
||||
)}
|
||||
{htmlCode.length > 0 && (
|
||||
<div
|
||||
style={{
|
||||
border: '1px solid var(--semi-color-border)',
|
||||
borderRadius: '8px',
|
||||
padding: '16px',
|
||||
margin: '12px 0',
|
||||
backgroundColor: 'var(--semi-color-bg-1)',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
marginBottom: '8px',
|
||||
fontSize: '12px',
|
||||
color: 'var(--semi-color-text-2)',
|
||||
}}
|
||||
>
|
||||
HTML预览:
|
||||
</div>
|
||||
<div dangerouslySetInnerHTML={{ __html: htmlCode }} />
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function CustomCode(props) {
|
||||
const ref = useRef(null);
|
||||
const [collapsed, setCollapsed] = useState(true);
|
||||
const [showToggle, setShowToggle] = useState(false);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const className = props?.className || '';
|
||||
// 行内代码 vs 代码块判定:带 language-* 类、或内容含换行 = 代码块;否则按行内代码渲染。
|
||||
// 关键:行内代码必须渲染成纯 <code>,绝不能套 <div>。行内代码位于 <p> 内,块级 <div>
|
||||
// 会被浏览器从 <p> 中提升出来、把段落拆开,导致 React 虚拟树与真实 DOM 错位;流式追加
|
||||
// 文本触发 reconcile 时就会报 removeChild "NotFoundError"。
|
||||
const isBlock =
|
||||
/language-(\w+)/.test(className) ||
|
||||
(typeof props.children === 'string' && props.children.includes('\n')) ||
|
||||
(Array.isArray(props.children) &&
|
||||
props.children.some((c) => typeof c === 'string' && c.includes('\n')));
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
const codeHeight = ref.current.scrollHeight;
|
||||
setShowToggle(codeHeight > 400);
|
||||
ref.current.scrollTop = ref.current.scrollHeight;
|
||||
}
|
||||
}, [props.children]);
|
||||
|
||||
const toggleCollapsed = () => {
|
||||
setCollapsed((collapsed) => !collapsed);
|
||||
};
|
||||
|
||||
const renderShowMoreButton = () => {
|
||||
if (showToggle && collapsed) {
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: 'absolute',
|
||||
bottom: '8px',
|
||||
right: '8px',
|
||||
left: '8px',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
}}
|
||||
>
|
||||
<Button size='small' onClick={toggleCollapsed} theme='solid'>
|
||||
{t('显示更多')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
// 行内代码:纯 <code>,不包裹任何块级元素,避免 <p> 内嵌 <div> 的非法嵌套
|
||||
if (!isBlock) {
|
||||
return <code className={clsx(className)}>{props.children}</code>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ position: 'relative' }}>
|
||||
<code
|
||||
className={clsx(className)}
|
||||
ref={ref}
|
||||
style={{
|
||||
maxHeight: collapsed ? '400px' : 'none',
|
||||
overflowY: 'hidden',
|
||||
display: 'block',
|
||||
padding: '8px 12px',
|
||||
backgroundColor: 'var(--semi-color-fill-0)',
|
||||
borderRadius: '4px',
|
||||
fontSize: '13px',
|
||||
lineHeight: '1.4',
|
||||
}}
|
||||
>
|
||||
{props.children}
|
||||
</code>
|
||||
{renderShowMoreButton()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function escapeBrackets(text) {
|
||||
const pattern =
|
||||
/(```[\s\S]*?```|`.*?`)|\\\[([\s\S]*?[^\\])\\\]|\\\((.*?)\\\)/g;
|
||||
return text.replace(
|
||||
pattern,
|
||||
(match, codeBlock, squareBracket, roundBracket) => {
|
||||
if (codeBlock) {
|
||||
return codeBlock;
|
||||
} else if (squareBracket) {
|
||||
return `$$${squareBracket}$$`;
|
||||
} else if (roundBracket) {
|
||||
return `$${roundBracket}$`;
|
||||
}
|
||||
return match;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function tryWrapHtmlCode(text) {
|
||||
// 尝试包装HTML代码
|
||||
if (text.includes('```')) {
|
||||
return text;
|
||||
}
|
||||
return text
|
||||
.replace(
|
||||
/([`]*?)(\w*?)([\n\r]*?)(<!DOCTYPE html>)/g,
|
||||
(match, quoteStart, lang, newLine, doctype) => {
|
||||
return !quoteStart ? '\n```html\n' + doctype : match;
|
||||
},
|
||||
)
|
||||
.replace(
|
||||
/(<\/body>)([\r\n\s]*?)(<\/html>)([\n\r]*)([`]*)([\n\r]*?)/g,
|
||||
(match, bodyEnd, space, htmlEnd, newLine, quoteEnd) => {
|
||||
return !quoteEnd ? bodyEnd + space + htmlEnd + '\n```\n' : match;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function MarkdownContentImpl(props) {
|
||||
const {
|
||||
content,
|
||||
className,
|
||||
animated = false,
|
||||
previousContentLength = 0,
|
||||
} = props;
|
||||
|
||||
const [previewImageUrl, setPreviewImageUrl] = useState(null);
|
||||
|
||||
const escapedContent = useMemo(() => {
|
||||
return tryWrapHtmlCode(escapeBrackets(content));
|
||||
}, [content]);
|
||||
|
||||
// 判断是否为用户消息
|
||||
const isUserMessage = className && className.includes('user-message');
|
||||
|
||||
const rehypePluginsBase = useMemo(() => {
|
||||
const base = [
|
||||
RehypeKatex,
|
||||
[
|
||||
RehypeHighlight,
|
||||
{
|
||||
detect: false,
|
||||
ignoreMissing: true,
|
||||
},
|
||||
],
|
||||
];
|
||||
if (animated) {
|
||||
base.push([rehypeSplitWordsIntoSpans, { previousContentLength }]);
|
||||
}
|
||||
return base;
|
||||
}, [animated, previousContentLength]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[RemarkMath, RemarkGfm, RemarkBreaks]}
|
||||
rehypePlugins={rehypePluginsBase}
|
||||
components={{
|
||||
pre: PreCode,
|
||||
code: CustomCode,
|
||||
p: (pProps) => (
|
||||
<p
|
||||
{...pProps}
|
||||
dir='auto'
|
||||
style={{
|
||||
lineHeight: '1.6',
|
||||
color: isUserMessage ? 'white' : 'inherit',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
a: (aProps) => {
|
||||
const href = aProps.href || '';
|
||||
if (/\.(aac|mp3|opus|wav)$/.test(href)) {
|
||||
return (
|
||||
<figure style={{ margin: '12px 0' }}>
|
||||
<audio controls src={href} style={{ width: '100%' }}></audio>
|
||||
</figure>
|
||||
);
|
||||
}
|
||||
if (/\.(3gp|3g2|webm|ogv|mpeg|mp4|avi)$/.test(href)) {
|
||||
return (
|
||||
<video
|
||||
controls
|
||||
style={{ width: '100%', maxWidth: '100%', margin: '12px 0' }}
|
||||
>
|
||||
<source src={href} />
|
||||
</video>
|
||||
);
|
||||
}
|
||||
const isInternal = /^\/#/i.test(href);
|
||||
const target = isInternal ? '_self' : (aProps.target ?? '_blank');
|
||||
return (
|
||||
<a
|
||||
{...aProps}
|
||||
target={target}
|
||||
style={{
|
||||
color: isUserMessage
|
||||
? '#87CEEB'
|
||||
: 'var(--semi-color-primary)',
|
||||
textDecoration: 'none',
|
||||
}}
|
||||
onMouseEnter={(e) => {
|
||||
e.target.style.textDecoration = 'underline';
|
||||
}}
|
||||
onMouseLeave={(e) => {
|
||||
e.target.style.textDecoration = 'none';
|
||||
}}
|
||||
/>
|
||||
);
|
||||
},
|
||||
h1: (props) => (
|
||||
<h1
|
||||
{...props}
|
||||
style={{
|
||||
fontSize: '24px',
|
||||
fontWeight: 'bold',
|
||||
margin: '20px 0 12px 0',
|
||||
color: isUserMessage ? 'white' : 'var(--semi-color-text-0)',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
h2: (props) => (
|
||||
<h2
|
||||
{...props}
|
||||
style={{
|
||||
fontSize: '20px',
|
||||
fontWeight: 'bold',
|
||||
margin: '18px 0 10px 0',
|
||||
color: isUserMessage ? 'white' : 'var(--semi-color-text-0)',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
h3: (props) => (
|
||||
<h3
|
||||
{...props}
|
||||
style={{
|
||||
fontSize: '18px',
|
||||
fontWeight: 'bold',
|
||||
margin: '16px 0 8px 0',
|
||||
color: isUserMessage ? 'white' : 'var(--semi-color-text-0)',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
h4: (props) => (
|
||||
<h4
|
||||
{...props}
|
||||
style={{
|
||||
fontSize: '16px',
|
||||
fontWeight: 'bold',
|
||||
margin: '14px 0 6px 0',
|
||||
color: isUserMessage ? 'white' : 'var(--semi-color-text-0)',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
h5: (props) => (
|
||||
<h5
|
||||
{...props}
|
||||
style={{
|
||||
fontSize: '14px',
|
||||
fontWeight: 'bold',
|
||||
margin: '12px 0 4px 0',
|
||||
color: isUserMessage ? 'white' : 'var(--semi-color-text-0)',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
h6: (props) => (
|
||||
<h6
|
||||
{...props}
|
||||
style={{
|
||||
fontSize: '13px',
|
||||
fontWeight: 'bold',
|
||||
margin: '10px 0 4px 0',
|
||||
color: isUserMessage ? 'white' : 'var(--semi-color-text-0)',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
blockquote: (props) => (
|
||||
<blockquote
|
||||
{...props}
|
||||
style={{
|
||||
borderLeft: isUserMessage
|
||||
? '4px solid rgba(255, 255, 255, 0.5)'
|
||||
: '4px solid var(--semi-color-primary)',
|
||||
paddingLeft: '16px',
|
||||
margin: '12px 0',
|
||||
backgroundColor: isUserMessage
|
||||
? 'rgba(255, 255, 255, 0.1)'
|
||||
: 'var(--semi-color-fill-0)',
|
||||
padding: '8px 16px',
|
||||
borderRadius: '0 4px 4px 0',
|
||||
fontStyle: 'italic',
|
||||
color: isUserMessage ? 'white' : 'inherit',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
ul: (props) => (
|
||||
<ul
|
||||
{...props}
|
||||
style={{
|
||||
margin: '8px 0',
|
||||
paddingLeft: '20px',
|
||||
color: isUserMessage ? 'white' : 'inherit',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
ol: (props) => (
|
||||
<ol
|
||||
{...props}
|
||||
style={{
|
||||
margin: '8px 0',
|
||||
paddingLeft: '20px',
|
||||
color: isUserMessage ? 'white' : 'inherit',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
li: (props) => (
|
||||
<li
|
||||
{...props}
|
||||
style={{
|
||||
margin: '4px 0',
|
||||
lineHeight: '1.6',
|
||||
color: isUserMessage ? 'white' : 'inherit',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
table: (props) => (
|
||||
<div style={{ overflow: 'auto', margin: '12px 0' }}>
|
||||
<table
|
||||
{...props}
|
||||
style={{
|
||||
width: '100%',
|
||||
borderCollapse: 'collapse',
|
||||
border: isUserMessage
|
||||
? '1px solid rgba(255, 255, 255, 0.3)'
|
||||
: '1px solid var(--semi-color-border)',
|
||||
borderRadius: '6px',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
th: (props) => (
|
||||
<th
|
||||
{...props}
|
||||
style={{
|
||||
padding: '8px 12px',
|
||||
backgroundColor: isUserMessage
|
||||
? 'rgba(255, 255, 255, 0.2)'
|
||||
: 'var(--semi-color-fill-1)',
|
||||
border: isUserMessage
|
||||
? '1px solid rgba(255, 255, 255, 0.3)'
|
||||
: '1px solid var(--semi-color-border)',
|
||||
fontWeight: 'bold',
|
||||
textAlign: 'left',
|
||||
color: isUserMessage ? 'white' : 'inherit',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
td: (props) => (
|
||||
<td
|
||||
{...props}
|
||||
style={{
|
||||
padding: '8px 12px',
|
||||
border: isUserMessage
|
||||
? '1px solid rgba(255, 255, 255, 0.3)'
|
||||
: '1px solid var(--semi-color-border)',
|
||||
color: isUserMessage ? 'white' : 'inherit',
|
||||
}}
|
||||
/>
|
||||
),
|
||||
img: (imgProps) => (
|
||||
<img
|
||||
{...imgProps}
|
||||
className='rounded-lg max-w-full h-auto shadow-sm border border-gray-200/60 dark:border-neutral-700/60 cursor-pointer hover:opacity-90 transition-opacity'
|
||||
style={{ maxHeight: '400px', margin: '8px 0' }}
|
||||
onClick={() => setPreviewImageUrl(imgProps.src)}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
>
|
||||
{escapedContent}
|
||||
</ReactMarkdown>
|
||||
|
||||
<ImagePreviewModal
|
||||
visible={!!previewImageUrl}
|
||||
imageUrl={previewImageUrl}
|
||||
onClose={() => setPreviewImageUrl(null)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export const MarkdownContent = React.memo(MarkdownContentImpl);
|
||||
|
||||
export function MarkdownRenderer(props) {
|
||||
const {
|
||||
content,
|
||||
loading,
|
||||
fontSize = 14,
|
||||
fontFamily = 'inherit',
|
||||
className,
|
||||
style,
|
||||
animated = false,
|
||||
previousContentLength = 0,
|
||||
...otherProps
|
||||
} = props;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={clsx('markdown-body', className)}
|
||||
style={{
|
||||
fontSize: `${fontSize}px`,
|
||||
fontFamily: fontFamily,
|
||||
lineHeight: '1.6',
|
||||
color: 'var(--semi-color-text-0)',
|
||||
...style,
|
||||
}}
|
||||
dir='auto'
|
||||
{...otherProps}
|
||||
>
|
||||
{loading ? (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '8px',
|
||||
padding: '16px',
|
||||
color: 'var(--semi-color-text-2)',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: '16px',
|
||||
height: '16px',
|
||||
border: '2px solid var(--semi-color-border)',
|
||||
borderTop: '2px solid var(--semi-color-primary)',
|
||||
borderRadius: '50%',
|
||||
animation: 'spin 1s linear infinite',
|
||||
}}
|
||||
/>
|
||||
正在渲染...
|
||||
</div>
|
||||
) : (
|
||||
<MarkdownContent
|
||||
content={content}
|
||||
className={className}
|
||||
animated={animated}
|
||||
previousContentLength={previousContentLength}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MarkdownRenderer;
|
||||
@@ -0,0 +1,607 @@
|
||||
/* 基础markdown样式 */
|
||||
.markdown-body {
|
||||
font-family: inherit;
|
||||
line-height: 1.6;
|
||||
color: var(--semi-color-text-0);
|
||||
overflow-wrap: break-word;
|
||||
word-wrap: break-word;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* 用户消息样式 - 白色字体适配蓝色背景 */
|
||||
.user-message {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message .markdown-body {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message h1,
|
||||
.user-message h2,
|
||||
.user-message h3,
|
||||
.user-message h4,
|
||||
.user-message h5,
|
||||
.user-message h6 {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message p {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message span {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message div {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message li {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message td,
|
||||
.user-message th {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.user-message blockquote {
|
||||
color: white !important;
|
||||
border-left-color: rgba(255, 255, 255, 0.5) !important;
|
||||
background-color: rgba(255, 255, 255, 0.1) !important;
|
||||
}
|
||||
|
||||
.user-message code:not(pre code) {
|
||||
color: #000 !important;
|
||||
background-color: rgba(255, 255, 255, 0.9) !important;
|
||||
}
|
||||
|
||||
.user-message a {
|
||||
color: #87ceeb !important;
|
||||
/* 浅蓝色链接 */
|
||||
}
|
||||
|
||||
.user-message a:hover {
|
||||
color: #b0e0e6 !important;
|
||||
/* hover时更浅的蓝色 */
|
||||
}
|
||||
|
||||
/* 表格在用户消息中的样式 */
|
||||
.user-message table {
|
||||
border-color: rgba(255, 255, 255, 0.3) !important;
|
||||
}
|
||||
|
||||
.user-message th {
|
||||
background-color: rgba(255, 255, 255, 0.2) !important;
|
||||
border-color: rgba(255, 255, 255, 0.3) !important;
|
||||
}
|
||||
|
||||
.user-message td {
|
||||
border-color: rgba(255, 255, 255, 0.3) !important;
|
||||
}
|
||||
|
||||
/* 加载动画 */
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* 代码高亮主题 - 适配Semi Design */
|
||||
.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
color: var(--semi-color-text-0);
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: var(--semi-color-text-2);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-keyword,
|
||||
.hljs-selector-tag,
|
||||
.hljs-subst {
|
||||
color: var(--semi-color-primary);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-number,
|
||||
.hljs-literal,
|
||||
.hljs-variable,
|
||||
.hljs-template-variable,
|
||||
.hljs-tag .hljs-attr {
|
||||
color: var(--semi-color-warning);
|
||||
}
|
||||
|
||||
.hljs-string,
|
||||
.hljs-doctag {
|
||||
color: var(--semi-color-success);
|
||||
}
|
||||
|
||||
.hljs-title,
|
||||
.hljs-section,
|
||||
.hljs-selector-id {
|
||||
color: var(--semi-color-primary);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-subst {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.hljs-type,
|
||||
.hljs-class .hljs-title {
|
||||
color: var(--semi-color-info);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.hljs-tag,
|
||||
.hljs-name,
|
||||
.hljs-attribute {
|
||||
color: var(--semi-color-primary);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.hljs-regexp,
|
||||
.hljs-link {
|
||||
color: var(--semi-color-tertiary);
|
||||
}
|
||||
|
||||
.hljs-symbol,
|
||||
.hljs-bullet {
|
||||
color: var(--semi-color-warning);
|
||||
}
|
||||
|
||||
.hljs-built_in,
|
||||
.hljs-builtin-name {
|
||||
color: var(--semi-color-info);
|
||||
}
|
||||
|
||||
.hljs-meta {
|
||||
color: var(--semi-color-text-2);
|
||||
}
|
||||
|
||||
.hljs-deletion {
|
||||
background: var(--semi-color-danger-light-default);
|
||||
}
|
||||
|
||||
.hljs-addition {
|
||||
background: var(--semi-color-success-light-default);
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Mermaid容器样式 */
|
||||
.mermaid-container {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.mermaid-container:hover {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* 代码块样式增强 */
|
||||
pre {
|
||||
position: relative;
|
||||
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
pre:hover {
|
||||
border-color: var(--semi-color-primary) !important;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
pre:hover .copy-code-button {
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
.copy-code-button {
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s ease;
|
||||
z-index: 10;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.copy-code-button:hover {
|
||||
opacity: 1 !important;
|
||||
}
|
||||
|
||||
.copy-code-button button {
|
||||
pointer-events: auto !important;
|
||||
cursor: pointer !important;
|
||||
}
|
||||
|
||||
/* 确保按钮可点击 */
|
||||
.copy-code-button .semi-button {
|
||||
pointer-events: auto !important;
|
||||
cursor: pointer !important;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.copy-code-button .semi-button:hover {
|
||||
background-color: var(--semi-color-fill-1) !important;
|
||||
border-color: var(--semi-color-primary) !important;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
/* ===== 服务大盘描述区域表格增强样式 ===== */
|
||||
.service-dashboard-description .markdown-body table {
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 12px;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body thead tr {
|
||||
background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 50%, #f0fdfa 100%);
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body th {
|
||||
padding: 12px 20px !important;
|
||||
font-weight: 600 !important;
|
||||
font-size: 13px;
|
||||
color: #065f46 !important;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
border-bottom: 2px solid #a7f3d0 !important;
|
||||
border-right: 1px solid #d1fae5 !important;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body th:last-child {
|
||||
border-right: none !important;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body td {
|
||||
padding: 10px 20px !important;
|
||||
font-size: 14px;
|
||||
color: #374151 !important;
|
||||
border-bottom: 1px solid #f3f4f6 !important;
|
||||
border-right: 1px solid #f3f4f6 !important;
|
||||
transition: background-color 0.15s ease;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body td:last-child {
|
||||
border-right: none !important;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body tbody tr:last-child td {
|
||||
border-bottom: none !important;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body tbody tr:hover {
|
||||
background-color: #f0fdf4;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body tbody tr:nth-child(even) {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body tbody tr:nth-child(even):hover {
|
||||
background-color: #f0fdf4;
|
||||
}
|
||||
|
||||
/* 服务大盘描述区域标题样式增强 */
|
||||
.service-dashboard-description .markdown-body h3,
|
||||
.service-dashboard-description .markdown-body h4 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: #1f2937 !important;
|
||||
margin-top: 24px !important;
|
||||
margin-bottom: 12px !important;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 2px solid #ecfdf5;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body h3:first-child,
|
||||
.service-dashboard-description .markdown-body h4:first-child {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
/* 暗色模式适配 */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.service-dashboard-description .markdown-body table {
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body thead tr {
|
||||
background: linear-gradient(135deg, #064e3b33 0%, #065f4633 100%);
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body th {
|
||||
color: #6ee7b7 !important;
|
||||
border-bottom-color: #065f46 !important;
|
||||
border-right-color: #1f2937 !important;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body td {
|
||||
color: #d1d5db !important;
|
||||
border-bottom-color: #1f2937 !important;
|
||||
border-right-color: #1f2937 !important;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body tbody tr:hover {
|
||||
background-color: #064e3b22;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body tbody tr:nth-child(even) {
|
||||
background-color: #11182722;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body h3,
|
||||
.service-dashboard-description .markdown-body h4 {
|
||||
color: #f3f4f6 !important;
|
||||
border-bottom-color: #1f2937;
|
||||
}
|
||||
}
|
||||
|
||||
/* dark class 模式适配 (tailwind dark mode) */
|
||||
.dark .service-dashboard-description .markdown-body table {
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
.dark .service-dashboard-description .markdown-body thead tr {
|
||||
background: linear-gradient(135deg, #064e3b33 0%, #065f4633 100%);
|
||||
}
|
||||
|
||||
.dark .service-dashboard-description .markdown-body th {
|
||||
color: #6ee7b7 !important;
|
||||
border-bottom-color: #065f46 !important;
|
||||
border-right-color: #1f2937 !important;
|
||||
}
|
||||
|
||||
.dark .service-dashboard-description .markdown-body td {
|
||||
color: #d1d5db !important;
|
||||
border-bottom-color: #1f2937 !important;
|
||||
border-right-color: #1f2937 !important;
|
||||
}
|
||||
|
||||
.dark .service-dashboard-description .markdown-body tbody tr:hover {
|
||||
background-color: #064e3b22;
|
||||
}
|
||||
|
||||
.dark .service-dashboard-description .markdown-body tbody tr:nth-child(even) {
|
||||
background-color: #11182722;
|
||||
}
|
||||
|
||||
.dark .service-dashboard-description .markdown-body h3,
|
||||
.dark .service-dashboard-description .markdown-body h4 {
|
||||
color: #f3f4f6 !important;
|
||||
border-bottom-color: #1f2937;
|
||||
}
|
||||
|
||||
/* 表格响应式 */
|
||||
@media (max-width: 768px) {
|
||||
.markdown-body table {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.markdown-body th,
|
||||
.markdown-body td {
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body th {
|
||||
padding: 8px 12px !important;
|
||||
}
|
||||
|
||||
.service-dashboard-description .markdown-body td {
|
||||
padding: 8px 12px !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* 数学公式样式 */
|
||||
.katex {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.katex-display {
|
||||
margin: 1em 0;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 链接hover效果 */
|
||||
.markdown-body a {
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
/* 引用块样式增强 */
|
||||
.markdown-body blockquote {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.markdown-body blockquote::before {
|
||||
content: '"';
|
||||
position: absolute;
|
||||
left: -8px;
|
||||
top: -8px;
|
||||
font-size: 24px;
|
||||
color: var(--semi-color-primary);
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
/* 列表样式增强 */
|
||||
.markdown-body ul li::marker {
|
||||
color: var(--semi-color-primary);
|
||||
}
|
||||
|
||||
.markdown-body ol li::marker {
|
||||
color: var(--semi-color-primary);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* 分隔线样式 */
|
||||
.markdown-body hr {
|
||||
border: none;
|
||||
height: 1px;
|
||||
background: linear-gradient(
|
||||
to right,
|
||||
transparent,
|
||||
var(--semi-color-border),
|
||||
transparent
|
||||
);
|
||||
margin: 24px 0;
|
||||
}
|
||||
|
||||
/* 图片样式 */
|
||||
.markdown-body img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
/* 内联代码样式 */
|
||||
.markdown-body code:not(pre code) {
|
||||
background-color: var(--semi-color-fill-1);
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 0.9em;
|
||||
color: var(--semi-color-primary);
|
||||
border: 1px solid var(--semi-color-border);
|
||||
}
|
||||
|
||||
/* 标题锚点样式 */
|
||||
.markdown-body h1:hover,
|
||||
.markdown-body h2:hover,
|
||||
.markdown-body h3:hover,
|
||||
.markdown-body h4:hover,
|
||||
.markdown-body h5:hover,
|
||||
.markdown-body h6:hover {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* 任务列表样式 */
|
||||
.markdown-body input[type='checkbox'] {
|
||||
margin-right: 8px;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.markdown-body li.task-list-item {
|
||||
list-style: none;
|
||||
margin-left: -20px;
|
||||
}
|
||||
|
||||
/* 键盘按键样式 */
|
||||
.markdown-body kbd {
|
||||
background-color: var(--semi-color-fill-0);
|
||||
border: 1px solid var(--semi-color-border);
|
||||
border-radius: 3px;
|
||||
box-shadow: 0 1px 0 var(--semi-color-border);
|
||||
color: var(--semi-color-text-0);
|
||||
display: inline-block;
|
||||
font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
|
||||
font-size: 0.85em;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
padding: 2px 4px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* 详情折叠样式 */
|
||||
.markdown-body details {
|
||||
border: 1px solid var(--semi-color-border);
|
||||
border-radius: 6px;
|
||||
padding: 12px;
|
||||
margin: 12px 0;
|
||||
}
|
||||
|
||||
.markdown-body summary {
|
||||
cursor: pointer;
|
||||
font-weight: bold;
|
||||
color: var(--semi-color-primary);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.markdown-body summary:hover {
|
||||
color: var(--semi-color-primary-hover);
|
||||
}
|
||||
|
||||
/* 脚注样式 */
|
||||
.markdown-body .footnote-ref {
|
||||
color: var(--semi-color-primary);
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.markdown-body .footnote-ref:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
/* 警告块样式 */
|
||||
.markdown-body .warning {
|
||||
background-color: var(--semi-color-warning-light-default);
|
||||
border-left: 4px solid var(--semi-color-warning);
|
||||
padding: 12px 16px;
|
||||
margin: 12px 0;
|
||||
border-radius: 0 6px 6px 0;
|
||||
}
|
||||
|
||||
.markdown-body .info {
|
||||
background-color: var(--semi-color-info-light-default);
|
||||
border-left: 4px solid var(--semi-color-info);
|
||||
padding: 12px 16px;
|
||||
margin: 12px 0;
|
||||
border-radius: 0 6px 6px 0;
|
||||
}
|
||||
|
||||
.markdown-body .success {
|
||||
background-color: var(--semi-color-success-light-default);
|
||||
border-left: 4px solid var(--semi-color-success);
|
||||
padding: 12px 16px;
|
||||
margin: 12px 0;
|
||||
border-radius: 0 6px 6px 0;
|
||||
}
|
||||
|
||||
.markdown-body .danger {
|
||||
background-color: var(--semi-color-danger-light-default);
|
||||
border-left: 4px solid var(--semi-color-danger);
|
||||
padding: 12px 16px;
|
||||
margin: 12px 0;
|
||||
border-radius: 0 6px 6px 0;
|
||||
}
|
||||
|
||||
@keyframes fade-in {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(6px) scale(0.98);
|
||||
filter: blur(3px);
|
||||
}
|
||||
60% {
|
||||
opacity: 0.85;
|
||||
filter: blur(0.5px);
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
filter: blur(0);
|
||||
}
|
||||
}
|
||||
|
||||
.animate-fade-in {
|
||||
animation: fade-in 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
|
||||
will-change: opacity, transform;
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React from 'react';
|
||||
import { Modal, Button, Typography } from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Gift,
|
||||
ArrowRight,
|
||||
Sparkles,
|
||||
X,
|
||||
Wallet,
|
||||
KeyRound,
|
||||
Star,
|
||||
} from 'lucide-react';
|
||||
import { renderQuota } from '../../../helpers';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const FEATURES = [
|
||||
{
|
||||
icon: Sparkles,
|
||||
title: '顶尖模型随心调',
|
||||
desc: '可调用 claude、codex 等全球顶尖大模型',
|
||||
},
|
||||
{
|
||||
icon: KeyRound,
|
||||
title: '一个 Key 接入一切',
|
||||
desc: '生成 API Key,直接对接 openclaw、opencode 等工具',
|
||||
},
|
||||
];
|
||||
|
||||
const NewUserGiftModal = ({ visible, onClose, quota }) => {
|
||||
const { t } = useTranslation();
|
||||
const quotaDisplay = renderQuota(quota || 0);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={visible}
|
||||
closable={false}
|
||||
maskClosable={true}
|
||||
onCancel={onClose}
|
||||
footer={null}
|
||||
width={440}
|
||||
className='new-user-gift-modal'
|
||||
bodyStyle={{ padding: 0 }}
|
||||
centered
|
||||
>
|
||||
<div className='relative overflow-hidden bg-white dark:bg-gray-900'>
|
||||
{/* 关闭按钮 */}
|
||||
<button
|
||||
onClick={onClose}
|
||||
className='absolute top-3.5 right-3.5 z-20 w-7 h-7 rounded-full bg-white/20 hover:bg-white/35 flex items-center justify-center transition-colors duration-150'
|
||||
aria-label={t('关闭')}
|
||||
>
|
||||
<X size={14} className='text-white' />
|
||||
</button>
|
||||
|
||||
{/* 头部 */}
|
||||
<div className='relative bg-gradient-to-br from-amber-400 via-orange-400 to-yellow-500 px-8 pt-8 pb-12 text-center overflow-hidden'>
|
||||
{/* 装饰圆 */}
|
||||
<div className='absolute -top-12 -right-12 w-48 h-48 bg-white/10 rounded-full' />
|
||||
<div className='absolute -bottom-8 -left-8 w-32 h-32 bg-white/10 rounded-full' />
|
||||
<div className='absolute top-6 left-8 w-1.5 h-1.5 bg-white/60 rounded-full' />
|
||||
<div className='absolute top-10 right-16 w-2 h-2 bg-white/40 rounded-full' />
|
||||
<div className='absolute bottom-10 right-10 w-1.5 h-1.5 bg-white/55 rounded-full' />
|
||||
<div className='absolute top-16 left-20 w-1 h-1 bg-white/45 rounded-full' />
|
||||
|
||||
{/* 星形装饰 */}
|
||||
<div className='absolute top-5 right-8 opacity-30'>
|
||||
<Star size={10} className='text-white fill-white' />
|
||||
</div>
|
||||
<div className='absolute bottom-14 left-12 opacity-25'>
|
||||
<Star size={8} className='text-white fill-white' />
|
||||
</div>
|
||||
|
||||
{/* 礼物图标 */}
|
||||
<div className='relative mx-auto mb-4 w-16 h-16 bg-white/25 backdrop-blur-sm rounded-2xl flex items-center justify-center shadow-2xl ring-2 ring-white/30 rotate-3'>
|
||||
<Gift size={30} className='text-white -rotate-3' />
|
||||
<div className='absolute -top-2 -right-2 w-6 h-6 bg-white rounded-full flex items-center justify-center shadow-lg'>
|
||||
<Sparkles size={12} className='text-amber-500' />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 className='text-white text-lg font-bold mb-1 leading-snug drop-shadow-sm'>
|
||||
{t('恭喜!新人礼包已到账')}
|
||||
</h2>
|
||||
<p className='text-amber-100 text-xs'>
|
||||
{t('专属体验额度已自动充入您的账户')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* 额度卡片 — 叠加在头部下边缘 */}
|
||||
<div className='relative -mt-7 mx-5 z-10'>
|
||||
<div className='bg-white dark:bg-gray-800 rounded-2xl shadow-xl shadow-amber-400/20 border border-amber-100 dark:border-amber-900/40 px-5 py-4 text-center'>
|
||||
<div className='flex items-center justify-center gap-1.5 mb-1.5'>
|
||||
<Wallet
|
||||
size={13}
|
||||
className='text-amber-500 dark:text-amber-400'
|
||||
/>
|
||||
<Text className='!text-amber-600 dark:!text-amber-400 text-xs font-medium'>
|
||||
{t('免费体验额度')}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='text-4xl font-extrabold bg-gradient-to-r from-amber-500 to-orange-500 bg-clip-text text-transparent leading-tight tracking-tight'>
|
||||
{quotaDisplay}
|
||||
</div>
|
||||
<Text className='!text-gray-400 dark:!text-gray-400 text-xs mt-1.5 block'>
|
||||
{t('已存入账户 · 无需任何操作 · 用完可随时充值')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 权益列表 */}
|
||||
<div className='px-5 pt-3.5 pb-3 space-y-2'>
|
||||
{FEATURES.map(({ icon: Icon, title, desc }) => (
|
||||
<div
|
||||
key={title}
|
||||
className='flex items-start gap-3 p-3 rounded-xl bg-amber-50/60 dark:bg-gray-800/50 hover:bg-amber-50 dark:hover:bg-amber-900/20 border border-amber-100/80 dark:border-amber-900/30 transition-colors duration-150'
|
||||
>
|
||||
<div className='w-8 h-8 bg-gradient-to-br from-amber-400 to-orange-400 rounded-lg flex items-center justify-center flex-shrink-0 shadow-sm shadow-amber-300/40'>
|
||||
<Icon size={14} className='text-white' />
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
<p className='text-gray-800 dark:text-gray-200 text-sm font-semibold leading-snug'>
|
||||
{t(title)}
|
||||
</p>
|
||||
<p className='text-gray-500 dark:text-gray-400 text-xs mt-0.5 leading-relaxed'>
|
||||
{t(desc)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* 底部按钮 */}
|
||||
<div className='px-5 pb-5 pt-1.5'>
|
||||
<Button
|
||||
theme='solid'
|
||||
size='large'
|
||||
onClick={onClose}
|
||||
className='w-full !bg-gradient-to-r !from-amber-400 !to-orange-500 hover:!from-amber-500 hover:!to-orange-600 !border-0 !rounded-xl !h-11 !font-semibold !shadow-lg !shadow-amber-400/30 transition-all duration-200 hover:!shadow-xl hover:!shadow-amber-400/40 active:!scale-[0.98]'
|
||||
>
|
||||
<span className='flex items-center justify-center gap-2 text-white'>
|
||||
{t('马上试一试')}
|
||||
<ArrowRight size={16} />
|
||||
</span>
|
||||
</Button>
|
||||
<p className='text-gray-400 dark:text-gray-500 text-xs text-center mt-2.5 leading-relaxed'>
|
||||
{t('在「用户中心」可随时查看余额和使用记录')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style jsx='true'>{`
|
||||
.new-user-gift-modal .semi-modal-content {
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
}
|
||||
.new-user-gift-modal .semi-modal-body {
|
||||
padding: 0;
|
||||
}
|
||||
`}</style>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default NewUserGiftModal;
|
||||
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Modal,
|
||||
Button,
|
||||
Input,
|
||||
Typography,
|
||||
Tabs,
|
||||
TabPane,
|
||||
} from '@douyinfe/semi-ui';
|
||||
|
||||
/**
|
||||
* 通用安全验证模态框组件
|
||||
* 配合 useSecureVerification Hook 使用
|
||||
* @param {Object} props
|
||||
* @param {boolean} props.visible - 是否显示模态框
|
||||
* @param {Object} props.verificationMethods - 可用的验证方式
|
||||
* @param {Object} props.verificationState - 当前验证状态
|
||||
* @param {Function} props.onVerify - 验证回调
|
||||
* @param {Function} props.onCancel - 取消回调
|
||||
* @param {Function} props.onCodeChange - 验证码变化回调
|
||||
* @param {Function} props.onMethodSwitch - 验证方式切换回调
|
||||
* @param {string} props.title - 模态框标题
|
||||
* @param {string} props.description - 验证描述文本
|
||||
*/
|
||||
const SecureVerificationModal = ({
|
||||
visible,
|
||||
verificationMethods,
|
||||
verificationState,
|
||||
onVerify,
|
||||
onCancel,
|
||||
onCodeChange,
|
||||
onMethodSwitch,
|
||||
title,
|
||||
description,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [, setIsAnimating] = useState(false);
|
||||
const [, setVerifySuccess] = useState(false);
|
||||
|
||||
const { has2FA, hasPasskey, passkeySupported } = verificationMethods;
|
||||
const { method, loading, code } = verificationState;
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setIsAnimating(true);
|
||||
setVerifySuccess(false);
|
||||
} else {
|
||||
setIsAnimating(false);
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
const handleKeyDown = (e) => {
|
||||
if (e.key === 'Enter' && code.trim() && !loading && method === '2fa') {
|
||||
onVerify(method, code);
|
||||
}
|
||||
if (e.key === 'Escape' && !loading) {
|
||||
onCancel();
|
||||
}
|
||||
};
|
||||
|
||||
// 如果用户没有启用任何验证方式
|
||||
if (visible && !has2FA && !hasPasskey) {
|
||||
return (
|
||||
<Modal
|
||||
title={title || t('安全验证')}
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
footer={<Button onClick={onCancel}>{t('确定')}</Button>}
|
||||
width={500}
|
||||
style={{ maxWidth: '90vw' }}
|
||||
>
|
||||
<div className='text-center py-6'>
|
||||
<div className='mb-4'>
|
||||
<svg
|
||||
className='w-16 h-16 text-yellow-500 mx-auto mb-4'
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<Typography.Title heading={4} className='mb-2'>
|
||||
{t('需要安全验证')}
|
||||
</Typography.Title>
|
||||
<Typography.Text type='tertiary'>
|
||||
{t('您需要先启用两步验证或 Passkey 才能查看敏感信息。')}
|
||||
</Typography.Text>
|
||||
<br />
|
||||
<Typography.Text type='tertiary'>
|
||||
{t('请前往个人设置 → 安全设置进行配置。')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={title || t('安全验证')}
|
||||
visible={visible}
|
||||
onCancel={loading ? undefined : onCancel}
|
||||
closeOnEsc={!loading}
|
||||
footer={null}
|
||||
width={460}
|
||||
centered
|
||||
style={{
|
||||
maxWidth: 'calc(100vw - 32px)',
|
||||
}}
|
||||
bodyStyle={{
|
||||
padding: '20px 24px',
|
||||
}}
|
||||
>
|
||||
<div style={{ width: '100%' }}>
|
||||
{/* 描述信息 */}
|
||||
{description && (
|
||||
<Typography.Paragraph
|
||||
type='tertiary'
|
||||
style={{
|
||||
margin: '0 0 20px 0',
|
||||
fontSize: '14px',
|
||||
lineHeight: '1.6',
|
||||
}}
|
||||
>
|
||||
{description}
|
||||
</Typography.Paragraph>
|
||||
)}
|
||||
|
||||
{/* 验证方式选择 */}
|
||||
<Tabs
|
||||
activeKey={method}
|
||||
onChange={onMethodSwitch}
|
||||
type='line'
|
||||
size='default'
|
||||
style={{ margin: 0 }}
|
||||
>
|
||||
{has2FA && (
|
||||
<TabPane tab={t('两步验证')} itemKey='2fa'>
|
||||
<div style={{ paddingTop: '20px' }}>
|
||||
<div style={{ marginBottom: '12px' }}>
|
||||
<Input
|
||||
placeholder={t('请输入6位验证码或8位备用码')}
|
||||
value={code}
|
||||
onChange={onCodeChange}
|
||||
size='large'
|
||||
maxLength={8}
|
||||
onKeyDown={handleKeyDown}
|
||||
autoFocus={method === '2fa'}
|
||||
disabled={loading}
|
||||
prefix={
|
||||
<svg
|
||||
style={{
|
||||
width: 16,
|
||||
height: 16,
|
||||
marginRight: 8,
|
||||
flexShrink: 0,
|
||||
}}
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M18 8a6 6 0 01-7.743 5.743L10 14l-1 1-1 1H6v2H2v-4l4.257-4.257A6 6 0 1118 8zm-6-4a1 1 0 100 2 2 2 0 012 2 1 1 0 102 0 4 4 0 00-4-4z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Typography.Text
|
||||
type='tertiary'
|
||||
size='small'
|
||||
style={{
|
||||
display: 'block',
|
||||
marginBottom: '20px',
|
||||
fontSize: '13px',
|
||||
lineHeight: '1.5',
|
||||
}}
|
||||
>
|
||||
{t('从认证器应用中获取验证码,或使用备用码')}
|
||||
</Typography.Text>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'flex-end',
|
||||
gap: '8px',
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
<Button onClick={onCancel} disabled={loading}>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
loading={loading}
|
||||
disabled={!code.trim() || loading}
|
||||
onClick={() => onVerify(method, code)}
|
||||
>
|
||||
{t('验证')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</TabPane>
|
||||
)}
|
||||
|
||||
{hasPasskey && passkeySupported && (
|
||||
<TabPane tab={t('Passkey')} itemKey='passkey'>
|
||||
<div style={{ paddingTop: '20px' }}>
|
||||
<div
|
||||
style={{
|
||||
textAlign: 'center',
|
||||
padding: '24px 16px',
|
||||
marginBottom: '20px',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
width: 56,
|
||||
height: 56,
|
||||
margin: '0 auto 16px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
borderRadius: '50%',
|
||||
background: 'var(--semi-color-primary-light-default)',
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
style={{
|
||||
width: 28,
|
||||
height: 28,
|
||||
color: 'var(--semi-color-primary)',
|
||||
}}
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M18 8a6 6 0 01-7.743 5.743L10 14l-1 1-1 1H6v2H2v-4l4.257-4.257A6 6 0 1118 8zm-6-4a1 1 0 100 2 2 2 0 012 2 1 1 0 102 0 4 4 0 00-4-4z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<Typography.Title
|
||||
heading={5}
|
||||
style={{ margin: '0 0 8px', fontSize: '16px' }}
|
||||
>
|
||||
{t('使用 Passkey 验证')}
|
||||
</Typography.Title>
|
||||
<Typography.Text
|
||||
type='tertiary'
|
||||
style={{
|
||||
display: 'block',
|
||||
margin: 0,
|
||||
fontSize: '13px',
|
||||
lineHeight: '1.5',
|
||||
}}
|
||||
>
|
||||
{t('点击验证按钮,使用您的生物特征或安全密钥')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'flex-end',
|
||||
gap: '8px',
|
||||
flexWrap: 'wrap',
|
||||
}}
|
||||
>
|
||||
<Button onClick={onCancel} disabled={loading}>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
loading={loading}
|
||||
disabled={loading}
|
||||
onClick={() => onVerify(method)}
|
||||
>
|
||||
{t('验证 Passkey')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</TabPane>
|
||||
)}
|
||||
</Tabs>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SecureVerificationModal;
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Modal, Button, Input, Typography } from '@douyinfe/semi-ui';
|
||||
|
||||
/**
|
||||
* 可复用的两步验证模态框组件
|
||||
* @param {Object} props
|
||||
* @param {boolean} props.visible - 是否显示模态框
|
||||
* @param {string} props.code - 验证码值
|
||||
* @param {boolean} props.loading - 是否正在验证
|
||||
* @param {Function} props.onCodeChange - 验证码变化回调
|
||||
* @param {Function} props.onVerify - 验证回调
|
||||
* @param {Function} props.onCancel - 取消回调
|
||||
* @param {string} props.title - 模态框标题
|
||||
* @param {string} props.description - 验证描述文本
|
||||
* @param {string} props.placeholder - 输入框占位文本
|
||||
*/
|
||||
const TwoFactorAuthModal = ({
|
||||
visible,
|
||||
code,
|
||||
loading,
|
||||
onCodeChange,
|
||||
onVerify,
|
||||
onCancel,
|
||||
title,
|
||||
description,
|
||||
placeholder,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleKeyDown = (e) => {
|
||||
if (e.key === 'Enter' && code && !loading) {
|
||||
onVerify();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={
|
||||
<div className='flex items-center'>
|
||||
<div className='w-8 h-8 rounded-full bg-blue-100 dark:bg-blue-900 flex items-center justify-center mr-3'>
|
||||
<svg
|
||||
className='w-4 h-4 text-blue-600 dark:text-blue-400'
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
{title || t('安全验证')}
|
||||
</div>
|
||||
}
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
footer={
|
||||
<>
|
||||
<Button onClick={onCancel}>{t('取消')}</Button>
|
||||
<Button
|
||||
type='primary'
|
||||
loading={loading}
|
||||
disabled={!code || loading}
|
||||
onClick={onVerify}
|
||||
>
|
||||
{t('验证')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
width={500}
|
||||
style={{ maxWidth: '90vw' }}
|
||||
>
|
||||
<div className='space-y-6'>
|
||||
{/* 安全提示 */}
|
||||
<div className='bg-blue-50 dark:bg-blue-900 rounded-lg p-4'>
|
||||
<div className='flex items-start'>
|
||||
<svg
|
||||
className='w-5 h-5 text-blue-600 dark:text-blue-400 mt-0.5 mr-3 flex-shrink-0'
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
<div>
|
||||
<Typography.Text
|
||||
strong
|
||||
className='text-blue-800 dark:text-blue-200'
|
||||
>
|
||||
{t('安全验证')}
|
||||
</Typography.Text>
|
||||
<Typography.Text className='block text-blue-700 dark:text-blue-300 text-sm mt-1'>
|
||||
{description || t('为了保护账户安全,请验证您的两步验证码。')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 验证码输入 */}
|
||||
<div>
|
||||
<Typography.Text strong className='block mb-2'>
|
||||
{t('验证身份')}
|
||||
</Typography.Text>
|
||||
<Input
|
||||
placeholder={placeholder || t('请输入认证器验证码或备用码')}
|
||||
value={code}
|
||||
onChange={onCodeChange}
|
||||
size='large'
|
||||
maxLength={8}
|
||||
onKeyDown={handleKeyDown}
|
||||
autoFocus
|
||||
/>
|
||||
<Typography.Text type='tertiary' size='small' className='mt-2 block'>
|
||||
{t(
|
||||
'支持6位TOTP验证码或8位备用码,可到`个人设置-安全设置-两步验证设置`配置或查看。',
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default TwoFactorAuthModal;
|
||||
@@ -0,0 +1,403 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useEffect, useContext } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
RadioGroup,
|
||||
Radio,
|
||||
Button,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
API,
|
||||
clearUserData,
|
||||
showSuccess,
|
||||
showError,
|
||||
showWarning,
|
||||
} from '../../../helpers';
|
||||
import {
|
||||
Sparkles,
|
||||
Briefcase,
|
||||
Cpu,
|
||||
ChevronRight,
|
||||
UserCircle,
|
||||
X,
|
||||
LogOut,
|
||||
} from 'lucide-react';
|
||||
import { UserContext } from '../../../context/User';
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
const UserSurveyModal = ({ visible, onClose, onSuccess }) => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const [, userDispatch] = useContext(UserContext);
|
||||
const [jobType, setJobType] = useState(null);
|
||||
const [aiToolUsage, setAIToolUsage] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [showExitConfirm, setShowExitConfirm] = useState(false);
|
||||
|
||||
// 弹窗显示时重置状态
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setJobType(null);
|
||||
setAIToolUsage(null);
|
||||
setLoading(false);
|
||||
setShowExitConfirm(false);
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
// 处理关闭按钮点击 - 显示确认提示
|
||||
const handleCloseClick = () => {
|
||||
setShowExitConfirm(true);
|
||||
};
|
||||
|
||||
// 确认退出 - 执行退出登录
|
||||
const handleConfirmExit = async () => {
|
||||
try {
|
||||
await API.get('/api/user/logout');
|
||||
showWarning(t('您已退出登录,填写问卷后方可使用平台'));
|
||||
userDispatch({ type: 'logout' });
|
||||
clearUserData();
|
||||
onClose?.();
|
||||
navigate('/org/login');
|
||||
} catch (error) {
|
||||
console.error('Logout failed:', error);
|
||||
// 即使请求失败也清除本地状态
|
||||
userDispatch({ type: 'logout' });
|
||||
clearUserData();
|
||||
onClose?.();
|
||||
navigate('/org/login');
|
||||
}
|
||||
};
|
||||
|
||||
// 取消退出 - 返回填写问卷
|
||||
const handleCancelExit = () => {
|
||||
setShowExitConfirm(false);
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!jobType) {
|
||||
showError(t('请选择您的职业类型'));
|
||||
return;
|
||||
}
|
||||
if (!aiToolUsage) {
|
||||
showError(t('请选择您的AI工具使用情况'));
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await API.post('/api/user/survey', {
|
||||
job_type: jobType,
|
||||
ai_tool_usage: aiToolUsage,
|
||||
});
|
||||
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(message || t('提交成功,感谢您的反馈!'));
|
||||
onSuccess?.();
|
||||
onClose?.();
|
||||
} else {
|
||||
showError(message || t('提交失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('提交失败,请稍后重试'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const jobTypeOptions = [
|
||||
{ value: 1, label: t('是,开发/测试/运维等技术岗位'), icon: '💻' },
|
||||
{ value: 2, label: t('是,产品/设计/运营等技术周边岗位'), icon: '🎨' },
|
||||
{ value: 3, label: t('否,其他行业'), icon: '🏢' },
|
||||
];
|
||||
|
||||
const aiToolOptions = [
|
||||
{ value: 1, label: t('是,正在使用'), icon: '🚀' },
|
||||
{ value: 2, label: t('是,了解或尝试过'), icon: '🔍' },
|
||||
{ value: 3, label: t('否,但有兴趣尝试'), icon: '✨' },
|
||||
{ value: 4, label: t('否,暂不需要'), icon: '💤' },
|
||||
];
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={visible}
|
||||
closable={false}
|
||||
maskClosable={false}
|
||||
footer={null}
|
||||
width={520}
|
||||
className='user-survey-modal'
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<div className='relative overflow-hidden'>
|
||||
{/* 关闭按钮 */}
|
||||
<button
|
||||
onClick={handleCloseClick}
|
||||
className='absolute top-4 right-4 z-10 p-2 rounded-full bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 transition-colors duration-200 group'
|
||||
title={t('暂不填写')}
|
||||
>
|
||||
<X
|
||||
size={18}
|
||||
className='text-gray-500 dark:text-gray-400 group-hover:text-gray-700 dark:group-hover:text-gray-200'
|
||||
/>
|
||||
</button>
|
||||
|
||||
{/* 背景装饰 */}
|
||||
<div className='absolute inset-0 pointer-events-none overflow-hidden'>
|
||||
<div className='absolute -top-20 -right-20 w-40 h-40 bg-gradient-to-br from-brand-from/20 to-brand-to/20 rounded-full blur-3xl' />
|
||||
<div className='absolute -bottom-20 -left-20 w-40 h-40 bg-gradient-to-br from-pink-500/15 to-rose-500/15 rounded-full blur-3xl' />
|
||||
</div>
|
||||
|
||||
{/* 确认退出弹层 */}
|
||||
{showExitConfirm && (
|
||||
<div className='absolute inset-0 z-20 bg-white/95 dark:bg-gray-900/95 backdrop-blur-sm flex flex-col items-center justify-center px-8'>
|
||||
<div className='p-4 bg-gradient-to-br from-amber-100 to-orange-100 dark:from-amber-900/30 dark:to-orange-900/30 rounded-full mb-6'>
|
||||
<LogOut
|
||||
size={32}
|
||||
className='text-amber-600 dark:text-amber-400'
|
||||
/>
|
||||
</div>
|
||||
<h3 className='text-xl font-semibold text-gray-900 dark:text-white mb-3'>
|
||||
{t('确认退出?')}
|
||||
</h3>
|
||||
<p className='text-gray-600 dark:text-gray-400 text-center mb-6 max-w-sm'>
|
||||
{t('不填写问卷将无法使用平台功能,系统将自动退出登录。')}
|
||||
</p>
|
||||
<div className='flex gap-3 w-full max-w-xs'>
|
||||
<Button
|
||||
theme='light'
|
||||
size='large'
|
||||
onClick={handleCancelExit}
|
||||
className='flex-1 !rounded-xl !h-11'
|
||||
>
|
||||
{t('继续填写')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='danger'
|
||||
size='large'
|
||||
onClick={handleConfirmExit}
|
||||
className='flex-1 !rounded-xl !h-11'
|
||||
>
|
||||
{t('确认退出')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 头部 */}
|
||||
<div className='relative px-8 pt-8 pb-6'>
|
||||
<div className='flex items-center gap-4 mb-4'>
|
||||
<div className='relative'>
|
||||
<div className='p-3.5 bg-gradient-to-br from-brand-from to-brand-to rounded-2xl shadow-lg shadow-brand/30'>
|
||||
<UserCircle size={28} className='text-white' />
|
||||
</div>
|
||||
<div className='absolute -top-1 -right-1 w-5 h-5 bg-gradient-to-r from-amber-400 to-orange-500 rounded-full flex items-center justify-center shadow-lg'>
|
||||
<Sparkles size={12} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Title
|
||||
heading={4}
|
||||
className='!mb-1 !text-gray-900 dark:!text-white'
|
||||
>
|
||||
{t('欢迎加入!')}
|
||||
</Title>
|
||||
<Text className='!text-gray-500 dark:!text-gray-400 text-sm'>
|
||||
{t('帮助我们更好地了解您')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='p-3 bg-gradient-to-r from-brand-from/5 to-brand-to/5 dark:from-brand-from/20 dark:to-brand-to/20 rounded-xl border border-brand/10 dark:border-brand-deep/50'>
|
||||
<Text className='!text-brand-deep dark:!text-brand-from text-sm'>
|
||||
💡 {t('回答两个小问题,让我们为您提供更适合的服务体验')}
|
||||
</Text>
|
||||
</div>
|
||||
<div className='mt-3 flex items-center gap-2 text-xs text-gray-400 dark:text-gray-500'>
|
||||
<span>✓</span>
|
||||
<span>{t('仅需填写一次,之后不会再弹出')}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 问题区域 */}
|
||||
<div className='relative px-8 pb-6 space-y-6'>
|
||||
{/* 问题1 */}
|
||||
<div className='space-y-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='w-6 h-6 rounded-full bg-brand/10 dark:bg-brand-deep/50 flex items-center justify-center'>
|
||||
<Briefcase
|
||||
size={14}
|
||||
className='text-brand-deep dark:text-brand-from'
|
||||
/>
|
||||
</div>
|
||||
<Text strong className='!text-gray-800 dark:!text-gray-200'>
|
||||
{t('您是IT相关从业者吗?')}
|
||||
</Text>
|
||||
</div>
|
||||
<RadioGroup
|
||||
value={jobType}
|
||||
onChange={(e) => setJobType(e.target.value)}
|
||||
direction='vertical'
|
||||
className='survey-radio-group'
|
||||
>
|
||||
{jobTypeOptions.map((option) => (
|
||||
<Radio
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
className={`survey-radio-item ${jobType === option.value ? 'selected' : ''}`}
|
||||
>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-lg'>{option.icon}</span>
|
||||
<span className='text-gray-700 dark:text-gray-300'>
|
||||
{option.label}
|
||||
</span>
|
||||
</div>
|
||||
</Radio>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
|
||||
{/* 问题2 */}
|
||||
<div className='space-y-3'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div className='w-6 h-6 rounded-full bg-brand/10 dark:bg-brand-deep/50 flex items-center justify-center'>
|
||||
<Cpu
|
||||
size={14}
|
||||
className='text-brand-deep dark:text-brand-from'
|
||||
/>
|
||||
</div>
|
||||
<Text strong className='!text-gray-800 dark:!text-gray-200'>
|
||||
{t('您使用过AI编程工具吗?')}
|
||||
</Text>
|
||||
<Text className='!text-gray-400 dark:!text-gray-500 text-xs'>
|
||||
{t('(如Cursor/Claude/Copilot等)')}
|
||||
</Text>
|
||||
</div>
|
||||
<RadioGroup
|
||||
value={aiToolUsage}
|
||||
onChange={(e) => setAIToolUsage(e.target.value)}
|
||||
direction='vertical'
|
||||
className='survey-radio-group'
|
||||
>
|
||||
{aiToolOptions.map((option) => (
|
||||
<Radio
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
className={`survey-radio-item ${aiToolUsage === option.value ? 'selected' : ''}`}
|
||||
>
|
||||
<div className='flex items-center gap-2'>
|
||||
<span className='text-lg'>{option.icon}</span>
|
||||
<span className='text-gray-700 dark:text-gray-300'>
|
||||
{option.label}
|
||||
</span>
|
||||
</div>
|
||||
</Radio>
|
||||
))}
|
||||
</RadioGroup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 底部按钮 */}
|
||||
<div className='relative px-8 py-5 border-t border-gray-100 dark:border-gray-800 bg-gray-50/50 dark:bg-gray-900/50'>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
size='large'
|
||||
loading={loading}
|
||||
onClick={handleSubmit}
|
||||
disabled={!jobType || !aiToolUsage}
|
||||
className='w-full !bg-gradient-to-r !from-brand-from !to-brand-to hover:!from-brand-from hover:!to-brand-to !border-0 !rounded-xl !h-12 !font-medium !shadow-lg !shadow-brand/25 transition-all duration-200 hover:!shadow-xl hover:!shadow-brand/30 disabled:!opacity-50 disabled:!cursor-not-allowed'
|
||||
>
|
||||
<span className='flex items-center justify-center gap-2'>
|
||||
{t('开始使用')}
|
||||
<ChevronRight size={18} />
|
||||
</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style jsx='true'>{`
|
||||
.user-survey-modal .semi-modal-content {
|
||||
border-radius: 20px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.survey-radio-group .semi-radio {
|
||||
margin-bottom: 8px;
|
||||
padding: 12px 16px;
|
||||
border-radius: 12px;
|
||||
border: 2px solid transparent;
|
||||
background: rgba(249, 250, 251, 0.8);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.dark .survey-radio-group .semi-radio {
|
||||
background: rgba(31, 41, 55, 0.5);
|
||||
}
|
||||
|
||||
.survey-radio-group .semi-radio:hover {
|
||||
background: rgba(243, 244, 246, 1);
|
||||
border-color: color-mix(in srgb, var(--brand-primary) 30%, transparent);
|
||||
}
|
||||
|
||||
.dark .survey-radio-group .semi-radio:hover {
|
||||
background: rgba(55, 65, 81, 0.8);
|
||||
border-color: color-mix(in srgb, var(--brand-primary) 40%, transparent);
|
||||
}
|
||||
|
||||
.survey-radio-group .semi-radio.semi-radio-checked {
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--brand-primary) 10%, transparent) 0%,
|
||||
color-mix(in srgb, var(--brand-gradient-via) 10%, transparent) 100%
|
||||
);
|
||||
border-color: color-mix(in srgb, var(--brand-primary) 50%, transparent);
|
||||
}
|
||||
|
||||
.dark .survey-radio-group .semi-radio.semi-radio-checked {
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--brand-primary) 20%, transparent) 0%,
|
||||
color-mix(in srgb, var(--brand-gradient-via) 20%, transparent) 100%
|
||||
);
|
||||
border-color: color-mix(in srgb, var(--brand-primary) 60%, transparent);
|
||||
}
|
||||
|
||||
.survey-radio-group .semi-radio .semi-radio-inner-display {
|
||||
border-color: #d1d5db;
|
||||
}
|
||||
|
||||
.survey-radio-group
|
||||
.semi-radio.semi-radio-checked
|
||||
.semi-radio-inner-display {
|
||||
border-color: var(--brand-primary);
|
||||
background: var(--brand-primary);
|
||||
}
|
||||
`}</style>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default UserSurveyModal;
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { Card, Divider, Button } from '@douyinfe/semi-ui';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
import { IconEyeOpened, IconEyeClosed } from '@douyinfe/semi-icons';
|
||||
|
||||
/**
|
||||
* CardPro 高级卡片组件
|
||||
*
|
||||
* 布局分为6个区域:
|
||||
* 1. 统计信息区域 (statsArea)
|
||||
* 2. 描述信息区域 (descriptionArea)
|
||||
* 3. 类型切换/标签区域 (tabsArea)
|
||||
* 4. 操作按钮区域 (actionsArea)
|
||||
* 5. 搜索表单区域 (searchArea)
|
||||
* 6. 分页区域 (paginationArea) - 固定在卡片底部
|
||||
*
|
||||
* 支持三种布局类型:
|
||||
* - type1: 操作型 (如TokensTable) - 描述信息 + 操作按钮 + 搜索表单
|
||||
* - type2: 查询型 (如LogsTable) - 统计信息 + 搜索表单
|
||||
* - type3: 复杂型 (如ChannelsTable) - 描述信息 + 类型切换 + 操作按钮 + 搜索表单
|
||||
*/
|
||||
const CardPro = ({
|
||||
type = 'type1',
|
||||
className = '',
|
||||
children,
|
||||
// 各个区域的内容
|
||||
statsArea,
|
||||
descriptionArea,
|
||||
tabsArea,
|
||||
actionsArea,
|
||||
searchArea,
|
||||
paginationArea, // 新增分页区域
|
||||
// 卡片属性
|
||||
shadows = '',
|
||||
bordered = true,
|
||||
// 自定义样式
|
||||
style,
|
||||
// 国际化函数
|
||||
t = (key) => key,
|
||||
...props
|
||||
}) => {
|
||||
const isMobile = useIsMobile();
|
||||
const [showMobileActions, setShowMobileActions] = useState(false);
|
||||
|
||||
const toggleMobileActions = () => {
|
||||
setShowMobileActions(!showMobileActions);
|
||||
};
|
||||
|
||||
const hasMobileHideableContent = actionsArea || searchArea;
|
||||
|
||||
const renderHeader = () => {
|
||||
const hasContent =
|
||||
statsArea || descriptionArea || tabsArea || actionsArea || searchArea;
|
||||
if (!hasContent) return null;
|
||||
|
||||
return (
|
||||
<div className='flex flex-col w-full'>
|
||||
{/* 统计信息区域 - 用于type2 */}
|
||||
{type === 'type2' && statsArea && <>{statsArea}</>}
|
||||
|
||||
{/* 描述信息区域 - 用于type1和type3 */}
|
||||
{(type === 'type1' || type === 'type3') && descriptionArea && (
|
||||
<>{descriptionArea}</>
|
||||
)}
|
||||
|
||||
{/* 第一个分隔线 - 在描述信息或统计信息后面 */}
|
||||
{((type === 'type1' || type === 'type3') && descriptionArea) ||
|
||||
(type === 'type2' && statsArea) ? (
|
||||
<Divider margin='12px' />
|
||||
) : null}
|
||||
|
||||
{/* 类型切换/标签区域 - 主要用于type3 */}
|
||||
{type === 'type3' && tabsArea && <>{tabsArea}</>}
|
||||
|
||||
{/* 移动端操作切换按钮 */}
|
||||
{isMobile && hasMobileHideableContent && (
|
||||
<>
|
||||
<div className='w-full mb-2'>
|
||||
<Button
|
||||
onClick={toggleMobileActions}
|
||||
icon={showMobileActions ? <IconEyeClosed /> : <IconEyeOpened />}
|
||||
type='tertiary'
|
||||
size='small'
|
||||
theme='outline'
|
||||
block
|
||||
>
|
||||
{showMobileActions ? t('隐藏操作项') : t('显示操作项')}
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 操作按钮和搜索表单的容器 */}
|
||||
<div
|
||||
className={`flex flex-col gap-2 ${isMobile && !showMobileActions ? 'hidden' : ''}`}
|
||||
>
|
||||
{/* 操作按钮区域 - 用于type1和type3 */}
|
||||
{(type === 'type1' || type === 'type3') &&
|
||||
actionsArea &&
|
||||
(Array.isArray(actionsArea) ? (
|
||||
actionsArea.map((area, idx) => (
|
||||
<React.Fragment key={idx}>
|
||||
{idx !== 0 && <Divider />}
|
||||
<div className='w-full'>{area}</div>
|
||||
</React.Fragment>
|
||||
))
|
||||
) : (
|
||||
<div className='w-full'>{actionsArea}</div>
|
||||
))}
|
||||
|
||||
{/* 当同时存在操作区和搜索区时,插入分隔线 */}
|
||||
{actionsArea && searchArea && <Divider />}
|
||||
|
||||
{/* 搜索表单区域 - 所有类型都可能有 */}
|
||||
{searchArea && <div className='w-full'>{searchArea}</div>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const headerContent = renderHeader();
|
||||
|
||||
// 渲染分页区域
|
||||
const renderFooter = () => {
|
||||
if (!paginationArea) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`flex w-full pt-4 border-t ${isMobile ? 'justify-center' : 'justify-between items-center'}`}
|
||||
style={{ borderColor: 'var(--semi-color-border)' }}
|
||||
>
|
||||
{paginationArea}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const footerContent = renderFooter();
|
||||
|
||||
return (
|
||||
<Card
|
||||
className={`table-scroll-card !rounded-2xl ${className}`}
|
||||
title={headerContent}
|
||||
footer={footerContent}
|
||||
shadows={shadows}
|
||||
bordered={bordered}
|
||||
style={style}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
CardPro.propTypes = {
|
||||
// 布局类型
|
||||
type: PropTypes.oneOf(['type1', 'type2', 'type3']),
|
||||
// 样式相关
|
||||
className: PropTypes.string,
|
||||
style: PropTypes.object,
|
||||
shadows: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||
bordered: PropTypes.bool,
|
||||
// 内容区域
|
||||
statsArea: PropTypes.node,
|
||||
descriptionArea: PropTypes.node,
|
||||
tabsArea: PropTypes.node,
|
||||
actionsArea: PropTypes.oneOfType([
|
||||
PropTypes.node,
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
]),
|
||||
searchArea: PropTypes.node,
|
||||
paginationArea: PropTypes.node,
|
||||
// 表格内容
|
||||
children: PropTypes.node,
|
||||
// 国际化函数
|
||||
t: PropTypes.func,
|
||||
};
|
||||
|
||||
export default CardPro;
|
||||
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Table,
|
||||
Card,
|
||||
Checkbox,
|
||||
Skeleton,
|
||||
Pagination,
|
||||
Empty,
|
||||
Button,
|
||||
Collapsible,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { IconChevronDown, IconChevronUp } from '@douyinfe/semi-icons';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
import { useMinimumLoadingTime } from '../../../hooks/common/useMinimumLoadingTime';
|
||||
|
||||
/**
|
||||
* CardTable 响应式表格组件
|
||||
*
|
||||
* 在桌面端渲染 Semi-UI 的 Table 组件,在移动端则将每一行数据渲染成 Card 形式。
|
||||
* 该组件与 Table 组件的大部分 API 保持一致,只需将原 Table 换成 CardTable 即可。
|
||||
*/
|
||||
const CardTable = ({
|
||||
columns = [],
|
||||
dataSource = [],
|
||||
loading = false,
|
||||
rowKey = 'key',
|
||||
hidePagination = false,
|
||||
...tableProps
|
||||
}) => {
|
||||
const isMobile = useIsMobile();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const showSkeleton = useMinimumLoadingTime(loading);
|
||||
|
||||
const getRowKey = (record, index) => {
|
||||
if (typeof rowKey === 'function') return rowKey(record);
|
||||
return record[rowKey] !== undefined ? record[rowKey] : index;
|
||||
};
|
||||
|
||||
// ===== 移动端多选支持 =====
|
||||
// 移动端卡片分支此前完全没有消费 rowSelection,导致调用方的 selectedKeys 永远是空数组,
|
||||
// 令牌/兑换码/渠道/模型/管理员令牌五个页面的批量操作在手机上全是死按钮
|
||||
// (点了只提示「请至少选择一个」,渠道页甚至会对空集合弹出删除确认)。
|
||||
// 这里补上:兼容 Semi 的受控(传 selectedRowKeys)与非受控(只传 onChange)两种用法。
|
||||
const rowSelection =
|
||||
tableProps.rowSelection && typeof tableProps.rowSelection === 'object'
|
||||
? tableProps.rowSelection
|
||||
: null;
|
||||
const selectionEnabled = Boolean(tableProps.rowSelection);
|
||||
const [internalSelectedKeys, setInternalSelectedKeys] = useState([]);
|
||||
const selectedKeys = rowSelection?.selectedRowKeys ?? internalSelectedKeys;
|
||||
|
||||
const isRowSelectable = (record, index) => {
|
||||
const props = rowSelection?.getCheckboxProps?.(record, index);
|
||||
return !props?.disabled;
|
||||
};
|
||||
|
||||
const emitSelection = (nextKeys) => {
|
||||
if (rowSelection?.selectedRowKeys === undefined) {
|
||||
setInternalSelectedKeys(nextKeys);
|
||||
}
|
||||
const keySet = new Set(nextKeys);
|
||||
const nextRows = dataSource.filter((record, index) =>
|
||||
keySet.has(getRowKey(record, index)),
|
||||
);
|
||||
rowSelection?.onChange?.(nextKeys, nextRows);
|
||||
};
|
||||
|
||||
const toggleRowSelected = (key, checked) => {
|
||||
const nextKeys = checked
|
||||
? [...selectedKeys.filter((k) => k !== key), key]
|
||||
: selectedKeys.filter((k) => k !== key);
|
||||
emitSelection(nextKeys);
|
||||
};
|
||||
|
||||
const selectableKeys = dataSource
|
||||
.map((record, index) =>
|
||||
isRowSelectable(record, index) ? getRowKey(record, index) : null,
|
||||
)
|
||||
.filter((key) => key !== null);
|
||||
const allSelected =
|
||||
selectableKeys.length > 0 &&
|
||||
selectableKeys.every((key) => selectedKeys.includes(key));
|
||||
|
||||
if (!isMobile) {
|
||||
const finalTableProps = hidePagination
|
||||
? { ...tableProps, pagination: false }
|
||||
: tableProps;
|
||||
|
||||
return (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={dataSource}
|
||||
loading={loading}
|
||||
rowKey={rowKey}
|
||||
{...finalTableProps}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (showSkeleton) {
|
||||
const visibleCols = columns.filter((col) => {
|
||||
if (tableProps?.visibleColumns && col.key) {
|
||||
return tableProps.visibleColumns[col.key];
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const renderSkeletonCard = (key) => {
|
||||
const placeholder = (
|
||||
<div className='p-2'>
|
||||
{visibleCols.map((col, idx) => {
|
||||
if (!col.title) {
|
||||
return (
|
||||
<div key={idx} className='mt-2 flex justify-end'>
|
||||
<Skeleton.Title active style={{ width: 100, height: 24 }} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className='flex justify-between items-center py-1 border-b last:border-b-0 border-dashed'
|
||||
style={{ borderColor: 'var(--semi-color-border)' }}
|
||||
>
|
||||
<Skeleton.Title active style={{ width: 80, height: 14 }} />
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{
|
||||
width: `${50 + (idx % 3) * 10}%`,
|
||||
maxWidth: 180,
|
||||
height: 14,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<Card key={key} className='!rounded-2xl shadow-sm'>
|
||||
<Skeleton loading={true} active placeholder={placeholder}></Skeleton>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-2'>
|
||||
{[1, 2, 3].map((i) => renderSkeletonCard(i))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const isEmpty = !showSkeleton && (!dataSource || dataSource.length === 0);
|
||||
|
||||
const MobileRowCard = ({ record, index }) => {
|
||||
const [showDetails, setShowDetails] = useState(false);
|
||||
const rowKeyVal = getRowKey(record, index);
|
||||
|
||||
const hasDetails =
|
||||
tableProps.expandedRowRender &&
|
||||
(!tableProps.rowExpandable || tableProps.rowExpandable(record));
|
||||
|
||||
// onRow 同样此前被丢弃:调用方用它给禁用/已删除记录着色、绑定行点击,
|
||||
// 移动端一并透传到卡片上,保持与桌面行为一致。
|
||||
const rowProps = tableProps.onRow?.(record, index) || {};
|
||||
const selectable = isRowSelectable(record, index);
|
||||
|
||||
return (
|
||||
<Card
|
||||
key={rowKeyVal}
|
||||
{...rowProps}
|
||||
className={`!rounded-2xl shadow-sm ${rowProps.className || ''}`}
|
||||
>
|
||||
{selectionEnabled && (
|
||||
<div
|
||||
className='flex items-center pb-1 mb-1 border-b border-dashed'
|
||||
style={{ borderColor: 'var(--semi-color-border)' }}
|
||||
>
|
||||
<Checkbox
|
||||
checked={selectedKeys.includes(rowKeyVal)}
|
||||
disabled={!selectable}
|
||||
onChange={(e) => {
|
||||
toggleRowSelected(rowKeyVal, e.target.checked);
|
||||
}}
|
||||
// 阻止冒泡,避免同时触发 onRow 的行点击
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<span className='text-xs text-gray-500'>{t('选择')}</span>
|
||||
</Checkbox>
|
||||
</div>
|
||||
)}
|
||||
{columns.map((col, colIdx) => {
|
||||
if (
|
||||
tableProps?.visibleColumns &&
|
||||
!tableProps.visibleColumns[col.key]
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const title = col.title;
|
||||
const cellContent = col.render
|
||||
? col.render(record[col.dataIndex], record, index)
|
||||
: record[col.dataIndex];
|
||||
|
||||
if (!title) {
|
||||
return (
|
||||
<div key={col.key || colIdx} className='mt-2 flex justify-end'>
|
||||
{cellContent}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
key={col.key || colIdx}
|
||||
className='flex justify-between items-start py-1 border-b last:border-b-0 border-dashed'
|
||||
style={{ borderColor: 'var(--semi-color-border)' }}
|
||||
>
|
||||
<span className='font-medium text-gray-600 mr-2 whitespace-nowrap select-none'>
|
||||
{title}
|
||||
</span>
|
||||
<div className='flex-1 break-all flex justify-end items-center gap-1'>
|
||||
{cellContent !== undefined && cellContent !== null
|
||||
? cellContent
|
||||
: '-'}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
{hasDetails && (
|
||||
<>
|
||||
<Button
|
||||
theme='borderless'
|
||||
size='small'
|
||||
className='w-full flex justify-center mt-2'
|
||||
icon={showDetails ? <IconChevronUp /> : <IconChevronDown />}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
setShowDetails(!showDetails);
|
||||
}}
|
||||
>
|
||||
{showDetails ? t('收起') : t('详情')}
|
||||
</Button>
|
||||
<Collapsible isOpen={showDetails} keepDOM>
|
||||
<div className='pt-2'>
|
||||
{tableProps.expandedRowRender(record, index)}
|
||||
</div>
|
||||
</Collapsible>
|
||||
</>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
if (isEmpty) {
|
||||
if (tableProps.empty) return tableProps.empty;
|
||||
return (
|
||||
<div className='flex justify-center p-4'>
|
||||
<Empty description='No Data' />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='flex flex-col gap-2'>
|
||||
{selectionEnabled && selectableKeys.length > 0 && (
|
||||
<div className='flex items-center justify-between px-3 py-2 rounded-xl bg-semi-color-fill-0'>
|
||||
<Checkbox
|
||||
checked={allSelected}
|
||||
indeterminate={!allSelected && selectedKeys.length > 0}
|
||||
onChange={(e) => {
|
||||
emitSelection(e.target.checked ? selectableKeys : []);
|
||||
}}
|
||||
>
|
||||
<span className='text-xs'>{t('全选')}</span>
|
||||
</Checkbox>
|
||||
<span className='text-xs text-gray-500'>
|
||||
{t('已选 {{count}} 项', { count: selectedKeys.length })}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{dataSource.map((record, index) => (
|
||||
<MobileRowCard
|
||||
key={getRowKey(record, index)}
|
||||
record={record}
|
||||
index={index}
|
||||
/>
|
||||
))}
|
||||
{!hidePagination && tableProps.pagination && dataSource.length > 0 && (
|
||||
<div className='mt-2 flex justify-center'>
|
||||
<Pagination {...tableProps.pagination} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
CardTable.propTypes = {
|
||||
columns: PropTypes.array.isRequired,
|
||||
dataSource: PropTypes.array,
|
||||
loading: PropTypes.bool,
|
||||
rowKey: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
||||
hidePagination: PropTypes.bool,
|
||||
};
|
||||
|
||||
export default CardTable;
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Card, Button, Typography, Tag } from '@douyinfe/semi-ui';
|
||||
import { copy, showSuccess } from '../../../helpers';
|
||||
|
||||
/**
|
||||
* 解析密钥数据,支持多种格式
|
||||
* @param {string} keyData - 密钥数据
|
||||
* @param {Function} t - 翻译函数
|
||||
* @returns {Array} 解析后的密钥数组
|
||||
*/
|
||||
const parseChannelKeys = (keyData, t) => {
|
||||
if (!keyData) return [];
|
||||
|
||||
const trimmed = keyData.trim();
|
||||
|
||||
// 检查是否是JSON数组格式(如Vertex AI)
|
||||
if (trimmed.startsWith('[')) {
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed);
|
||||
if (Array.isArray(parsed)) {
|
||||
return parsed.map((item, index) => ({
|
||||
id: index,
|
||||
content:
|
||||
typeof item === 'string' ? item : JSON.stringify(item, null, 2),
|
||||
type: typeof item === 'string' ? 'text' : 'json',
|
||||
label: `${t('密钥')} ${index + 1}`,
|
||||
}));
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果解析失败,按普通文本处理
|
||||
console.warn('Failed to parse JSON keys:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否是多行密钥(按换行符分割)
|
||||
const lines = trimmed.split('\n').filter((line) => line.trim());
|
||||
if (lines.length > 1) {
|
||||
return lines.map((line, index) => ({
|
||||
id: index,
|
||||
content: line.trim(),
|
||||
type: 'text',
|
||||
label: `${t('密钥')} ${index + 1}`,
|
||||
}));
|
||||
}
|
||||
|
||||
// 单个密钥
|
||||
return [
|
||||
{
|
||||
id: 0,
|
||||
content: trimmed,
|
||||
type: trimmed.startsWith('{') ? 'json' : 'text',
|
||||
label: t('密钥'),
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
/**
|
||||
* 可复用的密钥显示组件
|
||||
* @param {Object} props
|
||||
* @param {string} props.keyData - 密钥数据
|
||||
* @param {boolean} props.showSuccessIcon - 是否显示成功图标
|
||||
* @param {string} props.successText - 成功文本
|
||||
* @param {boolean} props.showWarning - 是否显示安全警告
|
||||
* @param {string} props.warningText - 警告文本
|
||||
*/
|
||||
const ChannelKeyDisplay = ({
|
||||
keyData,
|
||||
showSuccessIcon = true,
|
||||
successText,
|
||||
showWarning = true,
|
||||
warningText,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const parsedKeys = parseChannelKeys(keyData, t);
|
||||
const isMultipleKeys = parsedKeys.length > 1;
|
||||
|
||||
const handleCopyAll = () => {
|
||||
copy(keyData);
|
||||
showSuccess(t('所有密钥已复制到剪贴板'));
|
||||
};
|
||||
|
||||
const handleCopyKey = (content) => {
|
||||
copy(content);
|
||||
showSuccess(t('密钥已复制到剪贴板'));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
{/* 成功状态 */}
|
||||
{showSuccessIcon && (
|
||||
<div className='flex items-center gap-2'>
|
||||
<svg
|
||||
className='w-5 h-5 text-green-600'
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
<Typography.Text strong className='text-green-700'>
|
||||
{successText || t('验证成功')}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 密钥内容 */}
|
||||
<div className='space-y-3'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<Typography.Text strong>
|
||||
{isMultipleKeys ? t('渠道密钥列表') : t('渠道密钥')}
|
||||
</Typography.Text>
|
||||
{isMultipleKeys && (
|
||||
<div className='flex items-center gap-2'>
|
||||
<Typography.Text type='tertiary' size='small'>
|
||||
{t('共 {{count}} 个密钥', { count: parsedKeys.length })}
|
||||
</Typography.Text>
|
||||
<Button
|
||||
size='small'
|
||||
type='primary'
|
||||
theme='outline'
|
||||
onClick={handleCopyAll}
|
||||
>
|
||||
{t('复制全部')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className='space-y-3 max-h-80 overflow-auto'>
|
||||
{parsedKeys.map((keyItem) => (
|
||||
<Card
|
||||
key={keyItem.id}
|
||||
className='!rounded-lg !border !border-gray-200 dark:!border-gray-700'
|
||||
>
|
||||
<div className='space-y-2'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<Typography.Text
|
||||
strong
|
||||
size='small'
|
||||
className='text-gray-700 dark:text-gray-300'
|
||||
>
|
||||
{keyItem.label}
|
||||
</Typography.Text>
|
||||
<div className='flex items-center gap-2'>
|
||||
{keyItem.type === 'json' && (
|
||||
<Tag size='small' color='blue'>
|
||||
{t('JSON')}
|
||||
</Tag>
|
||||
)}
|
||||
<Button
|
||||
size='small'
|
||||
type='primary'
|
||||
theme='outline'
|
||||
icon={
|
||||
<svg
|
||||
className='w-3 h-3'
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path d='M8 3a1 1 0 011-1h2a1 1 0 110 2H9a1 1 0 01-1-1z' />
|
||||
<path d='M6 3a2 2 0 00-2 2v11a2 2 0 002 2h8a2 2 0 002-2V5a2 2 0 00-2-2 3 3 0 01-3 3H9a3 3 0 01-3-3z' />
|
||||
</svg>
|
||||
}
|
||||
onClick={() => handleCopyKey(keyItem.content)}
|
||||
>
|
||||
{t('复制')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='bg-gray-50 dark:bg-gray-800 rounded-lg p-3 max-h-40 overflow-auto'>
|
||||
<Typography.Text
|
||||
code
|
||||
className='text-xs font-mono break-all whitespace-pre-wrap text-gray-800 dark:text-gray-200'
|
||||
>
|
||||
{keyItem.content}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
|
||||
{keyItem.type === 'json' && (
|
||||
<Typography.Text
|
||||
type='tertiary'
|
||||
size='small'
|
||||
className='block'
|
||||
>
|
||||
{t('JSON格式密钥,请确保格式正确')}
|
||||
</Typography.Text>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{isMultipleKeys && (
|
||||
<div className='bg-blue-50 dark:bg-blue-900 rounded-lg p-3'>
|
||||
<Typography.Text
|
||||
type='tertiary'
|
||||
size='small'
|
||||
className='text-blue-700 dark:text-blue-300'
|
||||
>
|
||||
<svg
|
||||
className='w-4 h-4 inline mr-1'
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
{t(
|
||||
'检测到多个密钥,您可以单独复制每个密钥,或点击复制全部获取完整内容。',
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 安全警告 */}
|
||||
{showWarning && (
|
||||
<div className='bg-yellow-50 dark:bg-yellow-900 rounded-lg p-4'>
|
||||
<div className='flex items-start'>
|
||||
<svg
|
||||
className='w-5 h-5 text-yellow-600 dark:text-yellow-400 mt-0.5 mr-3 flex-shrink-0'
|
||||
fill='currentColor'
|
||||
viewBox='0 0 20 20'
|
||||
>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
<div>
|
||||
<Typography.Text
|
||||
strong
|
||||
className='text-yellow-800 dark:text-yellow-200'
|
||||
>
|
||||
{t('安全提醒')}
|
||||
</Typography.Text>
|
||||
<Typography.Text className='block text-yellow-700 dark:text-yellow-300 text-sm mt-1'>
|
||||
{warningText ||
|
||||
t(
|
||||
'请妥善保管密钥信息,不要泄露给他人。如有安全疑虑,请及时更换密钥。',
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChannelKeyDisplay;
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Button } from '@douyinfe/semi-ui';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
|
||||
/**
|
||||
* 紧凑模式切换按钮组件
|
||||
* 用于在自适应列表和紧凑列表之间切换
|
||||
* 在移动端时自动隐藏,因为移动端使用"显示操作项"按钮来控制内容显示
|
||||
*/
|
||||
const CompactModeToggle = ({
|
||||
compactMode,
|
||||
setCompactMode,
|
||||
t,
|
||||
size = 'small',
|
||||
type = 'tertiary',
|
||||
className = '',
|
||||
...props
|
||||
}) => {
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
// 在移动端隐藏紧凑列表切换按钮
|
||||
if (isMobile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
type={type}
|
||||
size={size}
|
||||
className={`w-full md:w-auto ${className}`}
|
||||
onClick={() => setCompactMode(!compactMode)}
|
||||
{...props}
|
||||
>
|
||||
{compactMode ? t('自适应列表') : t('紧凑列表')}
|
||||
</Button>
|
||||
);
|
||||
};
|
||||
|
||||
CompactModeToggle.propTypes = {
|
||||
compactMode: PropTypes.bool.isRequired,
|
||||
setCompactMode: PropTypes.func.isRequired,
|
||||
t: PropTypes.func.isRequired,
|
||||
size: PropTypes.string,
|
||||
type: PropTypes.string,
|
||||
className: PropTypes.string,
|
||||
};
|
||||
|
||||
export default CompactModeToggle;
|
||||
@@ -0,0 +1,716 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Typography,
|
||||
Banner,
|
||||
Tabs,
|
||||
TabPane,
|
||||
Card,
|
||||
Input,
|
||||
InputNumber,
|
||||
Switch,
|
||||
TextArea,
|
||||
Row,
|
||||
Col,
|
||||
Divider,
|
||||
Tooltip,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { IconPlus, IconDelete, IconAlertTriangle } from '@douyinfe/semi-icons';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 唯一 ID 生成器,确保在组件生命周期内稳定且递增
|
||||
const generateUniqueId = (() => {
|
||||
let counter = 0;
|
||||
return () => `kv_${counter++}`;
|
||||
})();
|
||||
|
||||
const JSONEditor = ({
|
||||
value = '',
|
||||
onChange,
|
||||
field,
|
||||
label,
|
||||
placeholder,
|
||||
extraText,
|
||||
extraFooter,
|
||||
showClear = true,
|
||||
template,
|
||||
templateLabel,
|
||||
editorType = 'keyValue',
|
||||
rules = [],
|
||||
formApi = null,
|
||||
...props
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// 将对象转换为键值对数组(包含唯一ID)
|
||||
const objectToKeyValueArray = useCallback((obj, prevPairs = []) => {
|
||||
if (!obj || typeof obj !== 'object') return [];
|
||||
|
||||
const entries = Object.entries(obj);
|
||||
return entries.map(([key, value], index) => {
|
||||
// 如果上一次转换后同位置的键一致,则沿用其 id,保持 React key 稳定
|
||||
const prev = prevPairs[index];
|
||||
const shouldReuseId = prev && prev.key === key;
|
||||
return {
|
||||
id: shouldReuseId ? prev.id : generateUniqueId(),
|
||||
key,
|
||||
value,
|
||||
};
|
||||
});
|
||||
}, []);
|
||||
|
||||
// 将键值对数组转换为对象(重复键时后面的会覆盖前面的)
|
||||
const keyValueArrayToObject = useCallback((arr) => {
|
||||
const result = {};
|
||||
arr.forEach((item) => {
|
||||
if (item.key) {
|
||||
result[item.key] = item.value;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}, []);
|
||||
|
||||
// 初始化键值对数组
|
||||
const [keyValuePairs, setKeyValuePairs] = useState(() => {
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
return objectToKeyValueArray(parsed);
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
return objectToKeyValueArray(value);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
// 手动模式下的本地文本缓冲
|
||||
const [manualText, setManualText] = useState(() => {
|
||||
if (typeof value === 'string') return value;
|
||||
if (value && typeof value === 'object')
|
||||
return JSON.stringify(value, null, 2);
|
||||
return '';
|
||||
});
|
||||
|
||||
// 根据键数量决定默认编辑模式
|
||||
const [editMode, setEditMode] = useState(() => {
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
try {
|
||||
const parsed = JSON.parse(value);
|
||||
const keyCount = Object.keys(parsed).length;
|
||||
return keyCount > 10 ? 'manual' : 'visual';
|
||||
} catch (error) {
|
||||
return 'manual';
|
||||
}
|
||||
}
|
||||
return 'visual';
|
||||
});
|
||||
|
||||
const [jsonError, setJsonError] = useState('');
|
||||
|
||||
// 计算重复的键
|
||||
const duplicateKeys = useMemo(() => {
|
||||
const keyCount = {};
|
||||
const duplicates = new Set();
|
||||
|
||||
keyValuePairs.forEach((pair) => {
|
||||
if (pair.key) {
|
||||
keyCount[pair.key] = (keyCount[pair.key] || 0) + 1;
|
||||
if (keyCount[pair.key] > 1) {
|
||||
duplicates.add(pair.key);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return duplicates;
|
||||
}, [keyValuePairs]);
|
||||
|
||||
// 数据同步 - 当value变化时更新键值对数组
|
||||
useEffect(() => {
|
||||
try {
|
||||
let parsed = {};
|
||||
if (typeof value === 'string' && value.trim()) {
|
||||
parsed = JSON.parse(value);
|
||||
} else if (typeof value === 'object' && value !== null) {
|
||||
parsed = value;
|
||||
}
|
||||
|
||||
// 只在外部值真正改变时更新,避免循环更新
|
||||
const currentObj = keyValueArrayToObject(keyValuePairs);
|
||||
if (JSON.stringify(parsed) !== JSON.stringify(currentObj)) {
|
||||
setKeyValuePairs(objectToKeyValueArray(parsed, keyValuePairs));
|
||||
}
|
||||
setJsonError('');
|
||||
} catch (error) {
|
||||
console.log('JSON解析失败:', error.message);
|
||||
setJsonError(error.message);
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
// 外部 value 变化时,若不在手动模式,则同步手动文本
|
||||
useEffect(() => {
|
||||
if (editMode !== 'manual') {
|
||||
if (typeof value === 'string') setManualText(value);
|
||||
else if (value && typeof value === 'object')
|
||||
setManualText(JSON.stringify(value, null, 2));
|
||||
else setManualText('');
|
||||
}
|
||||
}, [value, editMode]);
|
||||
|
||||
// 处理可视化编辑的数据变化
|
||||
const handleVisualChange = useCallback(
|
||||
(newPairs) => {
|
||||
setKeyValuePairs(newPairs);
|
||||
const jsonObject = keyValueArrayToObject(newPairs);
|
||||
const jsonString =
|
||||
Object.keys(jsonObject).length === 0
|
||||
? ''
|
||||
: JSON.stringify(jsonObject, null, 2);
|
||||
|
||||
setJsonError('');
|
||||
|
||||
// 通过formApi设置值
|
||||
if (formApi && field) {
|
||||
formApi.setValue(field, jsonString);
|
||||
}
|
||||
|
||||
onChange?.(jsonString);
|
||||
},
|
||||
[onChange, formApi, field, keyValueArrayToObject],
|
||||
);
|
||||
|
||||
// 处理手动编辑的数据变化
|
||||
const handleManualChange = useCallback(
|
||||
(newValue) => {
|
||||
setManualText(newValue);
|
||||
if (newValue && newValue.trim()) {
|
||||
try {
|
||||
const parsed = JSON.parse(newValue);
|
||||
setKeyValuePairs(objectToKeyValueArray(parsed, keyValuePairs));
|
||||
setJsonError('');
|
||||
onChange?.(newValue);
|
||||
} catch (error) {
|
||||
setJsonError(error.message);
|
||||
}
|
||||
} else {
|
||||
setKeyValuePairs([]);
|
||||
setJsonError('');
|
||||
onChange?.('');
|
||||
}
|
||||
},
|
||||
[onChange, objectToKeyValueArray, keyValuePairs],
|
||||
);
|
||||
|
||||
// 切换编辑模式
|
||||
const toggleEditMode = useCallback(() => {
|
||||
if (editMode === 'visual') {
|
||||
const jsonObject = keyValueArrayToObject(keyValuePairs);
|
||||
setManualText(
|
||||
Object.keys(jsonObject).length === 0
|
||||
? ''
|
||||
: JSON.stringify(jsonObject, null, 2),
|
||||
);
|
||||
setEditMode('manual');
|
||||
} else {
|
||||
try {
|
||||
let parsed = {};
|
||||
if (manualText && manualText.trim()) {
|
||||
parsed = JSON.parse(manualText);
|
||||
} else if (typeof value === 'string' && value.trim()) {
|
||||
parsed = JSON.parse(value);
|
||||
} else if (typeof value === 'object' && value !== null) {
|
||||
parsed = value;
|
||||
}
|
||||
setKeyValuePairs(objectToKeyValueArray(parsed, keyValuePairs));
|
||||
setJsonError('');
|
||||
setEditMode('visual');
|
||||
} catch (error) {
|
||||
setJsonError(error.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, [
|
||||
editMode,
|
||||
value,
|
||||
manualText,
|
||||
keyValuePairs,
|
||||
keyValueArrayToObject,
|
||||
objectToKeyValueArray,
|
||||
]);
|
||||
|
||||
// 添加键值对
|
||||
const addKeyValue = useCallback(() => {
|
||||
const newPairs = [...keyValuePairs];
|
||||
const existingKeys = newPairs.map((p) => p.key);
|
||||
let counter = 1;
|
||||
let newKey = `field_${counter}`;
|
||||
while (existingKeys.includes(newKey)) {
|
||||
counter += 1;
|
||||
newKey = `field_${counter}`;
|
||||
}
|
||||
newPairs.push({
|
||||
id: generateUniqueId(),
|
||||
key: newKey,
|
||||
value: '',
|
||||
});
|
||||
handleVisualChange(newPairs);
|
||||
}, [keyValuePairs, handleVisualChange]);
|
||||
|
||||
// 删除键值对
|
||||
const removeKeyValue = useCallback(
|
||||
(id) => {
|
||||
const newPairs = keyValuePairs.filter((pair) => pair.id !== id);
|
||||
handleVisualChange(newPairs);
|
||||
},
|
||||
[keyValuePairs, handleVisualChange],
|
||||
);
|
||||
|
||||
// 更新键名
|
||||
const updateKey = useCallback(
|
||||
(id, newKey) => {
|
||||
const newPairs = keyValuePairs.map((pair) =>
|
||||
pair.id === id ? { ...pair, key: newKey } : pair,
|
||||
);
|
||||
handleVisualChange(newPairs);
|
||||
},
|
||||
[keyValuePairs, handleVisualChange],
|
||||
);
|
||||
|
||||
// 更新值
|
||||
const updateValue = useCallback(
|
||||
(id, newValue) => {
|
||||
const newPairs = keyValuePairs.map((pair) =>
|
||||
pair.id === id ? { ...pair, value: newValue } : pair,
|
||||
);
|
||||
handleVisualChange(newPairs);
|
||||
},
|
||||
[keyValuePairs, handleVisualChange],
|
||||
);
|
||||
|
||||
// 填入模板
|
||||
const fillTemplate = useCallback(() => {
|
||||
if (template) {
|
||||
const templateString = JSON.stringify(template, null, 2);
|
||||
|
||||
if (formApi && field) {
|
||||
formApi.setValue(field, templateString);
|
||||
}
|
||||
|
||||
setManualText(templateString);
|
||||
setKeyValuePairs(objectToKeyValueArray(template, keyValuePairs));
|
||||
onChange?.(templateString);
|
||||
setJsonError('');
|
||||
}
|
||||
}, [
|
||||
template,
|
||||
onChange,
|
||||
formApi,
|
||||
field,
|
||||
objectToKeyValueArray,
|
||||
keyValuePairs,
|
||||
]);
|
||||
|
||||
// 渲染值输入控件(支持嵌套)
|
||||
const renderValueInput = (pairId, value) => {
|
||||
const valueType = typeof value;
|
||||
|
||||
if (valueType === 'boolean') {
|
||||
return (
|
||||
<div className='flex items-center'>
|
||||
<Switch
|
||||
checked={value}
|
||||
onChange={(newValue) => updateValue(pairId, newValue)}
|
||||
/>
|
||||
<Text type='tertiary' className='ml-2'>
|
||||
{value ? t('true') : t('false')}
|
||||
</Text>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (valueType === 'number') {
|
||||
return (
|
||||
<InputNumber
|
||||
value={value}
|
||||
onChange={(newValue) => updateValue(pairId, newValue)}
|
||||
style={{ width: '100%' }}
|
||||
placeholder={t('输入数字')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (valueType === 'object' && value !== null) {
|
||||
// 简化嵌套对象的处理,使用TextArea
|
||||
return (
|
||||
<TextArea
|
||||
rows={2}
|
||||
value={JSON.stringify(value, null, 2)}
|
||||
onChange={(txt) => {
|
||||
try {
|
||||
const obj = txt.trim() ? JSON.parse(txt) : {};
|
||||
updateValue(pairId, obj);
|
||||
} catch {
|
||||
// 忽略解析错误
|
||||
}
|
||||
}}
|
||||
placeholder={t('输入JSON对象')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// 字符串或其他原始类型
|
||||
return (
|
||||
<Input
|
||||
placeholder={t('参数值')}
|
||||
value={String(value)}
|
||||
onChange={(newValue) => {
|
||||
let convertedValue = newValue;
|
||||
if (newValue === 'true') convertedValue = true;
|
||||
else if (newValue === 'false') convertedValue = false;
|
||||
else if (!isNaN(newValue) && newValue !== '') {
|
||||
const num = Number(newValue);
|
||||
// 检查是否为整数
|
||||
if (Number.isInteger(num)) {
|
||||
convertedValue = num;
|
||||
}
|
||||
}
|
||||
updateValue(pairId, convertedValue);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染键值对编辑器
|
||||
const renderKeyValueEditor = () => {
|
||||
return (
|
||||
<div className='space-y-1'>
|
||||
{/* 重复键警告 */}
|
||||
{duplicateKeys.size > 0 && (
|
||||
<Banner
|
||||
type='warning'
|
||||
icon={<IconAlertTriangle />}
|
||||
description={
|
||||
<div>
|
||||
<Text strong>{t('存在重复的键名:')}</Text>
|
||||
<Text>{Array.from(duplicateKeys).join(', ')}</Text>
|
||||
<br />
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('注意:JSON中重复的键只会保留最后一个同名键的值')}
|
||||
</Text>
|
||||
</div>
|
||||
}
|
||||
className='mb-3'
|
||||
/>
|
||||
)}
|
||||
|
||||
{keyValuePairs.length === 0 && (
|
||||
<div className='text-center py-6 px-4'>
|
||||
<Text type='tertiary' className='text-gray-500 text-sm'>
|
||||
{t('暂无数据,点击下方按钮添加键值对')}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{keyValuePairs.map((pair, index) => {
|
||||
const isDuplicate = duplicateKeys.has(pair.key);
|
||||
const isLastDuplicate =
|
||||
isDuplicate &&
|
||||
keyValuePairs.slice(index + 1).every((p) => p.key !== pair.key);
|
||||
|
||||
return (
|
||||
<Row key={pair.id} gutter={8} align='middle'>
|
||||
<Col span={10}>
|
||||
<div className='relative'>
|
||||
<Input
|
||||
placeholder={t('键名')}
|
||||
value={pair.key}
|
||||
onChange={(newKey) => updateKey(pair.id, newKey)}
|
||||
status={isDuplicate ? 'warning' : undefined}
|
||||
/>
|
||||
{isDuplicate && (
|
||||
<Tooltip
|
||||
content={
|
||||
isLastDuplicate
|
||||
? t('这是重复键中的最后一个,其值将被使用')
|
||||
: t('重复的键名,此值将被后面的同名键覆盖')
|
||||
}
|
||||
>
|
||||
<IconAlertTriangle
|
||||
className='absolute right-2 top-1/2 transform -translate-y-1/2'
|
||||
style={{
|
||||
color: isLastDuplicate
|
||||
? 'var(--semi-color-danger)'
|
||||
: 'var(--semi-color-warning)',
|
||||
fontSize: '14px',
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={12}>{renderValueInput(pair.id, pair.value)}</Col>
|
||||
<Col span={2}>
|
||||
<Button
|
||||
icon={<IconDelete />}
|
||||
type='danger'
|
||||
theme='borderless'
|
||||
onClick={() => removeKeyValue(pair.id)}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
);
|
||||
})}
|
||||
|
||||
<div className='mt-2 flex justify-center'>
|
||||
<Button
|
||||
icon={<IconPlus />}
|
||||
type='primary'
|
||||
theme='outline'
|
||||
onClick={addKeyValue}
|
||||
>
|
||||
{t('添加键值对')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染区域编辑器(特殊格式)- 也需要改造以支持重复键
|
||||
const renderRegionEditor = () => {
|
||||
const defaultPair = keyValuePairs.find((pair) => pair.key === 'default');
|
||||
const modelPairs = keyValuePairs.filter((pair) => pair.key !== 'default');
|
||||
|
||||
return (
|
||||
<div className='space-y-2'>
|
||||
{/* 重复键警告 */}
|
||||
{duplicateKeys.size > 0 && (
|
||||
<Banner
|
||||
type='warning'
|
||||
icon={<IconAlertTriangle />}
|
||||
description={
|
||||
<div>
|
||||
<Text strong>{t('存在重复的键名:')}</Text>
|
||||
<Text>{Array.from(duplicateKeys).join(', ')}</Text>
|
||||
<br />
|
||||
<Text type='tertiary' size='small'>
|
||||
{t('注意:JSON中重复的键只会保留最后一个同名键的值')}
|
||||
</Text>
|
||||
</div>
|
||||
}
|
||||
className='mb-3'
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 默认区域 */}
|
||||
<Form.Slot label={t('默认区域')}>
|
||||
<Input
|
||||
placeholder={t('默认区域,如: us-central1')}
|
||||
value={defaultPair ? defaultPair.value : ''}
|
||||
onChange={(value) => {
|
||||
if (defaultPair) {
|
||||
updateValue(defaultPair.id, value);
|
||||
} else {
|
||||
const newPairs = [
|
||||
...keyValuePairs,
|
||||
{
|
||||
id: generateUniqueId(),
|
||||
key: 'default',
|
||||
value: value,
|
||||
},
|
||||
];
|
||||
handleVisualChange(newPairs);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</Form.Slot>
|
||||
|
||||
{/* 模型专用区域 */}
|
||||
<Form.Slot label={t('模型专用区域')}>
|
||||
<div>
|
||||
{modelPairs.map((pair) => {
|
||||
const isDuplicate = duplicateKeys.has(pair.key);
|
||||
return (
|
||||
<Row key={pair.id} gutter={8} align='middle' className='mb-2'>
|
||||
<Col span={10}>
|
||||
<div className='relative'>
|
||||
<Input
|
||||
placeholder={t('模型名称')}
|
||||
value={pair.key}
|
||||
onChange={(newKey) => updateKey(pair.id, newKey)}
|
||||
status={isDuplicate ? 'warning' : undefined}
|
||||
/>
|
||||
{isDuplicate && (
|
||||
<Tooltip content={t('重复的键名')}>
|
||||
<IconAlertTriangle
|
||||
className='absolute right-2 top-1/2 transform -translate-y-1/2'
|
||||
style={{ color: 'var(--semi-color-warning)', fontSize: '14px' }}
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Input
|
||||
placeholder={t('区域')}
|
||||
value={pair.value}
|
||||
onChange={(newValue) => updateValue(pair.id, newValue)}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={2}>
|
||||
<Button
|
||||
icon={<IconDelete />}
|
||||
type='danger'
|
||||
theme='borderless'
|
||||
onClick={() => removeKeyValue(pair.id)}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
);
|
||||
})}
|
||||
|
||||
<div className='mt-2 flex justify-center'>
|
||||
<Button
|
||||
icon={<IconPlus />}
|
||||
onClick={addKeyValue}
|
||||
type='primary'
|
||||
theme='outline'
|
||||
>
|
||||
{t('添加模型区域')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Form.Slot>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染可视化编辑器
|
||||
const renderVisualEditor = () => {
|
||||
switch (editorType) {
|
||||
case 'region':
|
||||
return renderRegionEditor();
|
||||
case 'object':
|
||||
case 'keyValue':
|
||||
default:
|
||||
return renderKeyValueEditor();
|
||||
}
|
||||
};
|
||||
|
||||
const hasJsonError = jsonError && jsonError.trim() !== '';
|
||||
|
||||
return (
|
||||
<Form.Slot label={label}>
|
||||
<Card
|
||||
header={
|
||||
<div className='flex justify-between items-center'>
|
||||
<Tabs
|
||||
type='slash'
|
||||
activeKey={editMode}
|
||||
onChange={(key) => {
|
||||
if (key === 'manual' && editMode === 'visual') {
|
||||
setEditMode('manual');
|
||||
} else if (key === 'visual' && editMode === 'manual') {
|
||||
toggleEditMode();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<TabPane tab={t('可视化')} itemKey='visual' />
|
||||
<TabPane tab={t('手动编辑')} itemKey='manual' />
|
||||
</Tabs>
|
||||
|
||||
{template && templateLabel && (
|
||||
<Button type='tertiary' onClick={fillTemplate} size='small'>
|
||||
{templateLabel}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
headerStyle={{ padding: '12px 16px' }}
|
||||
bodyStyle={{ padding: '16px' }}
|
||||
className='!rounded-2xl'
|
||||
>
|
||||
{/* JSON错误提示 */}
|
||||
{hasJsonError && (
|
||||
<Banner
|
||||
type='danger'
|
||||
description={`JSON 格式错误: ${jsonError}`}
|
||||
className='mb-3'
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 编辑器内容 */}
|
||||
{editMode === 'visual' ? (
|
||||
<div>
|
||||
{renderVisualEditor()}
|
||||
{/* 隐藏的Form字段用于验证和数据绑定 */}
|
||||
<Form.Input
|
||||
field={field}
|
||||
value={value}
|
||||
rules={rules}
|
||||
style={{ display: 'none' }}
|
||||
noLabel={true}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<TextArea
|
||||
placeholder={placeholder}
|
||||
value={manualText}
|
||||
onChange={handleManualChange}
|
||||
showClear={showClear}
|
||||
rows={Math.max(8, manualText ? manualText.split('\n').length : 8)}
|
||||
/>
|
||||
{/* 隐藏的Form字段用于验证和数据绑定 */}
|
||||
<Form.Input
|
||||
field={field}
|
||||
value={value}
|
||||
rules={rules}
|
||||
style={{ display: 'none' }}
|
||||
noLabel={true}
|
||||
{...props}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 额外文本显示在卡片底部 */}
|
||||
{extraText && (
|
||||
<Divider margin='12px' align='center'>
|
||||
<Text type='tertiary' size='small'>
|
||||
{extraText}
|
||||
</Text>
|
||||
</Divider>
|
||||
)}
|
||||
{extraFooter && <div className='mt-1'>{extraFooter}</div>}
|
||||
</Card>
|
||||
</Form.Slot>
|
||||
);
|
||||
};
|
||||
|
||||
export default JSONEditor;
|
||||
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
// 读品牌值:localStorage → window.__WL_BRAND__(index.html 内联脚本写入)→ 空。
|
||||
// 不用 getSystemName/getLogo —— 它们的终极兜底是 'Weelinking' / '/logo.svg'(老品牌),
|
||||
// 这里要严格白牌,宁可让旋转环单独转,也不能露出老标识。
|
||||
// 接 window 一层是为了和首屏 splash 对齐:冷启动 + 用户立刻进了懒路由的窗口期,
|
||||
// localStorage 还没被 /api/status 灌满,但 window 已有后端启动注入的品牌。
|
||||
const readBrand = (key, windowKey) => {
|
||||
try {
|
||||
const v = localStorage.getItem(key);
|
||||
if (v && v !== 'undefined' && v !== 'null') return v;
|
||||
} catch {
|
||||
/* 隐私模式:fall through */
|
||||
}
|
||||
if (typeof window !== 'undefined' && window.__WL_BRAND__) {
|
||||
return window.__WL_BRAND__[windowKey] || '';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
// 加载文案根据浏览器语言决定,避免 i18n 还没初始化时硬编码中文。
|
||||
const getLoadingText = () => {
|
||||
const lang = ((typeof navigator !== 'undefined' && navigator.language) || 'zh').toLowerCase();
|
||||
return lang.startsWith('zh') ? '加载中...' : 'Loading...';
|
||||
};
|
||||
|
||||
const Loading = () => {
|
||||
const systemName = readBrand('system_name', 'name');
|
||||
const logo = readBrand('logo', 'logo');
|
||||
const [logoFailed, setLogoFailed] = useState(false);
|
||||
// 防御性:同实例内 logo URL 变化(罕见,但 /api/status 在同一 Loading 生命周期内回来时可能发生),
|
||||
// 重置失败标志,避免新 URL 也被错判成"已坏"
|
||||
useEffect(() => {
|
||||
setLogoFailed(false);
|
||||
}, [logo]);
|
||||
|
||||
const loadingText = useMemo(getLoadingText, []);
|
||||
const monogram = useMemo(() => {
|
||||
const s = systemName.trim();
|
||||
return s ? Array.from(s)[0].toUpperCase() : '';
|
||||
}, [systemName]);
|
||||
|
||||
const showImg = logo && !logoFailed;
|
||||
// 没 logo 也没名字:旋转环里留空,避免出现"空着的渐变色方块"
|
||||
const showMono = !showImg && monogram;
|
||||
|
||||
return (
|
||||
<div className='wl-page-loading'>
|
||||
<div className='wl-page-box'>
|
||||
<div className='wl-page-logo-ring'>
|
||||
<span className='wl-page-logo-slot'>
|
||||
{showImg && (
|
||||
<img
|
||||
className='wl-page-logo'
|
||||
src={logo}
|
||||
alt={systemName || 'logo'}
|
||||
onError={() => setLogoFailed(true)}
|
||||
/>
|
||||
)}
|
||||
{showMono && <span className='wl-page-mono'>{monogram}</span>}
|
||||
</span>
|
||||
</div>
|
||||
{systemName && <div className='wl-page-brand'>{systemName}</div>}
|
||||
<div className='wl-page-text'>{loadingText}</div>
|
||||
</div>
|
||||
|
||||
<style>{`
|
||||
.wl-page-loading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
background: #fafbfc;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
user-select: none;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
}
|
||||
.wl-page-loading::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 420px;
|
||||
height: 420px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(
|
||||
circle,
|
||||
var(--brand-primary-soft, rgba(99, 102, 241, 0.12)),
|
||||
transparent 70%
|
||||
);
|
||||
filter: blur(24px);
|
||||
pointer-events: none;
|
||||
}
|
||||
.wl-page-box {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
animation: wl-page-fade 0.5s ease-out both;
|
||||
}
|
||||
@keyframes wl-page-fade {
|
||||
from { opacity: 0; transform: translateY(12px); }
|
||||
to { opacity: 1; transform: translateY(0); }
|
||||
}
|
||||
.wl-page-logo-ring {
|
||||
position: relative;
|
||||
width: 84px;
|
||||
height: 84px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
.wl-page-logo-ring::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: 50%;
|
||||
border: 3px solid var(--brand-primary-soft, rgba(22, 104, 220, 0.16));
|
||||
border-top-color: var(--brand-primary, #1668dc);
|
||||
animation: wl-page-spin 0.9s linear infinite;
|
||||
}
|
||||
@keyframes wl-page-spin {
|
||||
to { transform: rotate(360deg); }
|
||||
}
|
||||
.wl-page-logo-slot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
}
|
||||
.wl-page-logo {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 14px;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.wl-page-mono {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
color: #fff;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--brand-gradient-from, #4096ff),
|
||||
var(--brand-gradient-to, #0958d9)
|
||||
);
|
||||
}
|
||||
.wl-page-brand {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 1px;
|
||||
color: var(--brand-primary, #1668dc);
|
||||
margin-bottom: 14px;
|
||||
min-height: 24px;
|
||||
}
|
||||
.wl-page-text {
|
||||
font-size: 13px;
|
||||
color: #94a3b8;
|
||||
letter-spacing: 0.5px;
|
||||
animation: wl-page-blink 1.6s ease-in-out infinite;
|
||||
}
|
||||
@keyframes wl-page-blink {
|
||||
0%, 100% { opacity: 0.45; }
|
||||
50% { opacity: 1; }
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.wl-page-loading { background: #0f1115; }
|
||||
.wl-page-text { color: #64748b; }
|
||||
}
|
||||
html.dark .wl-page-loading,
|
||||
body[theme-mode='dark'] .wl-page-loading { background: #0f1115; }
|
||||
html.dark .wl-page-text,
|
||||
body[theme-mode='dark'] .wl-page-text { color: #64748b; }
|
||||
|
||||
/* 无障碍:尊重系统"减少动效"偏好 */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.wl-page-logo-ring::before,
|
||||
.wl-page-box,
|
||||
.wl-page-text {
|
||||
animation: none !important;
|
||||
}
|
||||
.wl-page-logo-ring::before {
|
||||
border-color: var(--brand-primary, #1668dc);
|
||||
opacity: 0.6;
|
||||
}
|
||||
.wl-page-text { opacity: 0.75; }
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Loading;
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { InputNumber, withField } from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getQuotaPerUnit } from '../../../helpers';
|
||||
|
||||
/**
|
||||
* 金额额度输入组件
|
||||
*
|
||||
* 对外的 value/onChange 始终使用系统内部额度单位(token,与后端一致),
|
||||
* UI 上则以人民币金额输入/展示(quotaPerUnit 额度 = ¥1,默认 500000),
|
||||
* 后端无需任何改动。
|
||||
*
|
||||
* quota_display_type = TOKENS 时退化为原始额度输入,行为与旧版一致。
|
||||
*
|
||||
* @param {number|string|null} value 内部额度值(token 单位)
|
||||
* @param {(quota:number|null)=>void} onChange 变更回调,参数为换算后的内部额度值;清空时为 null
|
||||
* @param {number} [minQuota] 最小值(token 单位)
|
||||
* @param {number} [maxQuota] 最大值(token 单位)
|
||||
* @param {string} [placeholder] 占位文案,缺省根据货币模式自动生成
|
||||
* 其余属性透传给 Semi InputNumber(size/style/disabled/prefix 等)
|
||||
*/
|
||||
|
||||
const FALLBACK_QUOTA_PER_UNIT = 500000;
|
||||
const CURRENCY_SYMBOL = '¥';
|
||||
|
||||
function getSafeQuotaPerUnit() {
|
||||
const qpu = getQuotaPerUnit();
|
||||
return Number.isFinite(qpu) && qpu > 0 ? qpu : FALLBACK_QUOTA_PER_UNIT;
|
||||
}
|
||||
|
||||
function isTokensMode() {
|
||||
return (localStorage.getItem('quota_display_type') || 'USD') === 'TOKENS';
|
||||
}
|
||||
|
||||
/** 内部额度 → 显示金额(人民币元),保留 6 位小数避免浮点噪声 */
|
||||
export function quotaToMoney(quota) {
|
||||
const n = typeof quota === 'string' ? parseFloat(quota) : quota;
|
||||
if (n === null || n === undefined || !Number.isFinite(n)) return null;
|
||||
return Number((n / getSafeQuotaPerUnit()).toFixed(6));
|
||||
}
|
||||
|
||||
/** 显示金额(人民币元)→ 内部额度(取整,支持负数) */
|
||||
export function moneyToQuota(money) {
|
||||
const n = typeof money === 'string' ? parseFloat(money) : money;
|
||||
if (n === null || n === undefined || !Number.isFinite(n)) return null;
|
||||
return Math.round(n * getSafeQuotaPerUnit());
|
||||
}
|
||||
|
||||
const QuotaInput = ({
|
||||
value,
|
||||
onChange,
|
||||
minQuota,
|
||||
maxQuota,
|
||||
placeholder,
|
||||
...rest
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const tokensMode = isTokensMode();
|
||||
|
||||
const toDisplay = (q) => {
|
||||
if (q === null || q === undefined || q === '') return null;
|
||||
if (tokensMode) {
|
||||
const n = typeof q === 'string' ? parseFloat(q) : q;
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
return quotaToMoney(q);
|
||||
};
|
||||
|
||||
const [innerValue, setInnerValue] = useState(() => toDisplay(value));
|
||||
// 记录组件自己最近一次上抛的额度值:外部值变化若并非来自本组件输入,
|
||||
// 才回写显示值,避免用户输入"1."之类中间态被换算打断
|
||||
const lastEmittedRef = useRef(
|
||||
value === null || value === undefined || value === ''
|
||||
? null
|
||||
: Number(value),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const normalized =
|
||||
value === null || value === undefined || value === ''
|
||||
? null
|
||||
: Number(value);
|
||||
if (normalized !== lastEmittedRef.current) {
|
||||
lastEmittedRef.current = normalized;
|
||||
setInnerValue(toDisplay(value));
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [value]);
|
||||
|
||||
const handleChange = (v) => {
|
||||
setInnerValue(v);
|
||||
const n = typeof v === 'string' ? parseFloat(v) : v;
|
||||
let quota;
|
||||
if (n === null || n === undefined || !Number.isFinite(n)) {
|
||||
quota = null;
|
||||
} else {
|
||||
quota = tokensMode ? Math.round(n) : moneyToQuota(n);
|
||||
}
|
||||
lastEmittedRef.current = quota;
|
||||
onChange?.(quota);
|
||||
};
|
||||
|
||||
const min =
|
||||
minQuota === undefined
|
||||
? undefined
|
||||
: tokensMode
|
||||
? minQuota
|
||||
: quotaToMoney(minQuota);
|
||||
const max =
|
||||
maxQuota === undefined
|
||||
? undefined
|
||||
: tokensMode
|
||||
? maxQuota
|
||||
: quotaToMoney(maxQuota);
|
||||
|
||||
return (
|
||||
<InputNumber
|
||||
value={innerValue}
|
||||
onChange={handleChange}
|
||||
min={min}
|
||||
max={max}
|
||||
prefix={tokensMode ? undefined : CURRENCY_SYMBOL}
|
||||
placeholder={
|
||||
placeholder ?? (tokensMode ? t('请输入额度') : t('请输入金额'))
|
||||
}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
/** Semi Form 版本:表单值仍为内部额度单位,可直接配合 field/rules 使用 */
|
||||
export const FormQuotaInput = withField(QuotaInput, {
|
||||
valueKey: 'value',
|
||||
onKeyChangeFnName: 'onChange',
|
||||
});
|
||||
|
||||
export default QuotaInput;
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Space, Tag, Typography, Popover } from '@douyinfe/semi-ui';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 通用渲染函数:限制项目数量显示,支持popover展开
|
||||
export function renderLimitedItems({ items, renderItem, maxDisplay = 3 }) {
|
||||
if (!items || items.length === 0) return '-';
|
||||
const displayItems = items.slice(0, maxDisplay);
|
||||
const remainingItems = items.slice(maxDisplay);
|
||||
return (
|
||||
<Space spacing={1} wrap>
|
||||
{displayItems.map((item, idx) => renderItem(item, idx))}
|
||||
{remainingItems.length > 0 && (
|
||||
<Popover
|
||||
content={
|
||||
<div className='p-2'>
|
||||
<Space spacing={1} wrap>
|
||||
{remainingItems.map((item, idx) => renderItem(item, idx))}
|
||||
</Space>
|
||||
</div>
|
||||
}
|
||||
position='top'
|
||||
>
|
||||
<Tag size='small' shape='circle' color='grey'>
|
||||
+{remainingItems.length}
|
||||
</Tag>
|
||||
</Popover>
|
||||
)}
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
|
||||
// 渲染描述字段,长文本支持tooltip
|
||||
export const renderDescription = (text, maxWidth = 200) => {
|
||||
return (
|
||||
<Text ellipsis={{ showTooltip: true }} style={{ maxWidth }}>
|
||||
{text || '-'}
|
||||
</Text>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,242 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, {
|
||||
useRef,
|
||||
useState,
|
||||
useEffect,
|
||||
useCallback,
|
||||
useMemo,
|
||||
useImperativeHandle,
|
||||
forwardRef,
|
||||
} from 'react';
|
||||
|
||||
/**
|
||||
* ScrollableContainer 可滚动容器组件
|
||||
*
|
||||
* 提供自动检测滚动状态和显示渐变指示器的功能
|
||||
* 当内容超出容器高度且未滚动到底部时,会显示底部渐变指示器
|
||||
*
|
||||
*/
|
||||
const ScrollableContainer = forwardRef(
|
||||
(
|
||||
{
|
||||
children,
|
||||
maxHeight = '24rem',
|
||||
className = '',
|
||||
contentClassName = '',
|
||||
fadeIndicatorClassName = '',
|
||||
checkInterval = 100,
|
||||
scrollThreshold = 5,
|
||||
debounceDelay = 16, // ~60fps
|
||||
onScroll,
|
||||
onScrollStateChange,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) => {
|
||||
const scrollRef = useRef(null);
|
||||
const containerRef = useRef(null);
|
||||
const debounceTimerRef = useRef(null);
|
||||
const resizeObserverRef = useRef(null);
|
||||
const onScrollStateChangeRef = useRef(onScrollStateChange);
|
||||
const onScrollRef = useRef(onScroll);
|
||||
|
||||
const [showScrollHint, setShowScrollHint] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
onScrollStateChangeRef.current = onScrollStateChange;
|
||||
}, [onScrollStateChange]);
|
||||
|
||||
useEffect(() => {
|
||||
onScrollRef.current = onScroll;
|
||||
}, [onScroll]);
|
||||
|
||||
const debounce = useCallback((func, delay) => {
|
||||
return (...args) => {
|
||||
if (debounceTimerRef.current) {
|
||||
clearTimeout(debounceTimerRef.current);
|
||||
}
|
||||
debounceTimerRef.current = setTimeout(() => func(...args), delay);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const checkScrollable = useCallback(() => {
|
||||
if (!scrollRef.current) return;
|
||||
|
||||
const element = scrollRef.current;
|
||||
const isScrollable = element.scrollHeight > element.clientHeight;
|
||||
const isAtBottom =
|
||||
element.scrollTop + element.clientHeight >=
|
||||
element.scrollHeight - scrollThreshold;
|
||||
const shouldShowHint = isScrollable && !isAtBottom;
|
||||
|
||||
setShowScrollHint(shouldShowHint);
|
||||
|
||||
if (onScrollStateChangeRef.current) {
|
||||
onScrollStateChangeRef.current({
|
||||
isScrollable,
|
||||
isAtBottom,
|
||||
showScrollHint: shouldShowHint,
|
||||
scrollTop: element.scrollTop,
|
||||
scrollHeight: element.scrollHeight,
|
||||
clientHeight: element.clientHeight,
|
||||
});
|
||||
}
|
||||
}, [scrollThreshold]);
|
||||
|
||||
const debouncedCheckScrollable = useMemo(
|
||||
() => debounce(checkScrollable, debounceDelay),
|
||||
[debounce, checkScrollable, debounceDelay],
|
||||
);
|
||||
|
||||
const handleScroll = useCallback(
|
||||
(e) => {
|
||||
debouncedCheckScrollable();
|
||||
if (onScrollRef.current) {
|
||||
onScrollRef.current(e);
|
||||
}
|
||||
},
|
||||
[debouncedCheckScrollable],
|
||||
);
|
||||
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
() => ({
|
||||
checkScrollable: () => {
|
||||
checkScrollable();
|
||||
},
|
||||
scrollToTop: () => {
|
||||
if (scrollRef.current) {
|
||||
scrollRef.current.scrollTop = 0;
|
||||
}
|
||||
},
|
||||
scrollToBottom: () => {
|
||||
if (scrollRef.current) {
|
||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
|
||||
}
|
||||
},
|
||||
getScrollInfo: () => {
|
||||
if (!scrollRef.current) return null;
|
||||
const element = scrollRef.current;
|
||||
return {
|
||||
scrollTop: element.scrollTop,
|
||||
scrollHeight: element.scrollHeight,
|
||||
clientHeight: element.clientHeight,
|
||||
isScrollable: element.scrollHeight > element.clientHeight,
|
||||
isAtBottom:
|
||||
element.scrollTop + element.clientHeight >=
|
||||
element.scrollHeight - scrollThreshold,
|
||||
};
|
||||
},
|
||||
}),
|
||||
[checkScrollable, scrollThreshold],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
checkScrollable();
|
||||
}, checkInterval);
|
||||
return () => clearTimeout(timer);
|
||||
}, [checkScrollable, checkInterval]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!scrollRef.current) return;
|
||||
|
||||
if (typeof ResizeObserver === 'undefined') {
|
||||
if (typeof MutationObserver !== 'undefined') {
|
||||
const observer = new MutationObserver(() => {
|
||||
debouncedCheckScrollable();
|
||||
});
|
||||
|
||||
observer.observe(scrollRef.current, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
characterData: true,
|
||||
});
|
||||
|
||||
return () => observer.disconnect();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
resizeObserverRef.current = new ResizeObserver((entries) => {
|
||||
for (const _entry of entries) {
|
||||
debouncedCheckScrollable();
|
||||
}
|
||||
});
|
||||
|
||||
resizeObserverRef.current.observe(scrollRef.current);
|
||||
|
||||
return () => {
|
||||
if (resizeObserverRef.current) {
|
||||
resizeObserverRef.current.disconnect();
|
||||
}
|
||||
};
|
||||
}, [debouncedCheckScrollable]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (debounceTimerRef.current) {
|
||||
clearTimeout(debounceTimerRef.current);
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
const containerStyle = useMemo(
|
||||
() => ({
|
||||
maxHeight,
|
||||
}),
|
||||
[maxHeight],
|
||||
);
|
||||
|
||||
const fadeIndicatorStyle = useMemo(
|
||||
() => ({
|
||||
opacity: showScrollHint ? 1 : 0,
|
||||
}),
|
||||
[showScrollHint],
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`card-content-container ${className}`}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
ref={scrollRef}
|
||||
className={`overflow-y-auto card-content-scroll ${contentClassName}`}
|
||||
style={containerStyle}
|
||||
onScroll={handleScroll}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
<div
|
||||
className={`card-content-fade-indicator ${fadeIndicatorClassName}`}
|
||||
style={fadeIndicatorStyle}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
ScrollableContainer.displayName = 'ScrollableContainer';
|
||||
|
||||
export default ScrollableContainer;
|
||||
@@ -0,0 +1,310 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useRef, useEffect } from 'react';
|
||||
import { useMinimumLoadingTime } from '../../../hooks/common/useMinimumLoadingTime';
|
||||
import { useContainerWidth } from '../../../hooks/common/useContainerWidth';
|
||||
import {
|
||||
Divider,
|
||||
Button,
|
||||
Tag,
|
||||
Row,
|
||||
Col,
|
||||
Collapsible,
|
||||
Checkbox,
|
||||
Skeleton,
|
||||
Tooltip,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { IconChevronDown, IconChevronUp } from '@douyinfe/semi-icons';
|
||||
|
||||
/**
|
||||
* 通用可选择按钮组组件
|
||||
*
|
||||
* @param {string} title 标题
|
||||
* @param {Array<{value:any,label:string,icon?:React.ReactNode,tagCount?:number}>} items 按钮项
|
||||
* @param {*|Array} activeValue 当前激活的值,可以是单个值或数组(多选)
|
||||
* @param {(value:any)=>void} onChange 选择改变回调
|
||||
* @param {function} t i18n
|
||||
* @param {object} style 额外样式
|
||||
* @param {boolean} collapsible 是否支持折叠,默认true
|
||||
* @param {number} collapseHeight 折叠时的高度,默认200
|
||||
* @param {boolean} withCheckbox 是否启用前缀 Checkbox 来控制激活状态
|
||||
* @param {boolean} loading 是否处于加载状态
|
||||
*/
|
||||
const SelectableButtonGroup = ({
|
||||
title,
|
||||
items = [],
|
||||
activeValue,
|
||||
onChange,
|
||||
t = (v) => v,
|
||||
style = {},
|
||||
collapsible = true,
|
||||
collapseHeight = 200,
|
||||
withCheckbox = false,
|
||||
loading = false,
|
||||
}) => {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [skeletonCount] = useState(12);
|
||||
const [containerRef, containerWidth] = useContainerWidth();
|
||||
|
||||
const ConditionalTooltipText = ({ text }) => {
|
||||
const textRef = useRef(null);
|
||||
const [isOverflowing, setIsOverflowing] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const el = textRef.current;
|
||||
if (!el) return;
|
||||
setIsOverflowing(el.scrollWidth > el.clientWidth);
|
||||
}, [text, containerWidth]);
|
||||
|
||||
const textElement = (
|
||||
<span ref={textRef} className='sbg-ellipsis'>
|
||||
{text}
|
||||
</span>
|
||||
);
|
||||
|
||||
return isOverflowing ? (
|
||||
<Tooltip content={text}>{textElement}</Tooltip>
|
||||
) : (
|
||||
textElement
|
||||
);
|
||||
};
|
||||
|
||||
// 基于容器宽度计算响应式列数和标签显示策略
|
||||
const getResponsiveConfig = () => {
|
||||
if (containerWidth <= 280) return { columns: 1, showTags: true }; // 极窄:1列+标签
|
||||
if (containerWidth <= 380) return { columns: 2, showTags: true }; // 窄屏:2列+标签
|
||||
if (containerWidth <= 460) return { columns: 3, showTags: false }; // 中等:3列不加标签
|
||||
return { columns: 3, showTags: true }; // 最宽:3列+标签
|
||||
};
|
||||
|
||||
const { columns: perRow, showTags: shouldShowTags } = getResponsiveConfig();
|
||||
const maxVisibleRows = Math.max(1, Math.floor(collapseHeight / 32)); // Approx row height 32
|
||||
const needCollapse = collapsible && items.length > perRow * maxVisibleRows;
|
||||
const showSkeleton = useMinimumLoadingTime(loading);
|
||||
|
||||
// 统一使用紧凑的网格间距
|
||||
const gutterSize = [4, 4];
|
||||
|
||||
// 计算 Semi UI Col 的 span 值
|
||||
const getColSpan = () => {
|
||||
return Math.floor(24 / perRow);
|
||||
};
|
||||
|
||||
const maskStyle = isOpen
|
||||
? {}
|
||||
: {
|
||||
WebkitMaskImage:
|
||||
'linear-gradient(to bottom, black 0%, rgba(0, 0, 0, 1) 60%, rgba(0, 0, 0, 0.2) 80%, transparent 100%)',
|
||||
};
|
||||
|
||||
const toggle = () => {
|
||||
setIsOpen(!isOpen);
|
||||
};
|
||||
|
||||
const linkStyle = {
|
||||
position: 'absolute',
|
||||
left: 0,
|
||||
right: 0,
|
||||
textAlign: 'center',
|
||||
bottom: -10,
|
||||
fontWeight: 400,
|
||||
cursor: 'pointer',
|
||||
fontSize: '12px',
|
||||
color: 'var(--semi-color-text-2)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
gap: 4,
|
||||
};
|
||||
|
||||
const renderSkeletonButtons = () => {
|
||||
const placeholder = (
|
||||
<Row gutter={gutterSize} style={{ lineHeight: '32px', ...style }}>
|
||||
{Array.from({ length: skeletonCount }).map((_, index) => (
|
||||
<Col span={getColSpan()} key={index}>
|
||||
<div
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '32px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'flex-start',
|
||||
border: '1px solid var(--semi-color-border)',
|
||||
borderRadius: 'var(--semi-border-radius-medium)',
|
||||
padding: '0 12px',
|
||||
gap: '6px',
|
||||
}}
|
||||
>
|
||||
{withCheckbox && (
|
||||
<Skeleton.Title active style={{ width: 14, height: 14 }} />
|
||||
)}
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{
|
||||
width: `${60 + (index % 3) * 20}px`,
|
||||
height: 14,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Col>
|
||||
))}
|
||||
</Row>
|
||||
);
|
||||
|
||||
return (
|
||||
<Skeleton loading={true} active placeholder={placeholder}></Skeleton>
|
||||
);
|
||||
};
|
||||
|
||||
const contentElement = showSkeleton ? (
|
||||
renderSkeletonButtons()
|
||||
) : (
|
||||
<Row gutter={gutterSize} style={{ lineHeight: '32px', ...style }}>
|
||||
{items.map((item) => {
|
||||
const isDisabled =
|
||||
item.disabled ||
|
||||
(typeof item.tagCount === 'number' && item.tagCount === 0);
|
||||
const isActive = Array.isArray(activeValue)
|
||||
? activeValue.includes(item.value)
|
||||
: activeValue === item.value;
|
||||
|
||||
if (withCheckbox) {
|
||||
return (
|
||||
<Col span={getColSpan()} key={item.value}>
|
||||
<Button
|
||||
onClick={() => {
|
||||
/* disabled */
|
||||
}}
|
||||
theme={isActive ? 'light' : 'outline'}
|
||||
type={isActive ? 'primary' : 'tertiary'}
|
||||
disabled={isDisabled}
|
||||
className='sbg-button'
|
||||
icon={
|
||||
<Checkbox
|
||||
checked={isActive}
|
||||
onChange={() => onChange(item.value)}
|
||||
disabled={isDisabled}
|
||||
style={{ pointerEvents: 'auto' }}
|
||||
/>
|
||||
}
|
||||
style={{ width: '100%', cursor: 'default' }}
|
||||
>
|
||||
<div className='sbg-content'>
|
||||
{item.icon && <span className='sbg-icon'>{item.icon}</span>}
|
||||
<ConditionalTooltipText text={item.label} />
|
||||
{item.tagCount !== undefined && shouldShowTags && (
|
||||
<Tag
|
||||
className='sbg-tag'
|
||||
color='white'
|
||||
shape='circle'
|
||||
size='small'
|
||||
>
|
||||
{item.tagCount}
|
||||
</Tag>
|
||||
)}
|
||||
</div>
|
||||
</Button>
|
||||
</Col>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Col span={getColSpan()} key={item.value}>
|
||||
<Button
|
||||
onClick={() => onChange(item.value)}
|
||||
theme={isActive ? 'light' : 'outline'}
|
||||
type={isActive ? 'primary' : 'tertiary'}
|
||||
disabled={isDisabled}
|
||||
className='sbg-button'
|
||||
style={{ width: '100%' }}
|
||||
>
|
||||
<div className='sbg-content'>
|
||||
{item.icon && <span className='sbg-icon'>{item.icon}</span>}
|
||||
<ConditionalTooltipText text={item.label} />
|
||||
{item.tagCount !== undefined && shouldShowTags && (
|
||||
<Tag
|
||||
className='sbg-tag'
|
||||
color='white'
|
||||
shape='circle'
|
||||
size='small'
|
||||
>
|
||||
{item.tagCount}
|
||||
</Tag>
|
||||
)}
|
||||
</div>
|
||||
</Button>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`mb-8 ${containerWidth <= 400 ? 'sbg-compact' : ''}`}
|
||||
ref={containerRef}
|
||||
>
|
||||
{title && (
|
||||
<Divider margin='12px' align='left'>
|
||||
{showSkeleton ? (
|
||||
<Skeleton.Title active style={{ width: 80, height: 14 }} />
|
||||
) : (
|
||||
title
|
||||
)}
|
||||
</Divider>
|
||||
)}
|
||||
{needCollapse && !showSkeleton ? (
|
||||
<div style={{ position: 'relative' }}>
|
||||
<Collapsible
|
||||
isOpen={isOpen}
|
||||
collapseHeight={collapseHeight}
|
||||
style={{ ...maskStyle }}
|
||||
>
|
||||
{contentElement}
|
||||
</Collapsible>
|
||||
{isOpen ? null : (
|
||||
<div onClick={toggle} style={{ ...linkStyle }}>
|
||||
<IconChevronDown size='small' />
|
||||
<span>{t('展开更多')}</span>
|
||||
</div>
|
||||
)}
|
||||
{isOpen && (
|
||||
<div
|
||||
onClick={toggle}
|
||||
style={{
|
||||
...linkStyle,
|
||||
position: 'static',
|
||||
marginTop: 8,
|
||||
bottom: 'auto',
|
||||
}}
|
||||
>
|
||||
<IconChevronUp size='small' />
|
||||
<span>{t('收起')}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
contentElement
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SelectableButtonGroup;
|
||||
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Avatar, Button } from '@douyinfe/semi-ui';
|
||||
import {
|
||||
MessageCircle,
|
||||
Sparkles,
|
||||
ScanLine,
|
||||
Zap,
|
||||
ArrowRight,
|
||||
} from 'lucide-react';
|
||||
import { API } from '../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
/**
|
||||
* 自定义 Hook:获取客服展示数据
|
||||
* 供父组件使用,避免多个 CustomerServiceQRCard 实例重复请求
|
||||
*/
|
||||
export const useCustomerServiceDisplay = () => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [agent, setAgent] = useState(null);
|
||||
const [hasConfig, setHasConfig] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchCustomerService = async () => {
|
||||
try {
|
||||
// 先检查是否有启用的客服配置
|
||||
const configRes = await API.get('/api/customer-service/config');
|
||||
if (configRes.data.success && configRes.data.data?.enabled) {
|
||||
setHasConfig(true);
|
||||
|
||||
// 使用专门的展示接口获取客服信息(只读,不增加会话计数)
|
||||
const agentRes = await API.get('/api/customer-service/display');
|
||||
if (agentRes.data.success && agentRes.data.data) {
|
||||
setAgent(agentRes.data.data);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// 静默处理错误,不显示给用户
|
||||
console.error('Failed to fetch customer service:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchCustomerService();
|
||||
}, []);
|
||||
|
||||
// 检查客服是否至少有一种联系方式
|
||||
const hasContactMethod = agent && (agent.qrcode_url || agent.wecom_url);
|
||||
// 是否应该显示客服卡片
|
||||
const showCard = !loading && hasConfig && !!agent && !!hasContactMethod;
|
||||
|
||||
return { loading, agent, hasConfig, showCard };
|
||||
};
|
||||
|
||||
/**
|
||||
* 客服二维码卡片组件(紧凑版)
|
||||
* 用于在密钥管理页面侧边栏展示客服二维码,引导用户添加客服咨询
|
||||
*
|
||||
* @param {Object} props
|
||||
* @param {Object} props.agent - 客服信息(由父组件通过 useCustomerServiceDisplay 获取后传入)
|
||||
*/
|
||||
const CustomerServiceQRCard = ({ agent }) => {
|
||||
const { t } = useTranslation();
|
||||
const [qrcodeError, setQrcodeError] = useState(false);
|
||||
|
||||
// 如果没有客服数据,不显示组件
|
||||
if (!agent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 处理二维码加载失败
|
||||
const handleQrcodeError = () => {
|
||||
console.warn('QR code image failed to load:', agent.qrcode_url);
|
||||
setQrcodeError(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='relative group/card'>
|
||||
{/* 卡片外发光 */}
|
||||
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from/20 via-brand-via/20 to-pink-500/20 rounded-[18px] blur-sm opacity-0 group-hover/card:opacity-100 transition-opacity duration-500' />
|
||||
|
||||
<div className='relative bg-white/80 dark:bg-neutral-900/80 backdrop-blur-xl rounded-2xl border border-gray-200/60 dark:border-neutral-800/60 overflow-hidden shadow-sm hover:shadow-lg transition-all duration-300'>
|
||||
{/* 顶部渐变装饰条 */}
|
||||
<div className='h-1 bg-gradient-to-r from-brand-from via-brand-via to-pink-500' />
|
||||
|
||||
<div className='p-4'>
|
||||
{/* 标题 + 客服信息 合并为一行 */}
|
||||
<div className='flex items-center gap-2.5 mb-3'>
|
||||
{agent.avatar ? (
|
||||
<div className='relative'>
|
||||
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from to-brand-to rounded-full opacity-60 blur-[2px]' />
|
||||
<Avatar
|
||||
src={agent.avatar}
|
||||
size='small'
|
||||
className='relative !w-9 !h-9 border-2 border-white dark:border-neutral-800 flex-shrink-0'
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<div className='relative'>
|
||||
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from to-brand-to rounded-full opacity-60 blur-[2px]' />
|
||||
<div className='relative w-9 h-9 rounded-full bg-gradient-to-br from-brand-from to-brand-to flex items-center justify-center text-white font-bold text-xs flex-shrink-0'>
|
||||
{agent.name ? (
|
||||
agent.name.charAt(0)
|
||||
) : (
|
||||
<MessageCircle size={16} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className='flex-1 min-w-0'>
|
||||
<div className='flex items-center gap-1.5'>
|
||||
<span className='font-semibold text-sm text-gray-900 dark:text-white truncate'>
|
||||
{agent.name || t('专属客服')}
|
||||
</span>
|
||||
<span className='inline-flex items-center gap-1 px-1.5 py-0.5 bg-emerald-50 dark:bg-emerald-900/20 text-emerald-600 dark:text-emerald-400 rounded-full text-[10px] font-medium flex-shrink-0'>
|
||||
<span className='w-1 h-1 bg-emerald-500 rounded-full animate-pulse'></span>
|
||||
{t('在线')}
|
||||
</span>
|
||||
</div>
|
||||
<p className='text-[11px] text-gray-400 dark:text-gray-500 mt-0.5'>
|
||||
{t('1对1 密钥配置指导')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 提示文案 - 吸引用户扫码 */}
|
||||
<div className='relative mb-3 overflow-hidden rounded-xl'>
|
||||
{/* 动态渐变背景 */}
|
||||
<div className='absolute inset-0 bg-gradient-to-r from-brand-from via-brand-via to-pink-500 opacity-[0.08] dark:opacity-[0.15]' />
|
||||
<div className='absolute inset-0 bg-gradient-to-br from-amber-400/10 to-transparent' />
|
||||
<div className='relative px-3 py-2.5 border border-brand/50 dark:border-brand-deep/30 rounded-xl'>
|
||||
<div className='flex items-start gap-2'>
|
||||
<div className='flex-shrink-0 mt-0.5'>
|
||||
<div className='w-5 h-5 rounded-md bg-gradient-to-br from-amber-400 to-orange-500 flex items-center justify-center shadow-sm shadow-amber-400/30'>
|
||||
<Zap size={11} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex-1 min-w-0'>
|
||||
<p className='text-xs font-medium text-gray-800 dark:text-gray-200 leading-relaxed'>
|
||||
{t('创建密钥后不知道怎么用?')}
|
||||
</p>
|
||||
<p className='text-[11px] text-brand-deep dark:text-brand-from font-medium mt-0.5 flex items-center gap-1'>
|
||||
<Sparkles
|
||||
size={10}
|
||||
className='text-amber-500 flex-shrink-0'
|
||||
/>
|
||||
{t('扫码咨询获取帮助')}
|
||||
<ArrowRight
|
||||
size={10}
|
||||
className='animate-bounce-x flex-shrink-0'
|
||||
style={{
|
||||
animation: 'bounce-x 1.5s ease-in-out infinite',
|
||||
}}
|
||||
/>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<style>{`
|
||||
@keyframes bounce-x {
|
||||
0%, 100% { transform: translateX(0); }
|
||||
50% { transform: translateX(3px); }
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
|
||||
{/* 二维码或联系方式 */}
|
||||
{agent.qrcode_url && !qrcodeError ? (
|
||||
<div className='flex flex-col items-center'>
|
||||
{/* 二维码 */}
|
||||
<div className='relative w-full group/qr'>
|
||||
<div className='absolute -inset-0.5 bg-gradient-to-br from-brand-from/20 via-brand-via/20 to-pink-400/20 rounded-xl blur opacity-0 group-hover/qr:opacity-100 transition-opacity duration-300' />
|
||||
<div className='relative w-full p-3 bg-white dark:bg-neutral-800/50 rounded-xl border border-gray-100 dark:border-neutral-700/50 shadow-inner'>
|
||||
<img
|
||||
src={agent.qrcode_url}
|
||||
alt={t('客服二维码')}
|
||||
className='w-full aspect-square object-contain rounded-lg'
|
||||
onError={handleQrcodeError}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className='mt-2.5 flex items-center gap-1.5 px-3 py-1.5 bg-gradient-to-r from-brand-from/5 to-brand-to/5 dark:from-brand-from/20 dark:to-brand-to/20 rounded-full'>
|
||||
<ScanLine
|
||||
size={12}
|
||||
className='text-brand dark:text-brand-from'
|
||||
/>
|
||||
<span className='text-xs font-medium text-brand-deep dark:text-brand-from'>
|
||||
{t('微信扫码添加客服')}
|
||||
</span>
|
||||
</div>
|
||||
{/* 备用企业微信按钮 */}
|
||||
{agent.wecom_url && (
|
||||
<Button
|
||||
theme='light'
|
||||
type='tertiary'
|
||||
size='small'
|
||||
icon={<MessageCircle size={12} />}
|
||||
onClick={() => window.open(agent.wecom_url, '_blank')}
|
||||
className='w-full !rounded-lg mt-2 !text-xs'
|
||||
>
|
||||
{t('或点击联系企微')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
) : agent.wecom_url ? (
|
||||
/* 降级方案 */
|
||||
<div className='text-center'>
|
||||
{qrcodeError && (
|
||||
<div className='mb-2 p-2 bg-amber-50 dark:bg-amber-900/20 rounded-lg'>
|
||||
<p className='text-[11px] text-amber-600 dark:text-amber-400'>
|
||||
{t('二维码加载失败,请点击下方按钮')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
icon={<MessageCircle size={14} />}
|
||||
onClick={() => window.open(agent.wecom_url, '_blank')}
|
||||
className='w-full !bg-gradient-to-r !from-brand-from !to-brand-to hover:!from-brand-from hover:!to-brand-to !rounded-xl'
|
||||
>
|
||||
{t('联系客服')}
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CustomerServiceQRCard;
|
||||
@@ -0,0 +1,515 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import {
|
||||
Avatar,
|
||||
Tag,
|
||||
Spin,
|
||||
Empty,
|
||||
Button,
|
||||
Typography,
|
||||
Tooltip,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
MessageCircle,
|
||||
X,
|
||||
ChevronRight,
|
||||
Users,
|
||||
RefreshCw,
|
||||
Headphones,
|
||||
QrCode,
|
||||
Sparkles,
|
||||
MessageSquareMore,
|
||||
} from 'lucide-react';
|
||||
import { API } from '../../helpers';
|
||||
import { getServerURL } from '../../helpers/config';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import './styles.css';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 本地存储 key
|
||||
const COLLAPSED_STORAGE_KEY = 'cs-collapsed';
|
||||
// 在线客服列表停留时的轮询间隔
|
||||
const ONLINE_POLL_INTERVAL = 15000;
|
||||
|
||||
const CustomerServiceFloat = () => {
|
||||
const { t } = useTranslation();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [isCollapsed, setIsCollapsed] = useState(() => {
|
||||
// 从本地存储读取收起状态
|
||||
return localStorage.getItem(COLLAPSED_STORAGE_KEY) === 'true';
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [currentAgent, setCurrentAgent] = useState(null);
|
||||
const [agentList, setAgentList] = useState([]);
|
||||
const [showAgentList, setShowAgentList] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
const [qrcodeError, setQrcodeError] = useState(false);
|
||||
const [config, setConfig] = useState({ enabled: false });
|
||||
|
||||
// 当前持有 +1 会话计数的客服 id(仅 /allocate 会自增计数)
|
||||
const allocatedIdRef = useRef(null);
|
||||
// isOpen 的同步镜像,用于异步回调里判断面板是否已被关闭
|
||||
const isOpenRef = useRef(false);
|
||||
// 容器(点击外部关闭)、面板(打开时聚焦)、触发器(关闭后归还焦点)
|
||||
const containerRef = useRef(null);
|
||||
const panelRef = useRef(null);
|
||||
const triggerRef = useRef(null);
|
||||
|
||||
// 结束当前持有的会话计数(精确释放 /allocate 自增的那一次)
|
||||
const endAllocatedSession = useCallback(({ beacon = false } = {}) => {
|
||||
const id = allocatedIdRef.current;
|
||||
if (!id) return;
|
||||
allocatedIdRef.current = null;
|
||||
const path = `/api/customer-service/end/${id}`;
|
||||
// 页面卸载场景用 sendBeacon,保证请求能在 unload 时发出(该接口公开、仅读 URL 参数)
|
||||
if (beacon && typeof navigator !== 'undefined' && navigator.sendBeacon) {
|
||||
try {
|
||||
navigator.sendBeacon(`${getServerURL()}${path}`);
|
||||
return;
|
||||
} catch {
|
||||
/* 退回普通请求 */
|
||||
}
|
||||
}
|
||||
API.post(path).catch(() => {});
|
||||
}, []);
|
||||
|
||||
// 切换收起状态
|
||||
const toggleCollapse = (e) => {
|
||||
e.stopPropagation();
|
||||
const newState = !isCollapsed;
|
||||
setIsCollapsed(newState);
|
||||
localStorage.setItem(COLLAPSED_STORAGE_KEY, String(newState));
|
||||
};
|
||||
|
||||
// 展开并打开面板
|
||||
const handleExpand = () => {
|
||||
if (isCollapsed) {
|
||||
setIsCollapsed(false);
|
||||
localStorage.setItem(COLLAPSED_STORAGE_KEY, 'false');
|
||||
}
|
||||
setIsOpen(true);
|
||||
};
|
||||
|
||||
// 获取客服配置
|
||||
const fetchConfig = useCallback(async () => {
|
||||
try {
|
||||
const res = await API.get('/api/customer-service/config');
|
||||
if (res.data.success) {
|
||||
setConfig(res.data.data);
|
||||
}
|
||||
} catch (err) {
|
||||
// 静默失败
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchConfig();
|
||||
}, [fetchConfig]);
|
||||
|
||||
// 获取分配的客服(会让后端 current_sessions +1)
|
||||
const fetchAllocatedAgent = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const res = await API.get(
|
||||
'/api/customer-service/allocate?strategy=weighted',
|
||||
);
|
||||
if (res.data.success && res.data.data) {
|
||||
const agent = res.data.data;
|
||||
// 竞态保护:如果分配返回前面板已关闭,立即释放刚分配的计数,不缓存
|
||||
if (!isOpenRef.current) {
|
||||
API.post(`/api/customer-service/end/${agent.id}`).catch(() => {});
|
||||
return;
|
||||
}
|
||||
setCurrentAgent(agent);
|
||||
allocatedIdRef.current = agent.id;
|
||||
setQrcodeError(false);
|
||||
} else {
|
||||
setError(res.data.message || t('暂无可用客服'));
|
||||
}
|
||||
} catch (err) {
|
||||
setError(t('获取客服失败,请重试'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [t]);
|
||||
|
||||
// 获取所有在线客服。silent=true 用于后台轮询,不触发整屏 loading(避免列表闪烁)
|
||||
const fetchOnlineAgents = useCallback(async ({ silent = false } = {}) => {
|
||||
if (!silent) setLoading(true);
|
||||
try {
|
||||
const res = await API.get('/api/customer-service/online');
|
||||
if (res.data.success) {
|
||||
setAgentList(res.data.data || []);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('获取客服列表失败', err);
|
||||
} finally {
|
||||
if (!silent) setLoading(false);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 打开面板时自动获取客服(已缓存则不重复分配)
|
||||
useEffect(() => {
|
||||
if (isOpen && !currentAgent && !showAgentList) {
|
||||
fetchAllocatedAgent();
|
||||
}
|
||||
}, [isOpen, currentAgent, showAgentList, fetchAllocatedAgent]);
|
||||
|
||||
// 在线列表停留期间轮询刷新,避免展示已下线/已满的客服
|
||||
useEffect(() => {
|
||||
if (!isOpen || !showAgentList) return;
|
||||
const timer = setInterval(
|
||||
() => fetchOnlineAgents({ silent: true }),
|
||||
ONLINE_POLL_INTERVAL,
|
||||
);
|
||||
return () => clearInterval(timer);
|
||||
}, [isOpen, showAgentList, fetchOnlineAgents]);
|
||||
|
||||
// 选择客服(仅展示,不触发 /allocate,因此不占用计数)
|
||||
const selectAgent = (agent) => {
|
||||
setCurrentAgent(agent);
|
||||
setShowAgentList(false);
|
||||
setQrcodeError(false);
|
||||
};
|
||||
|
||||
// 切换客服:先释放当前会话计数,再展示在线列表
|
||||
const switchAgent = () => {
|
||||
endAllocatedSession();
|
||||
setCurrentAgent(null);
|
||||
setShowAgentList(true);
|
||||
fetchOnlineAgents();
|
||||
};
|
||||
|
||||
// 关闭面板:乐观关闭(不等待网络),释放会话计数,但保留已分配客服以便下次秒开
|
||||
const handleClose = useCallback(() => {
|
||||
endAllocatedSession();
|
||||
setIsOpen(false);
|
||||
setShowAgentList(false);
|
||||
// 归还焦点到触发按钮(无障碍)
|
||||
requestAnimationFrame(() => triggerRef.current?.focus?.());
|
||||
}, [endAllocatedSession]);
|
||||
|
||||
// ESC 关闭 + 点击面板外部关闭
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const onKeyDown = (e) => {
|
||||
if (e.key === 'Escape') handleClose();
|
||||
};
|
||||
const onPointerDown = (e) => {
|
||||
if (containerRef.current && !containerRef.current.contains(e.target)) {
|
||||
handleClose();
|
||||
}
|
||||
};
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
document.addEventListener('mousedown', onPointerDown);
|
||||
return () => {
|
||||
document.removeEventListener('keydown', onKeyDown);
|
||||
document.removeEventListener('mousedown', onPointerDown);
|
||||
};
|
||||
}, [isOpen, handleClose]);
|
||||
|
||||
// 打开后将焦点移入面板(无障碍);同时同步 isOpenRef 供异步回调判断
|
||||
useEffect(() => {
|
||||
isOpenRef.current = isOpen;
|
||||
if (isOpen) {
|
||||
requestAnimationFrame(() => panelRef.current?.focus?.());
|
||||
}
|
||||
}, [isOpen]);
|
||||
|
||||
// 页面卸载 / 组件卸载时兜底释放会话计数,避免计数泄漏
|
||||
useEffect(() => {
|
||||
const onPageHide = () => endAllocatedSession({ beacon: true });
|
||||
window.addEventListener('pagehide', onPageHide);
|
||||
return () => {
|
||||
window.removeEventListener('pagehide', onPageHide);
|
||||
endAllocatedSession();
|
||||
};
|
||||
}, [endAllocatedSession]);
|
||||
|
||||
const getStatusTag = (status) => {
|
||||
const statusMap = {
|
||||
1: { text: t('在线'), color: 'green' },
|
||||
2: { text: t('忙碌'), color: 'orange' },
|
||||
0: { text: t('离线'), color: 'grey' },
|
||||
};
|
||||
const s = statusMap[status] || statusMap[0];
|
||||
return (
|
||||
<Tag color={s.color} size='small'>
|
||||
{s.text}
|
||||
</Tag>
|
||||
);
|
||||
};
|
||||
|
||||
// 如果没有启用客服,不显示
|
||||
if (!config.enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hasQrcode = currentAgent?.qrcode_url && !qrcodeError;
|
||||
const hasContact = hasQrcode || currentAgent?.wecom_url;
|
||||
|
||||
return (
|
||||
<div className='customer-service-container' ref={containerRef}>
|
||||
{/* 移动端遮罩:点击关闭(桌面端通过点击外部关闭,遮罩隐藏不挡操作) */}
|
||||
{isOpen && (
|
||||
<div className='cs-backdrop' onClick={handleClose} aria-hidden='true' />
|
||||
)}
|
||||
|
||||
{/* 收起状态 - 边缘小标签 */}
|
||||
{!isOpen && isCollapsed && (
|
||||
<Tooltip content={t('联系客服')} position='left'>
|
||||
<button
|
||||
className='cs-collapsed-tab'
|
||||
onClick={handleExpand}
|
||||
ref={triggerRef}
|
||||
aria-label={t('联系客服')}
|
||||
>
|
||||
<div className='cs-collapsed-icon'>
|
||||
<MessageSquareMore size={18} strokeWidth={2.5} />
|
||||
</div>
|
||||
<div className='cs-collapsed-indicator' />
|
||||
</button>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
{/* 展开状态的浮动按钮 - 精美客服图标 */}
|
||||
{!isOpen && !isCollapsed && (
|
||||
<div className='cs-float-wrapper'>
|
||||
<button
|
||||
className='cs-float-button cs-has-pulse'
|
||||
onClick={handleExpand}
|
||||
ref={triggerRef}
|
||||
aria-label={t('联系客服')}
|
||||
>
|
||||
{/* 装饰性光环 */}
|
||||
<div className='cs-glow-ring' />
|
||||
<div className='cs-glow-ring cs-glow-ring-2' />
|
||||
|
||||
{/* 主图标 */}
|
||||
<div className='cs-icon-wrapper'>
|
||||
<Headphones size={26} strokeWidth={2} />
|
||||
</div>
|
||||
|
||||
{/* 在线状态指示器 */}
|
||||
<div className='cs-online-indicator'>
|
||||
<div className='cs-online-dot' />
|
||||
</div>
|
||||
|
||||
{/* 悬浮文字提示 */}
|
||||
<div className='cs-float-label'>
|
||||
<span>{t('在线客服')}</span>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
{/* 收起按钮 */}
|
||||
<button
|
||||
className='cs-collapse-btn'
|
||||
onClick={toggleCollapse}
|
||||
title={t('收起')}
|
||||
aria-label={t('收起')}
|
||||
>
|
||||
<ChevronRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 展开的客服面板 */}
|
||||
<div
|
||||
className={`cs-panel ${isOpen ? 'cs-panel-open' : ''}`}
|
||||
role='dialog'
|
||||
aria-label={t('在线客服')}
|
||||
aria-hidden={!isOpen}
|
||||
/* 关闭时让面板内子元素(关闭按钮等)从 Tab 序列与可达性树中移除,
|
||||
避免键盘焦点跑进屏幕外的隐藏面板(也消除 aria-hidden 含焦点元素的告警) */
|
||||
inert={!isOpen ? '' : undefined}
|
||||
tabIndex={-1}
|
||||
ref={panelRef}
|
||||
>
|
||||
{/* 头部 - 渐变背景 */}
|
||||
<div className='cs-panel-header'>
|
||||
<div className='cs-header-content'>
|
||||
<div className='cs-header-icon'>
|
||||
<Headphones size={20} />
|
||||
</div>
|
||||
<div className='cs-header-text'>
|
||||
<span className='cs-header-title'>{t('在线客服')}</span>
|
||||
<span className='cs-header-subtitle'>{t('随时为您服务')}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='cs-panel-actions'>
|
||||
{currentAgent && (
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
icon={<Users size={14} />}
|
||||
onClick={switchAgent}
|
||||
style={{
|
||||
color: 'white',
|
||||
background: 'rgba(255,255,255,0.2)',
|
||||
borderRadius: '10px',
|
||||
}}
|
||||
>
|
||||
{t('切换')}
|
||||
</Button>
|
||||
)}
|
||||
<button
|
||||
className='cs-close-btn'
|
||||
onClick={handleClose}
|
||||
aria-label={t('关闭')}
|
||||
>
|
||||
<X size={18} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 内容区 */}
|
||||
<div className='cs-panel-content'>
|
||||
{loading ? (
|
||||
<div className='cs-loading'>
|
||||
<Spin size='large' />
|
||||
<p className='cs-loading-text'>{t('正在为您分配客服...')}</p>
|
||||
</div>
|
||||
) : error ? (
|
||||
<div className='cs-error'>
|
||||
<Empty title={t('暂无可用客服')} description={error} />
|
||||
<Button
|
||||
icon={<RefreshCw size={14} />}
|
||||
onClick={fetchAllocatedAgent}
|
||||
style={{ marginTop: 16 }}
|
||||
>
|
||||
{t('重新获取')}
|
||||
</Button>
|
||||
</div>
|
||||
) : showAgentList ? (
|
||||
/* 客服选择列表 */
|
||||
<div className='cs-agent-list'>
|
||||
<p className='cs-list-title'>{t('请选择客服')}</p>
|
||||
{agentList.length === 0 ? (
|
||||
<Empty description={t('暂无在线客服')} />
|
||||
) : (
|
||||
agentList.map((agent) => (
|
||||
<div
|
||||
key={agent.id}
|
||||
className='cs-agent-item'
|
||||
onClick={() => selectAgent(agent)}
|
||||
>
|
||||
<Avatar
|
||||
src={agent.avatar}
|
||||
size='small'
|
||||
style={{ marginRight: 12, backgroundColor: '#87d068' }}
|
||||
>
|
||||
{agent.name?.[0]}
|
||||
</Avatar>
|
||||
<div className='cs-agent-info'>
|
||||
<span className='cs-agent-name'>{agent.name}</span>
|
||||
{getStatusTag(agent.status)}
|
||||
</div>
|
||||
<span className='cs-agent-busy'>
|
||||
{agent.current_sessions}/{agent.max_sessions}
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
) : currentAgent ? (
|
||||
/* 客服聊天界面 */
|
||||
<div className='cs-chat-container'>
|
||||
{/* 当前客服信息 */}
|
||||
<div className='cs-current-agent'>
|
||||
<Avatar
|
||||
src={currentAgent.avatar}
|
||||
size='small'
|
||||
style={{ backgroundColor: '#87d068' }}
|
||||
>
|
||||
{currentAgent.name?.[0]}
|
||||
</Avatar>
|
||||
<span style={{ marginLeft: 8 }}>{currentAgent.name}</span>
|
||||
{getStatusTag(currentAgent.status)}
|
||||
</div>
|
||||
|
||||
{/* 客服内容 */}
|
||||
{hasContact ? (
|
||||
<div className='cs-contact-container'>
|
||||
{/* 二维码区域 */}
|
||||
{hasQrcode && (
|
||||
<div className='cs-qrcode'>
|
||||
<div className='cs-qrcode-label'>
|
||||
<QrCode size={16} />
|
||||
<span>{t('扫码联系客服')}</span>
|
||||
</div>
|
||||
<img
|
||||
src={currentAgent.qrcode_url}
|
||||
alt={t('客服二维码')}
|
||||
className='cs-qrcode-img'
|
||||
onError={() => setQrcodeError(true)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 跳转按钮区域 */}
|
||||
{currentAgent.wecom_url && (
|
||||
<div className='cs-wecom-link'>
|
||||
{hasQrcode && (
|
||||
<div className='cs-divider'>
|
||||
<span>{t('或')}</span>
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
className='cs-wecom-btn'
|
||||
onClick={() =>
|
||||
window.open(currentAgent.wecom_url, '_blank')
|
||||
}
|
||||
>
|
||||
<MessageCircle size={18} />
|
||||
{t('打开微信客服')}
|
||||
<Sparkles size={14} />
|
||||
</button>
|
||||
<Text
|
||||
type='tertiary'
|
||||
size='small'
|
||||
style={{ marginTop: 12, opacity: 0.7 }}
|
||||
>
|
||||
{t('点击后将跳转至微信')}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className='cs-no-contact'>
|
||||
<Empty
|
||||
description={
|
||||
qrcodeError
|
||||
? t('二维码加载失败,请稍后重试')
|
||||
: t('客服信息配置不完整')
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CustomerServiceFloat;
|
||||
@@ -0,0 +1,970 @@
|
||||
/* 客服容器 */
|
||||
.customer-service-container {
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
/* 遮罩:桌面端隐藏(点击外部由 JS 处理,不阻挡页面操作),
|
||||
移动端显示暗色遮罩,点击可关闭底部抽屉 */
|
||||
.cs-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1001;
|
||||
display: none;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
@media (max-width: 767.98px) {
|
||||
.cs-backdrop {
|
||||
display: block;
|
||||
background: rgba(0, 0, 0, 0.45);
|
||||
-webkit-backdrop-filter: blur(2px);
|
||||
backdrop-filter: blur(2px);
|
||||
animation: cs-backdrop-in 0.3s ease;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes cs-backdrop-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
收起状态 - 边缘小标签
|
||||
======================================== */
|
||||
.cs-collapsed-tab {
|
||||
position: fixed;
|
||||
bottom: 120px;
|
||||
right: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 48px;
|
||||
padding: 0;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--brand-gradient-from) 0%,
|
||||
var(--brand-gradient-to) 100%
|
||||
);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 12px 0 0 12px;
|
||||
cursor: pointer;
|
||||
box-shadow:
|
||||
-4px 0 15px color-mix(in srgb, var(--brand-primary) 30%, transparent),
|
||||
inset 1px 0 0 rgba(255, 255, 255, 0.2);
|
||||
transition: all 0.3s cubic-bezier(0.34, 0.69, 0.1, 1);
|
||||
z-index: 1001;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.cs-collapsed-tab::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
rgba(255, 255, 255, 0.15) 0%,
|
||||
transparent 50%
|
||||
);
|
||||
border-radius: 12px 0 0 12px;
|
||||
}
|
||||
|
||||
.cs-collapsed-tab:hover {
|
||||
width: 48px;
|
||||
box-shadow:
|
||||
-6px 0 20px color-mix(in srgb, var(--brand-primary) 40%, transparent),
|
||||
inset 1px 0 0 rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
|
||||
.cs-collapsed-icon {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
animation: cs-collapsed-bounce 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes cs-collapsed-bounce {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
50% {
|
||||
transform: translateX(-3px);
|
||||
}
|
||||
}
|
||||
|
||||
.cs-collapsed-indicator {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
background: #10b981;
|
||||
border-radius: 50%;
|
||||
box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
|
||||
animation: cs-indicator-blink 1.5s infinite;
|
||||
}
|
||||
|
||||
@keyframes cs-indicator-blink {
|
||||
0%,
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
浮动按钮包装器
|
||||
======================================== */
|
||||
.cs-float-wrapper {
|
||||
position: fixed;
|
||||
bottom: 32px;
|
||||
right: 32px;
|
||||
z-index: 1001;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
悬浮按钮 - 精美客服图标设计
|
||||
======================================== */
|
||||
.cs-float-button {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
padding: 0;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--brand-gradient-from) 0%,
|
||||
var(--brand-gradient-to) 100%
|
||||
);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 22px;
|
||||
cursor: pointer;
|
||||
box-shadow:
|
||||
0 8px 32px color-mix(in srgb, var(--brand-primary) 35%, transparent),
|
||||
0 0 0 0 color-mix(in srgb, var(--brand-primary) 40%, transparent),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
transition: all 0.4s cubic-bezier(0.34, 0.69, 0.1, 1);
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.cs-float-button::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
rgba(255, 255, 255, 0.25) 0%,
|
||||
transparent 60%
|
||||
);
|
||||
border-radius: 22px;
|
||||
}
|
||||
|
||||
.cs-float-button::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: radial-gradient(
|
||||
circle at 30% 30%,
|
||||
rgba(255, 255, 255, 0.35) 0%,
|
||||
transparent 50%
|
||||
);
|
||||
border-radius: 22px;
|
||||
}
|
||||
|
||||
.cs-float-button:hover {
|
||||
transform: translateY(-6px) scale(1.08);
|
||||
box-shadow:
|
||||
0 16px 40px color-mix(in srgb, var(--brand-primary) 45%, transparent),
|
||||
0 0 0 6px color-mix(in srgb, var(--brand-primary) 12%, transparent),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.3);
|
||||
border-radius: 24px;
|
||||
}
|
||||
|
||||
.cs-float-button:hover .cs-float-label {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.cs-float-button:active {
|
||||
transform: translateY(-3px) scale(1.04);
|
||||
}
|
||||
|
||||
/* 光环效果 */
|
||||
.cs-glow-ring {
|
||||
position: absolute;
|
||||
inset: -6px;
|
||||
border: 2px solid color-mix(in srgb, var(--brand-primary) 30%, transparent);
|
||||
border-radius: 28px;
|
||||
animation: cs-glow-pulse 3s ease-in-out infinite;
|
||||
}
|
||||
|
||||
.cs-glow-ring-2 {
|
||||
inset: -12px;
|
||||
border-color: color-mix(in srgb, var(--brand-primary) 15%, transparent);
|
||||
border-radius: 34px;
|
||||
animation-delay: 0.5s;
|
||||
}
|
||||
|
||||
@keyframes cs-glow-pulse {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
transform: scale(1.05);
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
/* 悬浮按钮图标容器 */
|
||||
.cs-float-button .cs-icon-wrapper {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.cs-float-button:hover .cs-icon-wrapper {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
/* 脉冲动画 */
|
||||
.cs-float-button.cs-has-pulse {
|
||||
animation: cs-button-breathe 4s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes cs-button-breathe {
|
||||
0%,
|
||||
100% {
|
||||
box-shadow:
|
||||
0 8px 32px color-mix(in srgb, var(--brand-primary) 35%, transparent),
|
||||
0 0 0 0 color-mix(in srgb, var(--brand-primary) 40%, transparent),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
50% {
|
||||
box-shadow:
|
||||
0 12px 36px color-mix(in srgb, var(--brand-primary) 40%, transparent),
|
||||
0 0 0 4px color-mix(in srgb, var(--brand-primary) 15%, transparent),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
/* 在线状态指示器 */
|
||||
.cs-online-indicator {
|
||||
position: absolute;
|
||||
top: -4px;
|
||||
right: -4px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
|
||||
border: 3px solid white;
|
||||
border-radius: 50%;
|
||||
box-shadow:
|
||||
0 2px 8px rgba(16, 185, 129, 0.5),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.3);
|
||||
z-index: 3;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.cs-online-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
background: white;
|
||||
border-radius: 50%;
|
||||
animation: cs-dot-pulse 1.5s infinite;
|
||||
}
|
||||
|
||||
@keyframes cs-dot-pulse {
|
||||
0%,
|
||||
100% {
|
||||
transform: scale(1);
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
transform: scale(0.8);
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
/* 悬浮文字提示 */
|
||||
.cs-float-label {
|
||||
position: absolute;
|
||||
right: calc(100% + 12px);
|
||||
top: 50%;
|
||||
transform: translateY(-50%) translateX(10px);
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
backdrop-filter: blur(10px);
|
||||
padding: 8px 14px;
|
||||
border-radius: 10px;
|
||||
box-shadow:
|
||||
0 4px 20px rgba(0, 0, 0, 0.1),
|
||||
0 0 0 1px color-mix(in srgb, var(--brand-primary) 10%, transparent);
|
||||
white-space: nowrap;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: all 0.3s cubic-bezier(0.34, 0.69, 0.1, 1);
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.cs-float-label span {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--brand-primary);
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--brand-gradient-from) 0%,
|
||||
var(--brand-gradient-to) 100%
|
||||
);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.cs-float-label::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
right: -6px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
border: 6px solid transparent;
|
||||
border-left-color: rgba(255, 255, 255, 0.95);
|
||||
}
|
||||
|
||||
.dark .cs-float-label {
|
||||
background: rgba(30, 30, 30, 0.95);
|
||||
box-shadow:
|
||||
0 4px 20px rgba(0, 0, 0, 0.3),
|
||||
0 0 0 1px rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.dark .cs-float-label::after {
|
||||
border-left-color: rgba(30, 30, 30, 0.95);
|
||||
}
|
||||
|
||||
/* 收起按钮 */
|
||||
.cs-collapse-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
backdrop-filter: blur(10px);
|
||||
color: var(--brand-primary);
|
||||
border: 1px solid color-mix(in srgb, var(--brand-primary) 20%, transparent);
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s;
|
||||
opacity: 0;
|
||||
transform: translateX(10px);
|
||||
}
|
||||
|
||||
.cs-float-wrapper:hover .cs-collapse-btn {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.cs-collapse-btn:hover {
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--brand-gradient-from) 0%,
|
||||
var(--brand-gradient-to) 100%
|
||||
);
|
||||
color: white;
|
||||
border-color: transparent;
|
||||
transform: translateX(4px);
|
||||
}
|
||||
|
||||
.dark .cs-collapse-btn {
|
||||
background: rgba(40, 40, 40, 0.9);
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.cs-button-text {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
客服面板 - 现代玻璃态设计
|
||||
======================================== */
|
||||
.cs-panel {
|
||||
position: fixed;
|
||||
right: -420px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 380px;
|
||||
height: 580px;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
border-radius: 24px;
|
||||
box-shadow:
|
||||
0 25px 50px -12px rgba(0, 0, 0, 0.15),
|
||||
0 0 0 1px rgba(255, 255, 255, 0.1);
|
||||
transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
z-index: 1002;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
border: 1px solid color-mix(in srgb, var(--brand-primary) 10%, transparent);
|
||||
}
|
||||
|
||||
.dark .cs-panel {
|
||||
background: rgba(23, 23, 23, 0.95);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
box-shadow:
|
||||
0 25px 50px -12px rgba(0, 0, 0, 0.5),
|
||||
0 0 0 1px rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.cs-panel-open {
|
||||
right: 24px;
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
面板头部 - 渐变背景
|
||||
======================================== */
|
||||
.cs-panel-header {
|
||||
position: relative;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20px 24px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--brand-gradient-from) 0%,
|
||||
var(--brand-gradient-to) 100%
|
||||
);
|
||||
color: white;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.cs-panel-header::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: -50%;
|
||||
right: -20%;
|
||||
width: 200px;
|
||||
height: 200px;
|
||||
background: radial-gradient(
|
||||
circle,
|
||||
rgba(255, 255, 255, 0.15) 0%,
|
||||
transparent 70%
|
||||
);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.cs-panel-header::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: -30%;
|
||||
left: -10%;
|
||||
width: 150px;
|
||||
height: 150px;
|
||||
background: radial-gradient(
|
||||
circle,
|
||||
rgba(255, 255, 255, 0.1) 0%,
|
||||
transparent 70%
|
||||
);
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.cs-header-content {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.cs-header-icon {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.cs-header-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.cs-header-title {
|
||||
font-weight: 700;
|
||||
font-size: 18px;
|
||||
letter-spacing: -0.02em;
|
||||
}
|
||||
|
||||
.cs-header-subtitle {
|
||||
font-size: 12px;
|
||||
opacity: 0.8;
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.cs-panel-actions {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.cs-close-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
cursor: pointer;
|
||||
border-radius: 10px;
|
||||
color: white;
|
||||
transition: all 0.2s;
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.cs-close-btn:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
面板内容区
|
||||
======================================== */
|
||||
.cs-panel-content {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--semi-color-bg-0);
|
||||
}
|
||||
|
||||
.cs-loading {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--semi-color-text-2);
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.cs-loading-text {
|
||||
font-size: 14px;
|
||||
color: var(--semi-color-text-2);
|
||||
}
|
||||
|
||||
.cs-error {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 32px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
客服列表
|
||||
======================================== */
|
||||
.cs-agent-list {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.cs-list-title {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--semi-color-text-2);
|
||||
margin-bottom: 16px;
|
||||
padding-left: 4px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.cs-agent-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 14px 16px;
|
||||
border-radius: 16px;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s cubic-bezier(0.34, 0.69, 0.1, 1);
|
||||
margin-bottom: 10px;
|
||||
border: 1px solid transparent;
|
||||
background: var(--semi-color-fill-0);
|
||||
}
|
||||
|
||||
.cs-agent-item:hover {
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--brand-gradient-from) 8%, transparent) 0%,
|
||||
color-mix(in srgb, var(--brand-gradient-to) 8%, transparent) 100%
|
||||
);
|
||||
transform: translateX(6px);
|
||||
border-color: color-mix(in srgb, var(--brand-primary) 30%, transparent);
|
||||
box-shadow: 0 4px 12px
|
||||
color-mix(in srgb, var(--brand-primary) 10%, transparent);
|
||||
}
|
||||
|
||||
.cs-agent-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
.cs-agent-name {
|
||||
font-weight: 600;
|
||||
color: var(--semi-color-text-0);
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.cs-agent-busy {
|
||||
font-size: 12px;
|
||||
color: var(--semi-color-text-2);
|
||||
background: var(--semi-color-fill-1);
|
||||
padding: 2px 8px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
聊天容器
|
||||
======================================== */
|
||||
.cs-chat-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.cs-current-agent {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--brand-gradient-from) 5%, transparent) 0%,
|
||||
color-mix(in srgb, var(--brand-gradient-to) 5%, transparent) 100%
|
||||
);
|
||||
gap: 10px;
|
||||
border-bottom: 1px solid var(--semi-color-border);
|
||||
}
|
||||
|
||||
.cs-current-agent-avatar {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cs-current-agent-avatar .cs-agent-online {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
background: #10b981;
|
||||
border: 2px solid white;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.cs-iframe {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
二维码区域
|
||||
======================================== */
|
||||
.cs-contact-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 32px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.cs-qrcode {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 24px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
color-mix(in srgb, var(--brand-gradient-from) 5%, transparent) 0%,
|
||||
color-mix(in srgb, var(--brand-gradient-to) 5%, transparent) 100%
|
||||
);
|
||||
border-radius: 20px;
|
||||
border: 1px solid color-mix(in srgb, var(--brand-primary) 10%, transparent);
|
||||
}
|
||||
|
||||
.cs-qrcode-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 16px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--semi-color-text-1);
|
||||
}
|
||||
|
||||
.cs-qrcode-img {
|
||||
max-width: 180px;
|
||||
border-radius: 16px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
|
||||
border: 1px solid var(--semi-color-border);
|
||||
padding: 12px;
|
||||
background: white;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.cs-qrcode-img:hover {
|
||||
transform: scale(1.02);
|
||||
}
|
||||
|
||||
.cs-wecom-link {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cs-wecom-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 14px 28px;
|
||||
background: linear-gradient(
|
||||
135deg,
|
||||
var(--brand-gradient-from) 0%,
|
||||
var(--brand-gradient-to) 100%
|
||||
);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 14px;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
box-shadow: 0 4px 15px
|
||||
color-mix(in srgb, var(--brand-primary) 30%, transparent);
|
||||
}
|
||||
|
||||
.cs-wecom-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px
|
||||
color-mix(in srgb, var(--brand-primary) 40%, transparent);
|
||||
}
|
||||
|
||||
.cs-divider {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
margin: 24px 0;
|
||||
color: var(--semi-color-text-2);
|
||||
}
|
||||
|
||||
.cs-divider::before,
|
||||
.cs-divider::after {
|
||||
content: '';
|
||||
flex: 1;
|
||||
height: 1px;
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
transparent,
|
||||
var(--semi-color-border),
|
||||
transparent
|
||||
);
|
||||
}
|
||||
|
||||
.cs-divider span {
|
||||
padding: 0 16px;
|
||||
font-size: 12px;
|
||||
color: var(--semi-color-text-3);
|
||||
}
|
||||
|
||||
.cs-no-contact {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
暗黑模式适配
|
||||
======================================== */
|
||||
.dark .cs-float-button {
|
||||
box-shadow:
|
||||
0 4px 20px color-mix(in srgb, var(--brand-primary) 30%, transparent),
|
||||
0 0 0 0 color-mix(in srgb, var(--brand-primary) 30%, transparent);
|
||||
}
|
||||
|
||||
.dark .cs-float-button:hover {
|
||||
box-shadow:
|
||||
0 8px 30px color-mix(in srgb, var(--brand-primary) 40%, transparent),
|
||||
0 0 0 4px color-mix(in srgb, var(--brand-primary) 10%, transparent);
|
||||
}
|
||||
|
||||
.dark .cs-online-indicator {
|
||||
border-color: #171717;
|
||||
}
|
||||
|
||||
.dark .cs-qrcode {
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.dark .cs-qrcode-img {
|
||||
background: #1a1a1a;
|
||||
border-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
移动端适配
|
||||
======================================== */
|
||||
@media (max-width: 767.98px) {
|
||||
.cs-float-wrapper {
|
||||
/* --composer-top-offset 由聊天输入区(CustomInputRender)实测发布:
|
||||
输入区顶边到视口底部的距离。聊天页(体验中心/控制台演练场)上浮球抬到
|
||||
输入区之上,否则 90px 正好压住发送按钮;其他页面变量不存在,回退 90px。 */
|
||||
bottom: calc(var(--composer-top-offset, 78px) + 12px);
|
||||
right: 16px;
|
||||
}
|
||||
|
||||
.cs-float-button {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 18px;
|
||||
}
|
||||
|
||||
.cs-glow-ring {
|
||||
inset: -4px;
|
||||
border-radius: 22px;
|
||||
}
|
||||
|
||||
.cs-glow-ring-2 {
|
||||
inset: -8px;
|
||||
border-radius: 26px;
|
||||
}
|
||||
|
||||
.cs-float-label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cs-collapse-btn {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cs-collapsed-tab {
|
||||
bottom: calc(var(--composer-top-offset, 78px) + 72px);
|
||||
}
|
||||
|
||||
.cs-panel {
|
||||
width: 100%;
|
||||
height: 80vh;
|
||||
right: 0;
|
||||
top: auto;
|
||||
bottom: 0;
|
||||
transform: translateY(100%);
|
||||
border-radius: 28px 28px 0 0;
|
||||
opacity: 1;
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.cs-panel-open {
|
||||
right: 0;
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.cs-panel-header {
|
||||
padding: 24px;
|
||||
border-radius: 28px 28px 0 0;
|
||||
}
|
||||
|
||||
.cs-close-btn {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
动画效果
|
||||
======================================== */
|
||||
@keyframes cs-float-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(20px) scale(0.9);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0) scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.cs-float-button {
|
||||
animation: cs-float-in 0.5s cubic-bezier(0.34, 0.69, 0.1, 1);
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
降低动效偏好 - 关闭常驻/大幅动画
|
||||
======================================== */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.cs-collapsed-icon,
|
||||
.cs-collapsed-indicator,
|
||||
.cs-float-button,
|
||||
.cs-float-button.cs-has-pulse,
|
||||
.cs-glow-ring,
|
||||
.cs-glow-ring-2,
|
||||
.cs-online-dot,
|
||||
.cs-backdrop {
|
||||
animation: none !important;
|
||||
}
|
||||
|
||||
.cs-panel,
|
||||
.cs-collapsed-tab,
|
||||
.cs-float-button,
|
||||
.cs-collapse-btn,
|
||||
.cs-float-label,
|
||||
.cs-agent-item,
|
||||
.cs-qrcode-img,
|
||||
.cs-wecom-btn {
|
||||
transition-duration: 0.01ms !important;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card, Tag, Timeline, Empty } from '@douyinfe/semi-ui';
|
||||
import { Bell } from 'lucide-react';
|
||||
import { marked } from 'marked';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const AnnouncementsPanel = ({
|
||||
announcementData,
|
||||
announcementLegendData,
|
||||
CARD_PROPS,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='shadow-sm !rounded-2xl lg:col-span-2'
|
||||
title={
|
||||
<div className='flex flex-col lg:flex-row lg:items-center lg:justify-between gap-2 w-full'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Bell size={16} />
|
||||
{t('系统公告')}
|
||||
<Tag color='white' shape='circle'>
|
||||
{t('显示最新20条')}
|
||||
</Tag>
|
||||
</div>
|
||||
{/* 图例 */}
|
||||
<div className='flex flex-wrap gap-3 text-xs'>
|
||||
{announcementLegendData.map((legend, index) => (
|
||||
<div key={index} className='flex items-center gap-1'>
|
||||
<div
|
||||
className='w-2 h-2 rounded-full'
|
||||
style={{
|
||||
backgroundColor:
|
||||
legend.color === 'grey'
|
||||
? '#8b9aa7'
|
||||
: legend.color === 'blue'
|
||||
? '#3b82f6'
|
||||
: legend.color === 'green'
|
||||
? '#10b981'
|
||||
: legend.color === 'orange'
|
||||
? '#f59e0b'
|
||||
: legend.color === 'red'
|
||||
? '#ef4444'
|
||||
: '#8b9aa7',
|
||||
}}
|
||||
/>
|
||||
<span className='text-gray-600'>{legend.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{announcementData.length > 0 ? (
|
||||
<Timeline mode='left'>
|
||||
{announcementData.map((item, idx) => {
|
||||
const htmlExtra = item.extra ? marked.parse(item.extra) : '';
|
||||
return (
|
||||
<Timeline.Item
|
||||
key={idx}
|
||||
type={item.type || 'default'}
|
||||
time={`${item.relative ? item.relative + ' ' : ''}${item.time}`}
|
||||
extra={
|
||||
item.extra ? (
|
||||
<div
|
||||
className='text-xs text-gray-500'
|
||||
dangerouslySetInnerHTML={{ __html: htmlExtra }}
|
||||
/>
|
||||
) : null
|
||||
}
|
||||
>
|
||||
<div>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: marked.parse(item.content || ''),
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Timeline.Item>
|
||||
);
|
||||
})}
|
||||
</Timeline>
|
||||
) : (
|
||||
<div className='flex justify-center items-center py-8'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无系统公告')}
|
||||
description={t('请联系管理员在系统设置中配置公告信息')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ScrollableContainer>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default AnnouncementsPanel;
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card, Avatar, Tag, Divider, Empty } from '@douyinfe/semi-ui';
|
||||
import { Server, Gauge, ExternalLink } from 'lucide-react';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const ApiInfoPanel = ({
|
||||
apiInfoData,
|
||||
handleCopyUrl,
|
||||
handleSpeedTest,
|
||||
CARD_PROPS,
|
||||
FLEX_CENTER_GAP2,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='bg-gray-50 border-0 !rounded-2xl'
|
||||
title={
|
||||
<div className={FLEX_CENTER_GAP2}>
|
||||
<Server size={16} />
|
||||
{t('API信息')}
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{apiInfoData.length > 0 ? (
|
||||
apiInfoData.map((api) => (
|
||||
<React.Fragment key={api.id}>
|
||||
<div className='flex p-2 hover:bg-white rounded-lg transition-colors cursor-pointer'>
|
||||
<div className='flex-shrink-0 mr-3'>
|
||||
<Avatar size='extra-small' color={api.color}>
|
||||
{api.route.substring(0, 2)}
|
||||
</Avatar>
|
||||
</div>
|
||||
<div className='flex-1'>
|
||||
<div className='flex flex-wrap items-center justify-between mb-1 w-full gap-2'>
|
||||
<span className='text-sm font-medium text-gray-900 !font-bold break-all'>
|
||||
{api.route}
|
||||
</span>
|
||||
<div className='flex items-center gap-1 mt-1 lg:mt-0'>
|
||||
<Tag
|
||||
prefixIcon={<Gauge size={12} />}
|
||||
size='small'
|
||||
color='white'
|
||||
shape='circle'
|
||||
onClick={() => handleSpeedTest(api.url)}
|
||||
className='cursor-pointer hover:opacity-80 text-xs'
|
||||
>
|
||||
{t('测速')}
|
||||
</Tag>
|
||||
<Tag
|
||||
prefixIcon={<ExternalLink size={12} />}
|
||||
size='small'
|
||||
color='white'
|
||||
shape='circle'
|
||||
onClick={() =>
|
||||
window.open(api.url, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
className='cursor-pointer hover:opacity-80 text-xs'
|
||||
>
|
||||
{t('跳转')}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className='!text-semi-color-primary break-all cursor-pointer hover:underline mb-1'
|
||||
onClick={() => handleCopyUrl(api.url)}
|
||||
>
|
||||
{api.url}
|
||||
</div>
|
||||
<div className='text-gray-500'>{api.description}</div>
|
||||
</div>
|
||||
</div>
|
||||
<Divider />
|
||||
</React.Fragment>
|
||||
))
|
||||
) : (
|
||||
<div className='flex justify-center items-center min-h-[20rem] w-full'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无API信息')}
|
||||
description={t('请联系管理员在系统设置中配置API信息')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ScrollableContainer>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default ApiInfoPanel;
|
||||
@@ -0,0 +1,339 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { AreaChart, Trophy } from 'lucide-react';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
|
||||
// 手机屏幕下的 VChart 渲染模式:桌面模式下 tooltip 依赖 hover,触屏点不出来
|
||||
const MOBILE_CHART_CONFIG = { mode: 'mobile-browser' };
|
||||
|
||||
// 手机端最多展示前 N 个模型,超出的合并成「其他」,避免图例和榜单被几十个模型撑爆
|
||||
const MOBILE_MAX_SERIES = 5;
|
||||
|
||||
// 轴标签在窄屏上截断,完整名称仍可在 tooltip 中看到
|
||||
const truncateLabel = (text, max = 12) => {
|
||||
const str = String(text ?? '');
|
||||
return str.length > max ? `${str.slice(0, max)}…` : str;
|
||||
};
|
||||
|
||||
/**
|
||||
* 把桌面版 spec 改写成手机可读的版本。
|
||||
*
|
||||
* 窄屏下的两个致命问题:
|
||||
* 1) 图例 orient:'right' 会横向吃掉一大半宽度,折线被压成一条竖带;
|
||||
* 2) 图内标题与卡片头部标题重复,白白占用本就紧张的高度。
|
||||
* 因此手机端把图例挪到底部并限制行数(多余的走翻页器),同时隐藏图内标题,
|
||||
* 「总计」改由卡片头部承载(见下方 totalText)。
|
||||
*/
|
||||
const toMobileSpec = (spec) => {
|
||||
if (!spec) return spec;
|
||||
|
||||
const next = {
|
||||
...spec,
|
||||
// 图内标题在手机端隐藏,信息由卡片头部承担
|
||||
title: { ...(spec.title || {}), visible: false },
|
||||
padding: { top: 4, right: 8, bottom: 4, left: 4 },
|
||||
};
|
||||
|
||||
if (spec.legends && spec.legends.visible !== false) {
|
||||
next.legends = {
|
||||
...spec.legends,
|
||||
orient: 'bottom',
|
||||
position: 'start',
|
||||
padding: { top: 8, left: 0, right: 0, bottom: 0 },
|
||||
maxRow: 2,
|
||||
pager: {
|
||||
textStyle: { fontSize: 10 },
|
||||
space: 4,
|
||||
},
|
||||
item: {
|
||||
...(spec.legends.item || {}),
|
||||
padding: { top: 2, bottom: 2, left: 0, right: 10 },
|
||||
shape: {
|
||||
...(spec.legends.item?.shape || {}),
|
||||
style: {
|
||||
...(spec.legends.item?.shape?.style || {}),
|
||||
symbolType: 'circle',
|
||||
size: 7,
|
||||
},
|
||||
},
|
||||
label: {
|
||||
...(spec.legends.item?.label || {}),
|
||||
style: {
|
||||
...(spec.legends.item?.label?.style || {}),
|
||||
fontSize: 10,
|
||||
},
|
||||
},
|
||||
// 长模型名(如 dreamina-seedance-2-0-260128)在窄屏必须截断,否则一条就占满一行
|
||||
maxWidth: 108,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (Array.isArray(spec.axes)) {
|
||||
next.axes = spec.axes.map((axis) => {
|
||||
if (!axis || axis.visible === false) return axis;
|
||||
const label = axis.label || {};
|
||||
return {
|
||||
...axis,
|
||||
label: {
|
||||
...label,
|
||||
style: { ...(label.style || {}), fontSize: 9 },
|
||||
// 横向柱状榜单的左轴是模型名,需要截断
|
||||
...(axis.orient === 'left' && spec.direction === 'horizontal'
|
||||
? { formatMethod: (text) => truncateLabel(text) }
|
||||
: {}),
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return next;
|
||||
};
|
||||
|
||||
/**
|
||||
* 手机端裁剪数据系列:只保留支出/调用量最高的前 N 个,其余合并为「其他」。
|
||||
*
|
||||
* - groupField:系列字段(模型名)
|
||||
* - valueField:排序与求和用的数值字段
|
||||
* - bucketField:折叠后按哪个维度分桶。走势图按时间点分桶(每个时间点一条「其他」),
|
||||
* 榜单没有第二维度,传 null 表示所有被折叠的系列合并成唯一一条。
|
||||
* 注意不要拿 spec.xField 推断——横向柱图的 xField 是度量而非维度,会导致「其他」被拆成多条。
|
||||
* - extraSumFields:除 valueField 外还需要累加的字段(如 tooltip 用的 rawQuota)
|
||||
*/
|
||||
const limitSeriesForMobile = (
|
||||
spec,
|
||||
{ groupField, valueField, bucketField = null, extraSumFields = [] },
|
||||
t,
|
||||
) => {
|
||||
const dataset = spec?.data?.[0];
|
||||
const values = dataset?.values;
|
||||
if (!Array.isArray(values) || values.length === 0) return spec;
|
||||
|
||||
const totals = new Map();
|
||||
values.forEach((row) => {
|
||||
const key = String(row?.[groupField] ?? '');
|
||||
if (!key) return;
|
||||
totals.set(key, (totals.get(key) || 0) + (Number(row?.[valueField]) || 0));
|
||||
});
|
||||
if (totals.size <= MOBILE_MAX_SERIES) return spec;
|
||||
|
||||
const keep = new Set(
|
||||
Array.from(totals.entries())
|
||||
.sort((a, b) => b[1] - a[1])
|
||||
.slice(0, MOBILE_MAX_SERIES)
|
||||
.map(([key]) => key),
|
||||
);
|
||||
|
||||
const otherLabel = t('其他');
|
||||
const merged = [];
|
||||
const otherBuckets = new Map();
|
||||
values.forEach((row) => {
|
||||
const key = String(row?.[groupField] ?? '');
|
||||
if (keep.has(key)) {
|
||||
merged.push(row);
|
||||
return;
|
||||
}
|
||||
const bucketKey = bucketField
|
||||
? String(row?.[bucketField] ?? '')
|
||||
: '__all__';
|
||||
const existing = otherBuckets.get(bucketKey);
|
||||
if (!existing) {
|
||||
otherBuckets.set(bucketKey, { ...row, [groupField]: otherLabel });
|
||||
return;
|
||||
}
|
||||
existing[valueField] =
|
||||
(Number(existing[valueField]) || 0) + (Number(row?.[valueField]) || 0);
|
||||
extraSumFields.forEach((field) => {
|
||||
existing[field] =
|
||||
(Number(existing[field]) || 0) + (Number(row?.[field]) || 0);
|
||||
});
|
||||
});
|
||||
|
||||
merged.push(...otherBuckets.values());
|
||||
|
||||
// 榜单类(无分桶维度)按数值重排,否则「其他」会固定落在末尾与排序语义冲突
|
||||
if (!bucketField) {
|
||||
merged.sort(
|
||||
(a, b) => (Number(b?.[valueField]) || 0) - (Number(a?.[valueField]) || 0),
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
...spec,
|
||||
data: [{ ...dataset, values: merged }],
|
||||
};
|
||||
};
|
||||
|
||||
// 双图配置 - 同行展示,统一品牌色系
|
||||
const BRAND_CHART_STYLE = {
|
||||
gradient: 'from-brand-from via-brand-via to-brand-to',
|
||||
glow: 'from-brand-from/20 via-brand-via/10 to-transparent',
|
||||
border: 'border-brand/15 dark:border-brand-deep/30',
|
||||
ring: 'ring-1 ring-brand/10 dark:ring-brand-from/15',
|
||||
badge:
|
||||
'bg-brand/10 dark:bg-brand-deep/40 text-brand-deep dark:text-brand-from border-brand/20 dark:border-brand-deep/40',
|
||||
};
|
||||
const CHARTS = [
|
||||
{
|
||||
key: 'consume',
|
||||
icon: AreaChart,
|
||||
label: '消费时段走势',
|
||||
sublabel: '按时间维度堆叠展示各模型支出',
|
||||
...BRAND_CHART_STYLE,
|
||||
badgeText: '面积图',
|
||||
},
|
||||
{
|
||||
key: 'pie',
|
||||
icon: Trophy,
|
||||
label: '模型调用排行',
|
||||
sublabel: '高到低排序的模型调用量榜单',
|
||||
...BRAND_CHART_STYLE,
|
||||
badgeText: '排行榜',
|
||||
},
|
||||
];
|
||||
|
||||
const ChartsPanel = ({
|
||||
spec_line,
|
||||
spec_pie,
|
||||
CHART_CONFIG,
|
||||
hasApiInfoPanel,
|
||||
t,
|
||||
}) => {
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const specs = useMemo(() => {
|
||||
if (!isMobile) {
|
||||
return { consume: spec_line, pie: spec_pie };
|
||||
}
|
||||
return {
|
||||
consume: toMobileSpec(
|
||||
limitSeriesForMobile(
|
||||
spec_line,
|
||||
{
|
||||
groupField: 'Model',
|
||||
valueField: 'Usage',
|
||||
bucketField: 'Time',
|
||||
extraSumFields: ['rawQuota'],
|
||||
},
|
||||
t,
|
||||
),
|
||||
),
|
||||
pie: toMobileSpec(
|
||||
limitSeriesForMobile(
|
||||
spec_pie,
|
||||
{ groupField: 'type', valueField: 'value', bucketField: null },
|
||||
t,
|
||||
),
|
||||
),
|
||||
};
|
||||
}, [isMobile, spec_line, spec_pie, t]);
|
||||
|
||||
// 手机端隐藏了图内标题,「总计」改挂到卡片头部,信息不丢
|
||||
const totals = {
|
||||
consume: spec_line?.title?.subtext || '',
|
||||
pie: spec_pie?.title?.subtext || '',
|
||||
};
|
||||
|
||||
const chartOption = isMobile ? MOBILE_CHART_CONFIG : CHART_CONFIG;
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`flex flex-col flex-1 min-h-0 ${hasApiInfoPanel ? 'lg:col-span-3' : ''}`}
|
||||
>
|
||||
<div className='grid grid-cols-1 xl:grid-cols-2 gap-4 flex-1 min-h-0'>
|
||||
{CHARTS.map((chart) => {
|
||||
const Icon = chart.icon;
|
||||
return (
|
||||
<div key={chart.key} className='relative flex flex-col min-h-0'>
|
||||
{/* 装饰渐变光晕 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute -inset-1 bg-gradient-to-br ${chart.glow} rounded-3xl blur-xl opacity-60`}
|
||||
/>
|
||||
|
||||
<div
|
||||
className={`relative flex-1 flex flex-col min-h-0 bg-white dark:bg-neutral-900/90 backdrop-blur-sm rounded-2xl border border-gray-100 dark:border-neutral-800 shadow-[0_2px_12px_-2px_rgba(0,0,0,0.06)] dark:shadow-[0_2px_12px_-2px_rgba(0,0,0,0.4)] overflow-hidden`}
|
||||
>
|
||||
{/* 顶部高光条 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute top-0 left-0 right-0 h-px bg-gradient-to-r ${chart.gradient} opacity-60`}
|
||||
/>
|
||||
|
||||
{/* 图表标题 + 副标题 + 类型徽章 */}
|
||||
<div className='relative flex items-center justify-between gap-3 px-4 pt-3.5 pb-2.5 shrink-0'>
|
||||
<div className='flex items-center gap-2.5 min-w-0'>
|
||||
<div
|
||||
className={`w-8 h-8 shrink-0 rounded-lg bg-gradient-to-br ${chart.gradient} flex items-center justify-center shadow-md`}
|
||||
>
|
||||
<Icon size={14} className='text-white' />
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
<h3 className='font-semibold text-gray-900 dark:text-white text-[13px] tracking-wide leading-tight'>
|
||||
{t(chart.label)}
|
||||
</h3>
|
||||
{/* 手机端图内标题被隐藏,这里改显示「总计」,其余尺寸仍显示副标题 */}
|
||||
<p className='text-[10px] text-gray-400 dark:text-gray-500 leading-tight mt-0.5 truncate'>
|
||||
{isMobile && totals[chart.key]
|
||||
? totals[chart.key]
|
||||
: t(chart.sublabel)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={`shrink-0 inline-flex items-center px-2 py-0.5 rounded-md text-[10px] font-semibold border ${chart.badge}`}
|
||||
>
|
||||
{t(chart.badgeText)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 分隔线 */}
|
||||
<div className='mx-4 h-px bg-gradient-to-r from-transparent via-gray-200/60 to-transparent dark:via-gray-700/40 shrink-0' />
|
||||
|
||||
{/* 图表区域 - flex-1 撑满剩余高度,min-h 兜底防止过矮 */}
|
||||
<div className='relative flex-1 min-h-[300px] sm:min-h-[320px] p-1.5 sm:p-3 overflow-hidden'>
|
||||
{/* 网格装饰 */}
|
||||
<div
|
||||
className='pointer-events-none absolute inset-0 opacity-[0.025] dark:opacity-[0.05]'
|
||||
style={{
|
||||
backgroundImage: `
|
||||
linear-gradient(rgba(100, 100, 100, 0.5) 1px, transparent 1px),
|
||||
linear-gradient(90deg, rgba(100, 100, 100, 0.5) 1px, transparent 1px)
|
||||
`,
|
||||
backgroundSize: '36px 36px',
|
||||
}}
|
||||
/>
|
||||
<div className='relative h-full'>
|
||||
{/* 注意是 options 复数:react-vchart 的 notSpecKeys 里只认 'options',
|
||||
写成 option 会被当成普通 prop 丢弃(原来的 option={CHART_CONFIG}
|
||||
一直是失效的),移动端 mobile-browser 触屏 tooltip 也就一直没生效 */}
|
||||
<VChart spec={specs[chart.key]} options={chartOption} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChartsPanel;
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Button } from '@douyinfe/semi-ui';
|
||||
import { RefreshCw, Search } from 'lucide-react';
|
||||
|
||||
const DashboardHeader = ({
|
||||
getGreeting,
|
||||
greetingVisible,
|
||||
showSearchModal,
|
||||
refresh,
|
||||
loading,
|
||||
t,
|
||||
}) => {
|
||||
const ICON_BUTTON_CLASS = 'text-white hover:bg-opacity-80 !rounded-full';
|
||||
|
||||
return (
|
||||
<div className='flex items-center justify-between mb-4'>
|
||||
<h2
|
||||
className='text-2xl font-semibold text-gray-800 transition-opacity duration-1000 ease-in-out'
|
||||
style={{ opacity: greetingVisible ? 1 : 0 }}
|
||||
>
|
||||
{getGreeting}
|
||||
</h2>
|
||||
<div className='flex gap-3'>
|
||||
<Button
|
||||
type='tertiary'
|
||||
icon={<Search size={16} />}
|
||||
onClick={showSearchModal}
|
||||
className={`bg-green-500 hover:bg-green-600 ${ICON_BUTTON_CLASS}`}
|
||||
/>
|
||||
<Button
|
||||
type='tertiary'
|
||||
icon={<RefreshCw size={16} />}
|
||||
onClick={refresh}
|
||||
loading={loading}
|
||||
className={`bg-blue-500 hover:bg-blue-600 ${ICON_BUTTON_CLASS}`}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DashboardHeader;
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Card, Collapse, Empty } from '@douyinfe/semi-ui';
|
||||
import { HelpCircle } from 'lucide-react';
|
||||
import { IconPlus, IconMinus } from '@douyinfe/semi-icons';
|
||||
import { marked } from 'marked';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const FaqPanel = ({
|
||||
faqData,
|
||||
CARD_PROPS,
|
||||
FLEX_CENTER_GAP2,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='shadow-sm !rounded-2xl lg:col-span-1'
|
||||
title={
|
||||
<div className={FLEX_CENTER_GAP2}>
|
||||
<HelpCircle size={16} />
|
||||
{t('常见问答')}
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{faqData.length > 0 ? (
|
||||
<Collapse
|
||||
accordion
|
||||
expandIcon={<IconPlus />}
|
||||
collapseIcon={<IconMinus />}
|
||||
>
|
||||
{faqData.map((item, index) => (
|
||||
<Collapse.Panel
|
||||
key={index}
|
||||
header={item.question}
|
||||
itemKey={index.toString()}
|
||||
>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: marked.parse(item.answer || ''),
|
||||
}}
|
||||
/>
|
||||
</Collapse.Panel>
|
||||
))}
|
||||
</Collapse>
|
||||
) : (
|
||||
<div className='flex justify-center items-center py-8'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无常见问答')}
|
||||
description={t('请联系管理员在系统设置中配置常见问答')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</ScrollableContainer>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default FaqPanel;
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Skeleton } from '@douyinfe/semi-ui';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ArrowUpRight, Wallet, TrendingUp, Zap, Clock } from 'lucide-react';
|
||||
|
||||
// 卡片调色板 —— 4 张指标卡用同一蓝色家族的冷色渐进(青→天蓝→蓝→靛),
|
||||
// 贴合云平台克制专业的观感;既能区分 4 张卡,又不像四色那样"花"。
|
||||
// 卡片本体为实底白(dark 实底深灰),强调色仅用于图标 / 顶部高光条 / 角落光斑 / 角标,
|
||||
// 既不透出页面 bg-glow 背景(解决"发灰"),又靠冷蓝 accent 提供层次。
|
||||
const CARD_PALETTES = [
|
||||
{
|
||||
// 账户 / 钱包 —— 青(cyan)
|
||||
iconBg: 'from-cyan-500 to-sky-600',
|
||||
iconShadow: 'shadow-cyan-500/25',
|
||||
glow: 'from-cyan-400/25 to-sky-300/5',
|
||||
bar: 'from-cyan-400 to-sky-500',
|
||||
badge: 'bg-cyan-50 text-cyan-600 dark:bg-cyan-500/15 dark:text-cyan-400',
|
||||
},
|
||||
{
|
||||
// 使用统计 —— 天蓝(sky)
|
||||
iconBg: 'from-sky-500 to-blue-600',
|
||||
iconShadow: 'shadow-sky-500/25',
|
||||
glow: 'from-sky-400/25 to-blue-300/5',
|
||||
bar: 'from-sky-400 to-blue-500',
|
||||
badge: 'bg-sky-50 text-sky-600 dark:bg-sky-500/15 dark:text-sky-400',
|
||||
},
|
||||
{
|
||||
// Token 消耗 —— 蓝(blue)
|
||||
iconBg: 'from-blue-500 to-indigo-600',
|
||||
iconShadow: 'shadow-blue-500/25',
|
||||
glow: 'from-blue-400/25 to-indigo-300/5',
|
||||
bar: 'from-blue-400 to-indigo-500',
|
||||
badge: 'bg-blue-50 text-blue-600 dark:bg-blue-500/15 dark:text-blue-400',
|
||||
},
|
||||
{
|
||||
// 性能指标 —— 靛(indigo)
|
||||
iconBg: 'from-indigo-500 to-violet-600',
|
||||
iconShadow: 'shadow-indigo-500/25',
|
||||
glow: 'from-indigo-400/25 to-violet-300/5',
|
||||
bar: 'from-indigo-400 to-violet-500',
|
||||
badge:
|
||||
'bg-indigo-50 text-indigo-600 dark:bg-indigo-500/15 dark:text-indigo-400',
|
||||
},
|
||||
];
|
||||
|
||||
// 分组图标映射
|
||||
const GROUP_ICONS = {
|
||||
0: Wallet, // 账户数据
|
||||
1: TrendingUp, // 使用统计
|
||||
2: Zap, // Token 消耗
|
||||
3: Clock, // 性能指标
|
||||
};
|
||||
|
||||
const StatsCards = ({
|
||||
groupedStatsData,
|
||||
loading,
|
||||
getTrendSpec,
|
||||
CARD_PROPS,
|
||||
CHART_CONFIG,
|
||||
}) => {
|
||||
const _navigate = useNavigate();
|
||||
const { t: _t } = useTranslation();
|
||||
const gridColsClass =
|
||||
groupedStatsData.length >= 4 ? 'xl:grid-cols-4' : 'xl:grid-cols-3';
|
||||
|
||||
return (
|
||||
<div className={`grid grid-cols-1 md:grid-cols-2 ${gridColsClass} gap-4`}>
|
||||
{groupedStatsData.map((group, idx) => {
|
||||
const palette = CARD_PALETTES[idx % CARD_PALETTES.length];
|
||||
const GroupIcon = GROUP_ICONS[idx] || Wallet;
|
||||
const isTwoColumnLayout = group.layout === 'two-column';
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className={`group/card relative overflow-hidden rounded-2xl bg-white dark:bg-neutral-900/90 border border-gray-100 dark:border-neutral-800 shadow-[0_2px_12px_-2px_rgba(0,0,0,0.06)] dark:shadow-[0_2px_12px_-2px_rgba(0,0,0,0.4)] hover:shadow-[0_12px_28px_-6px_rgba(0,0,0,0.12)] hover:-translate-y-0.5 transition-all duration-300 ease-out`}
|
||||
>
|
||||
{/* 装饰性渐变光斑 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute -top-12 -right-12 w-36 h-36 bg-gradient-to-br ${palette.glow} rounded-full blur-2xl group-hover/card:scale-110 transition-transform duration-500`}
|
||||
/>
|
||||
{/* 顶部高光条 */}
|
||||
<div
|
||||
className={`pointer-events-none absolute top-0 left-0 right-0 h-px bg-gradient-to-r ${palette.bar} opacity-60`}
|
||||
/>
|
||||
{/* 微点阵纹理 - 强化卡片质感 */}
|
||||
<div
|
||||
className='pointer-events-none absolute inset-0 opacity-[0.025] dark:opacity-[0.04]'
|
||||
style={{
|
||||
backgroundImage:
|
||||
'radial-gradient(circle, currentColor 0.5px, transparent 0.5px)',
|
||||
backgroundSize: '12px 12px',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 卡片头部 - 标题 + 角标编号 */}
|
||||
<div className='relative px-4 pt-3.5 pb-2.5 flex items-center justify-between'>
|
||||
<div className='flex items-center gap-2.5'>
|
||||
<div
|
||||
className={`relative w-9 h-9 rounded-xl bg-gradient-to-br ${palette.iconBg} flex items-center justify-center shadow-md ${palette.iconShadow} group-hover/card:scale-105 transition-transform duration-300`}
|
||||
>
|
||||
<GroupIcon size={16} className='text-white' />
|
||||
<div className='absolute inset-0 rounded-xl bg-gradient-to-t from-white/0 via-white/0 to-white/30' />
|
||||
</div>
|
||||
<h3 className='font-semibold text-gray-900 dark:text-white text-[13px] tracking-wide'>
|
||||
{group.title}
|
||||
</h3>
|
||||
</div>
|
||||
{/* 序号角标 - 弱化的装饰编号 */}
|
||||
<span
|
||||
className={`text-[10px] font-bold tracking-widest tabular-nums ${palette.badge} px-1.5 py-0.5 rounded-md opacity-70`}
|
||||
>
|
||||
{String(idx + 1).padStart(2, '0')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 分隔线 - 渐变细线 */}
|
||||
<div className='mx-4 h-px bg-gradient-to-r from-transparent via-gray-200/60 to-transparent dark:via-gray-700/40' />
|
||||
|
||||
{/* 卡片内容 - 紧凑布局
|
||||
- two-column 模式:4 项 2×2 紧凑网格(Token 消耗)
|
||||
- 默认模式:2 项 左标题 + 右大数字 的两端对齐,把右侧留白用数值填满 */}
|
||||
<div
|
||||
className={`relative px-3 py-2.5 ${
|
||||
isTwoColumnLayout ? 'grid grid-cols-2 gap-2' : 'space-y-1'
|
||||
}`}
|
||||
>
|
||||
{group.items.map((item, itemIdx) => {
|
||||
// 趋势图仅在 item 显式提供 trendData 且非空时渲染
|
||||
const hasTrend =
|
||||
Array.isArray(item.trendData) && item.trendData.length > 0;
|
||||
|
||||
if (isTwoColumnLayout) {
|
||||
// ========== Token 消耗 - 紧凑卡片样式 ==========
|
||||
return (
|
||||
<div
|
||||
key={itemIdx}
|
||||
className={`group relative flex min-w-0 items-center gap-2.5 px-2 py-2 rounded-xl transition-all ${
|
||||
item.onClick ? 'cursor-pointer' : ''
|
||||
} hover:bg-white/60 dark:hover:bg-white/[0.04]`}
|
||||
onClick={item.onClick}
|
||||
>
|
||||
<div
|
||||
className='w-8 h-8 shrink-0 rounded-lg flex items-center justify-center text-[13px]'
|
||||
style={{
|
||||
backgroundColor: `var(--semi-color-${item.avatarColor}-light-default)`,
|
||||
color: `var(--semi-color-${item.avatarColor})`,
|
||||
}}
|
||||
>
|
||||
{item.icon}
|
||||
</div>
|
||||
<div className='min-w-0'>
|
||||
<div className='truncate text-[11px] text-gray-500 dark:text-gray-400 leading-tight mb-0.5'>
|
||||
{item.title}
|
||||
</div>
|
||||
<div className='truncate text-[15px] font-extrabold text-gray-900 dark:text-white leading-tight tabular-nums tracking-tight'>
|
||||
<Skeleton
|
||||
loading={loading}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Paragraph
|
||||
active
|
||||
rows={1}
|
||||
style={{ width: '60px', height: '18px' }}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{item.value}
|
||||
</Skeleton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ========== 账户/使用统计/性能指标 - 单列 hero 行 ==========
|
||||
// 左:小图标 + 小标题;右:大数字(吃掉之前的留白)
|
||||
return (
|
||||
<div
|
||||
key={itemIdx}
|
||||
className={`group relative flex items-center justify-between gap-3 px-2.5 py-2.5 rounded-xl transition-all ${
|
||||
item.onClick ? 'cursor-pointer' : ''
|
||||
} hover:bg-white/60 dark:hover:bg-white/[0.04]`}
|
||||
onClick={item.onClick}
|
||||
>
|
||||
{/* 左侧:图标 + 标题 */}
|
||||
<div className='flex min-w-0 items-center gap-2.5'>
|
||||
<div
|
||||
className='w-7 h-7 shrink-0 rounded-lg flex items-center justify-center text-[12px]'
|
||||
style={{
|
||||
backgroundColor: `var(--semi-color-${item.avatarColor}-light-default)`,
|
||||
color: `var(--semi-color-${item.avatarColor})`,
|
||||
}}
|
||||
>
|
||||
{item.icon}
|
||||
</div>
|
||||
<span className='truncate text-[12px] text-gray-500 dark:text-gray-400'>
|
||||
{item.title}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 右侧:大数字 + 可选趋势图(仅当显式提供) */}
|
||||
<div className='flex items-center gap-3 min-w-0'>
|
||||
{hasTrend && (
|
||||
<div className='w-14 h-6 opacity-70 group-hover:opacity-100 transition-opacity'>
|
||||
<VChart
|
||||
spec={getTrendSpec(item.trendData, item.trendColor)}
|
||||
option={CHART_CONFIG}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className='truncate text-right text-lg font-extrabold text-gray-900 dark:text-white leading-none tabular-nums tracking-tight'>
|
||||
<Skeleton
|
||||
loading={loading}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Paragraph
|
||||
active
|
||||
rows={1}
|
||||
style={{ width: '80px', height: '20px' }}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{item.value}
|
||||
</Skeleton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 悬停箭头 */}
|
||||
{item.onClick && (
|
||||
<ArrowUpRight
|
||||
size={12}
|
||||
className='absolute right-1.5 top-1.5 text-gray-300 dark:text-gray-600 opacity-0 group-hover:opacity-100 transition-opacity'
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatsCards;
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
Card,
|
||||
Button,
|
||||
Spin,
|
||||
Tabs,
|
||||
TabPane,
|
||||
Tag,
|
||||
Empty,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { Gauge, RefreshCw } from 'lucide-react';
|
||||
import {
|
||||
IllustrationConstruction,
|
||||
IllustrationConstructionDark,
|
||||
} from '../common/illustrations';
|
||||
import ScrollableContainer from '../common/ui/ScrollableContainer';
|
||||
|
||||
const UptimePanel = ({
|
||||
uptimeData,
|
||||
uptimeLoading,
|
||||
activeUptimeTab,
|
||||
setActiveUptimeTab,
|
||||
loadUptimeData,
|
||||
uptimeLegendData,
|
||||
renderMonitorList,
|
||||
CARD_PROPS,
|
||||
ILLUSTRATION_SIZE,
|
||||
t,
|
||||
}) => {
|
||||
return (
|
||||
<Card
|
||||
{...CARD_PROPS}
|
||||
className='shadow-sm !rounded-2xl lg:col-span-1'
|
||||
title={
|
||||
<div className='flex items-center justify-between w-full gap-2'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<Gauge size={16} />
|
||||
{t('服务可用性')}
|
||||
</div>
|
||||
<Button
|
||||
icon={<RefreshCw size={14} />}
|
||||
onClick={loadUptimeData}
|
||||
loading={uptimeLoading}
|
||||
size='small'
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className='text-gray-500 hover:text-blue-500 hover:bg-blue-50 !rounded-full'
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
bodyStyle={{ padding: 0 }}
|
||||
>
|
||||
{/* 内容区域 */}
|
||||
<div className='relative'>
|
||||
<Spin spinning={uptimeLoading}>
|
||||
{uptimeData.length > 0 ? (
|
||||
uptimeData.length === 1 ? (
|
||||
<ScrollableContainer maxHeight='24rem'>
|
||||
{renderMonitorList(uptimeData[0].monitors)}
|
||||
</ScrollableContainer>
|
||||
) : (
|
||||
<Tabs
|
||||
type='card'
|
||||
collapsible
|
||||
activeKey={activeUptimeTab}
|
||||
onChange={setActiveUptimeTab}
|
||||
size='small'
|
||||
>
|
||||
{uptimeData.map((group, groupIdx) => (
|
||||
<TabPane
|
||||
tab={
|
||||
<span className='flex items-center gap-2'>
|
||||
<Gauge size={14} />
|
||||
{group.categoryName}
|
||||
<Tag
|
||||
color={
|
||||
activeUptimeTab === group.categoryName
|
||||
? 'red'
|
||||
: 'grey'
|
||||
}
|
||||
size='small'
|
||||
shape='circle'
|
||||
>
|
||||
{group.monitors ? group.monitors.length : 0}
|
||||
</Tag>
|
||||
</span>
|
||||
}
|
||||
itemKey={group.categoryName}
|
||||
key={groupIdx}
|
||||
>
|
||||
<ScrollableContainer maxHeight='21.5rem'>
|
||||
{renderMonitorList(group.monitors)}
|
||||
</ScrollableContainer>
|
||||
</TabPane>
|
||||
))}
|
||||
</Tabs>
|
||||
)
|
||||
) : (
|
||||
<div className='flex justify-center items-center py-8'>
|
||||
<Empty
|
||||
image={<IllustrationConstruction style={ILLUSTRATION_SIZE} />}
|
||||
darkModeImage={
|
||||
<IllustrationConstructionDark style={ILLUSTRATION_SIZE} />
|
||||
}
|
||||
title={t('暂无监控数据')}
|
||||
description={t('请联系管理员在系统设置中配置Uptime')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</div>
|
||||
|
||||
{/* 图例 */}
|
||||
{uptimeData.length > 0 && (
|
||||
<div className='p-3 bg-gray-50 rounded-b-2xl'>
|
||||
<div className='flex flex-wrap gap-3 text-xs justify-center'>
|
||||
{uptimeLegendData.map((legend, index) => (
|
||||
<div key={index} className='flex items-center gap-1'>
|
||||
<div
|
||||
className='w-2 h-2 rounded-full'
|
||||
style={{ backgroundColor: legend.color }}
|
||||
/>
|
||||
<span className='text-gray-600'>{legend.label}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default UptimePanel;
|
||||
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect } from 'react';
|
||||
import { getRelativeTime } from '../../helpers';
|
||||
import { UserContext } from '../../context/User';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
|
||||
import DashboardHeader from './DashboardHeader';
|
||||
import StatsCards from './StatsCards';
|
||||
import ChartsPanel from './ChartsPanel';
|
||||
import ApiInfoPanel from './ApiInfoPanel';
|
||||
import AnnouncementsPanel from './AnnouncementsPanel';
|
||||
import FaqPanel from './FaqPanel';
|
||||
import UptimePanel from './UptimePanel';
|
||||
import SearchModal from './modals/SearchModal';
|
||||
|
||||
import { useDashboardData } from '../../hooks/dashboard/useDashboardData';
|
||||
import { useDashboardStats } from '../../hooks/dashboard/useDashboardStats';
|
||||
import { useDashboardCharts } from '../../hooks/dashboard/useDashboardCharts';
|
||||
|
||||
import {
|
||||
CHART_CONFIG,
|
||||
CARD_PROPS,
|
||||
FLEX_CENTER_GAP2,
|
||||
ILLUSTRATION_SIZE,
|
||||
ANNOUNCEMENT_LEGEND_DATA,
|
||||
UPTIME_STATUS_MAP,
|
||||
} from '../../constants/dashboard.constants';
|
||||
import {
|
||||
getTrendSpec,
|
||||
handleCopyUrl,
|
||||
handleSpeedTest,
|
||||
getUptimeStatusColor,
|
||||
getUptimeStatusText,
|
||||
renderMonitorList,
|
||||
} from '../../helpers/dashboard';
|
||||
|
||||
const Dashboard = () => {
|
||||
// ========== Context ==========
|
||||
const [userState, userDispatch] = useContext(UserContext);
|
||||
const [statusState] = useContext(StatusContext);
|
||||
|
||||
// ========== 主要数据管理 ==========
|
||||
const dashboardData = useDashboardData(userState, userDispatch, statusState);
|
||||
|
||||
// ========== 图表管理 ==========
|
||||
const dashboardCharts = useDashboardCharts(
|
||||
dashboardData.dataExportDefaultTime,
|
||||
dashboardData.setTrendData,
|
||||
dashboardData.setConsumeQuota,
|
||||
dashboardData.setTimes,
|
||||
dashboardData.setConsumeTokens,
|
||||
dashboardData.setPieData,
|
||||
dashboardData.setLineData,
|
||||
dashboardData.setModelColors,
|
||||
dashboardData.t,
|
||||
);
|
||||
|
||||
// ========== 统计数据 ==========
|
||||
const { groupedStatsData } = useDashboardStats(
|
||||
userState,
|
||||
dashboardData.consumeQuota,
|
||||
dashboardData.consumeTokens,
|
||||
dashboardData.times,
|
||||
dashboardData.trendData,
|
||||
dashboardData.performanceMetrics,
|
||||
dashboardData.navigate,
|
||||
dashboardData.t,
|
||||
);
|
||||
|
||||
// ========== 数据处理 ==========
|
||||
const initChart = async () => {
|
||||
await dashboardData.loadQuotaData().then((data) => {
|
||||
if (data && data.length > 0) {
|
||||
dashboardCharts.updateChartData(data);
|
||||
}
|
||||
});
|
||||
await dashboardData.loadUptimeData();
|
||||
};
|
||||
|
||||
const handleRefresh = async () => {
|
||||
const data = await dashboardData.refresh();
|
||||
if (data && data.length > 0) {
|
||||
dashboardCharts.updateChartData(data);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSearchConfirm = async () => {
|
||||
await dashboardData.handleSearchConfirm(dashboardCharts.updateChartData);
|
||||
};
|
||||
|
||||
// ========== 数据准备 ==========
|
||||
const apiInfoData = statusState?.status?.api_info || [];
|
||||
const announcementData = (statusState?.status?.announcements || []).map(
|
||||
(item) => {
|
||||
const pubDate = item?.publishDate ? new Date(item.publishDate) : null;
|
||||
const absoluteTime =
|
||||
pubDate && !isNaN(pubDate.getTime())
|
||||
? `${pubDate.getFullYear()}-${String(pubDate.getMonth() + 1).padStart(2, '0')}-${String(pubDate.getDate()).padStart(2, '0')} ${String(pubDate.getHours()).padStart(2, '0')}:${String(pubDate.getMinutes()).padStart(2, '0')}`
|
||||
: item?.publishDate || '';
|
||||
const relativeTime = getRelativeTime(item.publishDate);
|
||||
return {
|
||||
...item,
|
||||
time: absoluteTime,
|
||||
relative: relativeTime,
|
||||
};
|
||||
},
|
||||
);
|
||||
const faqData = statusState?.status?.faq || [];
|
||||
|
||||
const uptimeLegendData = Object.entries(UPTIME_STATUS_MAP).map(
|
||||
([status, info]) => ({
|
||||
status: Number(status),
|
||||
color: info.color,
|
||||
label: dashboardData.t(info.label),
|
||||
}),
|
||||
);
|
||||
|
||||
// ========== Effects ==========
|
||||
useEffect(() => {
|
||||
initChart();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className='h-full'>
|
||||
<DashboardHeader
|
||||
getGreeting={dashboardData.getGreeting}
|
||||
greetingVisible={dashboardData.greetingVisible}
|
||||
showSearchModal={dashboardData.showSearchModal}
|
||||
refresh={handleRefresh}
|
||||
loading={dashboardData.loading}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
|
||||
<SearchModal
|
||||
searchModalVisible={dashboardData.searchModalVisible}
|
||||
handleSearchConfirm={handleSearchConfirm}
|
||||
handleCloseModal={dashboardData.handleCloseModal}
|
||||
isMobile={dashboardData.isMobile}
|
||||
isAdminUser={dashboardData.isAdminUser}
|
||||
inputs={dashboardData.inputs}
|
||||
dataExportDefaultTime={dashboardData.dataExportDefaultTime}
|
||||
timeOptions={dashboardData.timeOptions}
|
||||
handleInputChange={dashboardData.handleInputChange}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
|
||||
<StatsCards
|
||||
groupedStatsData={groupedStatsData}
|
||||
loading={dashboardData.loading}
|
||||
getTrendSpec={getTrendSpec}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
CHART_CONFIG={CHART_CONFIG}
|
||||
/>
|
||||
|
||||
{/* API信息和图表面板 */}
|
||||
<div className='mb-4'>
|
||||
<div
|
||||
className={`grid grid-cols-1 gap-4 ${dashboardData.hasApiInfoPanel ? 'lg:grid-cols-4' : ''}`}
|
||||
>
|
||||
<ChartsPanel
|
||||
activeChartTab={dashboardData.activeChartTab}
|
||||
setActiveChartTab={dashboardData.setActiveChartTab}
|
||||
spec_line={dashboardCharts.spec_line}
|
||||
spec_model_line={dashboardCharts.spec_model_line}
|
||||
spec_pie={dashboardCharts.spec_pie}
|
||||
spec_rank_bar={dashboardCharts.spec_rank_bar}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
CHART_CONFIG={CHART_CONFIG}
|
||||
FLEX_CENTER_GAP2={FLEX_CENTER_GAP2}
|
||||
hasApiInfoPanel={dashboardData.hasApiInfoPanel}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
|
||||
{dashboardData.hasApiInfoPanel && (
|
||||
<ApiInfoPanel
|
||||
apiInfoData={apiInfoData}
|
||||
handleCopyUrl={(url) => handleCopyUrl(url, dashboardData.t)}
|
||||
handleSpeedTest={handleSpeedTest}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
FLEX_CENTER_GAP2={FLEX_CENTER_GAP2}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 系统公告和常见问答卡片 */}
|
||||
{dashboardData.hasInfoPanels && (
|
||||
<div className='mb-4'>
|
||||
<div className='grid grid-cols-1 lg:grid-cols-4 gap-4'>
|
||||
{/* 公告卡片 */}
|
||||
{dashboardData.announcementsEnabled && (
|
||||
<AnnouncementsPanel
|
||||
announcementData={announcementData}
|
||||
announcementLegendData={ANNOUNCEMENT_LEGEND_DATA.map(
|
||||
(item) => ({
|
||||
...item,
|
||||
label: dashboardData.t(item.label),
|
||||
}),
|
||||
)}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 常见问答卡片 */}
|
||||
{dashboardData.faqEnabled && (
|
||||
<FaqPanel
|
||||
faqData={faqData}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
FLEX_CENTER_GAP2={FLEX_CENTER_GAP2}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* 服务可用性卡片 */}
|
||||
{dashboardData.uptimeEnabled && (
|
||||
<UptimePanel
|
||||
uptimeData={dashboardData.uptimeData}
|
||||
uptimeLoading={dashboardData.uptimeLoading}
|
||||
activeUptimeTab={dashboardData.activeUptimeTab}
|
||||
setActiveUptimeTab={dashboardData.setActiveUptimeTab}
|
||||
loadUptimeData={dashboardData.loadUptimeData}
|
||||
uptimeLegendData={uptimeLegendData}
|
||||
renderMonitorList={(monitors) =>
|
||||
renderMonitorList(
|
||||
monitors,
|
||||
(status) => getUptimeStatusColor(status, UPTIME_STATUS_MAP),
|
||||
(status) =>
|
||||
getUptimeStatusText(
|
||||
status,
|
||||
UPTIME_STATUS_MAP,
|
||||
dashboardData.t,
|
||||
),
|
||||
dashboardData.t,
|
||||
)
|
||||
}
|
||||
CARD_PROPS={CARD_PROPS}
|
||||
ILLUSTRATION_SIZE={ILLUSTRATION_SIZE}
|
||||
t={dashboardData.t}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Dashboard;
|
||||
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
import { Modal, Form, Button } from '@douyinfe/semi-ui';
|
||||
import { Filter, Calendar, Clock, User, Search, X } from 'lucide-react';
|
||||
|
||||
const SearchModal = ({
|
||||
searchModalVisible,
|
||||
handleSearchConfirm,
|
||||
handleCloseModal,
|
||||
isMobile,
|
||||
isAdminUser,
|
||||
inputs,
|
||||
dataExportDefaultTime,
|
||||
timeOptions,
|
||||
handleInputChange,
|
||||
t,
|
||||
}) => {
|
||||
const formRef = useRef();
|
||||
|
||||
const { start_timestamp, end_timestamp, username } = inputs;
|
||||
|
||||
// 自定义标题
|
||||
const customTitle = (
|
||||
<div className='flex items-center gap-3 pt-2'>
|
||||
<div className='relative'>
|
||||
<div className='absolute inset-0 bg-gradient-to-br from-blue-500 to-brand-to rounded-xl blur opacity-50' />
|
||||
<div className='relative p-2.5 bg-gradient-to-br from-blue-500 to-brand-to rounded-xl shadow-lg shadow-blue-500/25'>
|
||||
<Filter size={18} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className='text-lg font-bold bg-clip-text text-transparent bg-gradient-to-r from-gray-900 to-gray-600 dark:from-white dark:to-gray-300'>
|
||||
{t('筛选数据')}
|
||||
</h3>
|
||||
<p className='text-xs text-gray-400 dark:text-gray-500'>
|
||||
{t('设置查询条件以筛选数据')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
// 自定义底部按钮
|
||||
const customFooter = (
|
||||
<div className='flex items-center justify-end gap-3'>
|
||||
<Button
|
||||
type='tertiary'
|
||||
onClick={handleCloseModal}
|
||||
className='!rounded-xl !px-5 !h-10 !bg-gray-100 dark:!bg-gray-700 !border-0 hover:!bg-gray-200 dark:hover:!bg-gray-600 !transition-all'
|
||||
style={{ color: '#4b5563' }}
|
||||
icon={<X size={16} style={{ color: '#4b5563' }} />}
|
||||
>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
<Button
|
||||
type='tertiary'
|
||||
onClick={handleSearchConfirm}
|
||||
className='!rounded-xl !px-5 !h-10 !bg-gradient-to-r !from-blue-500 !to-brand-to !border-0 hover:!opacity-90 !transition-all !shadow-lg !shadow-blue-500/25'
|
||||
style={{ color: '#ffffff' }}
|
||||
icon={<Search size={16} style={{ color: '#ffffff' }} />}
|
||||
>
|
||||
{t('查询')}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
|
||||
// 表单字段包装器 - 紧凑版
|
||||
const FormFieldWrapper = ({ icon: Icon, label, children, gradient }) => (
|
||||
<div className='mb-3 last:mb-0'>
|
||||
<div className='flex items-center gap-2 mb-1.5'>
|
||||
<div
|
||||
className={`w-5 h-5 rounded-md bg-gradient-to-br ${gradient} flex items-center justify-center`}
|
||||
>
|
||||
<Icon size={10} className='text-white' />
|
||||
</div>
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-400'>
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
<div className='relative'>{children}</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={searchModalVisible}
|
||||
onCancel={handleCloseModal}
|
||||
closeOnEsc={true}
|
||||
size={isMobile ? 'full-width' : 'medium'}
|
||||
centered
|
||||
header={customTitle}
|
||||
footer={customFooter}
|
||||
className='search-modal-enhanced'
|
||||
style={{ maxWidth: isMobile ? '100%' : '480px' }}
|
||||
bodyStyle={{
|
||||
padding: '16px 20px',
|
||||
}}
|
||||
>
|
||||
<Form ref={formRef} layout='vertical' className='w-full'>
|
||||
{/* 时间范围区域 */}
|
||||
<div className='p-3 bg-gradient-to-br from-gray-50 to-gray-100/50 dark:from-gray-800/50 dark:to-gray-700/30 rounded-xl mb-3 border border-gray-100 dark:border-gray-700/50'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<div className='w-1 h-3 bg-gradient-to-b from-blue-500 to-brand-to rounded-full' />
|
||||
<span className='text-xs font-semibold text-gray-600 dark:text-gray-300'>
|
||||
{t('时间范围')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 时间选择器 - 单列布局确保宽度足够 */}
|
||||
<FormFieldWrapper
|
||||
icon={Calendar}
|
||||
label={t('起始时间')}
|
||||
gradient='from-emerald-500 to-teal-500'
|
||||
>
|
||||
<Form.DatePicker
|
||||
field='start_timestamp'
|
||||
noLabel
|
||||
initValue={start_timestamp}
|
||||
value={start_timestamp}
|
||||
type='dateTime'
|
||||
name='start_timestamp'
|
||||
onChange={(value) => handleInputChange(value, 'start_timestamp')}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-input-wrapper]:!rounded-lg [&_.semi-input]:!text-sm'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
|
||||
<FormFieldWrapper
|
||||
icon={Calendar}
|
||||
label={t('结束时间')}
|
||||
gradient='from-orange-500 to-amber-500'
|
||||
>
|
||||
<Form.DatePicker
|
||||
field='end_timestamp'
|
||||
noLabel
|
||||
initValue={end_timestamp}
|
||||
value={end_timestamp}
|
||||
type='dateTime'
|
||||
name='end_timestamp'
|
||||
onChange={(value) => handleInputChange(value, 'end_timestamp')}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-input-wrapper]:!rounded-lg [&_.semi-input]:!text-sm'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
</div>
|
||||
|
||||
{/* 其他选项区域 */}
|
||||
<div className='p-3 bg-gradient-to-br from-gray-50 to-gray-100/50 dark:from-gray-800/50 dark:to-gray-700/30 rounded-xl border border-gray-100 dark:border-gray-700/50'>
|
||||
<div className='flex items-center gap-2 mb-2'>
|
||||
<div className='w-1 h-3 bg-gradient-to-b from-brand-from to-pink-500 rounded-full' />
|
||||
<span className='text-xs font-semibold text-gray-600 dark:text-gray-300'>
|
||||
{t('查询选项')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<FormFieldWrapper
|
||||
icon={Clock}
|
||||
label={t('时间粒度')}
|
||||
gradient='from-blue-500 to-brand-to'
|
||||
>
|
||||
<Form.Select
|
||||
field='data_export_default_time'
|
||||
noLabel
|
||||
initValue={dataExportDefaultTime}
|
||||
placeholder={t('时间粒度')}
|
||||
name='data_export_default_time'
|
||||
optionList={timeOptions}
|
||||
onChange={(value) =>
|
||||
handleInputChange(value, 'data_export_default_time')
|
||||
}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-select]:!rounded-lg'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
|
||||
{isAdminUser && (
|
||||
<FormFieldWrapper
|
||||
icon={User}
|
||||
label={t('用户名称')}
|
||||
gradient='from-brand-from to-pink-500'
|
||||
>
|
||||
<Form.Input
|
||||
field='username'
|
||||
noLabel
|
||||
value={username}
|
||||
placeholder={t('可选值')}
|
||||
name='username'
|
||||
onChange={(value) => handleInputChange(value, 'username')}
|
||||
style={{ width: '100%' }}
|
||||
className='[&_.semi-input-wrapper]:!rounded-lg'
|
||||
/>
|
||||
</FormFieldWrapper>
|
||||
)}
|
||||
</div>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SearchModal;
|
||||
@@ -0,0 +1,613 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Input,
|
||||
Select,
|
||||
Card,
|
||||
Button,
|
||||
Collapse,
|
||||
Divider,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Slider,
|
||||
Switch,
|
||||
Typography,
|
||||
Alert,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
PlusCircle,
|
||||
Zap,
|
||||
Info,
|
||||
Palette,
|
||||
Image as ImageIcon,
|
||||
Eye,
|
||||
Sparkles,
|
||||
Trash2,
|
||||
} from 'lucide-react';
|
||||
|
||||
const { TextArea, InputNumber } = Input;
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
/**
|
||||
* 图像生成参数配置组件
|
||||
* @param {Object} props 组件属性
|
||||
* @param {Object} props.modelInfo 当前选择的模型信息
|
||||
* @param {Function} props.onParamsChange 参数变化回调函数
|
||||
* @param {Function} props.onGenerate 生成按钮点击回调
|
||||
* @param {boolean} props.isGenerating 是否正在生成中
|
||||
* @param {Object} props.initialParams 初始参数
|
||||
*/
|
||||
const ImageGenerationParams = ({
|
||||
modelInfo,
|
||||
onParamsChange,
|
||||
onGenerate,
|
||||
isGenerating = false,
|
||||
initialParams = {},
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// 提取模型能力信息
|
||||
const modelCapabilities = modelInfo?.capabilities || {};
|
||||
|
||||
// 状态管理
|
||||
const [params, setParams] = useState(() => ({
|
||||
prompt: initialParams.prompt || '',
|
||||
negativePrompt: initialParams.negativePrompt || '',
|
||||
n: initialParams.n || 1,
|
||||
size: initialParams.size || modelCapabilities.sizes?.[0] || '1024x1024',
|
||||
quality: initialParams.quality || 'standard',
|
||||
style: initialParams.style || 'natural',
|
||||
creativity: initialParams.creativity || 0.7,
|
||||
guidanceScale: initialParams.guidanceScale || 7.5,
|
||||
seed: initialParams.seed || null,
|
||||
useSeed: initialParams.useSeed || false,
|
||||
showAdvanced: initialParams.showAdvanced || false,
|
||||
}));
|
||||
|
||||
// 当模型信息变化时,更新可用参数
|
||||
useEffect(() => {
|
||||
setParams((prev) => {
|
||||
const newParams = { ...prev };
|
||||
|
||||
// 检查当前尺寸是否在模型支持的尺寸列表中
|
||||
if (
|
||||
modelCapabilities.sizes &&
|
||||
!modelCapabilities.sizes.includes(prev.size)
|
||||
) {
|
||||
newParams.size = modelCapabilities.sizes[0];
|
||||
}
|
||||
|
||||
// 如果模型不支持质量选择,确保质量设置为standard
|
||||
if (!modelCapabilities.supportsQuality && prev.quality !== 'standard') {
|
||||
newParams.quality = 'standard';
|
||||
}
|
||||
|
||||
// 限制生成数量不超过模型支持的最大值
|
||||
if (modelCapabilities.maxImages && prev.n > modelCapabilities.maxImages) {
|
||||
newParams.n = modelCapabilities.maxImages;
|
||||
}
|
||||
|
||||
return newParams;
|
||||
});
|
||||
}, [modelInfo]);
|
||||
|
||||
// 参数更新函数
|
||||
const updateParam = useCallback(
|
||||
(key, value) => {
|
||||
setParams((prev) => {
|
||||
const newParams = { ...prev, [key]: value };
|
||||
// 触发参数变化回调
|
||||
onParamsChange(newParams);
|
||||
return newParams;
|
||||
});
|
||||
},
|
||||
[onParamsChange],
|
||||
);
|
||||
|
||||
// 处理生成按钮点击
|
||||
const handleGenerate = useCallback(() => {
|
||||
// 验证提示词
|
||||
if (!params.prompt || !params.prompt.trim()) {
|
||||
alert(t('请输入提示词'));
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用生成回调
|
||||
onGenerate(params);
|
||||
}, [params, onGenerate, t]);
|
||||
|
||||
// 样式选项
|
||||
const styleOptions = [
|
||||
{
|
||||
value: 'natural',
|
||||
label: t('自然'),
|
||||
description: t('生成逼真、自然的图像'),
|
||||
},
|
||||
{
|
||||
value: 'vivid',
|
||||
label: t('生动'),
|
||||
description: t('生成更具表现力、丰富色彩的图像'),
|
||||
},
|
||||
{
|
||||
value: 'artistic',
|
||||
label: t('艺术'),
|
||||
description: t('生成具有艺术风格的图像'),
|
||||
},
|
||||
{
|
||||
value: 'photographic',
|
||||
label: t('摄影'),
|
||||
description: t('生成类似照片的真实图像'),
|
||||
},
|
||||
];
|
||||
|
||||
// 获取尺寸选项
|
||||
const getSizeOptions = useCallback(() => {
|
||||
const sizeMap = {
|
||||
'256x256': { label: '256×256', description: t('最小尺寸,生成速度快') },
|
||||
'512x512': {
|
||||
label: '512×512',
|
||||
description: t('中等尺寸,平衡质量和速度'),
|
||||
},
|
||||
'1024x1024': { label: '1024×1024', description: t('标准高清尺寸') },
|
||||
'1024x1792': {
|
||||
label: '1024×1792 (9:16)',
|
||||
description: t('纵向比例,适合手机壁纸'),
|
||||
},
|
||||
'1792x1024': {
|
||||
label: '1792×1024 (16:9)',
|
||||
description: t('横向比例,适合桌面壁纸'),
|
||||
},
|
||||
'1344x1024': { label: '1344×1024', description: t('宽屏比例') },
|
||||
'1024x1344': { label: '1024×1344', description: '竖屏比例' },
|
||||
};
|
||||
|
||||
// 如果有模型支持的尺寸列表,使用它过滤
|
||||
if (modelCapabilities.sizes) {
|
||||
return modelCapabilities.sizes.map((size) => ({
|
||||
value: size,
|
||||
label: sizeMap[size]?.label || size,
|
||||
description: sizeMap[size]?.description || '',
|
||||
}));
|
||||
}
|
||||
|
||||
// 否则返回所有尺寸
|
||||
return Object.keys(sizeMap).map((size) => ({
|
||||
value: size,
|
||||
label: sizeMap[size].label,
|
||||
description: sizeMap[size].description,
|
||||
}));
|
||||
}, [modelCapabilities.sizes, t]);
|
||||
|
||||
// 质量选项
|
||||
const qualityOptions = [
|
||||
{
|
||||
value: 'standard',
|
||||
label: t('标准'),
|
||||
description: t('标准质量,速度较快'),
|
||||
},
|
||||
{ value: 'hd', label: t('高清'), description: t('更高质量,细节更丰富') },
|
||||
];
|
||||
|
||||
// 预设提示词模板
|
||||
const promptTemplates = [
|
||||
{
|
||||
title: t('风景照片'),
|
||||
prompt: t(
|
||||
'a beautiful landscape with mountains, lake and trees, in realistic style, high detail, natural lighting',
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('肖像'),
|
||||
prompt: t(
|
||||
'portrait of a person, detailed facial features, professional photography, soft lighting',
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('科幻场景'),
|
||||
prompt: t(
|
||||
'futuristic cityscape, flying cars, neon lights, science fiction, highly detailed',
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('动画风格'),
|
||||
prompt: t(
|
||||
'cute anime character, colorful, detailed, digital illustration, anime style',
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
// 应用提示词模板
|
||||
const applyPromptTemplate = useCallback(
|
||||
(template) => {
|
||||
updateParam('prompt', template.prompt);
|
||||
},
|
||||
[updateParam],
|
||||
);
|
||||
|
||||
// 清除所有参数
|
||||
const clearAllParams = useCallback(() => {
|
||||
const clearedParams = {
|
||||
prompt: '',
|
||||
negativePrompt: '',
|
||||
n: 1,
|
||||
size: modelCapabilities.sizes?.[0] || '1024x1024',
|
||||
quality: 'standard',
|
||||
style: 'natural',
|
||||
creativity: 0.7,
|
||||
guidanceScale: 7.5,
|
||||
seed: null,
|
||||
useSeed: false,
|
||||
};
|
||||
|
||||
setParams(clearedParams);
|
||||
onParamsChange(clearedParams);
|
||||
}, [modelCapabilities.sizes, onParamsChange]);
|
||||
|
||||
// 渲染尺寸选项下拉框
|
||||
const renderSizeSelect = () => {
|
||||
const sizeOptions = getSizeOptions();
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
content={
|
||||
sizeOptions.find((option) => option.value === params.size)
|
||||
?.description || ''
|
||||
}
|
||||
position='topLeft'
|
||||
trigger={['hover']}
|
||||
>
|
||||
<Select
|
||||
value={params.size}
|
||||
onChange={(value) => updateParam('size', value)}
|
||||
options={sizeOptions.map((option) => ({
|
||||
value: option.value,
|
||||
label: option.label,
|
||||
}))}
|
||||
className='w-full'
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染质量选项下拉框
|
||||
const renderQualitySelect = () => {
|
||||
const disabled = !modelCapabilities.supportsQuality;
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
content={disabled ? t('当前模型不支持质量选择') : ''}
|
||||
position='topLeft'
|
||||
trigger={['hover']}
|
||||
>
|
||||
<Select
|
||||
value={params.quality}
|
||||
onChange={(value) => updateParam('quality', value)}
|
||||
options={qualityOptions}
|
||||
disabled={disabled}
|
||||
className='w-full'
|
||||
/>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
// 最大图片数量
|
||||
const maxImages = modelCapabilities.maxImages || 1;
|
||||
|
||||
return (
|
||||
<Card className='overflow-hidden'>
|
||||
<div className='p-6'>
|
||||
{/* 提示词输入 */}
|
||||
<div className='mb-6'>
|
||||
<div className='flex justify-between items-center mb-2'>
|
||||
<Title level={4} className='mb-0'>
|
||||
<div className='flex items-center'>
|
||||
<Sparkles size={16} className='mr-2 text-blue-500' />
|
||||
{t('提示词')}
|
||||
</div>
|
||||
</Title>
|
||||
<Tooltip content={t('提示词越详细,生成的图片越符合预期')}>
|
||||
<Info size={16} className='text-gray-400 cursor-help' />
|
||||
</Tooltip>
|
||||
</div>
|
||||
<TextArea
|
||||
value={params.prompt}
|
||||
onChange={(e) => updateParam('prompt', e.target.value)}
|
||||
placeholder={t('描述你想要生成的图像...')}
|
||||
rows={5}
|
||||
className='mb-3'
|
||||
maxLength={2000}
|
||||
/>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400 mb-4'>
|
||||
{params.prompt.length}/2000
|
||||
</div>
|
||||
|
||||
{/* 提示词模板 */}
|
||||
{promptTemplates.length > 0 && (
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-2'>
|
||||
{t('快速模板:')}
|
||||
</Text>
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
{promptTemplates.map((template, index) => (
|
||||
<Tag
|
||||
key={index}
|
||||
clickable
|
||||
color='blue'
|
||||
size='small'
|
||||
onClick={() => applyPromptTemplate(template)}
|
||||
className='cursor-pointer'
|
||||
>
|
||||
{template.title}
|
||||
</Tag>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 高级选项 */}
|
||||
<Collapse
|
||||
items={[
|
||||
{
|
||||
title: (
|
||||
<div className='flex items-center cursor-pointer'>
|
||||
<PlusCircle size={16} className='mr-2' />
|
||||
<span>{t('高级选项')}</span>
|
||||
</div>
|
||||
),
|
||||
content: (
|
||||
<div className='space-y-4 pt-2'>
|
||||
{/* 反向提示词 */}
|
||||
<div>
|
||||
<div className='flex justify-between items-center mb-2'>
|
||||
<Text type='secondary'>{t('反向提示词')}</Text>
|
||||
<Tooltip content={t('描述你不想要在图像中出现的内容')}>
|
||||
<Info size={14} className='text-gray-400 cursor-help' />
|
||||
</Tooltip>
|
||||
</div>
|
||||
<TextArea
|
||||
value={params.negativePrompt}
|
||||
onChange={(e) =>
|
||||
updateParam('negativePrompt', e.target.value)
|
||||
}
|
||||
placeholder={t('例如: 模糊, 扭曲, 低质量...')}
|
||||
rows={3}
|
||||
maxLength={1000}
|
||||
/>
|
||||
<div className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{params.negativePrompt.length}/1000
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 基本参数 */}
|
||||
<div>
|
||||
<div className='flex justify-between items-center mb-3'>
|
||||
<Text type='secondary'>{t('基本参数')}</Text>
|
||||
</div>
|
||||
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
|
||||
{/* 图片数量 */}
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
{t('图片数量')}
|
||||
</Text>
|
||||
<InputNumber
|
||||
value={params.n}
|
||||
onChange={(value) =>
|
||||
updateParam(
|
||||
'n',
|
||||
Math.min(Math.max(1, value), maxImages),
|
||||
)
|
||||
}
|
||||
min={1}
|
||||
max={maxImages}
|
||||
className='w-full'
|
||||
/>
|
||||
<Text type='secondary' className='text-xs mt-1'>
|
||||
{t('最大: {{max}}', { max: maxImages })}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
{/* 图片尺寸 */}
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
<div className='flex items-center'>
|
||||
<ImageIcon size={12} className='mr-1' />
|
||||
{t('图片尺寸')}
|
||||
</div>
|
||||
</Text>
|
||||
{renderSizeSelect()}
|
||||
</div>
|
||||
|
||||
{/* 图片质量 */}
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
<div className='flex items-center'>
|
||||
<Eye size={12} className='mr-1' />
|
||||
{t('图片质量')}
|
||||
</div>
|
||||
</Text>
|
||||
{renderQualitySelect()}
|
||||
</div>
|
||||
|
||||
{/* 风格 */}
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
<div className='flex items-center'>
|
||||
<Palette size={12} className='mr-1' />
|
||||
{t('风格')}
|
||||
</div>
|
||||
</Text>
|
||||
<Select
|
||||
value={params.style}
|
||||
onChange={(value) => updateParam('style', value)}
|
||||
options={styleOptions}
|
||||
className='w-full'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 高级控制参数 */}
|
||||
<div>
|
||||
<div className='flex justify-between items-center mb-3'>
|
||||
<Text type='secondary'>{t('高级控制')}</Text>
|
||||
</div>
|
||||
|
||||
{/* 创意思维度 */}
|
||||
<div className='mb-4'>
|
||||
<div className='flex justify-between items-center mb-1'>
|
||||
<Text type='secondary' className='text-xs'>
|
||||
{t('创意思维度')}
|
||||
</Text>
|
||||
<Text type='secondary' className='text-xs'>
|
||||
{params.creativity.toFixed(1)}
|
||||
</Text>
|
||||
</div>
|
||||
<Slider
|
||||
value={params.creativity}
|
||||
onChange={(value) => updateParam('creativity', value)}
|
||||
min={0.1}
|
||||
max={1.0}
|
||||
step={0.1}
|
||||
/>
|
||||
<div className='flex justify-between text-xs text-gray-500 dark:text-gray-400'>
|
||||
<Text>{t('保守')}</Text>
|
||||
<Text>{t('平衡')}</Text>
|
||||
<Text>{t('创新')}</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 引导系数 */}
|
||||
<div className='mb-4'>
|
||||
<div className='flex justify-between items-center mb-1'>
|
||||
<Text type='secondary' className='text-xs'>
|
||||
{t('引导系数')}
|
||||
</Text>
|
||||
<Text type='secondary' className='text-xs'>
|
||||
{params.guidanceScale.toFixed(1)}
|
||||
</Text>
|
||||
</div>
|
||||
<Slider
|
||||
value={params.guidanceScale}
|
||||
onChange={(value) =>
|
||||
updateParam('guidanceScale', value)
|
||||
}
|
||||
min={1}
|
||||
max={20}
|
||||
step={0.5}
|
||||
/>
|
||||
<div className='flex justify-between text-xs text-gray-500 dark:text-gray-400'>
|
||||
<Text>{t('更自由')}</Text>
|
||||
<Text>{t('更贴合提示')}</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 随机种子 */}
|
||||
<div>
|
||||
<div className='flex justify-between items-center mb-1'>
|
||||
<div className='flex items-center'>
|
||||
<Text type='secondary' className='text-xs mr-2'>
|
||||
{t('使用随机种子')}
|
||||
</Text>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={params.useSeed}
|
||||
onChange={(checked) =>
|
||||
updateParam('useSeed', checked)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<InputNumber
|
||||
value={params.seed}
|
||||
onChange={(value) => updateParam('seed', value || null)}
|
||||
disabled={!params.useSeed}
|
||||
placeholder={t('输入种子值')}
|
||||
className='w-full'
|
||||
min={0}
|
||||
max={Number.MAX_SAFE_INTEGER}
|
||||
/>
|
||||
<Text type='secondary' className='text-xs mt-1'>
|
||||
{t('相同种子值将生成相似的图像')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
isOpen: params.showAdvanced,
|
||||
onItemClick: () =>
|
||||
updateParam('showAdvanced', !params.showAdvanced),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Divider className='my-4' />
|
||||
|
||||
{/* 操作按钮 */}
|
||||
<div className='flex flex-col sm:flex-row gap-3'>
|
||||
<Button
|
||||
type='primary'
|
||||
onClick={handleGenerate}
|
||||
loading={isGenerating}
|
||||
disabled={isGenerating || !params.prompt?.trim()}
|
||||
icon={<Zap size={16} />}
|
||||
className='flex-1'
|
||||
>
|
||||
{isGenerating ? t('生成中...') : t('生成图片')}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type='tertiary'
|
||||
onClick={clearAllParams}
|
||||
disabled={isGenerating}
|
||||
icon={<Trash2 size={16} />}
|
||||
>
|
||||
{t('清空')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 提示信息 */}
|
||||
<Alert
|
||||
type='info'
|
||||
showIcon
|
||||
description={
|
||||
<div className='text-xs'>
|
||||
<Text type='secondary'>
|
||||
{t(
|
||||
'提示:详细的提示词能生成更符合您预期的图像。尝试描述场景、风格、光线、构图等元素。',
|
||||
)}
|
||||
</Text>
|
||||
</div>
|
||||
}
|
||||
className='mt-4'
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
export default ImageGenerationParams;
|
||||
@@ -0,0 +1,622 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useCallback, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Card,
|
||||
Empty,
|
||||
Button,
|
||||
Input,
|
||||
Tag,
|
||||
Space,
|
||||
Modal,
|
||||
Typography,
|
||||
Collapse,
|
||||
Spin,
|
||||
Divider,
|
||||
Popconfirm,
|
||||
Dropdown,
|
||||
Badge,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
History,
|
||||
Search,
|
||||
Clock,
|
||||
Image as ImageIcon,
|
||||
Download,
|
||||
Trash2,
|
||||
MoreVertical,
|
||||
X,
|
||||
Filter,
|
||||
} from 'lucide-react';
|
||||
|
||||
const { Title, Paragraph, Text } = Typography;
|
||||
|
||||
/**
|
||||
* 图像生成历史记录组件
|
||||
* @param {Object} props 组件属性
|
||||
* @param {Array} props.history 历史记录数据
|
||||
* @param {boolean} props.isLoading 是否正在加载
|
||||
* @param {Function} props.onLoadFromHistory 从历史记录加载参数的回调
|
||||
* @param {Function} props.onDeleteRecord 删除记录的回调
|
||||
* @param {Function} props.onClearAll 清空所有历史记录的回调
|
||||
* @param {Function} props.onRegenerate 重新生成图片的回调
|
||||
*/
|
||||
const ImageHistory = ({
|
||||
history = [],
|
||||
isLoading = false,
|
||||
onLoadFromHistory,
|
||||
onDeleteRecord,
|
||||
onClearAll,
|
||||
onRegenerate,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// 状态管理
|
||||
const [searchKeyword, setSearchKeyword] = useState('');
|
||||
const [filteredHistory, setFilteredHistory] = useState([]);
|
||||
const [showDetailModal, setShowDetailModal] = useState(false);
|
||||
const [selectedRecord, setSelectedRecord] = useState(null);
|
||||
const [sortOrder, setSortOrder] = useState('newest'); // 'newest' | 'oldest'
|
||||
const [filterModel, setFilterModel] = useState('');
|
||||
const [showFilters, setShowFilters] = useState(false);
|
||||
|
||||
// 获取所有模型列表
|
||||
const allModels = useMemo(() => {
|
||||
const modelsSet = new Set(
|
||||
history.map((item) => item.model).filter(Boolean),
|
||||
);
|
||||
return Array.from(modelsSet).sort();
|
||||
}, [history]);
|
||||
|
||||
// 过滤和排序历史记录
|
||||
useMemo(() => {
|
||||
let result = [...history];
|
||||
|
||||
// 应用搜索过滤
|
||||
if (searchKeyword && searchKeyword.trim()) {
|
||||
const keyword = searchKeyword.toLowerCase().trim();
|
||||
result = result.filter(
|
||||
(item) =>
|
||||
item.prompt.toLowerCase().includes(keyword) ||
|
||||
(item.negativePrompt &&
|
||||
item.negativePrompt.toLowerCase().includes(keyword)) ||
|
||||
item.model.toLowerCase().includes(keyword),
|
||||
);
|
||||
}
|
||||
|
||||
// 应用模型过滤
|
||||
if (filterModel) {
|
||||
result = result.filter((item) => item.model === filterModel);
|
||||
}
|
||||
|
||||
// 应用排序
|
||||
result.sort((a, b) => {
|
||||
const dateA = new Date(a.timestamp);
|
||||
const dateB = new Date(b.timestamp);
|
||||
return sortOrder === 'newest' ? dateB - dateA : dateA - dateB;
|
||||
});
|
||||
|
||||
setFilteredHistory(result);
|
||||
}, [history, searchKeyword, filterModel, sortOrder]);
|
||||
|
||||
// 加载历史记录
|
||||
const handleLoadFromHistory = useCallback(
|
||||
(record) => {
|
||||
if (onLoadFromHistory) {
|
||||
onLoadFromHistory(record);
|
||||
}
|
||||
},
|
||||
[onLoadFromHistory],
|
||||
);
|
||||
|
||||
// 显示详情
|
||||
const handleShowDetail = useCallback((record) => {
|
||||
setSelectedRecord(record);
|
||||
setShowDetailModal(true);
|
||||
}, []);
|
||||
|
||||
// 删除单条记录
|
||||
const handleDeleteRecord = useCallback(
|
||||
(recordId) => {
|
||||
if (onDeleteRecord) {
|
||||
onDeleteRecord(recordId);
|
||||
}
|
||||
// 如果当前显示的是被删除的记录的详情,关闭详情模态框
|
||||
if (selectedRecord && selectedRecord.id === recordId) {
|
||||
setShowDetailModal(false);
|
||||
setSelectedRecord(null);
|
||||
}
|
||||
},
|
||||
[onDeleteRecord, selectedRecord],
|
||||
);
|
||||
|
||||
// 重新生成图片
|
||||
const handleRegenerate = useCallback(
|
||||
(record) => {
|
||||
if (onRegenerate) {
|
||||
onRegenerate(record);
|
||||
}
|
||||
setShowDetailModal(false);
|
||||
},
|
||||
[onRegenerate],
|
||||
);
|
||||
|
||||
// 清空所有历史记录
|
||||
const handleClearAll = useCallback(() => {
|
||||
if (onClearAll) {
|
||||
onClearAll();
|
||||
}
|
||||
setShowDetailModal(false);
|
||||
setSelectedRecord(null);
|
||||
}, [onClearAll]);
|
||||
|
||||
// 切换排序顺序
|
||||
const toggleSortOrder = useCallback(() => {
|
||||
setSortOrder((prev) => (prev === 'newest' ? 'oldest' : 'newest'));
|
||||
}, []);
|
||||
|
||||
// 重置过滤器
|
||||
const resetFilters = useCallback(() => {
|
||||
setSearchKeyword('');
|
||||
setFilterModel('');
|
||||
}, []);
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = useCallback((timestamp) => {
|
||||
try {
|
||||
const date = new Date(timestamp);
|
||||
return date.toLocaleString();
|
||||
} catch (error) {
|
||||
return timestamp;
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 获取模型厂商信息
|
||||
const getVendorInfo = useCallback((modelValue) => {
|
||||
const vendorMap = {
|
||||
'dall-e-3': 'OpenAI',
|
||||
'dall-e-2': 'OpenAI',
|
||||
'gpt-image-1': 'OpenAI',
|
||||
'imagen-3': 'Google',
|
||||
'flux.1-schnell': 'Black Forest Labs',
|
||||
'flux.1-dev': 'Black Forest Labs',
|
||||
};
|
||||
return vendorMap[modelValue] || 'Unknown';
|
||||
}, []);
|
||||
|
||||
// 渲染历史记录项
|
||||
const renderHistoryItem = useCallback(
|
||||
(record) => {
|
||||
return (
|
||||
<Card
|
||||
key={record.id}
|
||||
className='cursor-pointer hover:shadow-md transition-all duration-200 mb-4'
|
||||
>
|
||||
<div className='p-4' onClick={() => handleShowDetail(record)}>
|
||||
<div className='flex justify-between items-start mb-3'>
|
||||
<div>
|
||||
<div className='flex items-center'>
|
||||
<Tag color='blue' className='mr-2'>
|
||||
{getVendorInfo(record.model)}
|
||||
</Tag>
|
||||
<span className='font-medium text-sm'>{record.model}</span>
|
||||
</div>
|
||||
<div className='flex items-center mt-1'>
|
||||
<Clock size={12} className='text-gray-400 mr-1' />
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{formatTime(record.timestamp)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='flex flex-col items-end'>
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{record.size}
|
||||
</span>
|
||||
<span className='text-xs text-gray-500 dark:text-gray-400'>
|
||||
{record.images.length} {t('张图片')}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Paragraph className='mb-3 text-sm line-clamp-2'>
|
||||
{record.prompt}
|
||||
</Paragraph>
|
||||
|
||||
<div className='grid grid-cols-4 gap-2'>
|
||||
{record.images.slice(0, 4).map((img, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className='relative rounded overflow-hidden aspect-square bg-gray-100 dark:bg-gray-800'
|
||||
>
|
||||
<img
|
||||
src={img.url}
|
||||
alt={`Generated ${idx}`}
|
||||
className='w-full h-full object-cover'
|
||||
loading='lazy'
|
||||
/>
|
||||
{record.images.length > 4 && idx === 3 && (
|
||||
<div className='absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center'>
|
||||
<span className='text-white text-xs'>
|
||||
+{record.images.length - 4}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='absolute top-2 right-2 z-10'>
|
||||
<Dropdown
|
||||
render={
|
||||
<Space className='bg-white dark:bg-gray-800 shadow-lg rounded p-2'>
|
||||
<Button
|
||||
type='tertiary'
|
||||
size='small'
|
||||
className='w-full justify-start'
|
||||
onClick={() => {
|
||||
handleLoadFromHistory(record);
|
||||
}}
|
||||
>
|
||||
{t('加载参数')}
|
||||
</Button>
|
||||
<Button
|
||||
type='tertiary'
|
||||
size='small'
|
||||
className='w-full justify-start'
|
||||
onClick={() => handleRegenerate(record)}
|
||||
>
|
||||
{t('重新生成')}
|
||||
</Button>
|
||||
<Divider className='my-1' />
|
||||
<Popconfirm
|
||||
title={t('确认删除')}
|
||||
content={t('确定要删除这条历史记录吗?')}
|
||||
onConfirm={() => handleDeleteRecord(record.id)}
|
||||
okText={t('确认')}
|
||||
cancelText={t('取消')}
|
||||
>
|
||||
<Button
|
||||
type='tertiary'
|
||||
size='small'
|
||||
danger
|
||||
className='w-full justify-start'
|
||||
>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
}
|
||||
>
|
||||
<Button type='text' size='small' className='hover:bg-transparent'>
|
||||
<MoreVertical size={16} />
|
||||
</Button>
|
||||
</Dropdown>
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
},
|
||||
[
|
||||
handleShowDetail,
|
||||
handleLoadFromHistory,
|
||||
handleRegenerate,
|
||||
handleDeleteRecord,
|
||||
getVendorInfo,
|
||||
formatTime,
|
||||
t,
|
||||
],
|
||||
);
|
||||
|
||||
// 渲染详情模态框
|
||||
const renderDetailModal = () => {
|
||||
if (!selectedRecord) return null;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={t('历史记录详情')}
|
||||
visible={showDetailModal}
|
||||
onCancel={() => setShowDetailModal(false)}
|
||||
width={800}
|
||||
footer={[
|
||||
<Button
|
||||
key='regenerate'
|
||||
type='primary'
|
||||
onClick={() => handleRegenerate(selectedRecord)}
|
||||
>
|
||||
{t('重新生成')}
|
||||
</Button>,
|
||||
<Button
|
||||
key='load'
|
||||
onClick={() => handleLoadFromHistory(selectedRecord)}
|
||||
>
|
||||
{t('加载参数')}
|
||||
</Button>,
|
||||
<Button key='close' onClick={() => setShowDetailModal(false)}>
|
||||
{t('关闭')}
|
||||
</Button>,
|
||||
]}
|
||||
>
|
||||
<div className='space-y-4'>
|
||||
{/* 基本信息 */}
|
||||
<div>
|
||||
<Title level={5} className='mb-2'>
|
||||
{t('基本信息')}
|
||||
</Title>
|
||||
<div className='grid grid-cols-2 gap-4'>
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
{t('模型')}
|
||||
</Text>
|
||||
<div className='flex items-center'>
|
||||
<Tag color='blue' className='mr-2'>
|
||||
{getVendorInfo(selectedRecord.model)}
|
||||
</Tag>
|
||||
<Text>{selectedRecord.model}</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
{t('生成时间')}
|
||||
</Text>
|
||||
<div className='flex items-center'>
|
||||
<Clock size={14} className='text-gray-400 mr-1' />
|
||||
<Text>{formatTime(selectedRecord.timestamp)}</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
{t('图片尺寸')}
|
||||
</Text>
|
||||
<div className='flex items-center'>
|
||||
<ImageIcon size={14} className='text-gray-400 mr-1' />
|
||||
<Text>{selectedRecord.size}</Text>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
{t('图片质量')}
|
||||
</Text>
|
||||
<Text>
|
||||
{selectedRecord.quality === 'hd' ? t('高清') : t('标准')}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 提示词 */}
|
||||
<div>
|
||||
<Title level={5} className='mb-2'>
|
||||
{t('提示词')}
|
||||
</Title>
|
||||
<Card className='bg-gray-50 dark:bg-gray-800/50'>
|
||||
<Paragraph className='mb-0'>{selectedRecord.prompt}</Paragraph>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* 反向提示词 */}
|
||||
{selectedRecord.negativePrompt && (
|
||||
<div>
|
||||
<Title level={5} className='mb-2'>
|
||||
{t('反向提示词')}
|
||||
</Title>
|
||||
<Card className='bg-gray-50 dark:bg-gray-800/50'>
|
||||
<Paragraph className='mb-0'>
|
||||
{selectedRecord.negativePrompt}
|
||||
</Paragraph>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 生成的图片 */}
|
||||
<div>
|
||||
<Title level={5} className='mb-2'>
|
||||
{t('生成结果')}
|
||||
</Title>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
|
||||
{selectedRecord.images.map((img, idx) => (
|
||||
<Card key={idx} className='overflow-hidden'>
|
||||
<div className='aspect-square relative'>
|
||||
<img
|
||||
src={img.url}
|
||||
alt={`Generated ${idx + 1}`}
|
||||
className='w-full h-full object-contain bg-white dark:bg-gray-800'
|
||||
/>
|
||||
<Button
|
||||
size='small'
|
||||
type='primary'
|
||||
circle
|
||||
icon={<Download size={14} />}
|
||||
className='absolute bottom-2 right-2 bg-white/90 hover:bg-white text-black'
|
||||
onClick={() => {
|
||||
const link = document.createElement('a');
|
||||
link.href = img.url;
|
||||
link.download = `history-image-${selectedRecord.id}-${idx}.png`;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
{/* 标题和操作栏 */}
|
||||
<div className='flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4'>
|
||||
<div className='flex items-center'>
|
||||
<History className='h-5 w-5 text-blue-600 dark:text-blue-400 mr-2' />
|
||||
<Title level={4} className='mb-0'>
|
||||
{t('生成历史')}
|
||||
{filteredHistory.length > 0 && (
|
||||
<Badge count={filteredHistory.length} className='ml-2' />
|
||||
)}
|
||||
</Title>
|
||||
</div>
|
||||
|
||||
<div className='flex flex-wrap gap-2 w-full sm:w-auto'>
|
||||
<Button
|
||||
type='tertiary'
|
||||
size='small'
|
||||
icon={<Filter size={16} />}
|
||||
onClick={() => setShowFilters(!showFilters)}
|
||||
>
|
||||
{t('筛选')}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
type='tertiary'
|
||||
size='small'
|
||||
icon={<Clock size={16} />}
|
||||
onClick={toggleSortOrder}
|
||||
>
|
||||
{sortOrder === 'newest' ? t('最新优先') : t('最早优先')}
|
||||
</Button>
|
||||
|
||||
<Popconfirm
|
||||
title={t('确认清空')}
|
||||
content={t('确定要清空所有历史记录吗?此操作不可恢复。')}
|
||||
onConfirm={handleClearAll}
|
||||
okText={t('确认')}
|
||||
cancelText={t('取消')}
|
||||
>
|
||||
<Button
|
||||
type='tertiary'
|
||||
size='small'
|
||||
danger
|
||||
icon={<Trash2 size={16} />}
|
||||
disabled={history.length === 0}
|
||||
>
|
||||
{t('清空全部')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 搜索框 */}
|
||||
<div className='space-y-3'>
|
||||
<Input
|
||||
value={searchKeyword}
|
||||
onChange={(e) => setSearchKeyword(e.target.value)}
|
||||
placeholder={t('搜索提示词、反向提示词或模型...')}
|
||||
prefix={<Search size={16} />}
|
||||
allowClear
|
||||
className='w-full'
|
||||
/>
|
||||
|
||||
{/* 高级筛选 */}
|
||||
<Collapse
|
||||
items={[
|
||||
{
|
||||
title: t('高级筛选'),
|
||||
content: (
|
||||
<div className='space-y-3 p-2'>
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs mb-1'>
|
||||
{t('按模型筛选')}
|
||||
</Text>
|
||||
<div className='flex flex-wrap gap-2'>
|
||||
<Tag
|
||||
color={filterModel === '' ? 'blue' : 'gray'}
|
||||
clickable
|
||||
onClick={() => setFilterModel('')}
|
||||
>
|
||||
{t('全部')}
|
||||
</Tag>
|
||||
{allModels.map((model) => (
|
||||
<Tag
|
||||
key={model}
|
||||
color={filterModel === model ? 'blue' : 'gray'}
|
||||
clickable
|
||||
onClick={() => setFilterModel(model)}
|
||||
>
|
||||
{model}
|
||||
</Tag>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{filterModel || searchKeyword ? (
|
||||
<Button
|
||||
type='text'
|
||||
size='small'
|
||||
onClick={resetFilters}
|
||||
icon={<X size={14} />}
|
||||
>
|
||||
{t('重置筛选')}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
),
|
||||
isOpen: showFilters,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 历史记录列表 */}
|
||||
<div className='space-y-4'>
|
||||
{isLoading ? (
|
||||
<div className='py-16 flex justify-center'>
|
||||
<Spin size='large' />
|
||||
</div>
|
||||
) : filteredHistory.length > 0 ? (
|
||||
filteredHistory.map((record) => renderHistoryItem(record))
|
||||
) : (
|
||||
<Card className='text-center py-16'>
|
||||
<Empty
|
||||
description={
|
||||
searchKeyword || filterModel
|
||||
? t('没有找到匹配的历史记录')
|
||||
: t('暂无历史记录')
|
||||
}
|
||||
>
|
||||
{searchKeyword || filterModel ? (
|
||||
<Button type='primary' size='small' onClick={resetFilters}>
|
||||
{t('清除筛选条件')}
|
||||
</Button>
|
||||
) : (
|
||||
<Text type='secondary' className='mt-2'>
|
||||
{t('生成图片后,历史记录将显示在这里')}
|
||||
</Text>
|
||||
)}
|
||||
</Empty>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 详情模态框 */}
|
||||
{renderDetailModal()}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ImageHistory;
|
||||
@@ -0,0 +1,457 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Spin,
|
||||
Progress,
|
||||
Alert,
|
||||
Button,
|
||||
Typography,
|
||||
Card,
|
||||
Empty,
|
||||
Space,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import {
|
||||
Loading3,
|
||||
AlertCircle,
|
||||
CheckCircle,
|
||||
Clock,
|
||||
Image as ImageIcon,
|
||||
FileQuestion,
|
||||
Wifi,
|
||||
CreditCard,
|
||||
AlertTriangle,
|
||||
Sparkles,
|
||||
} from 'lucide-react';
|
||||
|
||||
const { Title, Text, Paragraph } = Typography;
|
||||
|
||||
/**
|
||||
* 图片状态显示组件
|
||||
* 用于展示图片生成过程中的加载、错误和成功状态
|
||||
* @param {Object} props 组件属性
|
||||
*/
|
||||
const ImageStatusDisplay = ({
|
||||
isLoading = false,
|
||||
loadingStage = 'idle',
|
||||
progress = 0,
|
||||
error = null,
|
||||
successMessage = '',
|
||||
onRetry,
|
||||
onBack,
|
||||
onAction,
|
||||
detailMode = false,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
// 根据加载阶段获取图标和描述
|
||||
const loadingInfo = useMemo(() => {
|
||||
const stageInfo = {
|
||||
idle: {
|
||||
icon: <Loading3 className='animate-spin' size={detailMode ? 48 : 24} />,
|
||||
title: t('准备中'),
|
||||
description: t('正在初始化...'),
|
||||
},
|
||||
processing: {
|
||||
icon: (
|
||||
<Sparkles className='animate-pulse' size={detailMode ? 48 : 24} />
|
||||
),
|
||||
title: t('处理提示词'),
|
||||
description: t('正在分析您的提示词...'),
|
||||
},
|
||||
generating: {
|
||||
icon: (
|
||||
<ImageIcon
|
||||
className='animate-spin-slow'
|
||||
size={detailMode ? 48 : 24}
|
||||
/>
|
||||
),
|
||||
title: t('生成图像'),
|
||||
description: t('AI正在绘制图像...'),
|
||||
},
|
||||
completing: {
|
||||
icon: <Loading3 className='animate-spin' size={detailMode ? 48 : 24} />,
|
||||
title: t('优化质量'),
|
||||
description: t('正在优化图片细节...'),
|
||||
},
|
||||
};
|
||||
|
||||
return stageInfo[loadingStage] || stageInfo.idle;
|
||||
}, [loadingStage, detailMode, t]);
|
||||
|
||||
// 根据错误类型获取图标和建议
|
||||
const errorInfo = useMemo(() => {
|
||||
if (!error) return null;
|
||||
|
||||
const typeInfo = {
|
||||
network: {
|
||||
icon: <Wifi size={detailMode ? 48 : 24} />,
|
||||
title: t('网络错误'),
|
||||
action: t('重试连接'),
|
||||
},
|
||||
validation: {
|
||||
icon: <AlertTriangle size={detailMode ? 48 : 24} />,
|
||||
title: t('参数错误'),
|
||||
action: t('修改参数'),
|
||||
},
|
||||
api: {
|
||||
icon: <FileQuestion size={detailMode ? 48 : 24} />,
|
||||
title: t('API错误'),
|
||||
action: t('查看详情'),
|
||||
},
|
||||
rate_limit: {
|
||||
icon: <Clock size={detailMode ? 48 : 24} />,
|
||||
title: t('请求限制'),
|
||||
action: t('稍后重试'),
|
||||
},
|
||||
credit: {
|
||||
icon: <CreditCard size={detailMode ? 48 : 24} />,
|
||||
title: t('余额不足'),
|
||||
action: t('去充值'),
|
||||
},
|
||||
unknown: {
|
||||
icon: <AlertCircle size={detailMode ? 48 : 24} />,
|
||||
title: t('未知错误'),
|
||||
action: t('联系支持'),
|
||||
},
|
||||
};
|
||||
|
||||
return typeInfo[error.type] || typeInfo.unknown;
|
||||
}, [error, detailMode, t]);
|
||||
|
||||
// 渲染加载状态
|
||||
const renderLoading = () => {
|
||||
if (!isLoading) return null;
|
||||
|
||||
if (detailMode) {
|
||||
return (
|
||||
<Card className='text-center p-8'>
|
||||
<div className='mb-6 flex justify-center'>
|
||||
<div className='p-4 rounded-full bg-blue-50 dark:bg-blue-900/30 text-blue-600 dark:text-blue-400'>
|
||||
{loadingInfo.icon}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Title level={4} className='mb-2'>
|
||||
{loadingInfo.title}
|
||||
</Title>
|
||||
|
||||
<Paragraph className='text-gray-500 dark:text-gray-400 mb-6'>
|
||||
{loadingInfo.description}
|
||||
</Paragraph>
|
||||
|
||||
<Progress
|
||||
percent={progress}
|
||||
strokeWidth={8}
|
||||
status='active'
|
||||
showText={false}
|
||||
format={() => `${progress}%`}
|
||||
className='mb-2'
|
||||
/>
|
||||
|
||||
<Text type='secondary' className='text-xs'>
|
||||
{`${t('进度')}: ${progress}%`}
|
||||
</Text>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='flex items-center justify-center p-4'>
|
||||
<Space size='large' align='center'>
|
||||
<Spin size='large' />
|
||||
<div className='text-center'>
|
||||
<div className='font-medium mb-1'>{loadingInfo.title}</div>
|
||||
<div className='text-sm text-gray-500 dark:text-gray-400'>
|
||||
{loadingInfo.description}
|
||||
</div>
|
||||
</div>
|
||||
</Space>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染错误状态
|
||||
const renderError = () => {
|
||||
if (!error) return null;
|
||||
|
||||
const errorAction = () => {
|
||||
if (error.type === 'network' || error.type === 'rate_limit') {
|
||||
onRetry?.();
|
||||
} else if (onAction) {
|
||||
onAction(error.type, error);
|
||||
}
|
||||
};
|
||||
|
||||
if (detailMode) {
|
||||
return (
|
||||
<Card className='text-center p-8 bg-red-50/30 dark:bg-red-900/10'>
|
||||
<div className='mb-6 flex justify-center'>
|
||||
<div className='p-4 rounded-full bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400'>
|
||||
{errorInfo.icon}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Title level={4} className='mb-2'>
|
||||
{errorInfo.title}
|
||||
</Title>
|
||||
|
||||
<Paragraph className='text-gray-700 dark:text-gray-300 mb-6'>
|
||||
{error.message}
|
||||
</Paragraph>
|
||||
|
||||
{error.details && (
|
||||
<div className='mb-6 bg-white dark:bg-gray-800 p-4 rounded-md text-left'>
|
||||
<Text type='secondary' className='text-xs mb-2'>
|
||||
{t('错误详情')}
|
||||
</Text>
|
||||
<Text className='text-xs whitespace-pre-wrap'>
|
||||
{JSON.stringify(error.details, null, 2)}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Space className='justify-center'>
|
||||
<Button type='primary' onClick={errorAction}>
|
||||
{errorInfo.action}
|
||||
</Button>
|
||||
{onBack && <Button onClick={onBack}>{t('返回')}</Button>}
|
||||
</Space>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert
|
||||
type='error'
|
||||
message={errorInfo.title}
|
||||
description={error.message}
|
||||
action={
|
||||
<Button size='small' type='tertiary' onClick={errorAction}>
|
||||
{errorInfo.action}
|
||||
</Button>
|
||||
}
|
||||
className='my-4'
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染成功状态
|
||||
const renderSuccess = () => {
|
||||
if (isLoading || error || !successMessage) return null;
|
||||
|
||||
if (detailMode) {
|
||||
return (
|
||||
<Card className='text-center p-8 bg-green-50/30 dark:bg-green-900/10'>
|
||||
<div className='mb-6 flex justify-center'>
|
||||
<div className='p-4 rounded-full bg-green-50 dark:bg-green-900/30 text-green-600 dark:text-green-400'>
|
||||
<CheckCircle size={detailMode ? 48 : 24} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Title level={4} className='mb-2'>
|
||||
{t('成功')}
|
||||
</Title>
|
||||
|
||||
<Paragraph className='text-gray-700 dark:text-gray-300 mb-6'>
|
||||
{successMessage}
|
||||
</Paragraph>
|
||||
|
||||
{onBack && <Button onClick={onBack}>{t('返回')}</Button>}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert
|
||||
type='success'
|
||||
message={t('成功')}
|
||||
description={successMessage}
|
||||
showIcon
|
||||
className='my-4'
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染空状态
|
||||
const renderEmpty = () => {
|
||||
if (isLoading || error || successMessage) return null;
|
||||
|
||||
return (
|
||||
<Card className='text-center p-8'>
|
||||
<Empty
|
||||
description={
|
||||
<Text type='secondary'>{t('请输入提示词并开始生成图片')}</Text>
|
||||
}
|
||||
/>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
|
||||
// 如果在详情模式下,显示完整的状态卡片
|
||||
if (detailMode) {
|
||||
return (
|
||||
<div className='animate-fade-in'>
|
||||
{renderLoading()}
|
||||
{renderError()}
|
||||
{renderSuccess()}
|
||||
{renderEmpty()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 非详情模式下,显示紧凑的状态信息
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
{renderLoading()}
|
||||
{renderError()}
|
||||
{renderSuccess()}
|
||||
{renderEmpty()}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 图片生成进度条组件
|
||||
* 用于显示更详细的生成进度
|
||||
*/
|
||||
export const ImageProgressBar = ({ stage, progress }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const stages = [
|
||||
{ key: 'idle', label: t('准备'), icon: <Loading3 size={14} /> },
|
||||
{ key: 'processing', label: t('处理'), icon: <Sparkles size={14} /> },
|
||||
{ key: 'generating', label: t('生成'), icon: <ImageIcon size={14} /> },
|
||||
{ key: 'completing', label: t('完成'), icon: <CheckCircle size={14} /> },
|
||||
];
|
||||
|
||||
const currentStageIndex = stages.findIndex((s) => s.key === stage);
|
||||
|
||||
return (
|
||||
<div className='bg-gray-100 dark:bg-gray-800 rounded-lg p-4'>
|
||||
<Text type='secondary' className='text-xs mb-2'>
|
||||
{t('生成进度')}
|
||||
</Text>
|
||||
|
||||
<Progress
|
||||
percent={progress}
|
||||
strokeWidth={6}
|
||||
status='active'
|
||||
format={() => ''}
|
||||
className='mb-4'
|
||||
/>
|
||||
|
||||
<div className='flex items-center justify-between'>
|
||||
{stages.map((s, index) => {
|
||||
const isActive = index <= currentStageIndex;
|
||||
const isLast = index === stages.length - 1;
|
||||
|
||||
return (
|
||||
<React.Fragment key={s.key}>
|
||||
<div
|
||||
className={`flex flex-col items-center ${isActive ? 'text-blue-600 dark:text-blue-400' : 'text-gray-400'}`}
|
||||
>
|
||||
<div
|
||||
className={`w-7 h-7 flex items-center justify-center rounded-full mb-1 ${isActive ? 'bg-blue-100 dark:bg-blue-900/40' : 'bg-gray-200 dark:bg-gray-700'}`}
|
||||
>
|
||||
{s.icon}
|
||||
</div>
|
||||
<Text className='text-xs whitespace-nowrap'>{s.label}</Text>
|
||||
</div>
|
||||
|
||||
{!isLast && (
|
||||
<div
|
||||
className={`flex-1 mx-1 h-1 ${isActive ? 'bg-blue-600 dark:bg-blue-400' : 'bg-gray-300 dark:bg-gray-700'}`}
|
||||
/>
|
||||
)}
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 图片生成通知组件
|
||||
*/
|
||||
export const ImageNotification = ({ notification, onClose }) => {
|
||||
if (!notification) return null;
|
||||
|
||||
const getTypeProps = (type) => {
|
||||
switch (type) {
|
||||
case 'success':
|
||||
return {
|
||||
icon: <CheckCircle size={16} className='text-green-500' />,
|
||||
bg: 'bg-green-50 dark:bg-green-900/20',
|
||||
border: 'border-green-100 dark:border-green-800',
|
||||
};
|
||||
case 'error':
|
||||
return {
|
||||
icon: <AlertCircle size={16} className='text-red-500' />,
|
||||
bg: 'bg-red-50 dark:bg-red-900/20',
|
||||
border: 'border-red-100 dark:border-red-800',
|
||||
};
|
||||
case 'warning':
|
||||
return {
|
||||
icon: <AlertTriangle size={16} className='text-yellow-500' />,
|
||||
bg: 'bg-yellow-50 dark:bg-yellow-900/20',
|
||||
border: 'border-yellow-100 dark:border-yellow-800',
|
||||
};
|
||||
default:
|
||||
return {
|
||||
icon: <AlertCircle size={16} className='text-blue-500' />,
|
||||
bg: 'bg-blue-50 dark:bg-blue-900/20',
|
||||
border: 'border-blue-100 dark:border-blue-800',
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const typeProps = getTypeProps(notification.type);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`fixed top-4 right-4 z-50 w-80 animate-slide-in-right ${typeProps.bg} border ${typeProps.border} rounded-lg p-4 shadow-lg`}
|
||||
>
|
||||
<div className='flex items-start justify-between'>
|
||||
<div className='flex items-center'>
|
||||
{typeProps.icon}
|
||||
<Text className='ml-2 text-sm'>{notification.message}</Text>
|
||||
</div>
|
||||
<Button type='text' size='small' className='ml-2' onClick={onClose}>
|
||||
<X size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className='mt-2 h-1 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden'>
|
||||
<div
|
||||
className='h-full bg-gray-400 dark:bg-gray-500'
|
||||
style={{
|
||||
width: `${100 - (notification.duration * (Date.now() - notification.id)) / 1000}%`,
|
||||
transition: 'width 10ms linear',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ImageStatusDisplay;
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
const FooterBar = () => {
|
||||
// 全局隐藏页脚
|
||||
return null;
|
||||
};
|
||||
|
||||
export default FooterBar;
|
||||
@@ -0,0 +1,233 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useContext, useMemo, useRef, useState, useEffect } from 'react';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { Megaphone } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const Marquee = () => {
|
||||
const { t } = useTranslation();
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const marqueeContent = statusState?.status?.marquee_content || '';
|
||||
const containerRef = useRef(null);
|
||||
const measureRef = useRef(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
const [scrollConfig, setScrollConfig] = useState({
|
||||
padding: 0,
|
||||
duration: 20,
|
||||
});
|
||||
|
||||
// 将 | 分隔的多条公告拼接成一条,用分隔符分开
|
||||
const displayText = useMemo(() => {
|
||||
if (!marqueeContent.trim()) return '';
|
||||
const items = marqueeContent
|
||||
.split('|')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
if (items.length === 0) return '';
|
||||
// 每条公告之间添加装饰分隔符
|
||||
return items.join(' ✦ ');
|
||||
}, [marqueeContent]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!displayText) {
|
||||
setReady(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const update = () => {
|
||||
const container = containerRef.current;
|
||||
const measureEl = measureRef.current;
|
||||
if (!container || !measureEl) return;
|
||||
|
||||
const containerWidth = container.offsetWidth;
|
||||
const textWidth = measureEl.offsetWidth;
|
||||
|
||||
// 每份文本后留出容器宽度的间距
|
||||
// 这样文本1从左边消失时,文本2刚好从右边进入
|
||||
// 总 "单元" 宽度 = textWidth + containerWidth
|
||||
// translateX(-50%) 正好移动一个单元,形成无缝循环
|
||||
const scrollDistance = textWidth + containerWidth;
|
||||
const speed = 50; // 像素/秒
|
||||
const duration = Math.max(scrollDistance / speed, 5);
|
||||
|
||||
setScrollConfig({ padding: containerWidth, duration });
|
||||
setReady(true);
|
||||
};
|
||||
|
||||
// 等待下一帧让测量元素渲染完成
|
||||
const raf = requestAnimationFrame(update);
|
||||
window.addEventListener('resize', update);
|
||||
return () => {
|
||||
cancelAnimationFrame(raf);
|
||||
window.removeEventListener('resize', update);
|
||||
};
|
||||
}, [displayText]);
|
||||
|
||||
if (!displayText) return null;
|
||||
|
||||
return (
|
||||
<div className='marquee-bar relative w-full overflow-hidden z-[99]'>
|
||||
{/* 顶部发光线 */}
|
||||
<div className='absolute top-0 left-0 right-0 h-[1px] bg-gradient-to-r from-transparent via-white/50 to-transparent dark:via-white/20' />
|
||||
|
||||
<div className='flex items-center h-10 px-5'>
|
||||
{/* 左侧图标 - 固定不动 */}
|
||||
<div className='flex-shrink-0 flex items-center gap-2 mr-4 z-10'>
|
||||
<div
|
||||
className='flex items-center justify-center w-6 h-6 rounded-full bg-white/20 dark:bg-white/10 backdrop-blur-sm'
|
||||
style={{ boxShadow: '0 0 8px rgba(255,255,255,0.2)' }}
|
||||
>
|
||||
<Megaphone size={13} className='text-white drop-shadow-sm' />
|
||||
</div>
|
||||
<span className='text-[13px] font-semibold text-white hidden sm:inline tracking-wider drop-shadow-sm'>
|
||||
{t('公告')}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* 跑马灯滚动区域 */}
|
||||
<div ref={containerRef} className='flex-1 overflow-hidden relative'>
|
||||
{/* 隐藏的测量元素 - 用于获取文本自然宽度,不受动态 padding 影响 */}
|
||||
<span
|
||||
ref={measureRef}
|
||||
className='invisible absolute whitespace-nowrap text-[14px] font-medium tracking-wide'
|
||||
style={{ top: -9999, left: -9999 }}
|
||||
aria-hidden='true'
|
||||
>
|
||||
{displayText}
|
||||
</span>
|
||||
|
||||
{/* 左侧渐变遮罩 */}
|
||||
<div className='marquee-mask-left absolute left-0 top-0 bottom-0 w-10 z-10' />
|
||||
{/* 右侧渐变遮罩 */}
|
||||
<div className='marquee-mask-right absolute right-0 top-0 bottom-0 w-10 z-10' />
|
||||
|
||||
{ready && (
|
||||
<div
|
||||
className='marquee-scroll inline-flex whitespace-nowrap'
|
||||
style={{ animationDuration: `${scrollConfig.duration}s` }}
|
||||
>
|
||||
<span
|
||||
className='marquee-text inline-block shrink-0 text-[14px] text-white/95 dark:text-white/90 font-medium tracking-wide'
|
||||
style={{ paddingRight: scrollConfig.padding }}
|
||||
>
|
||||
{displayText}
|
||||
</span>
|
||||
<span
|
||||
className='marquee-text inline-block shrink-0 text-[14px] text-white/95 dark:text-white/90 font-medium tracking-wide'
|
||||
style={{ paddingRight: scrollConfig.padding }}
|
||||
aria-hidden='true'
|
||||
>
|
||||
{displayText}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 底部发光线 */}
|
||||
<div className='absolute bottom-0 left-0 right-0 h-[1px] bg-gradient-to-r from-transparent via-white/25 to-transparent dark:via-white/10' />
|
||||
|
||||
<style>{`
|
||||
/* 亮色模式 - 跟随主题色的 5 段渐变 */
|
||||
.marquee-bar {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
var(--brand-primary-hover) 0%,
|
||||
var(--brand-gradient-via) 25%,
|
||||
var(--brand-gradient-to) 50%,
|
||||
var(--brand-primary) 75%,
|
||||
var(--brand-primary-hover) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
animation: marquee-bg-shift 8s ease-in-out infinite;
|
||||
box-shadow:
|
||||
0 2px 8px color-mix(in srgb, var(--brand-primary) 30%, transparent),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
.marquee-mask-left {
|
||||
background: linear-gradient(to right, var(--brand-primary-hover), transparent);
|
||||
}
|
||||
|
||||
.marquee-mask-right {
|
||||
background: linear-gradient(to left, var(--brand-primary), transparent);
|
||||
}
|
||||
|
||||
/* 深色模式 - 同色调但与黑色混合更沉稳 */
|
||||
html.dark .marquee-bar {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
color-mix(in srgb, var(--brand-primary) 35%, #000) 0%,
|
||||
color-mix(in srgb, var(--brand-gradient-via) 35%, #000) 25%,
|
||||
color-mix(in srgb, var(--brand-primary) 40%, #000) 50%,
|
||||
color-mix(in srgb, var(--brand-primary) 35%, #000) 75%,
|
||||
color-mix(in srgb, var(--brand-primary) 35%, #000) 100%
|
||||
);
|
||||
background-size: 200% 100%;
|
||||
box-shadow:
|
||||
0 2px 12px color-mix(in srgb, var(--brand-primary) 30%, #000),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
html.dark .marquee-mask-left {
|
||||
background: linear-gradient(to right, color-mix(in srgb, var(--brand-primary) 35%, #000), transparent);
|
||||
}
|
||||
|
||||
html.dark .marquee-mask-right {
|
||||
background: linear-gradient(to left, color-mix(in srgb, var(--brand-primary) 35%, #000), transparent);
|
||||
}
|
||||
|
||||
@keyframes marquee-bg-shift {
|
||||
0%, 100% { background-position: 0% 0; }
|
||||
50% { background-position: 100% 0; }
|
||||
}
|
||||
|
||||
@keyframes marquee-scroll-anim {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
}
|
||||
|
||||
.marquee-scroll {
|
||||
animation: marquee-scroll-anim 20s linear infinite;
|
||||
}
|
||||
|
||||
.marquee-scroll:hover {
|
||||
animation-play-state: paused;
|
||||
}
|
||||
|
||||
.marquee-text {
|
||||
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15), 0 0 12px rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
html.dark .marquee-text {
|
||||
text-shadow:
|
||||
0 1px 3px rgba(0, 0, 0, 0.4),
|
||||
0 0 8px color-mix(in srgb, var(--brand-gradient-to) 15%, transparent);
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Marquee;
|
||||
@@ -0,0 +1,436 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState, useContext, useMemo } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { API, showError, getRelativeTime } from '../../helpers';
|
||||
import { marked } from 'marked';
|
||||
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import {
|
||||
Bell,
|
||||
Megaphone,
|
||||
Sparkles,
|
||||
X,
|
||||
CalendarClock,
|
||||
Volume2,
|
||||
Clock,
|
||||
ChevronRight,
|
||||
} from 'lucide-react';
|
||||
|
||||
const NoticeModal = ({
|
||||
visible,
|
||||
onClose,
|
||||
isMobile,
|
||||
defaultTab = 'inApp',
|
||||
unreadKeys = [],
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [noticeContent, setNoticeContent] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [activeTab, setActiveTab] = useState(defaultTab);
|
||||
|
||||
const [statusState] = useContext(StatusContext);
|
||||
|
||||
const announcements = statusState?.status?.announcements || [];
|
||||
|
||||
const unreadSet = useMemo(() => new Set(unreadKeys), [unreadKeys]);
|
||||
|
||||
const getKeyForItem = (item) =>
|
||||
`${item?.publishDate || ''}-${(item?.content || '').slice(0, 30)}`;
|
||||
|
||||
const processedAnnouncements = useMemo(() => {
|
||||
return (announcements || []).slice(0, 20).map((item) => {
|
||||
const pubDate = item?.publishDate ? new Date(item.publishDate) : null;
|
||||
const absoluteTime =
|
||||
pubDate && !isNaN(pubDate.getTime())
|
||||
? `${pubDate.getFullYear()}-${String(pubDate.getMonth() + 1).padStart(2, '0')}-${String(pubDate.getDate()).padStart(2, '0')} ${String(pubDate.getHours()).padStart(2, '0')}:${String(pubDate.getMinutes()).padStart(2, '0')}`
|
||||
: item?.publishDate || '';
|
||||
return {
|
||||
key: getKeyForItem(item),
|
||||
type: item.type || 'default',
|
||||
time: absoluteTime,
|
||||
content: item.content,
|
||||
extra: item.extra,
|
||||
relative: getRelativeTime(item.publishDate),
|
||||
isUnread: unreadSet.has(getKeyForItem(item)),
|
||||
};
|
||||
});
|
||||
}, [announcements, unreadSet]);
|
||||
|
||||
const handleCloseTodayNotice = () => {
|
||||
const today = new Date().toDateString();
|
||||
localStorage.setItem('notice_close_date', today);
|
||||
onClose();
|
||||
};
|
||||
|
||||
const displayNotice = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await API.get('/api/notice');
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
if (data !== '') {
|
||||
const htmlNotice = marked.parse(data);
|
||||
setNoticeContent(htmlNotice);
|
||||
} else {
|
||||
setNoticeContent('');
|
||||
}
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
displayNotice();
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) {
|
||||
setActiveTab(defaultTab);
|
||||
}
|
||||
}, [defaultTab, visible]);
|
||||
|
||||
const renderMarkdownNotice = () => {
|
||||
if (loading) {
|
||||
return (
|
||||
<div className='py-20 flex flex-col items-center justify-center'>
|
||||
<div className='relative'>
|
||||
<div className='w-16 h-16 border-4 border-brand/10 dark:border-brand-deep rounded-full' />
|
||||
<div className='absolute inset-0 w-16 h-16 border-4 border-transparent border-t-brand rounded-full animate-spin' />
|
||||
<div
|
||||
className='absolute inset-2 w-12 h-12 border-4 border-transparent border-t-brand-via rounded-full animate-spin'
|
||||
style={{
|
||||
animationDirection: 'reverse',
|
||||
animationDuration: '0.8s',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<span className='mt-4 text-gray-500 dark:text-gray-400 font-medium'>
|
||||
{t('加载中...')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!noticeContent) {
|
||||
return (
|
||||
<div className='py-16 flex flex-col items-center justify-center'>
|
||||
<div className='relative'>
|
||||
<div className='w-24 h-24 bg-gradient-to-br from-brand-from/5 to-brand-to/5 dark:from-brand-from/30 dark:to-brand-to/30 rounded-3xl flex items-center justify-center shadow-inner'>
|
||||
<Bell
|
||||
size={40}
|
||||
className='text-brand-from dark:text-brand-deep'
|
||||
/>
|
||||
</div>
|
||||
<div className='absolute -bottom-1 -right-1 w-8 h-8 bg-gradient-to-br from-emerald-400 to-teal-500 rounded-xl flex items-center justify-center shadow-lg'>
|
||||
<Sparkles size={16} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<span className='mt-5 text-gray-700 dark:text-gray-300 text-lg font-semibold'>
|
||||
{t('暂无公告')}
|
||||
</span>
|
||||
<span className='text-gray-400 dark:text-gray-500 text-sm mt-1'>
|
||||
{t('一切正常,稍后再来看看吧')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='notice-content-scroll max-h-[50vh] overflow-y-auto pr-2 custom-scrollbar'>
|
||||
<div className='p-4 bg-gray-50/80 dark:bg-gray-800/60 rounded-xl border border-gray-200/60 dark:border-gray-700/40'>
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: noticeContent }}
|
||||
className='prose prose-sm dark:prose-invert max-w-none
|
||||
prose-headings:text-gray-900 dark:prose-headings:text-gray-50 prose-headings:font-bold
|
||||
prose-h1:text-xl prose-h2:text-lg prose-h3:text-base
|
||||
prose-p:text-gray-600 dark:prose-p:text-gray-300 prose-p:leading-relaxed
|
||||
prose-a:text-brand-deep dark:prose-a:text-brand-from prose-a:no-underline hover:prose-a:underline prose-a:font-medium
|
||||
prose-strong:text-gray-800 dark:prose-strong:text-gray-100
|
||||
prose-code:bg-gray-100 dark:prose-code:bg-gray-800 prose-code:text-gray-700 dark:prose-code:text-gray-300 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded-md prose-code:text-xs
|
||||
prose-pre:bg-gray-900 dark:prose-pre:bg-gray-950 prose-pre:text-gray-100 prose-pre:rounded-xl
|
||||
prose-img:rounded-xl
|
||||
prose-ul:space-y-1 prose-ol:space-y-1
|
||||
prose-li:text-gray-600 dark:prose-li:text-gray-300'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const getTypeConfig = (type) => {
|
||||
const configs = {
|
||||
success: {
|
||||
bg: 'bg-emerald-50 dark:bg-emerald-900/20',
|
||||
border: 'border-emerald-200 dark:border-emerald-800',
|
||||
dot: 'bg-emerald-500',
|
||||
tag: 'green',
|
||||
},
|
||||
warning: {
|
||||
bg: 'bg-amber-50 dark:bg-amber-900/20',
|
||||
border: 'border-amber-200 dark:border-amber-800',
|
||||
dot: 'bg-amber-500',
|
||||
tag: 'orange',
|
||||
},
|
||||
error: {
|
||||
bg: 'bg-red-50 dark:bg-red-900/20',
|
||||
border: 'border-red-200 dark:border-red-800',
|
||||
dot: 'bg-red-500',
|
||||
tag: 'red',
|
||||
},
|
||||
ongoing: {
|
||||
bg: 'bg-blue-50 dark:bg-blue-900/20',
|
||||
border: 'border-blue-200 dark:border-blue-800',
|
||||
dot: 'bg-blue-500',
|
||||
tag: 'blue',
|
||||
},
|
||||
default: {
|
||||
bg: 'bg-gray-50 dark:bg-gray-800/50',
|
||||
border: 'border-gray-200 dark:border-gray-700',
|
||||
dot: 'bg-brand',
|
||||
tag: 'violet',
|
||||
},
|
||||
};
|
||||
return configs[type] || configs.default;
|
||||
};
|
||||
|
||||
const renderAnnouncementTimeline = () => {
|
||||
if (processedAnnouncements.length === 0) {
|
||||
return (
|
||||
<div className='py-16 flex flex-col items-center justify-center'>
|
||||
<div className='relative'>
|
||||
<div className='w-24 h-24 bg-gradient-to-br from-emerald-50 to-teal-50 dark:from-emerald-900/30 dark:to-teal-900/30 rounded-3xl flex items-center justify-center shadow-inner'>
|
||||
<Megaphone
|
||||
size={40}
|
||||
className='text-emerald-300 dark:text-emerald-600'
|
||||
/>
|
||||
</div>
|
||||
<div className='absolute -bottom-1 -right-1 w-8 h-8 bg-gradient-to-br from-emerald-400 to-teal-500 rounded-xl flex items-center justify-center shadow-lg'>
|
||||
<Sparkles size={16} className='text-white' />
|
||||
</div>
|
||||
</div>
|
||||
<span className='mt-5 text-gray-700 dark:text-gray-300 text-lg font-semibold'>
|
||||
{t('暂无系统公告')}
|
||||
</span>
|
||||
<span className='text-gray-400 dark:text-gray-500 text-sm mt-1'>
|
||||
{t('一切正常运行中')}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='max-h-[50vh] overflow-y-auto pr-2 custom-scrollbar space-y-3'>
|
||||
{processedAnnouncements.map((item, idx) => {
|
||||
const htmlContent = marked.parse(item.content || '');
|
||||
const htmlExtra = item.extra ? marked.parse(item.extra) : '';
|
||||
const typeConfig = getTypeConfig(item.type);
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className={`group relative rounded-xl border ${typeConfig.bg} ${typeConfig.border} p-4 transition-all duration-200 hover:shadow-md ${item.isUnread ? 'ring-1 ring-brand/30 ring-offset-1 ring-offset-white dark:ring-offset-gray-900' : ''}`}
|
||||
>
|
||||
{/* 未读标记 */}
|
||||
{item.isUnread && (
|
||||
<div className='absolute -top-1.5 -right-1.5'>
|
||||
<span className='relative flex h-4 w-4'>
|
||||
<span className='animate-ping absolute inline-flex h-full w-full rounded-full bg-brand-from opacity-60'></span>
|
||||
<span className='relative inline-flex rounded-full h-4 w-4 bg-gradient-to-r from-brand-from to-brand-to items-center justify-center'>
|
||||
<span className='text-[8px] text-white font-bold'>N</span>
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 时间和类型标签 */}
|
||||
<div className='flex items-center justify-between mb-2.5'>
|
||||
<div className='flex items-center gap-2'>
|
||||
<div
|
||||
className={`w-2 h-2 rounded-full ${typeConfig.dot} flex-shrink-0`}
|
||||
/>
|
||||
<div className='flex items-center gap-1.5 text-xs'>
|
||||
<span className='font-medium text-gray-700 dark:text-gray-300'>
|
||||
{item.relative}
|
||||
</span>
|
||||
<span className='text-gray-300 dark:text-gray-600'>·</span>
|
||||
<span className='text-gray-400 dark:text-gray-500 flex items-center gap-1'>
|
||||
<CalendarClock size={10} />
|
||||
{item.time}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{item.isUnread && (
|
||||
<span className='px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wider rounded-md bg-brand/10 dark:bg-brand/20 text-brand-deep dark:text-brand-from'>
|
||||
NEW
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 公告内容 */}
|
||||
<div
|
||||
className='prose prose-sm dark:prose-invert max-w-none
|
||||
prose-p:text-gray-600 dark:prose-p:text-gray-300 prose-p:my-1 prose-p:leading-relaxed
|
||||
prose-a:text-brand-deep dark:prose-a:text-brand-from prose-a:font-medium prose-a:no-underline hover:prose-a:underline
|
||||
prose-strong:text-gray-800 dark:prose-strong:text-gray-100
|
||||
prose-code:bg-gray-100 dark:prose-code:bg-gray-800 prose-code:text-gray-700 dark:prose-code:text-gray-300 prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-xs'
|
||||
dangerouslySetInnerHTML={{ __html: htmlContent }}
|
||||
/>
|
||||
|
||||
{/* 额外信息 */}
|
||||
{item.extra && (
|
||||
<div
|
||||
className='mt-2.5 pt-2.5 border-t border-gray-200/60 dark:border-gray-700/40 text-xs text-gray-500 dark:text-gray-400'
|
||||
dangerouslySetInnerHTML={{ __html: htmlExtra }}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const renderBody = () => {
|
||||
if (activeTab === 'inApp') {
|
||||
return renderMarkdownNotice();
|
||||
}
|
||||
return renderAnnouncementTimeline();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={null}
|
||||
visible={visible}
|
||||
onCancel={onClose}
|
||||
footer={null}
|
||||
closable={false}
|
||||
size={isMobile ? 'full-width' : 'large'}
|
||||
className='notice-modal-enhanced'
|
||||
bodyStyle={{ padding: 0 }}
|
||||
maskClosable={true}
|
||||
>
|
||||
<div className='relative overflow-hidden'>
|
||||
{/* 背景装饰 */}
|
||||
<div className='absolute inset-0 pointer-events-none overflow-hidden'>
|
||||
<div className='absolute -top-24 -right-24 w-48 h-48 bg-gradient-to-br from-brand-from/[0.08] to-brand-to/[0.08] dark:from-brand-from/15 dark:to-brand-to/15 rounded-full blur-3xl' />
|
||||
<div className='absolute -bottom-24 -left-24 w-48 h-48 bg-gradient-to-br from-pink-500/[0.08] to-rose-500/[0.08] dark:from-pink-500/15 dark:to-rose-500/15 rounded-full blur-3xl' />
|
||||
</div>
|
||||
|
||||
{/* 头部区域 */}
|
||||
<div className='relative px-6 pt-6 pb-4'>
|
||||
{/* 关闭按钮 */}
|
||||
<button
|
||||
onClick={onClose}
|
||||
className='absolute top-4 right-4 p-2 rounded-full bg-gray-100/80 dark:bg-gray-700/80 hover:bg-gray-200 dark:hover:bg-gray-600 transition-all duration-200 z-10 backdrop-blur-sm hover:scale-105 active:scale-95'
|
||||
aria-label='Close'
|
||||
>
|
||||
<X size={16} className='text-gray-500 dark:text-gray-400' />
|
||||
</button>
|
||||
|
||||
{/* 标题 */}
|
||||
<div className='flex items-center gap-3 mb-5'>
|
||||
<div className='relative'>
|
||||
<div className='p-2.5 bg-gradient-to-br from-brand-from to-brand-to rounded-xl shadow-lg shadow-brand/20 dark:shadow-brand/30'>
|
||||
<Volume2 size={22} className='text-white' />
|
||||
</div>
|
||||
<div className='absolute -top-1 -right-1 w-2.5 h-2.5 bg-rose-500 rounded-full animate-pulse ring-2 ring-white dark:ring-gray-900' />
|
||||
</div>
|
||||
<div>
|
||||
<h2 className='text-lg font-bold text-gray-900 dark:text-gray-50 flex items-center gap-2'>
|
||||
{t('系统公告')}
|
||||
<Sparkles size={14} className='text-amber-500' />
|
||||
</h2>
|
||||
<p className='text-xs text-gray-500 dark:text-gray-400 mt-0.5'>
|
||||
{t('了解最新动态和通知')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Tab 切换器 */}
|
||||
<div className='flex gap-1.5 p-1 bg-gray-100/80 dark:bg-gray-800/80 rounded-xl backdrop-blur-sm'>
|
||||
<button
|
||||
onClick={() => setActiveTab('inApp')}
|
||||
className={`flex-1 flex items-center justify-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 ${
|
||||
activeTab === 'inApp'
|
||||
? 'bg-white dark:bg-gray-700 text-brand-deep dark:text-brand-from shadow-sm ring-1 ring-black/5 dark:ring-white/10'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-white/50 dark:hover:bg-gray-700/50'
|
||||
}`}
|
||||
>
|
||||
<Bell size={15} />
|
||||
{t('通知')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setActiveTab('system')}
|
||||
className={`flex-1 flex items-center justify-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-all duration-200 ${
|
||||
activeTab === 'system'
|
||||
? 'bg-white dark:bg-gray-700 text-brand-deep dark:text-brand-from shadow-sm ring-1 ring-black/5 dark:ring-white/10'
|
||||
: 'text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 hover:bg-white/50 dark:hover:bg-gray-700/50'
|
||||
}`}
|
||||
>
|
||||
<Megaphone size={15} />
|
||||
{t('系统公告')}
|
||||
{processedAnnouncements.filter((a) => a.isUnread).length > 0 && (
|
||||
<span className='px-1.5 py-0.5 text-[10px] font-semibold bg-rose-500 text-white rounded-full min-w-[18px] text-center leading-tight'>
|
||||
{processedAnnouncements.filter((a) => a.isUnread).length}
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 内容区域 */}
|
||||
<div className='relative px-6 pb-2'>{renderBody()}</div>
|
||||
|
||||
{/* 底部按钮区域 */}
|
||||
<div className='relative px-6 py-4 border-t border-gray-200/60 dark:border-gray-700/60'>
|
||||
<div className='flex items-center justify-between'>
|
||||
<button
|
||||
onClick={handleCloseTodayNotice}
|
||||
className='flex items-center gap-1.5 px-3 py-2 text-xs text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 transition-colors rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800'
|
||||
>
|
||||
<Clock size={13} />
|
||||
{t('今日不再提示')}
|
||||
</button>
|
||||
<button
|
||||
onClick={onClose}
|
||||
className='flex items-center gap-1.5 px-5 py-2 bg-gradient-to-r from-brand-from to-brand-to hover:from-brand-from hover:to-brand-to text-white text-sm font-medium rounded-xl shadow-md shadow-brand/20 dark:shadow-brand/30 transition-all duration-200 hover:shadow-lg hover:shadow-brand/25 hover:-translate-y-0.5 active:translate-y-0'
|
||||
>
|
||||
{t('我知道了')}
|
||||
<ChevronRight size={14} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default NoticeModal;
|
||||
@@ -0,0 +1,482 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import HeaderBar from './headerbar';
|
||||
import { Layout } from '@douyinfe/semi-ui';
|
||||
import SiderBar from './SiderBar';
|
||||
import App from '../../App';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import React, {
|
||||
useContext,
|
||||
useEffect,
|
||||
useState,
|
||||
lazy,
|
||||
Suspense,
|
||||
useRef,
|
||||
} from 'react';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
API,
|
||||
clearUserData,
|
||||
getUserData,
|
||||
getLogo,
|
||||
getSystemName,
|
||||
isAuthPagePath,
|
||||
showError,
|
||||
setStatusData,
|
||||
setUserData,
|
||||
} from '../../helpers';
|
||||
import { UserContext } from '../../context/User';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { applyTheme, setPresetOverrides } from '../../helpers/theme';
|
||||
// 用户问卷功能已禁用
|
||||
// import UserSurveyModal from '../common/modals/UserSurveyModal';
|
||||
import NewUserGiftModal from '../common/modals/NewUserGiftModal';
|
||||
|
||||
// 懒加载客服浮窗组件 - 非核心功能,延迟加载
|
||||
const CustomerServiceFloat = lazy(() => import('../customer-service'));
|
||||
|
||||
// 跑马灯公告组件
|
||||
import Marquee from './Marquee';
|
||||
|
||||
const { Sider, Content, Header } = Layout;
|
||||
|
||||
// 控制台欢迎语只打印一次(loadStatus 可能被多次触发)
|
||||
let consoleWelcomePrinted = false;
|
||||
const printConsoleWelcome = (status) => {
|
||||
if (consoleWelcomePrinted) return;
|
||||
consoleWelcomePrinted = true;
|
||||
const title = (status?.console_welcome_title || '').trim();
|
||||
const link = (status?.official_website || '').trim();
|
||||
if (!title && !link) return;
|
||||
console.log(
|
||||
`%c${title}%c${link ? ` 官网: ${link}` : ''}`,
|
||||
'color: #10b981; font-weight: bold; font-size: 24px;',
|
||||
'color: inherit; font-size: 14px;',
|
||||
);
|
||||
};
|
||||
|
||||
const PageLayout = () => {
|
||||
console.log('[PageLayout] Component rendering...');
|
||||
const [userState, userDispatch] = useContext(UserContext);
|
||||
const [statusState, statusDispatch] = useContext(StatusContext);
|
||||
const isMobile = useIsMobile();
|
||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||
const { i18n } = useTranslation();
|
||||
const location = useLocation();
|
||||
|
||||
// 用户问卷弹窗状态 - 功能已禁用
|
||||
// const [showSurveyModal, setShowSurveyModal] = useState(false);
|
||||
// const surveyCheckedRef = useRef(false);
|
||||
|
||||
// 新用户注册赠送额度弹窗
|
||||
const [showGiftModal, setShowGiftModal] = useState(false);
|
||||
const [giftQuota, setGiftQuota] = useState(0);
|
||||
|
||||
const shouldInnerPadding =
|
||||
location.pathname.includes('/console') &&
|
||||
!location.pathname.startsWith('/console/chat') &&
|
||||
location.pathname !== '/console/playground';
|
||||
|
||||
const isConsoleRoute = location.pathname.startsWith('/console');
|
||||
const showSider = isConsoleRoute && (!isMobile || drawerOpen);
|
||||
const isHomePage = location.pathname === '/';
|
||||
|
||||
// 隐私政策和用户协议页面需要隐藏顶部工具栏
|
||||
const isLegalPage =
|
||||
location.pathname === '/user-agreement' ||
|
||||
location.pathname === '/privacy-policy';
|
||||
const hideHeader = isHomePage || isLegalPage;
|
||||
|
||||
// 这些页面有自己的滚动控制,不需要外部滚动
|
||||
const isExperienceCenter = location.pathname.includes('/experience-center');
|
||||
const isUserCenter = location.pathname.includes('/user-center');
|
||||
|
||||
// 认证页(登录/注册/企业登录等):内容垂直居中的独立屏
|
||||
const isAuthPage = isAuthPagePath(location.pathname);
|
||||
|
||||
// 企业管理页面有自己的布局和滚动控制。
|
||||
// 注意排除 /org/login、/org/register、/org/:slug/login 等认证页——
|
||||
// 它们没有内部滚动容器,若被禁用外层滚动,内容超出视口(如企业注册开启邮箱验证时)会被截断且无法滚动。
|
||||
const isOrgPage =
|
||||
location.pathname.startsWith('/org') &&
|
||||
location.pathname !== '/org/create' &&
|
||||
!isAuthPage;
|
||||
|
||||
// 需要禁用外层滚动的页面(这些页面内部有自己的滚动容器)
|
||||
const disableOuterScroll =
|
||||
isExperienceCenter || isUserCenter || isHomePage || isOrgPage;
|
||||
|
||||
// 需要显示可见滚动条的页面(覆盖 semi-layout 默认隐藏滚动条的行为)。
|
||||
// 认证页也纳入:内容确实超出视口时(小屏/长表单)用主题色滚动条明示,而不是隐形滚动导致卡片"莫名移动"。
|
||||
const isKeyManagement = location.pathname === '/key-management';
|
||||
const showVisibleScrollbar = isKeyManagement || isAuthPage;
|
||||
|
||||
// 跑马灯公告是否存在(用于动态计算头部总高度)。
|
||||
// 认证页(登录/注册/企业登录/企业注册)不展示:用户尚未进入平台,公告是面向平台内用户的信息。
|
||||
const hasMarquee =
|
||||
!hideHeader &&
|
||||
!isAuthPage &&
|
||||
!!statusState?.status?.marquee_content?.trim();
|
||||
const marqueeHeight = hasMarquee ? 40 : 0; // h-10 = 40px
|
||||
const headerBarHeight = isMobile ? 56 : 64; // h-14(56px) on mobile, h-16(64px) on desktop
|
||||
const totalHeaderHeight = headerBarHeight + marqueeHeight;
|
||||
|
||||
// 滚动容器引用
|
||||
const scrollContainerRef = useRef(null);
|
||||
const authBootstrappedRef = useRef(false);
|
||||
|
||||
// 路由切换兜底:
|
||||
// (1) 清除 Semi Modal/SideSheet 在并发开关/异常 unmount 时残留的 body 锁。
|
||||
// Semi 的 enabledBodyScroll 有 `bodyOverflow !== 'hidden'` 保护,多 modal 并发或
|
||||
// visible=true 时被强制卸载,会跳过还原,表现为"滚动条可见但滚不动,刷新才好"。
|
||||
// (2) 重置外层滚动位置(注:scrollContainerRef 当前挂在 Semi Layout 上无法直接拿到 DOM,
|
||||
// scrollTop 赋值是 no-op;保留是为了未来把 ref 换成原生 div 后能立即生效)。
|
||||
useEffect(() => {
|
||||
document.body.style.overflow = '';
|
||||
document.body.style.width = '';
|
||||
// 抽屉态必须跟着路由清掉:它此前只由 SiderBar 的 onNavigate 复位,
|
||||
// 用户从顶栏导航离开控制台时会残留 true,回到 /console 就自动带着遮罩打开,
|
||||
// 整页发暗且看不出原因(遮罩上线前这个残留是不可见的)。
|
||||
setDrawerOpen(false);
|
||||
if (scrollContainerRef.current) {
|
||||
scrollContainerRef.current.scrollTop = 0;
|
||||
}
|
||||
}, [location.pathname]);
|
||||
|
||||
// 跨断点同理:桌面态残留的 drawerOpen 会在缩窄到手机时凭空展开一个带遮罩的抽屉
|
||||
useEffect(() => {
|
||||
setDrawerOpen(false);
|
||||
}, [isMobile]);
|
||||
|
||||
// 手机抽屉恒定展开:不再用 setCollapsed(false) 改写持久化偏好——
|
||||
// 那会让用户在桌面端收起过的侧栏,因为在手机上开过一次抽屉就被重置。
|
||||
// 改为把 forceExpanded 透传给 SiderBar,只影响这一次渲染。
|
||||
const siderForceExpanded = isMobile && drawerOpen;
|
||||
|
||||
// 顶栏总高(顶栏 + 跑马灯)发布成全局 CSS 变量。
|
||||
// 顶栏是 position:fixed,内容区从视口 0 开始流动,任何 `sticky top-0` 的页内元素
|
||||
// 都会吸到顶栏底下被盖住。页面无从得知跑马灯开没开,只能由这里统一给出。
|
||||
useEffect(() => {
|
||||
const root = document.documentElement;
|
||||
root.style.setProperty('--app-header-height', `${totalHeaderHeight}px`);
|
||||
}, [totalHeaderHeight]);
|
||||
|
||||
// 抽屉支持 Esc 关闭:遮罩是 aria-hidden 的纯点击区,键盘用户否则只能回到汉堡按钮
|
||||
useEffect(() => {
|
||||
if (!siderForceExpanded) return;
|
||||
const onKeyDown = (e) => {
|
||||
if (e.key === 'Escape') setDrawerOpen(false);
|
||||
};
|
||||
document.addEventListener('keydown', onKeyDown);
|
||||
return () => document.removeEventListener('keydown', onKeyDown);
|
||||
}, [siderForceExpanded]);
|
||||
|
||||
const loadUser = async () => {
|
||||
const cachedUser = getUserData();
|
||||
if (!cachedUser) {
|
||||
userDispatch({ type: 'auth_checked' });
|
||||
return;
|
||||
}
|
||||
|
||||
userDispatch({ type: 'auth_start' });
|
||||
try {
|
||||
const res = await API.get('/api/user/self', {
|
||||
skipErrorHandler: true,
|
||||
disableDuplicate: true,
|
||||
});
|
||||
const { success, data } = res.data;
|
||||
if (success && data) {
|
||||
setUserData(data);
|
||||
userDispatch({ type: 'login', payload: data });
|
||||
} else {
|
||||
clearUserData();
|
||||
userDispatch({ type: 'logout' });
|
||||
}
|
||||
} catch (error) {
|
||||
if (error?.response?.status === 401 || error?.response?.status === 403) {
|
||||
clearUserData();
|
||||
userDispatch({ type: 'logout' });
|
||||
return;
|
||||
}
|
||||
|
||||
// 网络临时异常时保留本地展示态,后续接口仍会按真实 session 鉴权。
|
||||
userDispatch({ type: 'login', payload: cachedUser });
|
||||
}
|
||||
};
|
||||
|
||||
const loadStatus = async () => {
|
||||
console.log('[PageLayout] Loading status from API...');
|
||||
try {
|
||||
const res = await API.get('/api/status');
|
||||
console.log('[PageLayout] API response received:', res.data);
|
||||
const { success, data } = res.data;
|
||||
if (success) {
|
||||
statusDispatch({ type: 'set', payload: data });
|
||||
setStatusData(data);
|
||||
printConsoleWelcome(data);
|
||||
// 先同步预设覆盖(管理员编辑过的预设模板),再应用主题
|
||||
if (data.theme_presets !== undefined) {
|
||||
setPresetOverrides(data.theme_presets);
|
||||
}
|
||||
// 用服务器最新主题配置覆盖 cache 注入的版本
|
||||
if (data.theme_config !== undefined) {
|
||||
applyTheme(data.theme_config);
|
||||
}
|
||||
console.log('[PageLayout] Status loaded successfully');
|
||||
} else {
|
||||
console.error('[PageLayout] API returned success=false');
|
||||
showError('Unable to connect to server');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[PageLayout] Failed to load status:', error);
|
||||
showError('Failed to load status');
|
||||
throw error; // 重新抛出以便上层catch
|
||||
}
|
||||
};
|
||||
|
||||
// 检查用户是否需要填写问卷 - 功能已禁用
|
||||
// const checkUserSurvey = useCallback(async () => {
|
||||
// // 已经检查过且已完成,不再检查
|
||||
// if (surveyCheckedRef.current === 'completed') return;
|
||||
//
|
||||
// try {
|
||||
// const res = await API.get('/api/user/survey/check');
|
||||
// const { success, data } = res.data;
|
||||
// if (success) {
|
||||
// if (data && !data.survey_completed) {
|
||||
// setShowSurveyModal(true);
|
||||
// surveyCheckedRef.current = 'pending'; // 等待用户填写
|
||||
// } else {
|
||||
// surveyCheckedRef.current = 'completed'; // 已完成,不再检查
|
||||
// }
|
||||
// }
|
||||
// // 如果请求失败(success=false),不设置状态,下次还会重试
|
||||
// } catch (error) {
|
||||
// console.error('Check survey failed:', error);
|
||||
// // 网络错误时不设置状态,下次还会重试
|
||||
// }
|
||||
// }, []);
|
||||
|
||||
// 当用户登录状态变化时检查问卷 - 功能已禁用
|
||||
// useEffect(() => {
|
||||
// if (userState?.user?.id) {
|
||||
// checkUserSurvey();
|
||||
// } else {
|
||||
// // 用户登出时重置检查状态
|
||||
// surveyCheckedRef.current = null;
|
||||
// setShowSurveyModal(false);
|
||||
// }
|
||||
// }, [userState?.user?.id, checkUserSurvey]);
|
||||
|
||||
// 问卷提交成功后的回调 - 功能已禁用
|
||||
// const handleSurveySuccess = useCallback(() => {
|
||||
// surveyCheckedRef.current = 'completed';
|
||||
// setShowSurveyModal(false);
|
||||
// }, []);
|
||||
|
||||
// 新用户注册赠送额度弹窗:登录后检查是否是刚注册的用户
|
||||
useEffect(() => {
|
||||
const userId = userState?.user?.id;
|
||||
const username = userState?.user?.username;
|
||||
if (!userId || !username) return;
|
||||
|
||||
const pendingUser = localStorage.getItem('new_user_gift_pending');
|
||||
if (pendingUser === username) {
|
||||
localStorage.removeItem('new_user_gift_pending');
|
||||
const quota = userState?.user?.quota || 0;
|
||||
if (quota > 0) {
|
||||
setGiftQuota(quota);
|
||||
setShowGiftModal(true);
|
||||
}
|
||||
}
|
||||
}, [userState?.user?.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!authBootstrappedRef.current) {
|
||||
authBootstrappedRef.current = true;
|
||||
loadUser();
|
||||
}
|
||||
loadStatus().catch((error) => {
|
||||
console.error('Failed to load status:', error);
|
||||
// 即使加载失败也设置一个默认状态,避免卡住
|
||||
statusDispatch({ type: 'set', payload: { setup: true } });
|
||||
});
|
||||
let systemName = getSystemName();
|
||||
if (systemName) {
|
||||
document.title = systemName;
|
||||
}
|
||||
let logo = getLogo();
|
||||
if (logo) {
|
||||
let linkElement = document.querySelector("link[rel~='icon']");
|
||||
if (linkElement) {
|
||||
linkElement.href = logo;
|
||||
}
|
||||
}
|
||||
// 界面语言已由 i18n/bootstrap.js 在渲染前判定,这里不再读取语言缓存
|
||||
}, [i18n]);
|
||||
|
||||
return (
|
||||
<Layout
|
||||
style={{
|
||||
height: '100vh',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden', // 外层保持 hidden,滚动由内部 scrollContainerRef 控制
|
||||
}}
|
||||
>
|
||||
{!hideHeader && (
|
||||
<Header
|
||||
style={{
|
||||
padding: 0,
|
||||
height: 'auto',
|
||||
lineHeight: 'normal',
|
||||
position: 'fixed',
|
||||
width: '100%',
|
||||
top: 0,
|
||||
zIndex: 100,
|
||||
}}
|
||||
>
|
||||
<HeaderBar
|
||||
onMobileMenuToggle={() => setDrawerOpen((prev) => !prev)}
|
||||
drawerOpen={drawerOpen}
|
||||
/>
|
||||
{/* 跑马灯公告 - 固定在导航栏正下方;认证页不展示(与 hasMarquee 的高度计算保持一致) */}
|
||||
{!isAuthPage && <Marquee />}
|
||||
</Header>
|
||||
)}
|
||||
<Layout
|
||||
ref={scrollContainerRef}
|
||||
className={showVisibleScrollbar ? 'app-scrollbar' : undefined}
|
||||
style={{
|
||||
// 部分页面有自己的滚动控制,不需要外层滚动
|
||||
overflowY: disableOuterScroll ? 'hidden' : 'auto',
|
||||
overflowX: 'hidden',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
flex: 1,
|
||||
WebkitOverflowScrolling: 'touch', // iOS 平滑滚动
|
||||
}}
|
||||
>
|
||||
{/* 手机抽屉遮罩:点击关闭。没有它时抽屉浮在内容上、只能再点汉堡才能收,
|
||||
且看不出「当前处于抽屉态」。层级压在 Sider(99) 之下、内容之上。 */}
|
||||
{showSider && isMobile && (
|
||||
<div
|
||||
className='fixed inset-x-0 bottom-0 z-[98] bg-black/45 backdrop-blur-[2px]'
|
||||
style={{ top: `${totalHeaderHeight}px` }}
|
||||
onClick={() => setDrawerOpen(false)}
|
||||
aria-hidden='true'
|
||||
/>
|
||||
)}
|
||||
{showSider && (
|
||||
<Sider
|
||||
style={{
|
||||
position: 'fixed',
|
||||
left: 0,
|
||||
top: `${totalHeaderHeight}px`,
|
||||
zIndex: 99,
|
||||
border: 'none',
|
||||
paddingRight: '0',
|
||||
height: `calc(100vh - ${totalHeaderHeight}px)`,
|
||||
// 手机抽屉不跟随桌面的折叠宽度,否则用户在桌面收起过侧栏后,
|
||||
// 抽屉会变成 60px 纯图标窄条,等于看不到导航
|
||||
width: siderForceExpanded
|
||||
? 'var(--sidebar-width)'
|
||||
: 'var(--sidebar-current-width)',
|
||||
boxShadow: siderForceExpanded
|
||||
? '0 0 24px rgba(0,0,0,0.28)'
|
||||
: undefined,
|
||||
}}
|
||||
>
|
||||
<SiderBar
|
||||
forceExpanded={siderForceExpanded}
|
||||
onNavigate={() => {
|
||||
if (isMobile) setDrawerOpen(false);
|
||||
}}
|
||||
/>
|
||||
</Sider>
|
||||
)}
|
||||
<Layout
|
||||
style={{
|
||||
marginLeft: isMobile
|
||||
? '0'
|
||||
: showSider
|
||||
? 'var(--sidebar-current-width)'
|
||||
: '0',
|
||||
flex: '1 0 auto',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
minHeight: disableOuterScroll ? '100%' : 'auto', // 内部滚动的页面需要撑满高度
|
||||
}}
|
||||
>
|
||||
<Content
|
||||
style={{
|
||||
flex: '1 0 auto',
|
||||
WebkitOverflowScrolling: 'touch',
|
||||
padding: shouldInnerPadding
|
||||
? isMobile
|
||||
? '5px'
|
||||
: '24px 24px 0 24px'
|
||||
: '0',
|
||||
position: 'relative',
|
||||
// 认证页等 min-height:100vh 的独立屏用它抵扣上方跑马灯占位的高度,
|
||||
// 保证「占位 + 容器」总高恰为 100vh(无占位时回退 0px,不影响其他页面)
|
||||
'--content-top-offset': `${marqueeHeight}px`,
|
||||
}}
|
||||
>
|
||||
{/* 跑马灯占位:当跑马灯存在时,为内容区域顶部增加等高间距,防止被固定头部遮挡 */}
|
||||
{/* 注意:ExperienceCenter、UserCenter 和 Organization 使用 h-screen 并自行处理顶部偏移,不需要这个占位。
|
||||
认证页保留占位(防内容顶部被跑马灯遮挡且滚不出来),并通过 Content 上的
|
||||
--content-top-offset 变量让认证页容器等量收缩(calc(100vh - offset)),
|
||||
总高度恰为 100vh,不会出现"滚轮一动登录卡片就上下漂移"的幽灵滚动 */}
|
||||
{marqueeHeight > 0 &&
|
||||
!isExperienceCenter &&
|
||||
!isUserCenter &&
|
||||
!isOrgPage && (
|
||||
<div style={{ height: marqueeHeight, flexShrink: 0 }} />
|
||||
)}
|
||||
<App />
|
||||
</Content>
|
||||
</Layout>
|
||||
</Layout>
|
||||
<ToastContainer />
|
||||
<Suspense fallback={null}>
|
||||
<CustomerServiceFloat />
|
||||
</Suspense>
|
||||
|
||||
{/* 用户问卷弹窗 - 功能已禁用 */}
|
||||
{/* <UserSurveyModal
|
||||
visible={showSurveyModal}
|
||||
onClose={() => setShowSurveyModal(false)}
|
||||
onSuccess={handleSurveySuccess}
|
||||
/> */}
|
||||
|
||||
{/* 新用户注册赠送额度弹窗 */}
|
||||
<NewUserGiftModal
|
||||
visible={showGiftModal}
|
||||
onClose={() => setShowGiftModal(false)}
|
||||
quota={giftQuota}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default PageLayout;
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
|
||||
const SetupCheck = ({ children }) => {
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const location = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
statusState?.status?.setup === false &&
|
||||
location.pathname !== '/setup'
|
||||
) {
|
||||
window.location.href = '/setup';
|
||||
}
|
||||
}, [statusState?.status?.setup, location.pathname]);
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
export default SetupCheck;
|
||||
@@ -0,0 +1,656 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getLucideIcon } from '../../helpers/render';
|
||||
import { ChevronLeft } from 'lucide-react';
|
||||
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
|
||||
import { useSidebar } from '../../hooks/common/useSidebar';
|
||||
import { useMinimumLoadingTime } from '../../hooks/common/useMinimumLoadingTime';
|
||||
import { isAdmin, isRoot, showError } from '../../helpers';
|
||||
import { StatusContext } from '../../context/Status';
|
||||
import SkeletonWrapper from './components/SkeletonWrapper';
|
||||
import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi';
|
||||
|
||||
import { Nav, Divider, Button } from '@douyinfe/semi-ui';
|
||||
|
||||
const routerMap = {
|
||||
home: '/',
|
||||
channel: '/console/channel',
|
||||
'admin-token': '/console/token',
|
||||
redemption: '/console/redemption',
|
||||
topup: '/console/topup',
|
||||
user: '/console/user',
|
||||
log: '/console/log',
|
||||
midjourney: '/console/midjourney',
|
||||
setting: '/console/setting',
|
||||
about: '/about',
|
||||
detail: '/console',
|
||||
pricing: '/market',
|
||||
task: '/console/task',
|
||||
models: '/console/models',
|
||||
playground: '/console/playground',
|
||||
personal: '/console/personal',
|
||||
monitor: '/console/monitor',
|
||||
analytics: '/console/analytics',
|
||||
commission: '/console/commission',
|
||||
'my-commission': '/console/my-commission',
|
||||
partner: '/console/partner',
|
||||
organizations: '/console/organizations',
|
||||
'skill-platform': '/console/skill-platform',
|
||||
'expert-platform': '/console/expert-platform',
|
||||
order: '/console/order',
|
||||
invoice: '/console/invoice',
|
||||
subscription: '/console/subscription',
|
||||
};
|
||||
|
||||
// forceExpanded:手机端抽屉态。抽屉本来就是临时全宽浮层,折叠成 60px 图标条毫无意义,
|
||||
// 且不应把桌面端的折叠偏好一起改掉,所以只在本次渲染里强制展开。
|
||||
const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
|
||||
const { t } = useTranslation();
|
||||
const [persistedCollapsed, toggleCollapsed] = useSidebarCollapsed();
|
||||
const collapsed = forceExpanded ? false : persistedCollapsed;
|
||||
const {
|
||||
isModuleVisible,
|
||||
hasSectionVisibleModules,
|
||||
loading: sidebarLoading,
|
||||
} = useSidebar();
|
||||
|
||||
const [statusState] = useContext(StatusContext);
|
||||
// 系统设置 tab 权限下放:普通管理员在被下放了至少一个 tab 时,才显示「系统设置」入口
|
||||
const delegatedSettingTabs = useMemo(() => {
|
||||
try {
|
||||
const raw = statusState?.status?.AdminDelegatedSettingTabs;
|
||||
const parsed = raw ? JSON.parse(raw) : [];
|
||||
return Array.isArray(parsed) ? parsed : [];
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}, [statusState?.status?.AdminDelegatedSettingTabs]);
|
||||
const canAccessSetting =
|
||||
isRoot() || (isAdmin() && delegatedSettingTabs.length > 0);
|
||||
|
||||
const showSkeleton = useMinimumLoadingTime(sidebarLoading, 200);
|
||||
|
||||
const [selectedKeys, setSelectedKeys] = useState(['home']);
|
||||
const [chatItems, setChatItems] = useState([]);
|
||||
const [openedKeys, setOpenedKeys] = useState([]);
|
||||
const location = useLocation();
|
||||
const [routerMapState, setRouterMapState] = useState(routerMap);
|
||||
|
||||
const workspaceItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('数据看板'),
|
||||
itemKey: 'detail',
|
||||
to: '/detail',
|
||||
className:
|
||||
localStorage.getItem('enable_data_export') === 'true'
|
||||
? ''
|
||||
: 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('令牌管理'),
|
||||
itemKey: 'token',
|
||||
to: '/token',
|
||||
},
|
||||
{
|
||||
text: t('使用日志'),
|
||||
itemKey: 'log',
|
||||
to: '/log',
|
||||
},
|
||||
{
|
||||
text: t('绘图日志'),
|
||||
itemKey: 'midjourney',
|
||||
to: '/midjourney',
|
||||
className:
|
||||
localStorage.getItem('enable_drawing') === 'true'
|
||||
? ''
|
||||
: 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('任务日志'),
|
||||
itemKey: 'task',
|
||||
to: '/task',
|
||||
className:
|
||||
localStorage.getItem('enable_task') === 'true' ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('监控中心'),
|
||||
itemKey: 'monitor',
|
||||
to: '/monitor',
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
const configVisible = isModuleVisible('console', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
return filteredItems;
|
||||
}, [
|
||||
localStorage.getItem('enable_data_export'),
|
||||
localStorage.getItem('enable_drawing'),
|
||||
localStorage.getItem('enable_task'),
|
||||
t,
|
||||
isModuleVisible,
|
||||
]);
|
||||
|
||||
const financeItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('钱包管理'),
|
||||
itemKey: 'topup',
|
||||
to: '/topup',
|
||||
},
|
||||
{
|
||||
text: t('个人设置'),
|
||||
itemKey: 'personal',
|
||||
to: '/personal',
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
const configVisible = isModuleVisible('personal', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
// 我的提成:新模块不在 sidebar 配置注册表内,直接追加(非销售用户页面为空态)
|
||||
filteredItems.push({
|
||||
text: t('我的提成'),
|
||||
itemKey: 'my-commission',
|
||||
to: '/console/my-commission',
|
||||
});
|
||||
|
||||
// 合作伙伴:受平台总开关控制(参数设置页可配),开放后对全部登录用户可见
|
||||
if (statusState?.status?.commission_partner_portal_enabled === true) {
|
||||
filteredItems.push({
|
||||
text: t('合作伙伴'),
|
||||
itemKey: 'partner',
|
||||
to: '/console/partner',
|
||||
});
|
||||
}
|
||||
|
||||
return filteredItems;
|
||||
}, [
|
||||
t,
|
||||
isModuleVisible,
|
||||
statusState?.status?.commission_partner_portal_enabled,
|
||||
]);
|
||||
|
||||
const adminItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('运营看板'),
|
||||
itemKey: 'analytics',
|
||||
to: '/console/analytics',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('分佣管理'),
|
||||
itemKey: 'commission',
|
||||
to: '/console/commission',
|
||||
className: isRoot() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('渠道管理'),
|
||||
itemKey: 'channel',
|
||||
to: '/channel',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('模型管理'),
|
||||
itemKey: 'models',
|
||||
to: '/console/models',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('兑换码管理'),
|
||||
itemKey: 'redemption',
|
||||
to: '/redemption',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('用户管理'),
|
||||
itemKey: 'user',
|
||||
to: '/user',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('会员卡管理'),
|
||||
itemKey: 'subscription',
|
||||
to: '/console/subscription',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('秘钥管理'),
|
||||
itemKey: 'admin-token',
|
||||
to: '/console/token',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('企业管理'),
|
||||
itemKey: 'organizations',
|
||||
to: '/console/organizations',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('平台 Skill 中心'),
|
||||
itemKey: 'skill-platform',
|
||||
to: '/console/skill-platform',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('平台专家中心'),
|
||||
itemKey: 'expert-platform',
|
||||
to: '/console/expert-platform',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('订单管理'),
|
||||
itemKey: 'order',
|
||||
to: '/console/order',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('发票管理'),
|
||||
itemKey: 'invoice',
|
||||
to: '/console/invoice',
|
||||
className: isAdmin() ? '' : 'tableHiddle',
|
||||
},
|
||||
{
|
||||
text: t('系统设置'),
|
||||
itemKey: 'setting',
|
||||
to: '/setting',
|
||||
className: canAccessSetting ? '' : 'tableHiddle',
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
if (
|
||||
!CLOUD_BRAIN_UI_ENABLED &&
|
||||
(item.itemKey === 'skill-platform' ||
|
||||
item.itemKey === 'expert-platform')
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
// 分佣管理:新增模块不在 sidebar 配置注册表内,绕过 isModuleVisible(Root 硬门控)
|
||||
if (item.itemKey === 'commission') {
|
||||
return isRoot();
|
||||
}
|
||||
// 系统设置入口:被下放了至少一个 tab 的普通管理员强制可见
|
||||
// (需绕过 isModuleVisible,因为 GetSelf 默认对普通管理员置 admin.setting=false)。
|
||||
// root 及其它情况仍走原有 isModuleVisible 逻辑,保留 root 自行隐藏该入口的能力。
|
||||
if (
|
||||
item.itemKey === 'setting' &&
|
||||
isAdmin() &&
|
||||
!isRoot() &&
|
||||
delegatedSettingTabs.length > 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
const configVisible = isModuleVisible('admin', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
return filteredItems;
|
||||
}, [isAdmin(), isRoot(), t, isModuleVisible, canAccessSetting]);
|
||||
|
||||
const chatMenuItems = useMemo(() => {
|
||||
const items = [
|
||||
{
|
||||
text: t('操练场'),
|
||||
itemKey: 'playground',
|
||||
to: '/playground',
|
||||
},
|
||||
{
|
||||
text: t('聊天'),
|
||||
itemKey: 'chat',
|
||||
items: chatItems,
|
||||
},
|
||||
];
|
||||
|
||||
// 根据配置过滤项目
|
||||
const filteredItems = items.filter((item) => {
|
||||
const configVisible = isModuleVisible('chat', item.itemKey);
|
||||
return configVisible;
|
||||
});
|
||||
|
||||
return filteredItems;
|
||||
}, [chatItems, t, isModuleVisible]);
|
||||
|
||||
// 更新路由映射,添加聊天路由
|
||||
const updateRouterMapWithChats = (chats) => {
|
||||
const newRouterMap = { ...routerMap };
|
||||
|
||||
if (Array.isArray(chats) && chats.length > 0) {
|
||||
for (let i = 0; i < chats.length; i++) {
|
||||
newRouterMap['chat' + i] = '/console/chat/' + i;
|
||||
}
|
||||
}
|
||||
|
||||
setRouterMapState(newRouterMap);
|
||||
return newRouterMap;
|
||||
};
|
||||
|
||||
// 加载聊天项
|
||||
useEffect(() => {
|
||||
let chats = localStorage.getItem('chats');
|
||||
if (chats) {
|
||||
try {
|
||||
chats = JSON.parse(chats);
|
||||
if (Array.isArray(chats)) {
|
||||
let chatItems = [];
|
||||
for (let i = 0; i < chats.length; i++) {
|
||||
let shouldSkip = false;
|
||||
let chat = {};
|
||||
for (let key in chats[i]) {
|
||||
let link = chats[i][key];
|
||||
if (typeof link !== 'string') continue; // 确保链接是字符串
|
||||
if (link.startsWith('fluent')) {
|
||||
shouldSkip = true;
|
||||
break; // 跳过 Fluent Read
|
||||
}
|
||||
chat.text = key;
|
||||
chat.itemKey = 'chat' + i;
|
||||
chat.to = '/console/chat/' + i;
|
||||
}
|
||||
if (shouldSkip || !chat.text) continue; // 避免推入空项
|
||||
chatItems.push(chat);
|
||||
}
|
||||
setChatItems(chatItems);
|
||||
updateRouterMapWithChats(chats);
|
||||
}
|
||||
} catch (e) {
|
||||
showError(t('聊天数据解析失败'));
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 根据当前路径设置选中的菜单项
|
||||
useEffect(() => {
|
||||
const currentPath = location.pathname;
|
||||
let matchingKey = Object.keys(routerMapState).find(
|
||||
(key) => routerMapState[key] === currentPath,
|
||||
);
|
||||
|
||||
// 处理聊天路由
|
||||
if (!matchingKey && currentPath.startsWith('/console/chat/')) {
|
||||
const chatIndex = currentPath.split('/').pop();
|
||||
if (!isNaN(chatIndex)) {
|
||||
matchingKey = 'chat' + chatIndex;
|
||||
} else {
|
||||
matchingKey = 'chat';
|
||||
}
|
||||
}
|
||||
|
||||
// 如果找到匹配的键,更新选中的键
|
||||
if (matchingKey) {
|
||||
setSelectedKeys([matchingKey]);
|
||||
}
|
||||
}, [location.pathname, routerMapState]);
|
||||
|
||||
// 监控折叠状态变化以更新 body class(--sidebar-current-width 由它驱动)。
|
||||
// 抽屉态下跳过:body class 是全局的,抽屉临时展开不该顺手把桌面侧栏宽度也改掉。
|
||||
useEffect(() => {
|
||||
if (forceExpanded) return;
|
||||
if (persistedCollapsed) {
|
||||
document.body.classList.add('sidebar-collapsed');
|
||||
} else {
|
||||
document.body.classList.remove('sidebar-collapsed');
|
||||
}
|
||||
}, [persistedCollapsed, forceExpanded]);
|
||||
|
||||
// 选中高亮颜色(统一)
|
||||
const SELECTED_COLOR = 'var(--semi-color-primary)';
|
||||
|
||||
// 渲染自定义菜单项
|
||||
const renderNavItem = (item) => {
|
||||
// 跳过隐藏的项目
|
||||
if (item.className === 'tableHiddle') return null;
|
||||
|
||||
const isSelected = selectedKeys.includes(item.itemKey);
|
||||
const textColor = isSelected ? SELECTED_COLOR : 'inherit';
|
||||
|
||||
return (
|
||||
<Nav.Item
|
||||
key={item.itemKey}
|
||||
itemKey={item.itemKey}
|
||||
text={
|
||||
<span
|
||||
className='truncate font-medium text-sm'
|
||||
style={{ color: textColor }}
|
||||
>
|
||||
{item.text}
|
||||
</span>
|
||||
}
|
||||
icon={
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
{getLucideIcon(item.itemKey, isSelected)}
|
||||
</div>
|
||||
}
|
||||
className={item.className}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 渲染子菜单项
|
||||
const renderSubItem = (item) => {
|
||||
if (item.items && item.items.length > 0) {
|
||||
const isSelected = selectedKeys.includes(item.itemKey);
|
||||
const textColor = isSelected ? SELECTED_COLOR : 'inherit';
|
||||
|
||||
return (
|
||||
<Nav.Sub
|
||||
key={item.itemKey}
|
||||
itemKey={item.itemKey}
|
||||
text={
|
||||
<span
|
||||
className='truncate font-medium text-sm'
|
||||
style={{ color: textColor }}
|
||||
>
|
||||
{item.text}
|
||||
</span>
|
||||
}
|
||||
icon={
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
{getLucideIcon(item.itemKey, isSelected)}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{item.items.map((subItem) => {
|
||||
const isSubSelected = selectedKeys.includes(subItem.itemKey);
|
||||
const subTextColor = isSubSelected ? SELECTED_COLOR : 'inherit';
|
||||
|
||||
return (
|
||||
<Nav.Item
|
||||
key={subItem.itemKey}
|
||||
itemKey={subItem.itemKey}
|
||||
text={
|
||||
<span
|
||||
className='truncate font-medium text-sm'
|
||||
style={{ color: subTextColor }}
|
||||
>
|
||||
{subItem.text}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Nav.Sub>
|
||||
);
|
||||
} else {
|
||||
return renderNavItem(item);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className='sidebar-container'
|
||||
style={{
|
||||
width: forceExpanded
|
||||
? 'var(--sidebar-width)'
|
||||
: 'var(--sidebar-current-width)',
|
||||
background: 'var(--semi-color-bg-0)',
|
||||
}}
|
||||
>
|
||||
<SkeletonWrapper
|
||||
loading={showSkeleton}
|
||||
type='sidebar'
|
||||
className=''
|
||||
collapsed={collapsed}
|
||||
showAdmin={isAdmin()}
|
||||
>
|
||||
<Nav
|
||||
className='sidebar-nav'
|
||||
defaultIsCollapsed={collapsed}
|
||||
isCollapsed={collapsed}
|
||||
onCollapseChange={toggleCollapsed}
|
||||
selectedKeys={selectedKeys}
|
||||
itemStyle='sidebar-nav-item'
|
||||
hoverStyle='sidebar-nav-item:hover'
|
||||
selectedStyle='sidebar-nav-item-selected'
|
||||
renderWrapper={({ itemElement, props }) => {
|
||||
const to =
|
||||
routerMapState[props.itemKey] || routerMap[props.itemKey];
|
||||
|
||||
// 如果没有路由,直接返回元素
|
||||
if (!to) return itemElement;
|
||||
|
||||
return (
|
||||
<Link
|
||||
style={{ textDecoration: 'none' }}
|
||||
to={to}
|
||||
onClick={onNavigate}
|
||||
>
|
||||
{itemElement}
|
||||
</Link>
|
||||
);
|
||||
}}
|
||||
onSelect={(key) => {
|
||||
// 如果点击的是已经展开的子菜单的父项,则收起子菜单
|
||||
if (openedKeys.includes(key.itemKey)) {
|
||||
setOpenedKeys(openedKeys.filter((k) => k !== key.itemKey));
|
||||
}
|
||||
|
||||
setSelectedKeys([key.itemKey]);
|
||||
}}
|
||||
openKeys={openedKeys}
|
||||
onOpenChange={(data) => {
|
||||
setOpenedKeys(data.openKeys);
|
||||
}}
|
||||
>
|
||||
{/* 聊天区域 */}
|
||||
{hasSectionVisibleModules('chat') && (
|
||||
<div className='sidebar-section'>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('聊天')}</div>
|
||||
)}
|
||||
{chatMenuItems.map((item) => renderSubItem(item))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 控制台区域 */}
|
||||
{hasSectionVisibleModules('console') && (
|
||||
<>
|
||||
<Divider className='sidebar-divider' />
|
||||
<div>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('控制台')}</div>
|
||||
)}
|
||||
{workspaceItems.map((item) => renderNavItem(item))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 个人中心区域 */}
|
||||
{hasSectionVisibleModules('personal') && (
|
||||
<>
|
||||
<Divider className='sidebar-divider' />
|
||||
<div>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('个人中心')}</div>
|
||||
)}
|
||||
{financeItems.map((item) => renderNavItem(item))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 管理员区域 - 只在管理员时显示且配置允许时显示 */}
|
||||
{isAdmin() && hasSectionVisibleModules('admin') && (
|
||||
<>
|
||||
<Divider className='sidebar-divider' />
|
||||
<div>
|
||||
{!collapsed && (
|
||||
<div className='sidebar-group-label'>{t('管理员')}</div>
|
||||
)}
|
||||
{adminItems.map((item) => renderNavItem(item))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Nav>
|
||||
</SkeletonWrapper>
|
||||
|
||||
{/* 底部折叠按钮 —— 抽屉态不提供:收起后抽屉会变成 60px 窄条,等于自废 */}
|
||||
{!forceExpanded && (
|
||||
<div className='sidebar-collapse-button'>
|
||||
<SkeletonWrapper
|
||||
loading={showSkeleton}
|
||||
type='button'
|
||||
width={collapsed ? 36 : 156}
|
||||
height={24}
|
||||
className='w-full'
|
||||
>
|
||||
<Button
|
||||
theme='outline'
|
||||
type='tertiary'
|
||||
size='small'
|
||||
icon={
|
||||
<ChevronLeft
|
||||
size={16}
|
||||
strokeWidth={2.5}
|
||||
color='var(--semi-color-text-2)'
|
||||
style={{
|
||||
transform: collapsed ? 'rotate(180deg)' : 'rotate(0deg)',
|
||||
}}
|
||||
/>
|
||||
}
|
||||
onClick={toggleCollapsed}
|
||||
icononly={collapsed}
|
||||
style={
|
||||
collapsed
|
||||
? { width: 36, height: 24, padding: 0 }
|
||||
: { padding: '4px 12px', width: '100%' }
|
||||
}
|
||||
>
|
||||
{!collapsed ? t('收起侧边栏') : null}
|
||||
</Button>
|
||||
</SkeletonWrapper>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default SiderBar;
|
||||
@@ -0,0 +1,394 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Skeleton } from '@douyinfe/semi-ui';
|
||||
|
||||
const SkeletonWrapper = ({
|
||||
loading = false,
|
||||
type = 'text',
|
||||
count = 1,
|
||||
width = 60,
|
||||
height = 16,
|
||||
isMobile = false,
|
||||
className = '',
|
||||
collapsed = false,
|
||||
showAdmin = true,
|
||||
children,
|
||||
...props
|
||||
}) => {
|
||||
if (!loading) {
|
||||
return children;
|
||||
}
|
||||
|
||||
// 导航链接骨架屏
|
||||
const renderNavigationSkeleton = () => {
|
||||
const skeletonLinkClasses = isMobile
|
||||
? 'flex items-center gap-1 p-1 w-full rounded-md'
|
||||
: 'flex items-center gap-1 p-2 rounded-md';
|
||||
|
||||
return Array(count)
|
||||
.fill(null)
|
||||
.map((_, index) => (
|
||||
<div key={index} className={skeletonLinkClasses}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: isMobile ? 40 : width, height }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
));
|
||||
};
|
||||
|
||||
// 用户区域骨架屏 (头像 + 文本)
|
||||
const renderUserAreaSkeleton = () => {
|
||||
return (
|
||||
<div
|
||||
className={`flex items-center p-1 rounded-full bg-semi-color-fill-0 dark:bg-semi-color-fill-1 ${className}`}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar active size='extra-small' className='shadow-sm' />
|
||||
}
|
||||
/>
|
||||
<div className='ml-1.5 mr-1'>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: isMobile ? 15 : width, height: 12 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// Logo图片骨架屏
|
||||
const renderImageSkeleton = () => {
|
||||
return (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Image
|
||||
active
|
||||
className={`absolute inset-0 !rounded-full ${className}`}
|
||||
style={{ width: '100%', height: '100%' }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 系统名称骨架屏
|
||||
const renderTitleSkeleton = () => {
|
||||
return (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={<Skeleton.Title active style={{ width, height: 24 }} />}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
// 通用文本骨架屏
|
||||
const renderTextSkeleton = () => {
|
||||
return (
|
||||
<div className={className}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={<Skeleton.Title active style={{ width, height }} />}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 按钮骨架屏(支持圆角)
|
||||
const renderButtonSkeleton = () => {
|
||||
return (
|
||||
<div className={className}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width, height, borderRadius: 9999 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 侧边栏导航项骨架屏 (图标 + 文本)
|
||||
const renderSidebarNavItemSkeleton = () => {
|
||||
return Array(count)
|
||||
.fill(null)
|
||||
.map((_, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className={`flex items-center p-2 mb-1 rounded-md ${className}`}
|
||||
>
|
||||
{/* 图标骨架屏 */}
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar active size='extra-small' shape='square' />
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{/* 文本骨架屏 */}
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: width || 80, height: height || 14 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
));
|
||||
};
|
||||
|
||||
// 侧边栏组标题骨架屏
|
||||
const renderSidebarGroupTitleSkeleton = () => {
|
||||
return (
|
||||
<div className={`mb-2 ${className}`}>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: width || 60, height: height || 12 }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 完整侧边栏骨架屏 - 1:1 还原,去重实现
|
||||
const renderSidebarSkeleton = () => {
|
||||
const NAV_WIDTH = 164;
|
||||
const NAV_HEIGHT = 30;
|
||||
const COLLAPSED_WIDTH = 44;
|
||||
const COLLAPSED_HEIGHT = 44;
|
||||
const ICON_SIZE = 16;
|
||||
const TITLE_HEIGHT = 12;
|
||||
const TEXT_HEIGHT = 16;
|
||||
|
||||
const renderIcon = () => (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar
|
||||
active
|
||||
shape='square'
|
||||
style={{ width: ICON_SIZE, height: ICON_SIZE }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
const renderLabel = (labelWidth) => (
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: labelWidth, height: TEXT_HEIGHT }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
const NavRow = ({ labelWidth }) => (
|
||||
<div
|
||||
className='flex items-center p-2 mb-1 rounded-md'
|
||||
style={{
|
||||
width: `${NAV_WIDTH}px`,
|
||||
height: `${NAV_HEIGHT}px`,
|
||||
margin: '3px 8px',
|
||||
}}
|
||||
>
|
||||
<div className='sidebar-icon-container flex-shrink-0'>
|
||||
{renderIcon()}
|
||||
</div>
|
||||
{renderLabel(labelWidth)}
|
||||
</div>
|
||||
);
|
||||
|
||||
const CollapsedRow = ({ keyPrefix, index }) => (
|
||||
<div
|
||||
key={`${keyPrefix}-${index}`}
|
||||
className='flex items-center justify-center'
|
||||
style={{
|
||||
width: `${COLLAPSED_WIDTH}px`,
|
||||
height: `${COLLAPSED_HEIGHT}px`,
|
||||
margin: '0 8px 4px 8px',
|
||||
}}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Avatar
|
||||
active
|
||||
shape='square'
|
||||
style={{ width: ICON_SIZE, height: ICON_SIZE }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (collapsed) {
|
||||
return (
|
||||
<div className={`w-full ${className}`} style={{ paddingTop: '12px' }}>
|
||||
{Array(2)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-chat' index={i} />
|
||||
))}
|
||||
{Array(5)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-console' index={i} />
|
||||
))}
|
||||
{Array(2)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-personal' index={i} />
|
||||
))}
|
||||
{Array(5)
|
||||
.fill(null)
|
||||
.map((_, i) => (
|
||||
<CollapsedRow keyPrefix='c-admin' index={i} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const sections = [
|
||||
{ key: 'chat', titleWidth: 32, itemWidths: [54, 32], wrapper: 'section' },
|
||||
{ key: 'console', titleWidth: 48, itemWidths: [64, 64, 64, 64, 64] },
|
||||
{ key: 'personal', titleWidth: 64, itemWidths: [64, 64] },
|
||||
...(showAdmin
|
||||
? [{ key: 'admin', titleWidth: 48, itemWidths: [64, 64, 80, 64, 64] }]
|
||||
: []),
|
||||
];
|
||||
|
||||
return (
|
||||
<div className={`w-full ${className}`} style={{ paddingTop: '12px' }}>
|
||||
{sections.map((sec, idx) => (
|
||||
<React.Fragment key={sec.key}>
|
||||
{sec.wrapper === 'section' ? (
|
||||
<div className='sidebar-section'>
|
||||
<div
|
||||
className='sidebar-group-label'
|
||||
style={{ padding: '4px 15px 8px' }}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: sec.titleWidth, height: TITLE_HEIGHT }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{sec.itemWidths.map((w, i) => (
|
||||
<NavRow key={`${sec.key}-${i}`} labelWidth={w} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div
|
||||
className='sidebar-group-label'
|
||||
style={{ padding: '4px 15px 8px' }}
|
||||
>
|
||||
<Skeleton
|
||||
loading={true}
|
||||
active
|
||||
placeholder={
|
||||
<Skeleton.Title
|
||||
active
|
||||
style={{ width: sec.titleWidth, height: TITLE_HEIGHT }}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{sec.itemWidths.map((w, i) => (
|
||||
<NavRow key={`${sec.key}-${i}`} labelWidth={w} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// 根据类型渲染不同的骨架屏
|
||||
switch (type) {
|
||||
case 'navigation':
|
||||
return renderNavigationSkeleton();
|
||||
case 'userArea':
|
||||
return renderUserAreaSkeleton();
|
||||
case 'image':
|
||||
return renderImageSkeleton();
|
||||
case 'title':
|
||||
return renderTitleSkeleton();
|
||||
case 'sidebarNavItem':
|
||||
return renderSidebarNavItemSkeleton();
|
||||
case 'sidebarGroupTitle':
|
||||
return renderSidebarGroupTitleSkeleton();
|
||||
case 'sidebar':
|
||||
return renderSidebarSkeleton();
|
||||
case 'button':
|
||||
return renderButtonSkeleton();
|
||||
case 'text':
|
||||
default:
|
||||
return renderTextSkeleton();
|
||||
}
|
||||
};
|
||||
|
||||
export default SkeletonWrapper;
|
||||
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useState, useContext } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Button } from '@douyinfe/semi-ui';
|
||||
import { IconCreditCard } from '@douyinfe/semi-icons';
|
||||
import { Share2, BookOpen, MonitorDown } from 'lucide-react';
|
||||
import NewYearButton from './NewYearButton';
|
||||
import NotificationButton from './NotificationButton';
|
||||
import ThemeToggle from './ThemeToggle';
|
||||
import LanguageSelector from './LanguageSelector';
|
||||
import UserArea from './UserArea';
|
||||
import PromotionPosterModal from '../../promotion/PromotionPosterModal';
|
||||
import { StatusContext } from '../../../context/Status';
|
||||
import { isHeaderActionButtonVisible } from '../../../helpers/navigationVisibility';
|
||||
import { useWeyAiDownloadEntry } from '../../../hooks/common/useWeyAiWebEntry';
|
||||
|
||||
const ActionButtons = ({
|
||||
isAuthPage = false,
|
||||
isNewYear,
|
||||
unreadCount,
|
||||
onNoticeOpen,
|
||||
theme,
|
||||
onThemeToggle,
|
||||
currentLang,
|
||||
onLanguageChange,
|
||||
userState,
|
||||
isLoading,
|
||||
isMobile,
|
||||
isSelfUseMode,
|
||||
headerNavModules,
|
||||
sidebarModulesAdmin,
|
||||
isOrgUser,
|
||||
logout,
|
||||
navigate,
|
||||
t,
|
||||
}) => {
|
||||
const [promotionVisible, setPromotionVisible] = useState(false);
|
||||
const [statusState] = useContext(StatusContext);
|
||||
const isLoggedIn = userState?.user?.username;
|
||||
const userGroup = userState?.user?.group || 'default';
|
||||
// WeyAi 桌面端下载快捷入口:判定与用户中心侧栏项共用 useWeyAiDownloadEntry
|
||||
// (下载页开关 + 登录 + 网页端已配置时沿用其开放范围);管理员可在「功能按钮」
|
||||
// 里全局关闭,企业员工顶栏可在 rightActions 里单独关闭
|
||||
const { visible: weyaiDownloadVisible } = useWeyAiDownloadEntry();
|
||||
|
||||
// 顶栏功能按钮显示配置(新手教程 / 推广 / 充值)。
|
||||
// 数据源与 HeaderNavModules 一致,走公开的 /api/status(StatusContext / localStorage 缓存),
|
||||
// 普通用户也能读取;不要用 /api/option/,那是管理员(RootAuth)专用接口,普通用户会 403。
|
||||
let buttonConfig = null;
|
||||
try {
|
||||
const raw =
|
||||
statusState?.status?.HeaderActionButtons ||
|
||||
(localStorage.getItem('status')
|
||||
? JSON.parse(localStorage.getItem('status')).HeaderActionButtons
|
||||
: null);
|
||||
if (raw) {
|
||||
buttonConfig = JSON.parse(raw);
|
||||
}
|
||||
} catch (e) {
|
||||
buttonConfig = null;
|
||||
}
|
||||
|
||||
// 企业员工:教程/推广/充值 这三个主操作按钮由 HeaderActionButtons 控制,
|
||||
// 但企业顶栏配置走 headerNavModules.rightActions,故对 org 用户额外按 rightActions 隐藏。
|
||||
// 注意 key 映射:推广按钮在 HeaderActionButtons 里叫 'pricing',在 rightActions 里叫 'promotion'。
|
||||
const orgRightActionKey = {
|
||||
tutorial: 'tutorial',
|
||||
pricing: 'promotion',
|
||||
recharge: 'recharge',
|
||||
weyaiDownload: 'weyaiDownload',
|
||||
};
|
||||
|
||||
// 判断某个功能按钮是否显示:无配置、配置非数组(脏数据)或配置缺失该项时默认显示。
|
||||
// 认证页(登录/注册/企业登录等)一律隐藏主操作按钮:充值/教程/推广要么需要登录态,
|
||||
// 要么会把用户带离认证流程,行业惯例认证页顶栏只留最小化工具。
|
||||
const isButtonVisible = (key) => {
|
||||
if (isAuthPage) return false;
|
||||
if (isOrgUser) {
|
||||
const ra = orgRightActionKey[key];
|
||||
if (ra && headerNavModules?.rightActions?.[ra] === false) return false;
|
||||
}
|
||||
return isHeaderActionButtonVisible(buttonConfig, key, userGroup);
|
||||
};
|
||||
|
||||
// 右侧工具类按钮(新年 / 通知 / 主题切换)显隐:跟随 rightActions 配置,默认显示。
|
||||
// 认证页只保留主题切换(对未登录用户有意义且不打断认证流程),通知/新年装饰一并隐藏。
|
||||
const isActionVisible = (key) => {
|
||||
if (isAuthPage && key !== 'theme') return false;
|
||||
return headerNavModules?.rightActions?.[key] !== false;
|
||||
};
|
||||
|
||||
// 语言切换按钮(中/英):由管理员在 运营设置→通用设置 控制,默认显示。
|
||||
// 与 HeaderActionButtons 同源走公开 /api/status(普通用户可读),status 未加载时
|
||||
// 回退 localStorage 缓存;仅显式 false 才隐藏。认证页也展示(对未登录用户有意义)。
|
||||
let languageSwitchEnabled = true;
|
||||
try {
|
||||
const status =
|
||||
statusState?.status ||
|
||||
(localStorage.getItem('status')
|
||||
? JSON.parse(localStorage.getItem('status'))
|
||||
: null);
|
||||
if (status && status.language_switch_enabled === false) {
|
||||
languageSwitchEnabled = false;
|
||||
}
|
||||
} catch (e) {
|
||||
languageSwitchEnabled = true;
|
||||
}
|
||||
|
||||
// 是否存在「主操作区」按钮(新手教程 / 推广 / 充值),用于决定分隔线是否显示
|
||||
const showWeyAiDownload =
|
||||
isLoggedIn && weyaiDownloadVisible && isButtonVisible('weyaiDownload');
|
||||
|
||||
const hasPrimaryActions =
|
||||
(isLoggedIn && isButtonVisible('tutorial')) ||
|
||||
(isLoggedIn && isButtonVisible('pricing')) ||
|
||||
showWeyAiDownload ||
|
||||
isButtonVisible('recharge');
|
||||
|
||||
// 是否存在「工具区」按钮(新年 / 通知 / 主题 / 语言)
|
||||
const hasUtilityActions =
|
||||
isActionVisible('newYear') ||
|
||||
isActionVisible('notifications') ||
|
||||
isActionVisible('theme') ||
|
||||
languageSwitchEnabled;
|
||||
|
||||
// 进入用户区前是否需要分隔线(任一侧有按钮即显示)
|
||||
const hasHeaderActions = hasPrimaryActions || hasUtilityActions;
|
||||
|
||||
return (
|
||||
<div className='flex items-center shrink-0 gap-0.5 sm:gap-2 md:gap-3'>
|
||||
{/* Tutorial Button - 新手教程按钮 (桌面端显示) */}
|
||||
{isLoggedIn && isButtonVisible('tutorial') && (
|
||||
<Link to='/tutorial' className='hidden sm:block'>
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
icon={<BookOpen size={15} />}
|
||||
className='group/btn hover:!bg-brand/10 dark:hover:!bg-brand/20 !text-brand-deep dark:!text-brand-from !border !border-brand/30 dark:!border-brand/25 hover:!border-brand/50 !rounded-full !px-3.5 !h-8 !transition-all !duration-200 !shadow-sm hover:!shadow-md hover:!shadow-brand/20 hover:!-translate-y-0.5 active:!translate-y-0'
|
||||
style={{ background: 'var(--semi-color-primary-light-default)' }}
|
||||
>
|
||||
{!isMobile && <span className='font-medium'>{t('新手教程')}</span>}
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{/* Promotion Button - 推广按钮 (桌面端显示) */}
|
||||
{isLoggedIn && isButtonVisible('pricing') && (
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
icon={<Share2 size={15} />}
|
||||
className='hidden sm:!inline-flex hover:!bg-brand/10 dark:hover:!bg-brand/20 !text-brand-deep dark:!text-brand-from !border !border-brand/30 dark:!border-brand/25 hover:!border-brand/50 !rounded-full !px-3.5 !h-8 !transition-all !duration-200 !shadow-sm hover:!shadow-md hover:!shadow-brand/20 hover:!-translate-y-0.5 active:!translate-y-0'
|
||||
style={{ background: 'var(--semi-color-primary-light-default)' }}
|
||||
onClick={() => setPromotionVisible(true)}
|
||||
>
|
||||
{!isMobile && <span className='font-medium'>{t('推广')}</span>}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* WeyAi 桌面端下载 - 有 WeyAi 访问权限且下载页已开放时显示 (桌面端显示) */}
|
||||
{showWeyAiDownload && (
|
||||
<Link
|
||||
to='/weyai/download'
|
||||
className='hidden sm:block'
|
||||
aria-label={t('下载 WeyAi 桌面端')}
|
||||
>
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
icon={<MonitorDown size={15} />}
|
||||
className='group/btn hover:!bg-brand/10 dark:hover:!bg-brand/20 !text-brand-deep dark:!text-brand-from !border !border-brand/30 dark:!border-brand/25 hover:!border-brand/50 !rounded-full !px-3.5 !h-8 !transition-all !duration-200 !shadow-sm hover:!shadow-md hover:!shadow-brand/20 hover:!-translate-y-0.5 active:!translate-y-0'
|
||||
style={{ background: 'var(--semi-color-primary-light-default)' }}
|
||||
>
|
||||
{!isMobile && (
|
||||
<span className='font-medium'>{t('下载 WeyAi')}</span>
|
||||
)}
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{/* Recharge Button - 充值按钮 (primary CTA) */}
|
||||
{isButtonVisible('recharge') && (
|
||||
<Link to='/recharge'>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
icon={<IconCreditCard />}
|
||||
className='!bg-gradient-to-r !from-brand !to-brand-deep dark:!from-brand dark:!to-brand-deep !text-white !border-none !rounded-full !px-3 sm:!px-4 !h-7 sm:!h-8 !font-semibold !transition-all !duration-200 !shadow-md !shadow-brand/30 hover:!shadow-lg hover:!shadow-brand/45 hover:!-translate-y-0.5 active:!translate-y-0 active:!scale-[0.98]'
|
||||
>
|
||||
{!isMobile && <span className='font-medium'>{t('充值')}</span>}
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
|
||||
<PromotionPosterModal
|
||||
visible={promotionVisible}
|
||||
onClose={() => setPromotionVisible(false)}
|
||||
/>
|
||||
|
||||
{/* Divider */}
|
||||
{hasPrimaryActions && hasUtilityActions && (
|
||||
<div className='hidden md:block w-px h-6 bg-gradient-to-b from-transparent via-gray-300 dark:via-neutral-600 to-transparent mx-1' />
|
||||
)}
|
||||
|
||||
{isActionVisible('newYear') && (
|
||||
<NewYearButton isNewYear={isNewYear} t={t} />
|
||||
)}
|
||||
|
||||
{isActionVisible('notifications') && (
|
||||
<NotificationButton
|
||||
unreadCount={unreadCount}
|
||||
onNoticeOpen={onNoticeOpen}
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isActionVisible('theme') && (
|
||||
<ThemeToggle theme={theme} onThemeToggle={onThemeToggle} t={t} />
|
||||
)}
|
||||
|
||||
{languageSwitchEnabled && (
|
||||
<LanguageSelector
|
||||
currentLang={currentLang}
|
||||
onLanguageChange={onLanguageChange}
|
||||
t={t}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* Divider before user area(认证页 UserArea 通常为空,不渲染悬空分隔线) */}
|
||||
{hasHeaderActions && !isAuthPage && (
|
||||
<div className='hidden md:block w-px h-6 bg-gradient-to-b from-transparent via-gray-300 dark:via-neutral-600 to-transparent mx-1' />
|
||||
)}
|
||||
|
||||
<UserArea
|
||||
userState={userState}
|
||||
isLoading={isLoading}
|
||||
isMobile={isMobile}
|
||||
isSelfUseMode={isSelfUseMode}
|
||||
headerNavModules={headerNavModules}
|
||||
rightActions={headerNavModules?.rightActions}
|
||||
sidebarModulesAdmin={sidebarModulesAdmin}
|
||||
logout={logout}
|
||||
navigate={navigate}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ActionButtons;
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user