Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 86e0f83f73 | |||
| 2bc6fb7ab1 | |||
| 65be92ba43 | |||
| 98acb79a20 | |||
| d819cecfc6 | |||
| 2c3c6eb2c9 | |||
| d83ad25be3 | |||
| e86cd18f1d | |||
| eb7b769155 | |||
| 0e24ccf7b1 | |||
| f8ccad52f9 | |||
| 57cf34b0d0 | |||
| ad38a4a0e3 | |||
| c7adbc153b | |||
| 17152efa2c | |||
| a605fad7e0 | |||
| 30222cd830 | |||
| 4ca2ab4a9c | |||
| 588da45902 | |||
| 5466036349 | |||
| 9869c0c5e6 | |||
| c38f056527 |
Generated
+14
-8
@@ -9,6 +9,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "5.3.0",
|
"@ant-design/icons": "5.3.0",
|
||||||
|
"@phosphor-icons/react": "^2.1.10",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"scheduler": "0.23.0",
|
"scheduler": "0.23.0",
|
||||||
@@ -119,7 +120,6 @@
|
|||||||
"integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==",
|
"integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.29.7",
|
"@babel/code-frame": "^7.29.7",
|
||||||
"@babel/generator": "^7.29.7",
|
"@babel/generator": "^7.29.7",
|
||||||
@@ -851,6 +851,19 @@
|
|||||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@phosphor-icons/react": {
|
||||||
|
"version": "2.1.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/@phosphor-icons/react/-/react-2.1.10.tgz",
|
||||||
|
"integrity": "sha512-vt8Tvq8GLjheAZZYa+YG/pW7HDbov8El/MANW8pOAz4eGxrwhnbfrQZq0Cp4q8zBEu8NIhHdnr+r8thnfRSNYA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": ">= 16.8",
|
||||||
|
"react-dom": ">= 16.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@rollup/pluginutils": {
|
"node_modules/@rollup/pluginutils": {
|
||||||
"version": "5.4.0",
|
"version": "5.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.4.0.tgz",
|
||||||
@@ -1296,7 +1309,6 @@
|
|||||||
"integrity": "sha512-Y2Tz5P4yz23brwm2d7jNon39qoAtMMmalOQv6+fEFt1mT+FcM3D841wDpoUvFXhaYenuROCy3FZYqdTjM7qVyA==",
|
"integrity": "sha512-Y2Tz5P4yz23brwm2d7jNon39qoAtMMmalOQv6+fEFt1mT+FcM3D841wDpoUvFXhaYenuROCy3FZYqdTjM7qVyA==",
|
||||||
"devOptional": true,
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/prop-types": "*",
|
"@types/prop-types": "*",
|
||||||
"@types/scheduler": "*",
|
"@types/scheduler": "*",
|
||||||
@@ -1581,7 +1593,6 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"baseline-browser-mapping": "^2.10.12",
|
"baseline-browser-mapping": "^2.10.12",
|
||||||
"caniuse-lite": "^1.0.30001782",
|
"caniuse-lite": "^1.0.30001782",
|
||||||
@@ -2710,7 +2721,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz",
|
||||||
"integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==",
|
"integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"loose-envify": "^1.1.0"
|
"loose-envify": "^1.1.0"
|
||||||
},
|
},
|
||||||
@@ -2723,7 +2733,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",
|
||||||
"integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==",
|
"integrity": "sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"loose-envify": "^1.1.0",
|
"loose-envify": "^1.1.0",
|
||||||
"scheduler": "^0.23.0"
|
"scheduler": "^0.23.0"
|
||||||
@@ -2794,7 +2803,6 @@
|
|||||||
"integrity": "sha512-nc72Wgq62I7rtDV4izT5/aaS0zxy3kttkinf9586ApknY3jZO9NYsmtc24fUckA0X7Q2v+ML4a15pdUlV5V/jA==",
|
"integrity": "sha512-nc72Wgq62I7rtDV4izT5/aaS0zxy3kttkinf9586ApknY3jZO9NYsmtc24fUckA0X7Q2v+ML4a15pdUlV5V/jA==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/estree": "1.0.9"
|
"@types/estree": "1.0.9"
|
||||||
},
|
},
|
||||||
@@ -3166,7 +3174,6 @@
|
|||||||
"integrity": "sha512-STmSFzhY4ljuhz14bg9LkMTk3d98IO6DIArnTY6MeBwiD1Za2StcQtz7fzOUnRCqrHSD5+OS2reg4HOz1eoLnw==",
|
"integrity": "sha512-STmSFzhY4ljuhz14bg9LkMTk3d98IO6DIArnTY6MeBwiD1Za2StcQtz7fzOUnRCqrHSD5+OS2reg4HOz1eoLnw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"esbuild": "^0.19.3",
|
"esbuild": "^0.19.3",
|
||||||
"postcss": "^8.4.35",
|
"postcss": "^8.4.35",
|
||||||
@@ -3257,7 +3264,6 @@
|
|||||||
"integrity": "sha512-Ljb1cnSJSivGN0LqXd/zmDbWEM0RNNg2t1QW/XUhYl/qPqyu7CsqeWtqQXHVaJsecLPuDoak2oJcZN2QoRIOag==",
|
"integrity": "sha512-Ljb1cnSJSivGN0LqXd/zmDbWEM0RNNg2t1QW/XUhYl/qPqyu7CsqeWtqQXHVaJsecLPuDoak2oJcZN2QoRIOag==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"peer": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vitest/expect": "1.6.1",
|
"@vitest/expect": "1.6.1",
|
||||||
"@vitest/runner": "1.6.1",
|
"@vitest/runner": "1.6.1",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "5.3.0",
|
"@ant-design/icons": "5.3.0",
|
||||||
|
"@phosphor-icons/react": "^2.1.10",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"scheduler": "0.23.0",
|
"scheduler": "0.23.0",
|
||||||
|
|||||||
+35
-108
@@ -4,19 +4,16 @@ import {
|
|||||||
CheckCircleFilled,
|
CheckCircleFilled,
|
||||||
CloseOutlined,
|
CloseOutlined,
|
||||||
HomeOutlined,
|
HomeOutlined,
|
||||||
IdcardOutlined,
|
|
||||||
LockOutlined,
|
LockOutlined,
|
||||||
LoadingOutlined,
|
LoadingOutlined,
|
||||||
LoginOutlined,
|
|
||||||
LogoutOutlined,
|
LogoutOutlined,
|
||||||
MailOutlined,
|
MailOutlined,
|
||||||
MobileOutlined,
|
MobileOutlined,
|
||||||
PictureOutlined,
|
|
||||||
SafetyOutlined,
|
SafetyOutlined,
|
||||||
UserOutlined,
|
UserOutlined,
|
||||||
VideoCameraOutlined,
|
|
||||||
WalletOutlined,
|
|
||||||
} from "@ant-design/icons";
|
} from "@ant-design/icons";
|
||||||
|
import { LocalAvatar } from "./components/LocalAvatar";
|
||||||
|
import { Topbar } from "./components/Topbar";
|
||||||
import ErrorBoundary from "./components/ErrorBoundary";
|
import ErrorBoundary from "./components/ErrorBoundary";
|
||||||
import ToastContainer from "./components/toast/ToastContainer";
|
import ToastContainer from "./components/toast/ToastContainer";
|
||||||
import { toast } from "./components/toast/toastStore";
|
import { toast } from "./components/toast/toastStore";
|
||||||
@@ -40,6 +37,9 @@ const EcommercePage = lazy(() => import("./features/ecommerce/EcommercePage"));
|
|||||||
|
|
||||||
type AuthMode = "login" | "register";
|
type AuthMode = "login" | "register";
|
||||||
type AuthMethod = "account" | "email" | "phone";
|
type AuthMethod = "account" | "email" | "phone";
|
||||||
|
type WorkspaceChromeState = {
|
||||||
|
isToolPage: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
interface LocalProfilePageProps {
|
interface LocalProfilePageProps {
|
||||||
session: WebUserSession;
|
session: WebUserSession;
|
||||||
@@ -51,17 +51,6 @@ interface LocalProfilePageProps {
|
|||||||
onLogout: () => void;
|
onLogout: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function LocalAvatar({ session, size = "md" }: { session: WebUserSession; size?: "sm" | "md" | "lg" }) {
|
|
||||||
const displayName = session.user.displayName || session.user.username || "用户";
|
|
||||||
const label = displayName.trim().slice(0, 1).toUpperCase() || "用";
|
|
||||||
const avatarUrl = session.user.avatarUrl;
|
|
||||||
return (
|
|
||||||
<span className={`local-user-avatar local-user-avatar--${size}`}>
|
|
||||||
{avatarUrl ? <img src={avatarUrl} alt={displayName} /> : <span>{label}</span>}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function LocalProfilePage({ session, balance, imageCount, videoCount, onBack, onBugFeedback, onLogout }: LocalProfilePageProps) {
|
function LocalProfilePage({ session, balance, imageCount, videoCount, onBack, onBugFeedback, onLogout }: LocalProfilePageProps) {
|
||||||
const displayName = session.user.displayName || session.user.username || "用户";
|
const displayName = session.user.displayName || session.user.username || "用户";
|
||||||
const workCount = Math.max(imageCount + videoCount, 0);
|
const workCount = Math.max(imageCount + videoCount, 0);
|
||||||
@@ -166,6 +155,9 @@ function App() {
|
|||||||
const [sessionNotice, setSessionNotice] = useState<string | null>(null);
|
const [sessionNotice, setSessionNotice] = useState<string | null>(null);
|
||||||
const [profileMenuOpen, setProfileMenuOpen] = useState(false);
|
const [profileMenuOpen, setProfileMenuOpen] = useState(false);
|
||||||
const [currentPage, setCurrentPage] = useState<"workspace" | "profile">("workspace");
|
const [currentPage, setCurrentPage] = useState<"workspace" | "profile">("workspace");
|
||||||
|
const [workspaceChrome, setWorkspaceChrome] = useState<WorkspaceChromeState>({
|
||||||
|
isToolPage: false,
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void loadDarkGreenTheme();
|
void loadDarkGreenTheme();
|
||||||
@@ -318,20 +310,6 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const balance = Math.max(usage.balanceCents, 0) / 100;
|
const balance = Math.max(usage.balanceCents, 0) / 100;
|
||||||
const displayName = session?.user.displayName || session?.user.username || "用户";
|
|
||||||
const actualWorkCount = Math.max(usage.imageUsed + usage.videoUsed, 0);
|
|
||||||
const shownWorkCount = actualWorkCount;
|
|
||||||
|
|
||||||
const avatarMenuStats = useMemo(
|
|
||||||
() => [
|
|
||||||
{ icon: <IdcardOutlined />, label: "UID", value: session?.user.id ?? "-" },
|
|
||||||
{ icon: <WalletOutlined />, label: "积分", value: `${balance.toFixed(2)} 积分` },
|
|
||||||
{ icon: <PictureOutlined />, label: "图片", value: usage.imageUsed },
|
|
||||||
{ icon: <VideoCameraOutlined />, label: "视频", value: usage.videoUsed },
|
|
||||||
{ icon: <PictureOutlined />, label: "作品", value: shownWorkCount },
|
|
||||||
],
|
|
||||||
[balance, session?.user.id, shownWorkCount, usage.imageUsed, usage.videoUsed],
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleOpenProfile = () => {
|
const handleOpenProfile = () => {
|
||||||
setProfileMenuOpen(false);
|
setProfileMenuOpen(false);
|
||||||
@@ -349,86 +327,31 @@ function App() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ecommerce-standalone web-shell" data-theme="dark" data-ui-theme="dark-green" data-view="ecommerce">
|
<div
|
||||||
<header className="ecommerce-standalone__topbar">
|
className="ecommerce-standalone web-shell"
|
||||||
<button type="button" className="ecommerce-standalone__brand" onClick={handleOpenWorkspace}>
|
data-theme="dark"
|
||||||
<span className="ecommerce-standalone__logo" aria-hidden="true">
|
data-ui-theme="dark-green"
|
||||||
<img src="https://stringtest.oss-cn-hangzhou.aliyuncs.com/logo.png" alt="" />
|
data-view="ecommerce"
|
||||||
</span>
|
data-workspace-tool-page={workspaceChrome.isToolPage ? "true" : "false"}
|
||||||
<strong>OmniAI 电商智能体</strong>
|
>
|
||||||
</button>
|
<Topbar
|
||||||
<div className="ecommerce-standalone__account">
|
session={session}
|
||||||
{session ? (
|
usage={usage}
|
||||||
<div className="ecommerce-profile-menu">
|
profileMenuOpen={profileMenuOpen}
|
||||||
<span className="ecommerce-standalone__credits">
|
onProfileMenuOpenChange={setProfileMenuOpen}
|
||||||
{(Math.max(usage.balanceCents, 0) / 100).toFixed(2)} 积分
|
onOpenWorkspace={handleOpenWorkspace}
|
||||||
</span>
|
onOpenProfile={handleOpenProfile}
|
||||||
<button
|
onOpenAuth={openAuth}
|
||||||
type="button"
|
onLogout={handleLogout}
|
||||||
className="ecommerce-profile-menu__trigger"
|
onBugFeedback={handleBugFeedback}
|
||||||
onClick={() => setProfileMenuOpen((open) => !open)}
|
/>
|
||||||
aria-haspopup="dialog"
|
|
||||||
aria-expanded={profileMenuOpen}
|
|
||||||
>
|
|
||||||
<LocalAvatar session={session} size="sm" />
|
|
||||||
<span>{displayName}</span>
|
|
||||||
</button>
|
|
||||||
{profileMenuOpen ? (
|
|
||||||
<>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className="ecommerce-profile-popover__backdrop"
|
|
||||||
aria-label="关闭账户信息"
|
|
||||||
onClick={() => setProfileMenuOpen(false)}
|
|
||||||
/>
|
|
||||||
<section className="ecommerce-profile-popover" role="dialog" aria-label="账户信息">
|
|
||||||
<div className="ecommerce-profile-popover__head">
|
|
||||||
<LocalAvatar session={session} size="md" />
|
|
||||||
<div>
|
|
||||||
<strong>{displayName}</strong>
|
|
||||||
<span>{session.user.username}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<dl className="ecommerce-profile-popover__stats">
|
|
||||||
{avatarMenuStats.map((item) => (
|
|
||||||
<div key={item.label}>
|
|
||||||
<dt>{item.icon}{item.label}</dt>
|
|
||||||
<dd>{item.value}</dd>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<div className="ecommerce-profile-popover__actions">
|
|
||||||
<button type="button" className="is-primary" onClick={handleOpenProfile}>
|
|
||||||
<UserOutlined />
|
|
||||||
个人中心
|
|
||||||
</button>
|
|
||||||
<button type="button" onClick={handleBugFeedback}>
|
|
||||||
<BugOutlined />
|
|
||||||
Bug 反馈
|
|
||||||
</button>
|
|
||||||
<button type="button" className="is-danger" onClick={handleLogout}>
|
|
||||||
<LogoutOutlined />
|
|
||||||
退出
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<button type="button" onClick={() => openAuth("login")}>
|
|
||||||
<LoginOutlined />
|
|
||||||
<span>登录 / 注册</span>
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<main className="ecommerce-standalone__content">
|
<main className="ecommerce-standalone__content">
|
||||||
{session ? (
|
{session ? (
|
||||||
<div className="ecommerce-standalone__page" hidden={currentPage !== "profile"}>
|
<div
|
||||||
|
className="ecommerce-standalone__page ecommerce-standalone__page--profile"
|
||||||
|
hidden={currentPage !== "profile"}
|
||||||
|
>
|
||||||
<LocalProfilePage
|
<LocalProfilePage
|
||||||
session={session}
|
session={session}
|
||||||
balance={balance}
|
balance={balance}
|
||||||
@@ -442,7 +365,10 @@ function App() {
|
|||||||
) : null}
|
) : null}
|
||||||
{/* 工作台常驻挂载,仅用 hidden 切换。切到个人中心时不卸载,
|
{/* 工作台常驻挂载,仅用 hidden 切换。切到个人中心时不卸载,
|
||||||
生成任务、进度动画、已上传图片等本地状态全部保留,切回即继续。 */}
|
生成任务、进度动画、已上传图片等本地状态全部保留,切回即继续。 */}
|
||||||
<div className="ecommerce-standalone__page" hidden={Boolean(session) && currentPage === "profile"}>
|
<div
|
||||||
|
className="ecommerce-standalone__page ecommerce-standalone__page--workspace"
|
||||||
|
hidden={Boolean(session) && currentPage === "profile"}
|
||||||
|
>
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<Suspense
|
<Suspense
|
||||||
fallback={
|
fallback={
|
||||||
@@ -455,6 +381,7 @@ function App() {
|
|||||||
<EcommercePage
|
<EcommercePage
|
||||||
projects={[]}
|
projects={[]}
|
||||||
isAuthenticated={Boolean(session)}
|
isAuthenticated={Boolean(session)}
|
||||||
|
onWorkspaceChromeChange={setWorkspaceChrome}
|
||||||
onStartCreate={() => undefined}
|
onStartCreate={() => undefined}
|
||||||
onOpenProject={() => undefined}
|
onOpenProject={() => undefined}
|
||||||
onDeleteProject={() => undefined}
|
onDeleteProject={() => undefined}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import type { WebUserSession } from "../types";
|
||||||
|
|
||||||
|
interface LocalAvatarProps {
|
||||||
|
session: WebUserSession;
|
||||||
|
size?: "sm" | "md" | "lg";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function LocalAvatar({ session, size = "md" }: LocalAvatarProps) {
|
||||||
|
const displayName = session.user.displayName || session.user.username || "用户";
|
||||||
|
const label = displayName.trim().slice(0, 1).toUpperCase() || "用";
|
||||||
|
const avatarUrl = session.user.avatarUrl;
|
||||||
|
return (
|
||||||
|
<span className={`local-user-avatar local-user-avatar--${size}`}>
|
||||||
|
{avatarUrl ? <img src={avatarUrl} alt={displayName} /> : <span>{label}</span>}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
import { useEffect, useMemo, useState } from "react";
|
||||||
|
import {
|
||||||
|
BugOutlined,
|
||||||
|
IdcardOutlined,
|
||||||
|
LoginOutlined,
|
||||||
|
LogoutOutlined,
|
||||||
|
PictureOutlined,
|
||||||
|
UserOutlined,
|
||||||
|
VideoCameraOutlined,
|
||||||
|
WalletOutlined,
|
||||||
|
} from "@ant-design/icons";
|
||||||
|
import { LocalAvatar } from "./LocalAvatar";
|
||||||
|
import type { WebUserSession } from "../types";
|
||||||
|
|
||||||
|
interface TopbarProps {
|
||||||
|
session: WebUserSession | null;
|
||||||
|
usage: { balanceCents: number; imageUsed: number; videoUsed: number };
|
||||||
|
profileMenuOpen: boolean;
|
||||||
|
onProfileMenuOpenChange: (open: boolean) => void;
|
||||||
|
onOpenWorkspace: () => void;
|
||||||
|
onOpenProfile: () => void;
|
||||||
|
onOpenAuth: (mode: "login" | "register") => void;
|
||||||
|
onLogout: () => void;
|
||||||
|
onBugFeedback: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Topbar({
|
||||||
|
session,
|
||||||
|
usage,
|
||||||
|
profileMenuOpen,
|
||||||
|
onProfileMenuOpenChange,
|
||||||
|
onOpenWorkspace,
|
||||||
|
onOpenProfile,
|
||||||
|
onOpenAuth,
|
||||||
|
onLogout,
|
||||||
|
onBugFeedback,
|
||||||
|
}: TopbarProps) {
|
||||||
|
const [isTopbarHidden, setIsTopbarHidden] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let restoreTimer: number | undefined;
|
||||||
|
|
||||||
|
const handleScroll = (event: Event) => {
|
||||||
|
if (profileMenuOpen) return;
|
||||||
|
const target = event.target;
|
||||||
|
const activeWorkspace = document.querySelector<HTMLElement>(".ecommerce-standalone__page--workspace:not([hidden])");
|
||||||
|
if (!activeWorkspace) return;
|
||||||
|
const isWorkspacePreviewScroll =
|
||||||
|
target instanceof HTMLElement && target.classList.contains("clone-ai-preview") && activeWorkspace.contains(target);
|
||||||
|
const isPageScroll =
|
||||||
|
target === document ||
|
||||||
|
target === document.scrollingElement ||
|
||||||
|
target === document.documentElement ||
|
||||||
|
target === document.body;
|
||||||
|
if (!isWorkspacePreviewScroll && !isPageScroll) return;
|
||||||
|
|
||||||
|
setIsTopbarHidden(true);
|
||||||
|
if (restoreTimer) window.clearTimeout(restoreTimer);
|
||||||
|
restoreTimer = window.setTimeout(() => {
|
||||||
|
setIsTopbarHidden(false);
|
||||||
|
}, 240);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("scroll", handleScroll, { capture: true, passive: true });
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("scroll", handleScroll, { capture: true });
|
||||||
|
if (restoreTimer) window.clearTimeout(restoreTimer);
|
||||||
|
};
|
||||||
|
}, [profileMenuOpen]);
|
||||||
|
|
||||||
|
const balance = Math.max(usage.balanceCents, 0) / 100;
|
||||||
|
const displayName = session?.user.displayName || session?.user.username || "用户";
|
||||||
|
const actualWorkCount = Math.max(usage.imageUsed + usage.videoUsed, 0);
|
||||||
|
const shownWorkCount = actualWorkCount;
|
||||||
|
|
||||||
|
const avatarMenuStats = useMemo(
|
||||||
|
() => [
|
||||||
|
{ icon: <IdcardOutlined />, label: "UID", value: session?.user.id ?? "-" },
|
||||||
|
{ icon: <WalletOutlined />, label: "积分", value: `${balance.toFixed(2)} 积分` },
|
||||||
|
{ icon: <PictureOutlined />, label: "图片", value: usage.imageUsed },
|
||||||
|
{ icon: <VideoCameraOutlined />, label: "视频", value: usage.videoUsed },
|
||||||
|
{ icon: <PictureOutlined />, label: "作品", value: shownWorkCount },
|
||||||
|
],
|
||||||
|
[balance, session?.user.id, shownWorkCount, usage.imageUsed, usage.videoUsed],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<header
|
||||||
|
className="ecommerce-standalone__topbar"
|
||||||
|
data-scroll-hidden={isTopbarHidden ? "true" : "false"}
|
||||||
|
style={{
|
||||||
|
position: "fixed",
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
zIndex: 1000,
|
||||||
|
pointerEvents: "none",
|
||||||
|
background: "transparent",
|
||||||
|
border: 0,
|
||||||
|
boxShadow: "none",
|
||||||
|
backdropFilter: "none",
|
||||||
|
WebkitBackdropFilter: "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ecommerce-standalone__brand"
|
||||||
|
style={{ pointerEvents: "auto" }}
|
||||||
|
onClick={onOpenWorkspace}
|
||||||
|
>
|
||||||
|
<span className="ecommerce-standalone__logo" aria-hidden="true">
|
||||||
|
<img src="https://stringtest.oss-cn-hangzhou.aliyuncs.com/logo.png" alt="" />
|
||||||
|
</span>
|
||||||
|
<strong>OmniAI 电商智能体</strong>
|
||||||
|
</button>
|
||||||
|
<div className="ecommerce-standalone__account">
|
||||||
|
{session ? (
|
||||||
|
<div className="ecommerce-profile-menu">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ecommerce-profile-menu__trigger"
|
||||||
|
style={{ pointerEvents: "auto" }}
|
||||||
|
onClick={() => onProfileMenuOpenChange(!profileMenuOpen)}
|
||||||
|
aria-haspopup="dialog"
|
||||||
|
aria-expanded={profileMenuOpen}
|
||||||
|
>
|
||||||
|
<span className="ecommerce-standalone__credits">
|
||||||
|
{(Math.max(usage.balanceCents, 0) / 100).toFixed(2)} 积分
|
||||||
|
</span>
|
||||||
|
<LocalAvatar session={session} size="sm" />
|
||||||
|
<span className="ecommerce-profile-menu__name">{displayName}</span>
|
||||||
|
</button>
|
||||||
|
{profileMenuOpen ? (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ecommerce-profile-popover__backdrop"
|
||||||
|
aria-label="关闭账户信息"
|
||||||
|
onClick={() => onProfileMenuOpenChange(false)}
|
||||||
|
/>
|
||||||
|
<section className="ecommerce-profile-popover" role="dialog" aria-label="账户信息">
|
||||||
|
<div className="ecommerce-profile-popover__head">
|
||||||
|
<LocalAvatar session={session} size="md" />
|
||||||
|
<div>
|
||||||
|
<strong>{displayName}</strong>
|
||||||
|
<span>{session.user.username}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl className="ecommerce-profile-popover__stats">
|
||||||
|
{avatarMenuStats.map((item) => (
|
||||||
|
<div key={item.label}>
|
||||||
|
<dt>
|
||||||
|
{item.icon}
|
||||||
|
{item.label}
|
||||||
|
</dt>
|
||||||
|
<dd>{item.value}</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<div className="ecommerce-profile-popover__actions">
|
||||||
|
<button type="button" className="is-primary" onClick={onOpenProfile}>
|
||||||
|
<UserOutlined />
|
||||||
|
个人中心
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={onBugFeedback}>
|
||||||
|
<BugOutlined />
|
||||||
|
Bug 反馈
|
||||||
|
</button>
|
||||||
|
<button type="button" className="is-danger" onClick={onLogout}>
|
||||||
|
<LogoutOutlined />
|
||||||
|
退出
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ecommerce-standalone__login-button"
|
||||||
|
style={{ pointerEvents: "auto" }}
|
||||||
|
onClick={() => onOpenAuth("login")}
|
||||||
|
>
|
||||||
|
<LoginOutlined />
|
||||||
|
<span>登录 / 注册</span>
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,289 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import {
|
||||||
|
AppstoreOutlined,
|
||||||
|
CopyOutlined,
|
||||||
|
EditOutlined,
|
||||||
|
FileTextOutlined,
|
||||||
|
FireOutlined,
|
||||||
|
GlobalOutlined,
|
||||||
|
MessageOutlined,
|
||||||
|
SmileOutlined,
|
||||||
|
ThunderboltOutlined,
|
||||||
|
} from "@ant-design/icons";
|
||||||
|
|
||||||
|
export type CopywritingType =
|
||||||
|
| "self-media"
|
||||||
|
| "universal"
|
||||||
|
| "original"
|
||||||
|
| "imitate"
|
||||||
|
| "wechat"
|
||||||
|
| "crossborder"
|
||||||
|
| "emoji"
|
||||||
|
| "more";
|
||||||
|
|
||||||
|
interface CopywritingTypeOption {
|
||||||
|
key: CopywritingType;
|
||||||
|
label: string;
|
||||||
|
icon: React.ReactNode;
|
||||||
|
description: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const copywritingTypes: CopywritingTypeOption[] = [
|
||||||
|
{ key: "self-media", label: "自媒体文案", icon: <MessageOutlined />, description: "小红书/抖音/公众号风格" },
|
||||||
|
{ key: "universal", label: "万能写作", icon: <EditOutlined />, description: "通用场景长文短句" },
|
||||||
|
{ key: "original", label: "一键原创", icon: <ThunderboltOutlined />, description: "快速改写去重" },
|
||||||
|
{ key: "imitate", label: "文案仿写", icon: <CopyOutlined />, description: "参照爆款风格重写" },
|
||||||
|
{ key: "wechat", label: "微信营销文案", icon: <FileTextOutlined />, description: "朋友圈/社群转化文案" },
|
||||||
|
{ key: "crossborder", label: "跨境商品文案", icon: <GlobalOutlined />, description: "Amazon/Temu 卖点描述" },
|
||||||
|
{ key: "emoji", label: "文案加Emoji", icon: <SmileOutlined />, description: "自动插入表情符号" },
|
||||||
|
{ key: "more", label: "更多场景", icon: <AppstoreOutlined />, description: "持续更新中" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const wordCountOptions = ["不限", "100字", "300字", "500字", "800字"];
|
||||||
|
|
||||||
|
const exampleResults: Record<CopywritingType, Array<{ title: string; body: string; points: string[] }>> = {
|
||||||
|
"self-media": [
|
||||||
|
{
|
||||||
|
title: "超值干发神器,吸水力 MAX!",
|
||||||
|
body: "家人们,我发现了一款干发帽,双层加厚吸水力超强!而且只要个位数就能到手啊!",
|
||||||
|
points: [
|
||||||
|
"超强吸水力:这款干发帽采用微纤维材质,轻轻一裹,水分立马被吸走,头发快速告别湿漉漉。",
|
||||||
|
"柔软亲肤:触感超级柔软,对皮肤和头发都是温柔的抚摸,不会有摩擦伤害哦。",
|
||||||
|
"加厚设计:比普通干发帽更厚实,吸水效果自然更胜一筹,长发妹子的福音!",
|
||||||
|
"方便携带:轻巧不占空间,不论是去健身房还是旅行,携带都毫无负担。",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
universal: [
|
||||||
|
{
|
||||||
|
title: "直接抄作业!科学的减重方法必试!",
|
||||||
|
body: "姐妹们冲鸭!有很多科学有效的方式可以帮助我们实现理想体重,今天就来分享一下必试的方法!",
|
||||||
|
points: [
|
||||||
|
"快乐有氧运动:科学的减重方式,通过有氧运动如慢跑、游泳等,能够促进脂肪燃烧,让身体更健康!",
|
||||||
|
"均衡饮食规划:摄入足够的蛋白质、蔬果以及谷物,避免过多的高糖和高脂食物,帮助达到减重目标!",
|
||||||
|
"科学计算热量:了解自己每日所需的卡路里摄入量,合理安排每餐的热量搭配,控制总摄入量。",
|
||||||
|
"坚持低强度运动:逐渐增加日常活动量,如步行、瑜伽等,通过持续的轻度运动,加速代谢!",
|
||||||
|
"合理休息调节:不要忽视睡眠的重要性,保证每晚充足的睡眠时间,帮助恢复体力和新陈代谢。",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
original: [
|
||||||
|
{
|
||||||
|
title: "原创种草|这款干发帽真的值得入!",
|
||||||
|
body: "洗完头最烦的就是湿哒哒滴水?试试这条双层加厚干发帽,吸水速度真的惊艳到我。",
|
||||||
|
points: [
|
||||||
|
"加厚材质,吸水更快更彻底",
|
||||||
|
"柔软不勒头,长发短发都能用",
|
||||||
|
"轻便好收纳,差旅党必备",
|
||||||
|
"性价比超高,入手不亏",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
imitate: [
|
||||||
|
{
|
||||||
|
title: "仿写爆款|让头发速干的小心机",
|
||||||
|
body: "姐妹们有没有发现,最近超火的干发帽真的太好用了!轻轻一裹,几分钟头发就半干了。",
|
||||||
|
points: [
|
||||||
|
"双层加厚,吸水力翻倍",
|
||||||
|
"柔软亲肤,不伤发质",
|
||||||
|
"小巧便携,出门也能带",
|
||||||
|
"颜值在线,多色可选",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
wechat: [
|
||||||
|
{
|
||||||
|
title: "朋友圈文案|个位数到手的干发神器",
|
||||||
|
body: "今天必须给大家安利这个干发帽!双层加厚,吸水超强,个位数就能到手,真的不冲吗?",
|
||||||
|
points: [
|
||||||
|
"微纤维材质,轻柔速干",
|
||||||
|
"加厚设计,吸水更彻底",
|
||||||
|
"小巧便携,旅行出差都能带",
|
||||||
|
"限时好价,手慢无",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
crossborder: [
|
||||||
|
{
|
||||||
|
title: "Amazon Listing|Super Absorbent Hair Turban",
|
||||||
|
body: "Made with ultra-soft microfiber, this double-layer hair turban dries hair quickly while protecting delicate strands.",
|
||||||
|
points: [
|
||||||
|
"Double-layer microfiber for maximum absorbency",
|
||||||
|
"Gentle on hair and skin, no frizz or breakage",
|
||||||
|
"Lightweight and travel-friendly design",
|
||||||
|
"Secure button closure stays in place",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
emoji: [
|
||||||
|
{
|
||||||
|
title: "✨个位数到手的干发神器,吸水力 MAX!",
|
||||||
|
body: "家人们👋,我发现了一款超棒的干发帽💧,双层加厚吸水力超强!而且只要个位数就能到手啊🛒!",
|
||||||
|
points: [
|
||||||
|
"💦 超强吸水力:微纤维材质,轻轻一裹水分吸走",
|
||||||
|
"☁️ 柔软亲肤:触感温柔,不伤头发和皮肤",
|
||||||
|
"🎒 方便携带:轻巧不占空间,旅行健身都能带",
|
||||||
|
"💰 超值价格:个位数到手,性价比拉满",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
more: [
|
||||||
|
{
|
||||||
|
title: "更多场景示例",
|
||||||
|
body: "选择左侧具体文案类型即可生成对应场景内容,更多场景持续更新中。",
|
||||||
|
points: ["选择合适的文案类型", "填写内容需求", "选择生成字数", "点击开始生成"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface EcommerceCopywritingPanelProps {
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EcommerceCopywritingPanel({ onClose }: EcommerceCopywritingPanelProps) {
|
||||||
|
const [selectedType, setSelectedType] = useState<CopywritingType>("self-media");
|
||||||
|
const [requirement, setRequirement] = useState("");
|
||||||
|
const [wordCount, setWordCount] = useState("不限");
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [results, setResults] = useState<typeof exampleResults["self-media"]>([]);
|
||||||
|
|
||||||
|
const handleGenerate = () => {
|
||||||
|
setLoading(true);
|
||||||
|
setResults([]);
|
||||||
|
// 模拟生成延迟
|
||||||
|
window.setTimeout(() => {
|
||||||
|
setResults(exampleResults[selectedType]);
|
||||||
|
setLoading(false);
|
||||||
|
}, 1200);
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectedTypeLabel = copywritingTypes.find((item) => item.key === selectedType)?.label ?? "文案";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="ecom-copywriting-page ecom-tool-page-enter" aria-label="一键文案">
|
||||||
|
<div className="ecom-copywriting-body">
|
||||||
|
<aside className="ecom-copywriting-panel" aria-label="文案设置">
|
||||||
|
<header className="ecom-copywriting-panel-head">
|
||||||
|
<strong className="ecom-copywriting-page-title">一键文案</strong>
|
||||||
|
<button type="button" className="ecom-copywriting-back" onClick={onClose}>
|
||||||
|
首页
|
||||||
|
</button>
|
||||||
|
<button type="button" className="ecom-copywriting-back" onClick={onClose}>
|
||||||
|
上一页
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section className="ecom-copywriting-section">
|
||||||
|
<strong className="ecom-copywriting-section-title">选择文案类型</strong>
|
||||||
|
<div className="ecom-copywriting-type-grid">
|
||||||
|
{copywritingTypes.map((item) => (
|
||||||
|
<button
|
||||||
|
key={item.key}
|
||||||
|
type="button"
|
||||||
|
className={`ecom-copywriting-type-card${selectedType === item.key ? " is-active" : ""}`}
|
||||||
|
onClick={() => setSelectedType(item.key)}
|
||||||
|
>
|
||||||
|
<span className="ecom-copywriting-type-icon" aria-hidden="true">
|
||||||
|
{item.icon}
|
||||||
|
</span>
|
||||||
|
<span className="ecom-copywriting-type-label">{item.label}</span>
|
||||||
|
<span className="ecom-copywriting-type-desc">{item.description}</span>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="ecom-copywriting-section">
|
||||||
|
<strong className="ecom-copywriting-section-title">内容需求</strong>
|
||||||
|
<textarea
|
||||||
|
className="ecom-copywriting-textarea"
|
||||||
|
value={requirement}
|
||||||
|
onChange={(event) => setRequirement(event.target.value)}
|
||||||
|
placeholder="例如:主题、核心卖点、适用人群、期望场景等"
|
||||||
|
rows={5}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="ecom-copywriting-section">
|
||||||
|
<strong className="ecom-copywriting-section-title">生成字数</strong>
|
||||||
|
<div className="ecom-copywriting-wordcount">
|
||||||
|
{wordCountOptions.map((item) => (
|
||||||
|
<button
|
||||||
|
key={item}
|
||||||
|
type="button"
|
||||||
|
className={wordCount === item ? "is-active" : ""}
|
||||||
|
onClick={() => setWordCount(item)}
|
||||||
|
>
|
||||||
|
{item}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ecom-copywriting-generate"
|
||||||
|
onClick={handleGenerate}
|
||||||
|
disabled={loading}
|
||||||
|
>
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<span className="ecom-copywriting-spinner" />
|
||||||
|
生成中…
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ThunderboltOutlined />
|
||||||
|
开始生成
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<section className="ecom-copywriting-stage" aria-label="生成文案预览">
|
||||||
|
<header className="ecom-copywriting-preview-head">
|
||||||
|
<h1>生成文案</h1>
|
||||||
|
<p>
|
||||||
|
基于 <span>{selectedTypeLabel}</span> 风格,AI 为你生成高转化文案。
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div className="ecom-copywriting-results">
|
||||||
|
{results.length === 0 && !loading ? (
|
||||||
|
<div className="ecom-copywriting-empty">
|
||||||
|
<FileTextOutlined />
|
||||||
|
<strong>等待生成</strong>
|
||||||
|
<em>填写需求后点击「开始生成」即可查看文案结果</em>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<div className="ecom-copywriting-loading">
|
||||||
|
<span className="ecom-copywriting-spinner" />
|
||||||
|
<span>AI 正在生成文案,请稍候…</span>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
{results.map((item, index) => (
|
||||||
|
<article key={index} className="ecom-copywriting-result-card">
|
||||||
|
<header>
|
||||||
|
<span>示例 {index + 1}</span>
|
||||||
|
<strong>{item.title}</strong>
|
||||||
|
</header>
|
||||||
|
<p className="ecom-copywriting-result-body">{item.body}</p>
|
||||||
|
<ul className="ecom-copywriting-result-points">
|
||||||
|
{item.points.map((point, pointIndex) => (
|
||||||
|
<li key={pointIndex}>
|
||||||
|
<span>{pointIndex + 1}</span>
|
||||||
|
{point}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</article>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
import {
|
||||||
|
FileImageOutlined,
|
||||||
|
PlusOutlined,
|
||||||
|
ThunderboltOutlined,
|
||||||
|
VideoCameraOutlined,
|
||||||
|
} from "@ant-design/icons";
|
||||||
|
import { useMemo, useRef, useState, type ChangeEvent, type DragEvent, type KeyboardEvent, type RefObject } from "react";
|
||||||
|
import EcommerceVideoWorkspace from "../EcommerceVideoWorkspace";
|
||||||
|
|
||||||
|
interface CloneImageItem {
|
||||||
|
id: string;
|
||||||
|
src: string;
|
||||||
|
name: string;
|
||||||
|
file?: File;
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloneVideoQualityKey = "standard" | "high" | "ultra";
|
||||||
|
|
||||||
|
interface EcommerceOneClickVideoPanelProps {
|
||||||
|
onClose: () => void;
|
||||||
|
isAuthenticated: boolean;
|
||||||
|
onRequestLogin: () => void;
|
||||||
|
productImages: CloneImageItem[];
|
||||||
|
productInputRef: RefObject<HTMLInputElement>;
|
||||||
|
isProductUploadDragging: boolean;
|
||||||
|
setIsProductUploadDragging: (value: boolean) => void;
|
||||||
|
handleProductDrop: (event: DragEvent<HTMLDivElement>) => void;
|
||||||
|
handleProductUpload: (event: ChangeEvent<HTMLInputElement>) => void;
|
||||||
|
removeProductImage: (imageId: string) => void;
|
||||||
|
maxProductImages: number;
|
||||||
|
requirement: string;
|
||||||
|
onRequirementChange: (value: string) => void;
|
||||||
|
platform: string;
|
||||||
|
platformOptions: string[];
|
||||||
|
onPlatformChange: (value: string) => void;
|
||||||
|
ratio: string;
|
||||||
|
ratioOptions: string[];
|
||||||
|
onRatioChange: (value: string) => void;
|
||||||
|
videoQuality: CloneVideoQualityKey;
|
||||||
|
videoQualityOptions: Array<{ key: CloneVideoQualityKey; label: string; desc: string }>;
|
||||||
|
onVideoQualityChange: (value: CloneVideoQualityKey) => void;
|
||||||
|
videoDuration: number;
|
||||||
|
videoDurationMin: number;
|
||||||
|
videoDurationMax: number;
|
||||||
|
onVideoDurationChange: (value: number) => void;
|
||||||
|
videoSmart: boolean;
|
||||||
|
onVideoSmartChange: (value: boolean) => void;
|
||||||
|
onOpenHistory: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getVideoAspectRatio(ratio: string): string {
|
||||||
|
if (ratio.includes("9:16")) return "9:16";
|
||||||
|
if (ratio.includes("16:9")) return "16:9";
|
||||||
|
if (ratio.includes("3:4")) return "3:4";
|
||||||
|
return "9:16";
|
||||||
|
}
|
||||||
|
|
||||||
|
function openQuickUploadWithKeyboard(
|
||||||
|
event: KeyboardEvent<HTMLDivElement>,
|
||||||
|
inputRef: { current: HTMLInputElement | null },
|
||||||
|
) {
|
||||||
|
if (event.key !== "Enter" && event.key !== " ") return;
|
||||||
|
event.preventDefault();
|
||||||
|
inputRef.current?.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EcommerceOneClickVideoPanel({
|
||||||
|
onClose,
|
||||||
|
isAuthenticated,
|
||||||
|
onRequestLogin,
|
||||||
|
productImages,
|
||||||
|
productInputRef,
|
||||||
|
isProductUploadDragging,
|
||||||
|
setIsProductUploadDragging,
|
||||||
|
handleProductDrop,
|
||||||
|
handleProductUpload,
|
||||||
|
removeProductImage,
|
||||||
|
maxProductImages,
|
||||||
|
requirement,
|
||||||
|
onRequirementChange,
|
||||||
|
platform,
|
||||||
|
platformOptions,
|
||||||
|
onPlatformChange,
|
||||||
|
ratio,
|
||||||
|
ratioOptions,
|
||||||
|
onRatioChange,
|
||||||
|
videoQuality,
|
||||||
|
videoQualityOptions,
|
||||||
|
onVideoQualityChange,
|
||||||
|
videoDuration,
|
||||||
|
videoDurationMin,
|
||||||
|
videoDurationMax,
|
||||||
|
onVideoDurationChange,
|
||||||
|
videoSmart,
|
||||||
|
onVideoSmartChange,
|
||||||
|
onOpenHistory,
|
||||||
|
}: EcommerceOneClickVideoPanelProps) {
|
||||||
|
const [openSelect, setOpenSelect] = useState<"platform" | "ratio" | null>(null);
|
||||||
|
const [planTrigger, setPlanTrigger] = useState(0);
|
||||||
|
const selectAnchorRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const productImageDataUrls = useMemo(() => productImages.map((img) => img.src), [productImages]);
|
||||||
|
const productImageFiles = useMemo(() => productImages.map((img) => img.file), [productImages]);
|
||||||
|
|
||||||
|
const canGenerate = productImages.length > 0 || requirement.trim().length > 0;
|
||||||
|
|
||||||
|
const handleGenerate = () => {
|
||||||
|
if (!isAuthenticated) {
|
||||||
|
onRequestLogin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setPlanTrigger((value) => value + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePlatformSelect = (value: string) => {
|
||||||
|
onPlatformChange(value);
|
||||||
|
setOpenSelect(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRatioSelect = (value: string) => {
|
||||||
|
onRatioChange(value);
|
||||||
|
setOpenSelect(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleSelect = (key: "platform" | "ratio") => {
|
||||||
|
setOpenSelect((current) => (current === key ? null : key));
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderThumbs = () => (
|
||||||
|
<div className="ecom-quick-upload-thumbs" aria-label="已上传商品原图">
|
||||||
|
{productImages.map((item) => (
|
||||||
|
<figure key={item.id} className="ecom-command-asset-thumb ecom-quick-upload-thumb">
|
||||||
|
<img src={item.src} alt={item.name} />
|
||||||
|
<span className="ecom-command-asset-zoom" aria-hidden="true">
|
||||||
|
<img src={item.src} alt="" />
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label="删除图片"
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
removeProductImage(item.id);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</figure>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="ecom-one-click-video-page ecom-quick-hot-page ecom-quick-set-page ecom-tool-page-enter" aria-label="一键视频">
|
||||||
|
<div className="ecom-quick-set-body">
|
||||||
|
<aside className="ecom-quick-set-panel" aria-label="一键视频设置">
|
||||||
|
<header className="ecom-quick-set-panel-head">
|
||||||
|
<strong className="ecom-quick-set-page-title">
|
||||||
|
<VideoCameraOutlined /> 一键视频
|
||||||
|
</strong>
|
||||||
|
<button type="button" className="ecom-quick-set-back" onClick={onClose}>
|
||||||
|
首页
|
||||||
|
</button>
|
||||||
|
<button type="button" className="ecom-quick-set-back" onClick={onClose}>
|
||||||
|
上一页
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<strong><FileImageOutlined /> 上传商品原图</strong>
|
||||||
|
{productImages.length ? (
|
||||||
|
<div
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
className={`ecom-quick-set-upload ecom-quick-hot-material has-images${isProductUploadDragging ? " is-dragging" : ""}`}
|
||||||
|
onClick={() => productInputRef.current?.click()}
|
||||||
|
onKeyDown={(event) => openQuickUploadWithKeyboard(event, productInputRef)}
|
||||||
|
onDragOver={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
if (event.dataTransfer.types.includes("Files")) setIsProductUploadDragging(true);
|
||||||
|
}}
|
||||||
|
onDragLeave={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
if (event.currentTarget === event.target || !event.currentTarget.contains(event.relatedTarget as Node)) {
|
||||||
|
setIsProductUploadDragging(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onDrop={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
setIsProductUploadDragging(false);
|
||||||
|
handleProductDrop(event);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{renderThumbs()}
|
||||||
|
{productImages.length < maxProductImages ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ecom-quick-hot-add-btn"
|
||||||
|
aria-label="添加更多素材"
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
productInputRef.current?.click();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PlusOutlined />
|
||||||
|
</button>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
className={`ecom-quick-set-upload ecom-quick-hot-material${isProductUploadDragging ? " is-dragging" : ""}`}
|
||||||
|
onClick={() => productInputRef.current?.click()}
|
||||||
|
onKeyDown={(event) => openQuickUploadWithKeyboard(event, productInputRef)}
|
||||||
|
onDragOver={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
if (event.dataTransfer.types.includes("Files")) setIsProductUploadDragging(true);
|
||||||
|
}}
|
||||||
|
onDragLeave={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
if (event.currentTarget === event.target || !event.currentTarget.contains(event.relatedTarget as Node)) {
|
||||||
|
setIsProductUploadDragging(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
onDrop={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
setIsProductUploadDragging(false);
|
||||||
|
handleProductDrop(event);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FileImageOutlined />
|
||||||
|
<span>拖拽或点击上传</span>
|
||||||
|
<em>上传商品素材图,最多 {maxProductImages} 张</em>
|
||||||
|
<b>+ 上传图片</b>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<input
|
||||||
|
ref={productInputRef}
|
||||||
|
type="file"
|
||||||
|
accept="image/*"
|
||||||
|
multiple
|
||||||
|
className="ecom-command-hidden-file"
|
||||||
|
onChange={handleProductUpload}
|
||||||
|
aria-label="上传商品图片"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="ecom-quick-hot-requirement">
|
||||||
|
<div className="ecom-quick-hot-requirement__head">
|
||||||
|
<strong>视频需求</strong>
|
||||||
|
</div>
|
||||||
|
<div className="ecom-quick-hot-requirement__input">
|
||||||
|
<textarea
|
||||||
|
value={requirement}
|
||||||
|
onChange={(event) => onRequirementChange(event.target.value.slice(0, 500))}
|
||||||
|
placeholder="建议包含以下信息:产品名称、核心卖点、期望场景、口播风格、具体参数"
|
||||||
|
maxLength={500}
|
||||||
|
rows={4}
|
||||||
|
/>
|
||||||
|
<span>{requirement.length}/500</span>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="ecom-quick-set-basic-section">
|
||||||
|
<span className="ecom-quick-set-label">基础设置</span>
|
||||||
|
<div className="ecom-quick-set-select-anchor" ref={selectAnchorRef}>
|
||||||
|
<div className="ecom-quick-set-selects">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={openSelect === "platform" ? "is-active" : ""}
|
||||||
|
onClick={() => toggleSelect("platform")}
|
||||||
|
>
|
||||||
|
<span>平台</span>
|
||||||
|
<strong>{platform}</strong>
|
||||||
|
<em>⌄</em>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={openSelect === "ratio" ? "is-active" : ""}
|
||||||
|
onClick={() => toggleSelect("ratio")}
|
||||||
|
>
|
||||||
|
<span>尺寸比例</span>
|
||||||
|
<strong>{ratio.replace(/\s+/g, " ").trim()}</strong>
|
||||||
|
<em>⌄</em>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{openSelect ? (
|
||||||
|
<div
|
||||||
|
className="ecom-quick-set-dropdown"
|
||||||
|
role="listbox"
|
||||||
|
aria-label={openSelect === "platform" ? "平台" : "尺寸比例"}
|
||||||
|
>
|
||||||
|
{(openSelect === "platform" ? platformOptions : ratioOptions).map((option) => (
|
||||||
|
<button
|
||||||
|
key={option}
|
||||||
|
type="button"
|
||||||
|
className={
|
||||||
|
(openSelect === "platform" ? platform === option : ratio === option) ? "is-active" : ""
|
||||||
|
}
|
||||||
|
role="option"
|
||||||
|
aria-selected={openSelect === "platform" ? platform === option : ratio === option}
|
||||||
|
onClick={() => {
|
||||||
|
if (openSelect === "platform") {
|
||||||
|
handlePlatformSelect(option);
|
||||||
|
} else {
|
||||||
|
handleRatioSelect(option);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{option.replace(/\s+/g, " ").trim()}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<strong>视频画质</strong>
|
||||||
|
<div className="ecom-quick-detail-modules">
|
||||||
|
{videoQualityOptions.map((option) => (
|
||||||
|
<button
|
||||||
|
key={option.key}
|
||||||
|
type="button"
|
||||||
|
className={videoQuality === option.key ? "is-active" : ""}
|
||||||
|
aria-pressed={videoQuality === option.key}
|
||||||
|
onClick={() => onVideoQualityChange(option.key)}
|
||||||
|
>
|
||||||
|
<strong>{option.label}</strong>
|
||||||
|
<span>{option.desc}</span>
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<strong>视频时长</strong>
|
||||||
|
<div className="ecom-one-click-video-duration">
|
||||||
|
<span>{videoDuration} 秒</span>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
className="ecom-one-click-video-range"
|
||||||
|
min={videoDurationMin}
|
||||||
|
max={videoDurationMax}
|
||||||
|
step={5}
|
||||||
|
value={videoDuration}
|
||||||
|
onChange={(event) => onVideoDurationChange(Number(event.target.value))}
|
||||||
|
aria-label="视频时长"
|
||||||
|
/>
|
||||||
|
<div className="ecom-one-click-video-duration-scale" aria-hidden="true">
|
||||||
|
<span>{videoDurationMin}秒</span>
|
||||||
|
<span>{videoDurationMax}秒</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`ecom-one-click-video-smart${videoSmart ? " is-on" : ""}`}
|
||||||
|
aria-pressed={videoSmart}
|
||||||
|
onClick={() => onVideoSmartChange(!videoSmart)}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<strong>智能优化</strong>
|
||||||
|
<em>根据平台、商品图和尺寸自动匹配推荐参数</em>
|
||||||
|
</span>
|
||||||
|
<i aria-hidden="true" />
|
||||||
|
</button>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div className="ecom-quick-hot-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="ecom-quick-set-primary ecom-one-click-video-generate"
|
||||||
|
onClick={handleGenerate}
|
||||||
|
disabled={!canGenerate}
|
||||||
|
>
|
||||||
|
<ThunderboltOutlined /> {isAuthenticated ? "一键生成视频" : "登录后生成"}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<section className="ecom-quick-set-stage">
|
||||||
|
<EcommerceVideoWorkspace
|
||||||
|
isAuthenticated={isAuthenticated}
|
||||||
|
productImageDataUrls={productImageDataUrls}
|
||||||
|
productImageFiles={productImageFiles}
|
||||||
|
requirement={requirement}
|
||||||
|
platform={platform}
|
||||||
|
aspectRatio={getVideoAspectRatio(ratio)}
|
||||||
|
durationSeconds={videoDuration}
|
||||||
|
resolution={videoQuality === "standard" ? "720P" : "1080P"}
|
||||||
|
onRequestLogin={onRequestLogin}
|
||||||
|
onOpenHistory={onOpenHistory}
|
||||||
|
triggerPlan={planTrigger}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
+1760
-44
File diff suppressed because it is too large
Load Diff
@@ -371,3 +371,14 @@
|
|||||||
border-color: rgba(var(--accent-rgb), 0.42);
|
border-color: rgba(var(--accent-rgb), 0.42);
|
||||||
background: var(--bg-panel);
|
background: var(--bg-panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ── Product set count stepper: align with local light theme ── */
|
||||||
|
html body #root .ecommerce-standalone .product-clone-page[data-tool="clone"] .clone-ai-count-stepper {
|
||||||
|
border-color: var(--border-subtle) !important;
|
||||||
|
background: var(--bg-inset) !important;
|
||||||
|
color: var(--fg-body) !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
html body #root .ecommerce-standalone .product-clone-page[data-tool="clone"] .clone-ai-count-stepper b {
|
||||||
|
color: var(--fg-body) !important;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user