diff --git a/mobile-uni/src/pages/user/sop/index.vue b/mobile-uni/src/pages/user/sop/index.vue index 1f3399c6..3947b39b 100644 --- a/mobile-uni/src/pages/user/sop/index.vue +++ b/mobile-uni/src/pages/user/sop/index.vue @@ -442,7 +442,7 @@ import { resetPageScroll } from '@/services/navigation'; import { ApiError, authenticatedFileUrl, releaseAuthenticatedFileUrl } from '@/services/api'; import { ensureEmployeePosition, fetchMobileIdentity } from '@/services/position'; import { chooseSpeechAudio, createSpeechPlaybackController, measureAudioDuration, MENTOR_VOICE_PROFILE, transcribeSpeechCapture, transcribeSpeechFile } from '@/services/speech'; -import type { SpeechCapture } from '@/services/speech-capture'; +import { isNativeAppRuntime, type SpeechCapture } from '@/services/speech-capture'; import { downloadSummaryCardImage } from '@/services/summary-card-image'; import { getMemoryCandidates } from '@/services/personal-assistant'; import { currentAccountKey } from '@/services/request-scope'; @@ -1209,10 +1209,10 @@ const openKnowledgeResource = async (resource: KnowledgeResource) => { try { if (resource.type === 'FILE') { const downloadUrl = await requestKnowledgeResourceDownloadLink(resource.attachmentId); - if (typeof document !== 'undefined') { + if (!isNativeAppRuntime() && typeof document !== 'undefined') { const link = document.createElement('a'); link.href = downloadUrl; - link.target = '_blank'; + link.download = resource.title || '资料文件'; link.rel = 'noreferrer'; document.body.appendChild(link); link.click(); diff --git a/mobile-uni/tests/ask-memory.test.mjs b/mobile-uni/tests/ask-memory.test.mjs index 867c4f1a..61eaac6e 100644 --- a/mobile-uni/tests/ask-memory.test.mjs +++ b/mobile-uni/tests/ask-memory.test.mjs @@ -29,6 +29,9 @@ test('问师傅支持显式新对话、版本回写和受控原文件或视频 assert.match(page, /releaseAuthenticatedFileUrl\(resource\.localUrl\)/); assert.match(page, /resource\.type === 'VIDEO' && resource\.localUrl/); assert.doesNotMatch(page, /link\.href = localUrl/); + assert.match(page, /!isNativeAppRuntime\(\) && typeof document !== 'undefined'/); + assert.match(page, /link\.download = resource\.title \|\| '资料文件'/); + assert.doesNotMatch(page, /link\.target = '_blank'/); assert.match(page, /link\.rel = 'noreferrer'/); assert.match(page, /点击下载原文件/); assert.match(page, /msg\.result\.rewrittenQuery !== msg\.result\.queryText/);