ow
This commit is contained in:
1 parent
6710b429b0
commit
15d8eb3f4e
6 files changed
+39
-1
No files matched your search
@@ -42,6 +42,7 @@ import { pageUrl } from "@/router/routes";
|
||||
import { chooseFiles } from "@/utils/chooseFiles";
|
||||
import { saveFileBytes } from "@/utils/dmsBytes";
|
||||
import { absoluteFileUrl, backupFileUrl } from "@/utils/fileUrl";
|
||||
import { isWeixinBrowser } from "@/utils/weixin";
|
||||
|
||||
/** ready:组件挂载完成通知(时序口径见文件底部 onMounted 注释) */
|
||||
const emit = defineEmits<{ (e: "ready"): void }>();
|
||||
@@ -151,6 +152,16 @@ const downloadGlyph = `data:image/svg+xml,${encodeURIComponent(downloadSvg)}`;
|
||||
/** H5 下载 App 安装包:复用网盘 file 页同一条下载链——requestBuffer 按当前线路取字节
|
||||
* (后端报错回的是 JSON,按 content-type 转成错误提示,不会跳错误页),saveFileBytes 走 blob <a download> 落盘 */
|
||||
async function onDownloadApp(): Promise<void> {
|
||||
// 微信内置浏览器屏蔽 <a download> 且 apk 在微信下载封禁名单里(点击静默无反应),
|
||||
// 只能引导用户到系统浏览器下载
|
||||
if (isWeixinBrowser()) {
|
||||
uni.showModal({
|
||||
title: t("storage.downloadApp"),
|
||||
content: t("storage.openInBrowserTip"),
|
||||
showCancel: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showLoading({ title: t("storage.downloadingApp"), mask: true });
|
||||
try {
|
||||
const bytes = await requestBuffer({ url: "/FileServer/youjiala.apk", method: "GET" });
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"avatarUploadFailed": "Avatar upload failed",
|
||||
"downloadApp": "Download App",
|
||||
"downloadingApp": "Downloading…",
|
||||
"openInBrowserTip": "Downloads are blocked inside WeChat. Please tap \"···\" at the top right, choose \"Open in browser\", then tap download again.",
|
||||
"downloadStarted": "Downloading youjiala.apk…"
|
||||
},
|
||||
"article": {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"avatarUploadFailed": "头像上传失败",
|
||||
"downloadApp": "下载 App",
|
||||
"downloadingApp": "正在下载…",
|
||||
"openInBrowserTip": "微信内无法直接下载文件,请点击右上角「···」,选择「在浏览器打开」后再点击下载",
|
||||
"downloadStarted": "开始下载 youjiala.apk…"
|
||||
},
|
||||
"article": {
|
||||
|
||||
@@ -40,6 +40,7 @@ import { fetchFileBytes, saveFileBytes, toImageUrl, toPlayableUrl } from "@/util
|
||||
import { absoluteFileUrl } from "@/utils/fileUrl";
|
||||
import { clearPlayback, setPlayback } from "@/utils/playbackBus";
|
||||
import { transferGlyph } from "@/utils/transferGlyph";
|
||||
import { isWeixinBrowser } from "@/utils/weixin";
|
||||
|
||||
const { t } = useLocale();
|
||||
|
||||
@@ -584,6 +585,15 @@ async function actionDownload(targets: FileItem[]): Promise<void> {
|
||||
toast(t("FilePage.downloadNoFile"));
|
||||
return;
|
||||
}
|
||||
// 微信内置浏览器屏蔽 blob/<a download>(点击静默无反应),只能引导转系统浏览器下载
|
||||
if (isWeixinBrowser()) {
|
||||
uni.showModal({
|
||||
title: t("FilePage.actionDownload"),
|
||||
content: t("storage.openInBrowserTip"),
|
||||
showCancel: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
await withBusy(async () => {
|
||||
for (const file of picked) {
|
||||
const record = recordOf(file);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 微信内置浏览器检测(iOS WKWebView / 安卓 XWeb 的 UA 都带 MicroMessenger 标记):
|
||||
* 微信屏蔽 <a download> 与 blob 落盘(点击静默无反应、无任何报错),apk 更在
|
||||
* 微信下载封禁名单里,客户端没有绕过手段——H5 的下载入口命中微信时必须弹窗
|
||||
* 引导用户「右上角··· → 在浏览器打开」后回系统浏览器下载。
|
||||
* 非 H5 端(App/小程序)不存在微信网页环境,恒为 false。
|
||||
*/
|
||||
export function isWeixinBrowser(): boolean {
|
||||
// #ifdef H5
|
||||
return /MicroMessenger/i.test(navigator.userAgent);
|
||||
// #endif
|
||||
// #ifndef H5
|
||||
return false;
|
||||
// #endif
|
||||
}
|
||||
Reference in new issue
Block a user