Initial import of weiyuan frontend

This commit is contained in:
qiubaishen
2026-10-15 16:33:46 +08:00
commit d8f3aee261
774 changed files with 374914 additions and 0 deletions
+679
View File
@@ -0,0 +1,679 @@
/*
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
*/
// WeyAi 桌面端下载页(方案 4.8)。两种挂载方式,同一个组件:
// - /weyai/download 独立公开路由,不需要登录,自带顶部让位与页面背景;
// - /user-center/weyai-download 嵌在用户中心里(embedded),侧栏保留、背景由 shell 提供。
// 结构:hero(版本/动作)→ 为你推荐 → 客户端能做什么 → 全部安装包 → 三步开始。
// 加载失败 / 未开放 / 暂无安装包三种状态都保留 hero 与说明区,只替换安装包区域。
import React, { useContext, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button, Skeleton, Tag } from '@douyinfe/semi-ui';
import {
AlertTriangle,
Cpu,
Download,
ExternalLink,
Globe,
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 PageBackground from '../../components/common/PageBackground';
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';
// 更新源清单里的 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 <Icon size={size} aria-hidden='true' />;
}
// 状态卡:加载失败 / 未开放 / 暂无安装包共用一个壳
function StateCard({ icon, title, desc, danger, actions }) {
return (
<section
className={`wd-card wd-state${danger ? ' wd-state--danger' : ''}`}
role={danger ? 'alert' : undefined}
>
<div className='wd-state__icon'>{icon}</div>
<div className='wd-state__title'>{title}</div>
{desc && <div className='wd-state__desc'>{desc}</div>}
{actions && <div className='wd-state__actions'>{actions}</div>}
</section>
);
}
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 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 androidMeta = androidApk
? [
androidApk.name,
androidApk.size ? formatSize(androidApk.size) : '',
// 和桌面端同版本时不重复写版本号(同桌面端安装包行的规则),免得这一行被截断
mobileRelease.version && mobileRelease.version !== release?.version
? `v${mobileRelease.version}`
: '',
]
.filter(Boolean)
.join(' · ')
: '';
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 = () => {
document
.getElementById(ALL_PACKAGES_ID)
?.scrollIntoView({ behavior: 'smooth', block: 'start' });
};
const download = (url) => window.open(url, '_self');
const fileMeta = (file) =>
[
file.name,
file.size ? formatSize(file.size) : '',
file.version && file.version !== release?.version
? `v${file.version}`
: '',
]
.filter(Boolean)
.join(' · ');
const renderFileRow = (file) => {
const isReco = recommended && recommended.url === file.url;
return (
<div
key={file.url}
className={`wd-file${isReco ? ' wd-file--reco' : ''}`}
>
<div className='wd-file__main'>
<div className='wd-file__title'>
<span>{archLabel(file.arch) || file.name}</span>
{file.kind && <Tag size='small'>{file.kind}</Tag>}
{isReco && (
<Tag size='small' color='blue'>
{t('推荐')}
</Tag>
)}
</div>
<span className='wd-file__meta' title={file.name}>
{fileMeta(file)}
</span>
</div>
<Button
icon={<Download size={14} />}
theme={isReco ? 'solid' : 'light'}
type='primary'
aria-label={`${t('下载')} ${file.name}`}
onClick={() => download(file.url)}
>
{t('下载')}
</Button>
</div>
);
};
const renderRecommended = () => {
if (recommended) {
return (
<section className='wd-card wd-reco'>
<div className='wd-reco__row'>
<div className='wd-reco__main'>
<div className='wd-os-badge'>
<PlatformIcon platform={recommended.platform} size={26} />
</div>
<div className='min-w-0'>
<div className='wd-eyebrow'>
{t('为你的 {{os}} 推荐', {
os: PLATFORM_LABEL[recommended.platform],
})}
</div>
<h2 className='wd-reco__title'>
{PLATFORM_LABEL[recommended.platform]}
{archLabel(recommended.arch)
? ` · ${archLabel(recommended.arch)}`
: ''}
</h2>
<div className='wd-reco__meta'>
<code>{recommended.name}</code>
{recommended.size && (
<span>{formatSize(recommended.size)}</span>
)}
{release?.version && <span>v{release.version}</span>}
</div>
{/* 只在"猜了 Apple 芯片包但其实不知道芯片"时提示;推荐的已是
universal 或 x64 包时提示反而误导 */}
{client.os === 'mac' &&
!client.arch &&
recommended.arch === 'arm64' && (
<div className='wd-reco__hint'>
{t(
'未能识别芯片类型:Apple 芯片请用此包,Intel 芯片请在下方选择 x86 64 位版本',
)}
</div>
)}
</div>
</div>
<div className='wd-reco__actions'>
<Button
size='large'
theme='solid'
type='primary'
icon={<Download size={16} />}
onClick={() => download(recommended.url)}
>
{t('下载 WeyAi')}
</Button>
<Button theme='borderless' type='tertiary' onClick={scrollToAll}>
{t('其他平台与架构')}
</Button>
</div>
</div>
</section>
);
}
if (client.os === 'mobile' && client.mobile === 'android' && androidApk) {
return (
<section className='wd-card wd-reco'>
<div className='wd-reco__row'>
<div className='wd-reco__main'>
<div className='wd-os-badge'>
<Smartphone size={26} aria-hidden='true' />
</div>
<div className='min-w-0'>
<div className='wd-eyebrow'>{t('为你的 Android 手机推荐')}</div>
<h2 className='wd-reco__title'>{t('WeyAi 手机端')}</h2>
<div className='wd-reco__meta'>
<code>{androidApk.name}</code>
{androidApk.size > 0 && (
<span>{formatSize(androidApk.size)}</span>
)}
{mobileRelease.version && (
<span>v{mobileRelease.version}</span>
)}
</div>
<div className='wd-reco__hint'>
{t(
'安装时如果提示「未知来源」,请在手机设置里允许当前浏览器安装应用',
)}
</div>
</div>
</div>
<div className='wd-reco__actions'>
<Button
size='large'
theme='solid'
type='primary'
icon={<Download size={16} />}
onClick={() => download(androidApk.url)}
>
{t('下载 Android 版')}
</Button>
</div>
</div>
</section>
);
}
return (
<section className='wd-card wd-reco'>
<div className='wd-reco__row'>
<div className='wd-reco__main'>
<div className='wd-os-badge'>
<MonitorDown size={26} aria-hidden='true' />
</div>
<div className='min-w-0'>
<h2 className='wd-reco__title'>
{client.os === 'mobile'
? t('请在电脑上下载')
: t('选择你的安装包')}
</h2>
<div className='wd-reco__hint'>
{client.os === 'mobile'
? t(
'WeyAi 桌面端支持 Windows、macOS 和 Linux,请在电脑上打开此页面下载',
)
: t('未能识别你的系统,请在下方选择对应的安装包')}
</div>
{client.os === 'mobile' &&
client.mobile === 'ios' &&
androidApk && (
<div className='wd-reco__hint'>
{t('iOS 版暂未推出,手机端目前只有 Android 版')}
</div>
)}
</div>
</div>
{client.os !== 'mobile' && (
<div className='wd-reco__actions'>
<Button theme='solid' type='primary' onClick={scrollToAll}>
{t('查看全部安装包')}
</Button>
</div>
)}
</div>
</section>
);
};
const renderPackages = () => {
if (!statusLoaded || loading) {
return (
<section className='wd-card wd-skeleton' aria-busy='true'>
<Skeleton
loading
active
placeholder={
<>
<Skeleton.Title style={{ width: 240 }} />
<Skeleton.Paragraph rows={2} style={{ marginTop: 12 }} />
<Skeleton.Button style={{ width: 160, marginTop: 12 }} />
</>
}
/>
</section>
);
}
if (!downloadEnabled || releaseDisabled) {
return (
<StateCard
icon={<MonitorDown size={26} aria-hidden='true' />}
title={t('桌面端下载暂未开放')}
desc={t('请稍后再来,或联系管理员')}
/>
);
}
if (loadError) {
return (
<StateCard
danger
icon={<AlertTriangle size={26} aria-hidden='true' />}
title={t('获取版本信息失败')}
desc={loadError}
actions={
<Button
theme='solid'
type='primary'
icon={<RefreshCw size={14} />}
onClick={load}
>
{t('重试')}
</Button>
}
/>
);
}
if (files.length === 0) {
return (
<StateCard
icon={<Package size={26} aria-hidden='true' />}
title={t('暂无可下载的安装包')}
desc={t('请稍后再来,或联系管理员')}
/>
);
}
return (
<>
{renderRecommended()}
<section id={ALL_PACKAGES_ID} className='flex flex-col gap-3'>
<div className='wd-section-head'>
<h2>{t('全部安装包')}</h2>
<p>
{t('共 {{count}} 个文件', {
count: files.length + (androidApk ? 1 : 0),
})}
{release?.version ? ` · v${release.version}` : ''}
</p>
</div>
<div className='wd-platforms'>
{platformsWithFiles.map((platform) => (
<section key={platform} className='wd-card wd-platform'>
<div className='wd-platform__head'>
<span className='wd-platform__name'>
<PlatformIcon platform={platform} />
{PLATFORM_LABEL[platform]}
</span>
<span className='wd-platform__count'>
{t('{{count}} 个安装包', {
count: groups[platform].length,
})}
</span>
</div>
{groups[platform].map(renderFileRow)}
</section>
))}
{androidApk && (
<section className='wd-card wd-platform'>
<div className='wd-platform__head'>
<span className='wd-platform__name'>
<Smartphone size={18} aria-hidden='true' />
{t('手机端 · Android')}
</span>
<span className='wd-platform__count'>
{t('{{count}} 个安装包', { count: 1 })}
</span>
</div>
<div className='wd-file'>
<div className='wd-file__main'>
<div className='wd-file__title'>
<span>Android</span>
<Tag size='small'>apk</Tag>
</div>
<span className='wd-file__meta' title={androidApk.name}>
{androidMeta}
</span>
</div>
<Button
icon={<Download size={14} />}
theme='light'
type='primary'
aria-label={`${t('下载')} ${androidApk.name}`}
onClick={() => download(androidApk.url)}
>
{t('下载')}
</Button>
</div>
<div className='wd-platform__note'>
{t(
'在手机上扫码连接电脑上的 WeyAi,或用本站账号登录网页版,随时继续对话',
)}
</div>
</section>
)}
</div>
</section>
</>
);
};
const rootClass = `weyai-download ${
embedded
? 'weyai-download--embedded'
: 'weyai-download--standalone mt-[60px]'
}`;
return (
<div className={rootClass}>
{!embedded && <PageBackground grid />}
<div className='weyai-download__inner'>
<header className='wd-hero'>
<div className='min-w-0'>
<div className='wd-eyebrow'>
<MonitorDown size={14} aria-hidden='true' />
WeyAi Desktop
</div>
<h1>{t('下载 WeyAi 桌面端')}</h1>
<p>{t('用你的账号登录,直接使用平台提供的模型和余额')}</p>
<div className='wd-hero-meta'>
{release?.version && (
<span className='wd-chip'>
{t('最新版本 v{{version}}', { version: release.version })}
</span>
)}
{release?.releaseDate && (
<span className='wd-chip wd-chip--muted'>
{t('发布于 {{date}}', {
date: formatReleaseDate(release.releaseDate),
})}
</span>
)}
{/* 有清单时按实际有安装包的平台展示,别在缺某平台 feed 时还声称支持 */}
<span className='wd-chip wd-chip--muted'>
{[
...(platformsWithFiles.length
? platformsWithFiles
: PLATFORMS
).map((platform) => PLATFORM_LABEL[platform]),
...(androidApk ? ['Android'] : []),
].join(' · ')}
</span>
</div>
</div>
<div className='wd-hero-actions'>
{/* 未登录访客不给网页版按钮:hook 对匿名恒可见,点了会直接打到网关的
/sso/start 再被弹回登录,不如顶栏那样先引导登录 */}
{isLoggedIn && webVisible && webUrl && (
<Button
icon={<Globe size={14} />}
theme='light'
type='primary'
onClick={() => window.open(webUrl, '_blank', 'noopener')}
>
{t('使用网页版')}
</Button>
)}
<Button
icon={<ExternalLink size={14} />}
onClick={() => {
window.location.href = OPEN_APP_URL;
}}
>
{t('已安装?打开 WeyAi')}
</Button>
</div>
</header>
{renderPackages()}
<section className='flex flex-col gap-3'>
<div className='wd-section-head'>
<h2>{t('客户端能做什么')}</h2>
</div>
<div className='wd-features'>
{features.map(({ icon: Icon, title, desc }, index) => (
<div key={index} className='wd-card wd-feature'>
<div className='wd-feature__icon'>
<Icon size={18} aria-hidden='true' />
</div>
<div className='min-w-0'>
<span className='wd-feature__title'>{title}</span>
<span className='wd-feature__desc'>{desc}</span>
</div>
</div>
))}
</div>
</section>
<section className='flex flex-col gap-3'>
<div className='wd-section-head'>
<h2>{t('三步开始使用')}</h2>
<p>{t('登录在浏览器完成,客户端不保存你的密码')}</p>
</div>
<div className='wd-steps'>
{steps.map((step, index) => (
<div key={index} className='wd-card wd-step'>
<span className='wd-step__num'>{index + 1}</span>
<span className='wd-step__title'>{step.title}</span>
<span className='wd-step__desc'>{step.desc}</span>
</div>
))}
</div>
</section>
<p className='wd-footnote'>{t('遇到安装或登录问题,请联系管理员')}</p>
</div>
</div>
);
};
export default WeyAiDownload;
+330
View File
@@ -0,0 +1,330 @@
/*
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
*/
// WeyAi 桌面端下载页的纯函数:整理 GET /api/weyai/desktop/release 的返回、识别访问者系统。
// 安装包命名沿用 electron-builder 的 artifactName:WeyAi-<version>-<os>-<arch>.<ext>
// (os 为 win / mac / linux;deb 的 arch 为 amd64 / arm64)。
// 发布布局:<base_url>/latest*.yml + <base_url>/<version>/<安装包>;后端已按清单来源
// 给出 arch 和绝对地址,这里只做兜底解析和协议过滤。
import { toSafeHttpUrl } from '../../helpers/safeUrl.js';
export const PLATFORMS = ['windows', 'mac', 'linux'];
const PLATFORM_ALIASES = {
windows: 'windows',
win: 'windows',
win32: 'windows',
mac: 'mac',
macos: 'mac',
darwin: 'mac',
osx: 'mac',
linux: 'linux',
};
// 每个平台内安装包的推荐顺序(越靠前越推荐)
const KIND_RANK = {
windows: ['exe', 'msi', 'zip'],
mac: ['dmg', 'pkg', 'zip'],
linux: ['deb', 'AppImage', 'rpm', 'tar.gz'],
};
export function normalizePlatform(value) {
if (!value) return '';
return PLATFORM_ALIASES[`${value}`.toLowerCase()] || '';
}
export function normalizeArch(value) {
const v = `${value || ''}`.toLowerCase();
if (['x64', 'amd64', 'x86_64', 'x86-64'].includes(v)) return 'x64';
// armv7l 要排在 arm 之前:后端 guessArch 会原样给出 armv7l,落到 arm64 分支
// 或返回空都不对——返回空会让它在推荐排序里被当成"架构未知"而优于"架构不符"
if (['armv7l', 'armv7', 'armhf'].includes(v)) return 'armv7l';
if (['arm64', 'aarch64', 'arm'].includes(v)) return 'arm64';
if (v === 'universal') return 'universal';
if (['ia32', 'x86', 'i386'].includes(v)) return 'ia32';
return '';
}
function fileNameOf(url) {
const clean = `${url || ''}`.split(/[?#]/)[0];
const parts = clean.split('/');
try {
return decodeURIComponent(parts[parts.length - 1] || '');
} catch (_e) {
return parts[parts.length - 1] || '';
}
}
export function inferKind(name) {
const lower = `${name || ''}`.toLowerCase();
if (lower.endsWith('.tar.gz')) return 'tar.gz';
if (lower.endsWith('.appimage')) return 'AppImage';
const match = lower.match(/\.([a-z0-9]+)$/);
return match ? match[1] : '';
}
export function inferPlatform(name) {
const lower = `${name || ''}`.toLowerCase();
if (/[-_.](win|windows|win32)[-_.]/.test(lower)) return 'windows';
if (/[-_.](mac|macos|darwin|osx)[-_.]/.test(lower)) return 'mac';
if (/[-_.]linux[-_.]/.test(lower)) return 'linux';
const kind = inferKind(lower);
if (kind === 'exe' || kind === 'msi') return 'windows';
if (kind === 'dmg' || kind === 'pkg') return 'mac';
if (['deb', 'rpm', 'appimage', 'AppImage'].includes(kind)) return 'linux';
return '';
}
export function inferArch(name) {
const lower = `${name || ''}`.toLowerCase();
if (/(armv7l|armv7|armhf)/.test(lower)) return 'armv7l';
if (/(arm64|aarch64)/.test(lower)) return 'arm64';
if (/universal/.test(lower)) return 'universal';
if (/(x64|amd64|x86_64)/.test(lower)) return 'x64';
if (/(ia32|i386)/.test(lower)) return 'ia32';
return '';
}
// 只产出 http(s) 地址:带协议的必须是 http(s),相对地址按 <base_url>/<version>/ 补全,
// 补不全(没有合法 base_url)或协议不对的文件直接丢弃。
function resolveUrl(url, baseUrl, version) {
if (!url) return '';
if (/^[a-z][a-z0-9+.-]*:/i.test(url) || url.startsWith('//')) {
return toSafeHttpUrl(url);
}
const base = toSafeHttpUrl(baseUrl).replace(/\/+$/, '');
if (!base) return '';
const dir = version ? `${encodeURIComponent(version)}/` : '';
return `${base}/${dir}${url.replace(/^\/+/, '')}`;
}
function normalizeFile(raw, fallback) {
if (!raw) return null;
const rawUrl = raw.url || raw.path || '';
const name = raw.name || fileNameOf(rawUrl);
const kind = raw.ext || raw.kind || raw.type || inferKind(name);
// 差分更新用的 blockmap 等文件不给用户下载
if (!rawUrl || kind === 'blockmap' || kind === 'yml') return null;
const platform =
normalizePlatform(raw.platform || raw.os) ||
fallback.platform ||
inferPlatform(name);
if (!platform) return null;
const version = raw.version || fallback.version || '';
const url = resolveUrl(rawUrl, fallback.baseUrl, version);
if (!url) return null;
return {
platform,
arch: normalizeArch(raw.arch) || inferArch(name),
kind,
name,
url,
size: Number(raw.size) || 0,
version,
releaseDate: raw.release_date || fallback.releaseDate || '',
};
}
/**
* 把接口返回整理成 { enabled, version, releaseDate, files }。兼容两种形态:
* 1. { enabled?, version, base_url?, platforms: { windows|mac|linux: { version, release_date,
* files: [{ name, url, size, sha512, arch, ext }] } } }(后端当前实现)
* 2. { version, release_date, base_url?, files: [{ platform?, arch?, url, name?, size? }] }
* 缺 platform / arch 时按安装包文件名推断,相对地址按 base_url 补全。
*/
export function normalizeRelease(data) {
if (!data || typeof data !== 'object') {
return { enabled: true, version: '', releaseDate: '', files: [] };
}
const baseUrl = data.base_url || data.baseUrl || '';
const files = [];
const push = (list, fallback) => {
(Array.isArray(list) ? list : []).forEach((raw) => {
const file = normalizeFile(raw, { baseUrl, ...fallback });
if (file) files.push(file);
});
};
push(data.files, {
version: data.version,
releaseDate: data.release_date,
});
if (data.platforms && typeof data.platforms === 'object') {
Object.entries(data.platforms).forEach(([key, value]) => {
if (!value) return;
push(value.files, {
platform: normalizePlatform(key),
version: value.version || data.version,
releaseDate: value.release_date || data.release_date,
});
});
}
// 同一个地址只保留一次
const seen = new Set();
const unique = files.filter((file) => {
if (seen.has(file.url)) return false;
seen.add(file.url);
return true;
});
const versions = unique.map((file) => file.version).filter(Boolean);
// 后端只在各平台里给 release_date,顶层没有这个字段:取各平台里最新的一个
// (ISO 日期串按字典序比较即按时间先后),data.release_date 仅为兼容扁平形态。
const latestReleaseDate = unique.reduce(
(latest, file) =>
file.releaseDate && file.releaseDate > latest ? file.releaseDate : latest,
'',
);
return {
// 后端在关闭下载页时返回 enabled: false
enabled: data.enabled !== false,
version: data.version || versions[0] || '',
releaseDate: latestReleaseDate || data.release_date || '',
files: unique,
mobile: normalizeMobile(data.mobile),
};
}
/**
* 整理接口里的手机端发布信息(后端读的是 <base_url>/mobile/manifest.json):
* { version, release_date, android: { name, url, size, sha256 } } →
* { version, releaseDate, android: { name, url, size } | null }。
* 没有发布手机端、或地址不是 http(s) 时返回 null,页面就不显示手机端。
*/
export function normalizeMobile(data) {
if (!data || typeof data !== 'object') return null;
const raw = data.android;
const url = raw ? toSafeHttpUrl(raw.url || '') : '';
if (!url) return null;
return {
version: `${data.version || ''}`,
releaseDate: `${data.release_date || ''}`,
android: {
name: raw.name || fileNameOf(url),
url,
size: Number(raw.size) || 0,
},
};
}
/** 手机系统:android | ios | ''(iPadOS 的 Safari 自称 Macintosh,识别不出来,按电脑处理)。 */
export function detectMobileOS(userAgent) {
const ua = `${userAgent || ''}`;
if (/android/i.test(ua)) return 'android';
if (/iphone|ipad|ipod/i.test(ua)) return 'ios';
return '';
}
function kindRank(file) {
const rank = (KIND_RANK[file.platform] || []).indexOf(file.kind);
return rank === -1 ? 99 : rank;
}
/**
* 按平台分组,组内按安装包类型、架构排序。
*/
export function groupByPlatform(files) {
const groups = {};
PLATFORMS.forEach((platform) => {
groups[platform] = files
.filter((file) => file.platform === platform)
.sort(
(a, b) => kindRank(a) - kindRank(b) || a.arch.localeCompare(b.arch),
);
});
return groups;
}
/**
* 为访问者挑选推荐安装包:同平台、优先匹配架构(mac 的 universal 包视为匹配),
* 再按安装包类型排序。架构未知时 Windows、Linux 取 x64,mac 取 arm64。
*/
export function pickRecommended(files, client) {
if (!client || !PLATFORMS.includes(client.os)) return null;
const candidates = files.filter((file) => file.platform === client.os);
if (candidates.length === 0) return null;
const wantArch = client.arch || (client.os === 'mac' ? 'arm64' : 'x64');
const archScore = (file) => {
if (file.arch === wantArch) return 0;
if (file.arch === 'universal') return 1;
if (!file.arch) return 2;
return 3;
};
return [...candidates].sort(
(a, b) => archScore(a) - archScore(b) || kindRank(a) - kindRank(b),
)[0];
}
/**
* 从 userAgent / platform 字符串识别系统和架构(同步部分)。
* os:windows | mac | linux | mobile | '';arch:x64 | arm64 | ''。
* 手机另带 mobile:android | ios | ''(用来推荐手机端安装包)。
*/
export function detectClientFromUA(userAgent, platform) {
const ua = `${userAgent || ''}`;
const plat = `${platform || ''}`;
if (/android|iphone|ipad|ipod|mobile/i.test(ua)) {
return { os: 'mobile', arch: '', mobile: detectMobileOS(ua) };
}
let os = '';
if (/windows/i.test(ua) || /^win/i.test(plat)) os = 'windows';
else if (/macintosh|mac os x/i.test(ua) || /^mac/i.test(plat)) os = 'mac';
else if (/linux|x11|cros/i.test(ua) || /linux/i.test(plat)) os = 'linux';
let arch = '';
if (/arm64|aarch64/i.test(ua) || /arm|aarch64/i.test(plat)) arch = 'arm64';
else if (/win64|x64|wow64|x86_64|amd64/i.test(ua) || /x86_64/i.test(plat)) {
arch = 'x64';
}
// Safari 在 Apple 芯片上仍报 Intel,UA 里的 Intel 不可信,交给高熵接口或默认值
if (os === 'mac') arch = '';
return { os, arch };
}
/**
* 识别访问者系统和架构:先用 UA,再用 Chromium 的 userAgentData 高熵值修正架构。
*/
export async function detectClient(nav) {
const n = nav || (typeof navigator !== 'undefined' ? navigator : {});
const result = detectClientFromUA(n.userAgent, n.platform);
try {
if (n.userAgentData?.getHighEntropyValues) {
const info = await n.userAgentData.getHighEntropyValues([
'architecture',
'bitness',
]);
if (info?.architecture === 'arm') result.arch = 'arm64';
else if (info?.architecture === 'x86' && info?.bitness === '64') {
result.arch = 'x64';
}
}
} catch (_e) {
// 浏览器不支持时保留 UA 的判断
}
return result;
}
export function formatSize(bytes) {
if (!bytes) return '';
const mb = bytes / 1024 / 1024;
if (mb >= 1024) return `${(mb / 1024).toFixed(2)} GB`;
return `${mb.toFixed(1)} MB`;
}
+333
View File
@@ -0,0 +1,333 @@
/*
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 assert from 'node:assert/strict';
import test from 'node:test';
import {
detectClientFromUA,
groupByPlatform,
normalizeRelease,
pickRecommended,
} from './release.js';
const flat = {
version: '1.2.3',
release_date: '2026-09-10T08:00:00.000Z',
base_url: 'https://download.example.com/releases/',
files: [
{ url: 'WeyAi-1.2.3-win-x64.exe', size: 104857600 },
{ url: 'WeyAi-1.2.3-win-x64.exe.blockmap' },
{ url: 'WeyAi-1.2.3-mac-arm64.dmg' },
{ url: 'WeyAi-1.2.3-mac-x64.dmg' },
{ url: 'WeyAi-1.2.3-mac-arm64.zip' },
{ url: 'https://cdn.example.com/WeyAi-1.2.3-linux-amd64.deb' },
{ url: 'WeyAi-1.2.3-linux-arm64.deb' },
],
};
test('normalizeRelease infers platform/arch and resolves relative urls', () => {
const release = normalizeRelease(flat);
assert.equal(release.version, '1.2.3');
assert.equal(release.files.length, 6);
const win = release.files.find((f) => f.platform === 'windows');
assert.equal(win.arch, 'x64');
assert.equal(win.kind, 'exe');
assert.equal(
win.url,
'https://download.example.com/releases/1.2.3/WeyAi-1.2.3-win-x64.exe',
);
const deb = release.files.find(
(f) => f.platform === 'linux' && f.arch === 'x64',
);
assert.equal(deb.url, 'https://cdn.example.com/WeyAi-1.2.3-linux-amd64.deb');
});
test('normalizeRelease accepts the per-platform shape', () => {
const release = normalizeRelease({
platforms: {
win: { version: '1.2.3', files: [{ url: 'https://x/a.exe' }] },
mac: { version: '1.2.2', files: [{ url: 'https://x/b-arm64.dmg' }] },
},
});
assert.equal(release.files.length, 2);
assert.equal(release.files[0].platform, 'windows');
assert.equal(release.files[1].platform, 'mac');
assert.equal(release.files[1].version, '1.2.2');
assert.equal(release.version, '1.2.3');
});
test('pickRecommended matches os and arch, preferring installers', () => {
const { files } = normalizeRelease(flat);
assert.equal(
pickRecommended(files, { os: 'mac', arch: '' }).name,
'WeyAi-1.2.3-mac-arm64.dmg',
);
assert.equal(
pickRecommended(files, { os: 'mac', arch: 'x64' }).name,
'WeyAi-1.2.3-mac-x64.dmg',
);
assert.equal(
pickRecommended(files, { os: 'linux', arch: 'arm64' }).name,
'WeyAi-1.2.3-linux-arm64.deb',
);
assert.equal(pickRecommended(files, { os: 'mobile', arch: '' }), null);
const groups = groupByPlatform(files);
assert.equal(groups.mac[groups.mac.length - 1].kind, 'zip');
});
test('detectClientFromUA recognizes desktop systems', () => {
assert.deepEqual(
detectClientFromUA(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
'Win32',
),
{ os: 'windows', arch: 'x64' },
);
assert.deepEqual(
detectClientFromUA(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15',
'MacIntel',
),
{ os: 'mac', arch: '' },
);
assert.equal(
detectClientFromUA('Mozilla/5.0 (X11; Linux aarch64)', 'Linux aarch64')
.arch,
'arm64',
);
assert.equal(
detectClientFromUA('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0)', 'iPhone').os,
'mobile',
);
});
test('detectClientFromUA tells Android from iOS phones', () => {
assert.deepEqual(
detectClientFromUA(
'Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 Mobile',
'Linux armv8l',
),
{ os: 'mobile', arch: '', mobile: 'android' },
);
assert.equal(
detectClientFromUA('Mozilla/5.0 (iPhone; CPU iPhone OS 17_0)', 'iPhone')
.mobile,
'ios',
);
});
test('normalizeRelease carries the mobile release when published', () => {
const release = normalizeRelease({
...flat,
mobile: {
version: '1.2.3',
release_date: '2026-10-02T08:00:00.000Z',
android: {
name: 'WeyAi-Mobile-1.2.3-android.apk',
url: 'https://download.example.com/releases/mobile/1.2.3/WeyAi-Mobile-1.2.3-android.apk',
size: 52428800,
sha256: 'x',
},
},
});
assert.deepEqual(release.mobile, {
version: '1.2.3',
releaseDate: '2026-10-02T08:00:00.000Z',
android: {
name: 'WeyAi-Mobile-1.2.3-android.apk',
url: 'https://download.example.com/releases/mobile/1.2.3/WeyAi-Mobile-1.2.3-android.apk',
size: 52428800,
},
});
// Desktop files are untouched by the mobile part.
assert.equal(release.files.length, 6);
});
test('normalizeRelease leaves mobile out when absent or unsafe', () => {
assert.equal(normalizeRelease(flat).mobile, null);
assert.equal(
normalizeRelease({
...flat,
mobile: { version: '1', android: { url: 'javascript:alert(1)' } },
}).mobile,
null,
);
assert.equal(
normalizeRelease({ ...flat, mobile: { version: '1' } }).mobile,
null,
);
});
test('normalizeRelease reads the backend payload shape', () => {
const release = normalizeRelease({
enabled: true,
version: '1.3.0',
base_url: 'https://download.example.com/releases',
platforms: {
windows: {
version: '1.3.0',
release_date: '2026-09-18T00:00:00.000Z',
files: [
{
name: 'WeyAi-1.3.0-win-x64.exe',
url: 'https://download.example.com/releases/WeyAi-1.3.0-win-x64.exe',
size: 1,
sha512: 'x',
arch: 'x64',
ext: 'exe',
},
],
},
linux: {
version: '1.3.0',
files: [
{
name: 'WeyAi-1.3.0-linux-amd64.deb',
url: 'WeyAi-1.3.0-linux-amd64.deb',
arch: '',
ext: 'deb',
},
],
},
},
});
assert.equal(release.enabled, true);
assert.equal(release.files.length, 2);
const deb = release.files.find((f) => f.platform === 'linux');
assert.equal(deb.arch, 'x64');
assert.equal(deb.kind, 'deb');
assert.equal(
deb.url,
'https://download.example.com/releases/1.3.0/WeyAi-1.3.0-linux-amd64.deb',
);
assert.equal(normalizeRelease({ enabled: false }).enabled, false);
});
test('normalizeRelease drops files that are not http(s)', () => {
const release = normalizeRelease({
version: '1.3.0',
base_url: 'https://download.example.com/releases',
platforms: {
windows: {
version: '1.3.0',
files: [
{ name: 'a-win-x64.exe', url: 'javascript:alert(1)', ext: 'exe' },
{ name: 'b-win-x64.exe', url: 'data:text/html,x', ext: 'exe' },
{
name: 'c-win-x64.exe',
url: '//evil.example.com/c.exe',
ext: 'exe',
},
{
name: 'd-win-x64.exe',
url: 'https://download.example.com/releases/1.3.0/d-win-x64.exe',
ext: 'exe',
},
],
},
},
});
assert.deepEqual(
release.files.map((f) => f.name),
['d-win-x64.exe'],
);
// A relative file needs an http(s) base_url.
const badBase = normalizeRelease({
version: '1.3.0',
base_url: 'javascript:alert(1)//',
files: [{ url: 'WeyAi-1.3.0-win-x64.exe' }],
});
assert.equal(badBase.files.length, 0);
});
test('mac visitors get the arm64 build now that its feed is merged', () => {
const { files } = normalizeRelease({
version: '1.4.0',
platforms: {
mac: {
version: '1.4.0',
files: [
{
name: 'WeyAi-1.4.0.dmg',
url: 'https://dl.example.com/releases/1.4.0/WeyAi-1.4.0.dmg',
arch: 'x64',
ext: 'dmg',
},
{
name: 'WeyAi-1.4.0-mac-arm64.dmg',
url: 'https://dl.example.com/releases/1.4.0/WeyAi-1.4.0-mac-arm64.dmg',
arch: 'arm64',
ext: 'dmg',
},
],
},
},
});
assert.equal(
pickRecommended(files, { os: 'mac', arch: '' }).name,
'WeyAi-1.4.0-mac-arm64.dmg',
);
assert.equal(
pickRecommended(files, { os: 'mac', arch: 'x64' }).name,
'WeyAi-1.4.0.dmg',
);
});
test('normalizeRelease takes the newest platform release date', () => {
const release = normalizeRelease({
version: '1.3.0',
base_url: 'https://download.example.com/releases',
platforms: {
windows: {
version: '1.3.0',
release_date: '2026-09-18T00:00:00.000Z',
files: [{ name: 'a-win-x64.exe', url: 'a-win-x64.exe', ext: 'exe' }],
},
mac: {
version: '1.3.1',
release_date: '2026-09-20T00:00:00.000Z',
files: [
{ name: 'b-mac-arm64.dmg', url: 'b-mac-arm64.dmg', ext: 'dmg' },
],
},
linux: {
version: '1.2.0',
files: [
{ name: 'c-linux-amd64.deb', url: 'c-linux-amd64.deb', ext: 'deb' },
],
},
},
});
// 后端顶层没有 release_date,取各平台里最新的一个
assert.equal(release.releaseDate, '2026-09-20T00:00:00.000Z');
// 一个平台都没有发布日期时留空,而不是报未定义
const none = normalizeRelease({
version: '1.3.0',
base_url: 'https://download.example.com/releases',
platforms: {
windows: {
version: '1.3.0',
files: [{ name: 'a-win-x64.exe', url: 'a-win-x64.exe', ext: 'exe' }],
},
},
});
assert.equal(none.releaseDate, '');
// 扁平形态仍然认顶层 release_date
assert.equal(normalizeRelease(flat).releaseDate, '2026-09-10T08:00:00.000Z');
});
+536
View File
@@ -0,0 +1,536 @@
/* WeyAi 桌面端下载页:控制台风格,配色全部从主题 token 派生。
独立路由时由本页渲染 <PageBackground>;嵌入用户中心时 shell 已提供背景,本页不再自绘。 */
.weyai-download {
--wd-ink: var(--text-primary);
--wd-muted: var(--text-secondary);
--wd-line: var(--border-subtle);
--wd-card: var(--surface-card);
--wd-accent: var(--semi-color-primary);
--wd-accent-deep: var(--semi-color-primary-active, var(--semi-color-primary));
--wd-tint: color-mix(in srgb, var(--semi-color-primary) 8%, transparent);
--wd-tint-strong: color-mix(
in srgb,
var(--semi-color-primary) 14%,
transparent
);
--wd-accent-line: color-mix(
in srgb,
var(--semi-color-primary) 28%,
transparent
);
--wd-danger: var(--semi-color-danger);
--wd-danger-tint: color-mix(
in srgb,
var(--semi-color-danger) 8%,
transparent
);
position: relative;
color: var(--wd-ink);
}
.weyai-download--standalone {
min-height: calc(100vh - 60px);
overflow: hidden;
}
.weyai-download__inner {
position: relative;
z-index: 10;
max-width: 1120px;
margin: 0 auto;
padding: 16px;
display: flex;
flex-direction: column;
gap: 20px;
}
@media (min-width: 640px) {
.weyai-download__inner {
padding: 24px;
gap: 24px;
}
}
@media (min-width: 1024px) {
.weyai-download__inner {
padding: 32px;
}
}
/* 嵌入用户中心:跟随内容区宽度,不再居中收窄;内边距对齐同级页面的 p-4 sm:p-6 */
.weyai-download--embedded .weyai-download__inner {
max-width: none;
}
@media (min-width: 1024px) {
.weyai-download--embedded .weyai-download__inner {
padding: 24px;
}
}
/* 「其他平台与架构」锚点:独立路由下顶栏 64px 与跑马灯 40px 都是 fixed,
scrollIntoView 会把标题顶到它们后面;嵌入模式滚动容器本身在顶栏之下 */
.weyai-download--standalone #weyai-download-all {
scroll-margin-top: 120px;
}
.weyai-download--embedded #weyai-download-all {
scroll-margin-top: 16px;
}
/* ───── hero ───── */
.wd-hero {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
justify-content: space-between;
gap: 16px 24px;
}
.wd-eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
color: var(--wd-accent);
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.wd-hero h1 {
margin: 8px 0 6px;
font-size: 24px;
font-weight: 700;
letter-spacing: -0.01em;
line-height: 1.3;
color: var(--wd-ink);
}
@media (min-width: 640px) {
.wd-hero h1 {
font-size: 28px;
}
}
.wd-hero p {
margin: 0;
font-size: 13px;
line-height: 20px;
color: var(--wd-muted);
}
.wd-hero-meta {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
margin-top: 12px;
}
.wd-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 3px 10px;
border: 1px solid var(--wd-accent-line);
border-radius: 999px;
background: var(--wd-tint);
font-size: 12px;
font-weight: 600;
color: var(--wd-accent-deep);
font-variant-numeric: tabular-nums;
}
.wd-chip--muted {
border-color: var(--wd-line);
background: transparent;
color: var(--wd-muted);
font-weight: 500;
}
.wd-hero-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
/* ───── 卡片基础 ───── */
.wd-card {
border: 1px solid var(--wd-line);
border-radius: 14px;
background: var(--wd-card);
}
/* ───── 推荐安装包 ───── */
.wd-reco {
position: relative;
overflow: hidden;
padding: 20px;
border-color: var(--wd-accent-line);
background: radial-gradient(
120% 160% at 100% 0%,
var(--wd-tint) 0%,
transparent 55%
),
var(--wd-card);
}
@media (min-width: 640px) {
.wd-reco {
padding: 24px 28px;
}
}
.wd-reco::before {
content: '';
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: linear-gradient(180deg, var(--wd-accent), var(--wd-accent-deep));
}
.wd-reco__row {
display: flex;
flex-direction: column;
gap: 18px;
}
@media (min-width: 768px) {
.wd-reco__row {
flex-direction: row;
align-items: center;
justify-content: space-between;
}
}
.wd-reco__main {
display: flex;
align-items: flex-start;
gap: 16px;
min-width: 0;
}
.wd-os-badge {
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
width: 52px;
height: 52px;
border-radius: 14px;
border: 1px solid var(--wd-accent-line);
background: var(--wd-tint-strong);
color: var(--wd-accent-deep);
}
/* 推荐卡的眉标带插值的平台名(macOS),不能全大写 */
.wd-reco .wd-eyebrow {
text-transform: none;
letter-spacing: 0.04em;
}
.wd-reco__title {
margin: 2px 0 4px;
font-size: 20px;
font-weight: 700;
letter-spacing: -0.01em;
line-height: 1.3;
color: var(--wd-ink);
}
.wd-reco__meta {
display: flex;
flex-wrap: wrap;
gap: 4px 12px;
font-size: 12px;
color: var(--wd-muted);
font-variant-numeric: tabular-nums;
}
.wd-reco__meta code {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
color: var(--wd-muted);
word-break: break-all;
}
.wd-reco__hint {
margin-top: 8px;
font-size: 12px;
color: var(--wd-muted);
}
.wd-reco__actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
}
@media (min-width: 768px) {
.wd-reco__actions {
flex-direction: column;
align-items: stretch;
flex-shrink: 0;
}
}
/* ───── 特性条 ───── */
.wd-features {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 12px;
}
@media (min-width: 640px) {
.wd-features {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (min-width: 1024px) {
.wd-features {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
/* 嵌入用户中心时内容区少了 240px 侧栏,1024–1279 之间四列每列不足 200px,
英文描述会折五六行;这一档保持两列,到 1280 再放四列 */
.weyai-download--embedded .wd-features {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (min-width: 1280px) {
.weyai-download--embedded .wd-features {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
}
.wd-feature {
display: flex;
gap: 12px;
padding: 14px 16px;
transition:
transform 0.18s ease,
box-shadow 0.18s ease;
}
.wd-feature:hover {
transform: translateY(-2px);
box-shadow: 0 8px 24px -12px
color-mix(in srgb, var(--semi-color-primary) 45%, transparent);
}
.wd-feature__icon {
flex-shrink: 0;
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 36px;
border-radius: 10px;
background: var(--wd-tint);
color: var(--wd-accent-deep);
}
.wd-feature__title {
display: block;
font-size: 13px;
font-weight: 600;
color: var(--wd-ink);
}
.wd-feature__desc {
display: block;
margin-top: 2px;
font-size: 12px;
line-height: 18px;
color: var(--wd-muted);
}
/* ───── 分区标题 ───── */
.wd-section-head {
display: flex;
flex-wrap: wrap;
align-items: baseline;
justify-content: space-between;
gap: 8px;
}
.wd-section-head h2 {
margin: 0;
font-size: 16px;
font-weight: 700;
letter-spacing: -0.01em;
color: var(--wd-ink);
}
.wd-section-head p {
margin: 0;
font-size: 12px;
color: var(--wd-muted);
}
/* ───── 全部安装包 ───── */
.wd-platforms {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 12px;
}
@media (min-width: 768px) {
.wd-platforms {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (min-width: 1024px) {
.wd-platforms {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
.wd-platform {
overflow: hidden;
}
/* 手机端卡片底部的用途说明 */
.wd-platform__note {
padding: 10px 16px 12px;
font-size: 12px;
color: var(--wd-muted);
}
.wd-platform__head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 12px 16px;
border-bottom: 1px solid var(--wd-line);
}
.wd-platform__name {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 600;
color: var(--wd-ink);
}
.wd-platform__name svg {
color: var(--wd-accent-deep);
}
.wd-platform__count {
font-size: 12px;
color: var(--wd-muted);
font-variant-numeric: tabular-nums;
}
.wd-file {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 12px 16px;
border-bottom: 1px solid var(--wd-line);
transition: background 0.15s ease;
}
.wd-file:last-child {
border-bottom: 0;
}
.wd-file:hover {
background: var(--wd-tint);
}
.wd-file--reco {
box-shadow: inset 3px 0 0 var(--wd-accent);
}
.wd-file__main {
min-width: 0;
}
.wd-file__title {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
font-size: 13px;
font-weight: 600;
color: var(--wd-ink);
}
.wd-file__meta {
display: block;
margin-top: 2px;
font-size: 12px;
color: var(--wd-muted);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
/* ───── 步骤 ───── */
.wd-steps {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 12px;
}
@media (min-width: 768px) {
.wd-steps {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
.wd-step {
position: relative;
padding: 16px 16px 16px 56px;
}
.wd-step__num {
position: absolute;
left: 16px;
top: 16px;
display: inline-flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
border-radius: 999px;
background: linear-gradient(135deg, var(--wd-accent), var(--wd-accent-deep));
color: var(--semi-color-white, var(--surface-card));
font-size: 13px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.wd-step__title {
display: block;
font-size: 13px;
font-weight: 600;
color: var(--wd-ink);
}
.wd-step__desc {
display: block;
margin-top: 2px;
font-size: 12px;
line-height: 18px;
color: var(--wd-muted);
}
/* ───── 状态卡(加载失败 / 未开放 / 暂无安装包) ───── */
.wd-state {
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
gap: 8px;
padding: 36px 20px;
}
.wd-state__icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 56px;
height: 56px;
border-radius: 16px;
background: var(--wd-tint);
color: var(--wd-accent-deep);
margin-bottom: 4px;
}
.wd-state--danger .wd-state__icon {
background: var(--wd-danger-tint);
color: var(--wd-danger);
}
.wd-state__title {
font-size: 15px;
font-weight: 600;
color: var(--wd-ink);
}
.wd-state__desc {
max-width: 520px;
font-size: 13px;
line-height: 20px;
color: var(--wd-muted);
overflow-wrap: anywhere;
}
.wd-state__actions {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 8px;
margin-top: 8px;
}
/* ───── 骨架 ───── */
.wd-skeleton {
padding: 24px;
display: flex;
flex-direction: column;
gap: 12px;
}
.wd-footnote {
font-size: 12px;
color: var(--wd-muted);
text-align: center;
}
.weyai-download button:focus-visible,
.weyai-download a:focus-visible {
outline: 2px solid
color-mix(in srgb, var(--semi-color-primary) 55%, transparent);
outline-offset: 2px;
}