|
@@ -22,6 +22,7 @@ import { isCloudUrl } from '../../../core/s3-link';
|
|
|
import { downloadAs, needsBlobPreview, toBlobUrl } from '../../../core/attachment-fetch';
|
|
import { downloadAs, needsBlobPreview, toBlobUrl } from '../../../core/attachment-fetch';
|
|
|
import { copyLink, openInNewTab } from '../../../core/open-link';
|
|
import { copyLink, openInNewTab } from '../../../core/open-link';
|
|
|
import { isNativeApp } from '../../../core/api/platform-proxy.service';
|
|
import { isNativeApp } from '../../../core/api/platform-proxy.service';
|
|
|
|
|
+import { FileShareService } from '../../../core/file-share.service';
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 预览呈现形态。
|
|
* 预览呈现形态。
|
|
@@ -117,6 +118,11 @@ export type PreviewPresentation = 'rail' | 'full' | 'modal';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
<div class="fp-tools">
|
|
<div class="fp-tools">
|
|
|
|
|
+ @if (fileShare.available) {
|
|
|
|
|
+ <button type="button" class="fp-icon" aria-label="分享文件" [disabled]="fileShare.busy()" (click)="shareFile()">
|
|
|
|
|
+ <i class="fa-solid" [class.fa-share-nodes]="!fileShare.busy()" [class.fa-spinner]="fileShare.busy()" [class.fa-spin]="fileShare.busy()" aria-hidden="true"></i>
|
|
|
|
|
+ </button>
|
|
|
|
|
+ }
|
|
|
<ui-tooltip [disabled]="touchUi" content="下载">
|
|
<ui-tooltip [disabled]="touchUi" content="下载">
|
|
|
<button type="button" class="fp-icon" aria-label="下载" (click)="download()">
|
|
<button type="button" class="fp-icon" aria-label="下载" (click)="download()">
|
|
|
<i class="fa-solid fa-download" aria-hidden="true"></i>
|
|
<i class="fa-solid fa-download" aria-hidden="true"></i>
|
|
@@ -334,7 +340,7 @@ export type PreviewPresentation = 'rail' | 'full' | 'modal';
|
|
|
@if (frameStalled()) {
|
|
@if (frameStalled()) {
|
|
|
<div class="fp-html-stall">
|
|
<div class="fp-html-stall">
|
|
|
<i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i>
|
|
<i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i>
|
|
|
- <p>页面加载超时,可能是 CDN 缓存了旧版本或缺少跨域头。</p>
|
|
|
|
|
|
|
+ <p>文件加载失败。请检查网络连接后重试;若网络正常,可能是文件地址已失效。</p>
|
|
|
<div class="fp-actions">
|
|
<div class="fp-actions">
|
|
|
<button type="button" class="fp-btn fp-btn--primary" (click)="retryFrame()">
|
|
<button type="button" class="fp-btn fp-btn--primary" (click)="retryFrame()">
|
|
|
重新加载
|
|
重新加载
|
|
@@ -1010,6 +1016,7 @@ export class FilePreviewComponent {
|
|
|
* 平板横屏会判成 desktop;而「有没有鼠标」这件事只有原生壳能确定。
|
|
* 平板横屏会判成 desktop;而「有没有鼠标」这件事只有原生壳能确定。
|
|
|
*/
|
|
*/
|
|
|
protected readonly touchUi = isNativeApp();
|
|
protected readonly touchUi = isNativeApp();
|
|
|
|
|
+ protected readonly fileShare = inject(FileShareService);
|
|
|
|
|
|
|
|
/** 请求关闭 */
|
|
/** 请求关闭 */
|
|
|
readonly closed = output<void>();
|
|
readonly closed = output<void>();
|
|
@@ -1295,6 +1302,10 @@ export class FilePreviewComponent {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async shareFile(): Promise<void> {
|
|
|
|
|
+ await this.fileShare.share({ url: this.url(), name: this.name(), mimeType: this.mimeType() });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 复制文件的在线链接到剪贴板。
|
|
* 复制文件的在线链接到剪贴板。
|
|
|
*
|
|
*
|
|
@@ -1490,15 +1501,124 @@ export class FilePreviewComponent {
|
|
|
|
|
|
|
|
onFrameLoad(): void {
|
|
onFrameLoad(): void {
|
|
|
this.clearFrameTimer();
|
|
this.clearFrameTimer();
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 🔴 断网时浏览器会**正常触发 load 事件**(渲染它自己的错误页),
|
|
|
|
|
+ * 于是原来的 `frameStalled.set(false)` 把「加载失败」当成了成功,
|
|
|
|
|
+ * 用户看到的是 Chrome 原生错误页:「网页无法打开 / net::ERR_NAME_NOT_RESOLVED」,
|
|
|
|
|
+ * 与 App 的设计语言完全不符(2026-11-18 真机实测)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * ## 为什么不能用 navigator.onLine
|
|
|
|
|
+ *
|
|
|
|
|
+ * 真机实测:开启飞行模式后 `navigator.onLine` **仍然返回 true**
|
|
|
|
|
+ * (`connection.effectiveType` 还是 `4g`)—— MIUI 下 Android 的
|
|
|
|
|
+ * NetworkInfo 没有及时更新,这个属性在本场景**完全不可信**。
|
|
|
|
|
+ *
|
|
|
|
|
+ * ## 现在怎么做
|
|
|
|
|
+ *
|
|
|
|
|
+ * ① 同源 iframe 能读到内容 → 直接检查是不是浏览器错误页
|
|
|
|
|
+ * ② 跨域读不到 → 用一次**真实远程探测**判断网络(HEAD 一个已知域名)
|
|
|
|
|
+ */
|
|
|
|
|
+ void this.verifyFrameLoaded();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * iframe 加载完成后校验是不是真的加载成功了(2026-11-18)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 分两步:先看能否读到同源内容(能读就直接判断),
|
|
|
|
|
+ * 读不到(跨域)再做一次远程可达性探测 —— 这是唯一可靠的方式。
|
|
|
|
|
+ */
|
|
|
|
|
+ private async verifyFrameLoaded(): Promise<void> {
|
|
|
|
|
+ const el = this.htmlFrame()?.nativeElement;
|
|
|
|
|
+ let readable = false;
|
|
|
|
|
+ try {
|
|
|
|
|
+ const doc = el?.contentDocument;
|
|
|
|
|
+ if (doc?.body) {
|
|
|
|
|
+ readable = true;
|
|
|
|
|
+ const text = (doc.body.innerText ?? '').trim();
|
|
|
|
|
+ if (text === '' || /ERR_[A-Z_]+|网页无法打开|无法访问此网站/.test(text)) {
|
|
|
|
|
+ this.failFrame();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ readable = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (readable) {
|
|
|
|
|
+ this.frameStalled.set(false);
|
|
|
|
|
+ this.frameLoading.set(false);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 🔴 跨域 iframe 读不到内容(2026-11-18 第三次修正)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * ## 关键事实(真机实测)
|
|
|
|
|
+ *
|
|
|
|
|
+ * 断网时 iframe **仍然会触发 load 事件**(浏览器渲染自己的错误页),
|
|
|
|
|
+ * 所以「有 load 事件 = 加载成功」这个假设**不成立**。
|
|
|
|
|
+ * 而跨域又读不到 `contentDocument`,DOM 层面无从区分。
|
|
|
|
|
+ *
|
|
|
|
|
+ * ## 做法:直接探测**目标文件本身**
|
|
|
|
|
+ *
|
|
|
|
|
+ * · 断网 → 抛异常 → 判失败
|
|
|
|
|
+ * · 文件 404 / 不可达 → 判失败
|
|
|
|
|
+ * · 正常 → 判成功
|
|
|
|
|
+ *
|
|
|
|
|
+ * 探目标地址而不是别的域名,语义最准确:既不会被无关服务的慢响应误伤,
|
|
|
|
|
+ * 也顺带覆盖了「文件已失效」这种真实场景。
|
|
|
|
|
+ */
|
|
|
|
|
+ const ok = await this.probeTarget();
|
|
|
|
|
+ if (!this.open()) return; // 探测期间预览已关闭
|
|
|
|
|
+ if (!ok) {
|
|
|
|
|
+ this.failFrame();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
this.frameStalled.set(false);
|
|
this.frameStalled.set(false);
|
|
|
this.frameLoading.set(false);
|
|
this.frameLoading.set(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 探测预览目标文件是否可读(2026-11-18)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 用 `HEAD` 省流量;不支持 HEAD 的服务端会回 405,那也算「连得上」。
|
|
|
|
|
+ */
|
|
|
|
|
+ private async probeTarget(): Promise<boolean> {
|
|
|
|
|
+ const target = this.buildFrameSrc() || this.safeUrl() || this.url();
|
|
|
|
|
+ if (!target) return true; // 无目标地址不判失败,交给超时兜底
|
|
|
|
|
+ try {
|
|
|
|
|
+ const ctrl = new AbortController();
|
|
|
|
|
+ const timer = setTimeout(() => ctrl.abort(), 6000);
|
|
|
|
|
+ const res = await fetch(target, { method: 'HEAD', signal: ctrl.signal, cache: 'no-store' });
|
|
|
|
|
+ clearTimeout(timer);
|
|
|
|
|
+ return res.ok || res.status === 405;
|
|
|
|
|
+ } catch {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private failFrame(): void {
|
|
|
|
|
+ this.frameStalled.set(true);
|
|
|
|
|
+ this.frameLoading.set(false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
retryFrame(): void {
|
|
retryFrame(): void {
|
|
|
this.frameStalled.set(false);
|
|
this.frameStalled.set(false);
|
|
|
this.frameRetry++;
|
|
this.frameRetry++;
|
|
|
const el = this.htmlFrame()?.nativeElement;
|
|
const el = this.htmlFrame()?.nativeElement;
|
|
|
- if (el) el.setAttribute('src', '');
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ * 🔴 先清空 src 再**显式写回目标地址**(2026-11-18 真机实测修复)。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 原来只做了 `el.setAttribute('src', '')` —— 清空后 Angular 的
|
|
|
|
|
+ * 属性绑定没有变化,不会重新写回,于是 iframe 落在了
|
|
|
|
|
+ * `https://localhost/`(App 首页),既没加载目标文件,
|
|
|
|
|
+ * 错误提示框又因为 stall 状态还在而继续显示,两者叠在一起。
|
|
|
|
|
+ *
|
|
|
|
|
+ * 改为:清空 → 强制回流 → 写回真实地址,确保这次是**重新发起请求**。
|
|
|
|
|
+ */
|
|
|
|
|
+ if (el) {
|
|
|
|
|
+ el.setAttribute('src', 'about:blank');
|
|
|
|
|
+ void el.offsetHeight; // 强制回流,让浏览器立即应用清空
|
|
|
|
|
+ el.setAttribute('src', this.buildFrameSrc() || this.safeUrl() || this.url());
|
|
|
|
|
+ }
|
|
|
this.startFrameTimer();
|
|
this.startFrameTimer();
|
|
|
}
|
|
}
|
|
|
|
|
|