// WeyAi 桌面端下载页(方案 4.8)。两种挂载方式,同一个组件:
// - /weyai/download 独立公开路由,不需要登录,自带顶部让位与页面背景;
// - /user-center/weyai-download 嵌在用户中心里(embedded),侧栏保留、背景由 shell 提供。
// 首屏展示版本、入口和推荐安装包,后续按系统列出安装包和使用说明。
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
import {
Download as ActionDownload,
RefreshCw as ActionRefreshCw,
Globe as ActionGlobe,
ExternalLink as ActionExternalLink,
} from '@/components/common/icons/ActionIcons';
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Skeleton, Tag } from 'antd';
import {
AlertTriangle,
Cpu,
Laptop,
LogIn,
Monitor,
MonitorDown,
Package,
RefreshCw,
Smartphone,
Terminal,
Wallet,
} from 'lucide-react';
import { API } from '../../helpers/api';
import { StatusContext } from '../../context/Status';
import { UserContext } from '../../context/User';
import UserCenterPageHeader from '../../components/common/UserCenterPageHeader';
import { useWeyAiWebEntry } from '../../hooks/common/useWeyAiWebEntry';
import {
PLATFORMS,
detectClient,
formatSize,
groupByPlatform,
normalizeRelease,
pickRecommended,
} from './release';
import './weyai-download.css';
// 不带动作只唤起应用(navigate 动作要求目标路由在桌面端白名单里)
const OPEN_APP_URL = 'weyai://';
const ALL_PACKAGES_ID = 'weyai-download-all';
const PACKAGES_HEADING_ID = 'weyai-download-all-title';
// 更新源清单里的 releaseDate 是 ISO 时间串(2026-09-20T08:00:00.000Z),
// 展示只需要日期。固定用 ISO 日期(UTC):按语种本地化会让泰语走佛历、
// 让 UTC-9 以西的访客看到前一天;解析不了的原样返回,绝不因此把 hero 弄空
function formatReleaseDate(value) {
if (!value) return '';
const date = new Date(value);
if (Number.isNaN(date.getTime())) return value;
return date.toISOString().slice(0, 10);
}
const PLATFORM_LABEL = { windows: 'Windows', mac: 'macOS', linux: 'Linux' };
const PLATFORM_ICON = { windows: Monitor, mac: Laptop, linux: Terminal };
function PlatformIcon({ platform, size = 18 }) {
const Icon = PLATFORM_ICON[platform] || MonitorDown;
return ;
}
function FileMeta({ name, size, version, releaseVersion }) {
const details = [
size ? formatSize(size) : '',
version && version !== releaseVersion ? `v${version}` : '',
].filter(Boolean);
return (
{name}
{details.length > 0 && {details.join(' · ')}}
);
}
// 状态卡:加载失败 / 未开放 / 暂无安装包共用一个壳
function StateCard({ icon, title, desc, danger, actions }) {
return (
{icon}
{title}
{desc && {desc}
}
{actions && {actions}
}
);
}
const WeyAiDownload = ({ embedded = false }) => {
const { t } = useTranslation();
const [statusState] = useContext(StatusContext);
const [userState] = useContext(UserContext);
const isLoggedIn = !!userState?.user?.id;
const status = statusState?.status;
const statusLoaded = status !== undefined;
const downloadEnabled =
status?.weyai_download_enabled === true ||
status?.weyai_download_enabled === 'true';
// 网页版入口:与顶栏同一套判定(开关 + 地址 + 开放范围),有权限才给链接
const { visible: webVisible, url: webUrl } = useWeyAiWebEntry();
const [loading, setLoading] = useState(true);
const [loadError, setLoadError] = useState('');
const [release, setRelease] = useState(null);
const [client, setClient] = useState({ os: '', arch: '' });
const packagesRef = useRef(null);
const packagesHeadingRef = useRef(null);
const archLabel = (arch) => {
if (arch === 'arm64') return t('ARM 64 位');
if (arch === 'armv7l') return t('ARM 32 位');
if (arch === 'x64') return t('x86 64 位');
if (arch === 'universal') return t('通用(Universal)');
if (arch === 'ia32') return t('x86 32 位');
// 兜底给出原始架构名,好过让整行标题退化成文件名、与下一行重复
return arch || '';
};
const load = async () => {
setLoading(true);
setLoadError('');
try {
const res = await API.get('/api/weyai/desktop/release', {
skipErrorHandler: true,
disableDuplicate: true,
});
const body = res?.data;
if (body?.success === false) {
setLoadError(body.message || t('获取版本信息失败,请稍后重试'));
return;
}
const data = body && 'data' in body ? body.data : body;
setRelease(normalizeRelease(data));
} catch (error) {
// 本地化串优先:服务端故障时后端恒返回中文「服务器内部错误」,直显会让
// 九个语种的访客都看到中文,而且这句话对访客零信息量。后端文案只留给
// 带具体说明的业务错误(4xx),5xx 一律用本页自己的提示
const httpStatus = error?.response?.status;
const backendMessage = error?.response?.data?.message;
setLoadError(
httpStatus && httpStatus < 500 && backendMessage
? backendMessage
: t('获取版本信息失败,请稍后重试'),
);
} finally {
setLoading(false);
}
};
useEffect(() => {
let cancelled = false;
detectClient().then((result) => {
if (!cancelled) setClient(result);
});
return () => {
cancelled = true;
};
}, []);
useEffect(() => {
if (statusLoaded && downloadEnabled) {
load();
} else if (statusLoaded) {
setLoading(false);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [statusLoaded, downloadEnabled]);
const files = release?.files || [];
const releaseDisabled = release?.enabled === false;
const recommended = pickRecommended(files, client);
const groups = groupByPlatform(files);
const platformsWithFiles = PLATFORMS.filter(
(platform) => groups[platform].length > 0,
);
// 手机端(目前只有 Android):发布过才有,没有就整块不显示
const mobileRelease = release?.mobile || null;
const androidApk = mobileRelease?.android || null;
const showPackages =
statusLoaded &&
loading === false &&
downloadEnabled &&
!releaseDisabled &&
!loadError &&
files.length > 0;
const features = useMemo(
() => [
{
icon: LogIn,
title: t('账号直登'),
desc: t('用本站账号在浏览器里登录一次,客户端自动接入,无需手填密钥'),
},
{
icon: Wallet,
title: t('余额通用'),
desc: t('个人钱包或企业额度直接消费,与网页端同一套账'),
},
{
icon: Cpu,
title: t('模型同步'),
desc: t(
'使用与网页端相同的分组与模型,由平台统一下发,无需在客户端配置',
),
},
{
icon: RefreshCw,
title: t('版本统一发布'),
desc: t('安装包与更新源同一来源,版本低于平台要求时客户端会提示升级'),
},
],
[t],
);
const steps = useMemo(
() => [
{
title: t('下载并安装'),
desc: t('选择与你系统匹配的安装包,安装过程与普通桌面软件一致'),
},
{
title: t('打开 WeyAi,点击登录'),
desc: t('客户端会拉起浏览器,用本站账号完成登录'),
},
{
title: t('选择使用范围'),
desc: t('个人或所在企业,授权后自动返回客户端即可开始对话'),
},
],
[t],
);
const scrollToAll = () => {
packagesHeadingRef.current?.focus({ preventScroll: true });
packagesRef.current?.scrollIntoView({
behavior: window.matchMedia('(prefers-reduced-motion: reduce)').matches
? 'auto'
: 'smooth',
block: 'start',
});
};
const download = (url) => window.open(url, '_self');
const renderFileRow = (file) => {
const isReco = recommended && recommended.url === file.url;
return (
{archLabel(file.arch) || file.name}
{file.kind && {file.kind}}
{isReco && {t('推荐')}}
}
type={isReco ? 'primary' : 'default'}
aria-label={`${t('下载')} ${file.name}`}
onClick={() => download(file.url)}
>
{t('下载')}
);
};
const renderRecommended = () => {
if (recommended) {
return (
{t('为你的 {{os}} 推荐', {
os: PLATFORM_LABEL[recommended.platform],
})}
{PLATFORM_LABEL[recommended.platform]}
{archLabel(recommended.arch)
? ` · ${archLabel(recommended.arch)}`
: ''}
{recommended.name}
{recommended.size > 0 && (
{formatSize(recommended.size)}
)}
{release?.version && v{release.version}}
{/* 只在"猜了 Apple 芯片包但其实不知道芯片"时提示;推荐的已是
universal 或 x64 包时提示反而误导 */}
{client.os === 'mac' &&
!client.arch &&
recommended.arch === 'arm64' && (
{t(
'未能识别芯片类型:Apple 芯片请用此包,Intel 芯片请在下方选择 x86 64 位版本',
)}
)}
}
onClick={() => download(recommended.url)}
>
{t('下载 WeyAi')}
);
}
if (client.os === 'mobile' && client.mobile === 'android' && androidApk) {
return (
{t('为你的 Android 手机推荐')}
{t('WeyAi 手机端')}
{androidApk.name}
{androidApk.size > 0 && (
{formatSize(androidApk.size)}
)}
{mobileRelease.version && (
v{mobileRelease.version}
)}
{t(
'安装时如果提示「未知来源」,请在手机设置里允许当前浏览器安装应用',
)}
}
onClick={() => download(androidApk.url)}
>
{t('下载 Android 版')}
);
}
return (
{client.os === 'mobile'
? t('请在电脑上下载')
: t('选择你的安装包')}
{client.os === 'mobile'
? t(
'WeyAi 桌面端支持 Windows、macOS 和 Linux,请在电脑上打开此页面下载',
)
: t('未能识别你的系统,请在下方选择对应的安装包')}
{client.os === 'mobile' &&
client.mobile === 'ios' &&
androidApk && (
{t('iOS 版暂未推出,手机端目前只有 Android 版')}
)}
{client.os !== 'mobile' && (
)}
);
};
const renderPackageState = () => {
if (!statusLoaded || loading) {
return (
);
}
if (!downloadEnabled || releaseDisabled) {
return (
}
title={t('桌面端下载暂未开放')}
desc={t('请稍后再来,或联系管理员')}
/>
);
}
if (loadError) {
return (
}
title={t('获取版本信息失败')}
desc={loadError}
actions={
}
onClick={load}
>
{t('重试')}
}
/>
);
}
return (
}
title={t('暂无可下载的安装包')}
desc={t('请稍后再来,或联系管理员')}
/>
);
};
const renderPackages = () => (
{t('全部安装包')}
{t('共 {{count}} 个文件', {
count: files.length + (androidApk ? 1 : 0),
})}
{release?.version ? ` · v${release.version}` : ''}
{platformsWithFiles.map((platform) => (
{PLATFORM_LABEL[platform]}
{t('{{count}} 个安装包', {
count: groups[platform].length,
})}
{groups[platform].map(renderFileRow)}
))}
{androidApk && (
{t('手机端 · Android')}
{t('{{count}} 个安装包', { count: 1 })}
{I18N_TECHNICAL_TEXT.ANDROID}
apk
}
aria-label={`${t('下载')} ${androidApk.name}`}
onClick={() => download(androidApk.url)}
>
{t('下载')}
{t(
'在手机上扫码连接电脑上的 WeyAi,或用本站账号登录网页版,随时继续对话',
)}
)}
);
const rootClass = `weyai-download ${
embedded ? 'weyai-download--embedded' : 'weyai-download--standalone'
}`;
const heroActions = (
{isLoggedIn && webVisible && webUrl && (
}
onClick={() => window.open(webUrl, '_blank', 'noopener')}
>
{t('使用网页版')}
)}
}
onClick={() => {
window.location.href = OPEN_APP_URL;
}}
>
{t('已安装?打开 WeyAi')}
);
return (
{!embedded && (
{I18N_TECHNICAL_TEXT.WEYAI_DESKTOP}
)}
{release?.version && (
{t('最新版本 v{{version}}', { version: release.version })}
)}
{release?.releaseDate && (
{t('发布于 {{date}}', {
date: formatReleaseDate(release.releaseDate),
})}
)}
{/* 有清单时按实际有安装包的平台展示,别在缺某平台 feed 时还声称支持 */}
{[
...(platformsWithFiles.length
? platformsWithFiles
: PLATFORMS
).map((platform) => PLATFORM_LABEL[platform]),
...(androidApk ? ['Android'] : []),
].join(' · ')}
{showPackages ? renderRecommended() : renderPackageState()}
{showPackages && renderPackages()}
{t('客户端能做什么')}
{features.map(({ icon: Icon, title, desc }, index) => (
))}
{t('三步开始使用')}
{t('登录在浏览器完成,客户端不保存你的密码')}
{steps.map((step, index) => (
{index + 1}
{step.title}
{step.desc}
))}
{t('遇到安装或登录问题,请联系管理员')}
);
};
export default WeyAiDownload;