Просмотр исходного кода

fix(app): 修复扫码下载时间与空白页(Web 2.4.441)

Co-authored-by: Cursor <cursoragent@cursor.com>
YY968XX 11 часов назад
Родитель
Сommit
93435f45fb

+ 1 - 1
Web/package.json

@@ -1,7 +1,7 @@
 {
 	"name": "admin.net",
 	"type": "module",
-	"version": "2.4.440",
+	"version": "2.4.441",
 	"packageManager": "pnpm@10.32.1",
 	"lastBuildTime": "2026.03.15",
 	"description": "Admin.NET 站在巨人肩膀上的 .NET 通用权限开发框架",

+ 19 - 6
Web/src/views/app/download.vue

@@ -40,13 +40,21 @@
 				/>
 
 				<el-button class="download-button" type="primary" size="large" :disabled="downloading" @click="download">
-					{{ downloading ? '正在跳转…' : '下载 Android 安装包' }}
+					{{ downloading ? '下载任务已提交' : '下载 Android 安装包' }}
 				</el-button>
+				<el-alert
+					v-if="downloading"
+					class="download-hint"
+					title="请查看浏览器下载列表;下载页面会继续保留,无需返回空白页。"
+					type="success"
+					:closable="false"
+					show-icon
+				/>
 
 				<div class="security">
 					<p>SHA-256</p>
 					<code>{{ release.sha256 }}</code>
-					<p>下载票据仅可使用一次;如下载中断,请在 PC 端重新生成。</p>
+					<p>二维码票据仅消费一次;下载开始后支持短时间内重试和断点续传。</p>
 				</div>
 			</template>
 		</main>
@@ -57,6 +65,7 @@
 import { computed, onMounted, ref } from 'vue';
 import { useRoute } from 'vue-router';
 import { buildAppDownloadUrl, getAppTicketInfo, type AppReleaseInfo } from './api';
+import { formatAppServerDate, startBrowserDownload } from './downloadUi';
 
 const route = useRoute();
 const loading = ref(true);
@@ -84,7 +93,8 @@ onMounted(async () => {
 function download() {
 	if (!ticket.value || downloading.value) return;
 	downloading.value = true;
-	window.location.assign(buildAppDownloadUrl(ticket.value));
+	const versionName = release.value?.versionName || 'release';
+	startBrowserDownload(buildAppDownloadUrl(ticket.value), `MDIOP-${versionName}.apk`);
 }
 
 function formatSize(bytes?: number) {
@@ -93,9 +103,7 @@ function formatSize(bytes?: number) {
 }
 
 function formatDate(value?: string) {
-	if (!value) return '-';
-	const date = new Date(value);
-	return Number.isNaN(date.getTime()) ? value : date.toLocaleString('zh-CN', { hour12: false });
+	return formatAppServerDate(value);
 }
 </script>
 
@@ -163,6 +171,11 @@ h1 {
 	margin-top: 20px;
 }
 
+.download-hint {
+	margin-top: 12px;
+	text-align: left;
+}
+
 .security {
 	margin-top: 20px;
 	color: #909399;

+ 2 - 2
Web/src/views/app/downloadDialog.vue

@@ -31,6 +31,7 @@ import { ElMessage } from 'element-plus';
 import QRCode from 'qrcodejs2-fixes';
 import { createAppDownloadTicket, type AppDownloadTicket } from './api';
 import { buildAppDownloadPageUrl } from './downloadEntry';
+import { formatAppServerDate } from './downloadUi';
 
 const visible = ref(false);
 const loading = ref(false);
@@ -81,8 +82,7 @@ function reset() {
 }
 
 function formatDate(value?: string) {
-	if (!value) return '-';
-	return new Date(value).toLocaleString('zh-CN', { hour12: false });
+	return formatAppServerDate(value);
 }
 
 defineExpose({ openDialog });

+ 37 - 0
Web/src/views/app/downloadUi.spec.ts

@@ -0,0 +1,37 @@
+import { describe, expect, it, vi } from 'vitest';
+import { formatAppServerDate, parseAppServerDate, startBrowserDownload, type DownloadAnchor } from './downloadUi';
+
+describe('APP download UI', () => {
+	it('treats timezone-less server timestamps as UTC', () => {
+		expect(parseAppServerDate('2026-12-02T13:43:01')?.toISOString()).toBe('2026-12-02T13:43:01.000Z');
+		expect(formatAppServerDate('2026-12-02T13:43:01Z')).toContain('21:43:01');
+	});
+
+	it('preserves timestamps that already carry an offset', () => {
+		expect(parseAppServerDate('2026-12-02T21:43:01+08:00')?.toISOString()).toBe('2026-12-02T13:43:01.000Z');
+		expect(formatAppServerDate('2026-12-02T21:43:01+08:00')).toContain('21:43:01');
+	});
+
+	it('starts an attachment download without replacing the current page', () => {
+		const anchor: DownloadAnchor = {
+			href: '',
+			download: '',
+			style: { display: '' },
+			click: vi.fn(),
+			remove: vi.fn(),
+		};
+		const appendChild = vi.fn();
+
+		startBrowserDownload('https://mdiop.example.com/app.apk', 'MDIOP-1.0.0.apk', {
+			body: { appendChild },
+			createElement: () => anchor,
+		});
+
+		expect(anchor.href).toBe('https://mdiop.example.com/app.apk');
+		expect(anchor.download).toBe('MDIOP-1.0.0.apk');
+		expect(anchor.style.display).toBe('none');
+		expect(appendChild).toHaveBeenCalledWith(anchor);
+		expect(anchor.click).toHaveBeenCalledOnce();
+		expect(anchor.remove).toHaveBeenCalledOnce();
+	});
+});

+ 42 - 0
Web/src/views/app/downloadUi.ts

@@ -0,0 +1,42 @@
+const EXPLICIT_TIME_ZONE = /(Z|[+-]\d{2}:\d{2})$/i;
+
+export function parseAppServerDate(value?: string): Date | null {
+	if (!value) return null;
+	const normalized = EXPLICIT_TIME_ZONE.test(value) ? value : `${value}Z`;
+	const date = new Date(normalized);
+	return Number.isNaN(date.getTime()) ? null : date;
+}
+
+export function formatAppServerDate(value?: string): string {
+	const date = parseAppServerDate(value);
+	if (!date) return value || '-';
+	return date.toLocaleString('zh-CN', {
+		hour12: false,
+		timeZone: 'Asia/Shanghai',
+	});
+}
+
+export interface DownloadDocument {
+	body: {
+		appendChild(node: DownloadAnchor): void;
+	};
+	createElement(tagName: 'a'): DownloadAnchor;
+}
+
+export interface DownloadAnchor {
+	href: string;
+	download: string;
+	style: { display: string };
+	click(): void;
+	remove(): void;
+}
+
+export function startBrowserDownload(url: string, fileName: string, target: DownloadDocument = document): void {
+	const anchor = target.createElement('a');
+	anchor.href = url;
+	anchor.download = fileName;
+	anchor.style.display = 'none';
+	target.body.appendChild(anchor);
+	anchor.click();
+	anchor.remove();
+}