continuous-integration/drone/tag Build is passing
鸿蒙微信 ArkWeb 下 H5 window.open 常静默失败,仅出现「开始下载…」。 OA/市场附件在小程序 WebView 内改为跳转 pages/oa/file-preview, 用 uni.downloadFile + openDocument 打开,浏览器环境仍用预签名直链。 Refs: #74 Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
/**
|
|
* OA / 市场附件:小程序宿主预览页的 query 与 openDocument 类型
|
|
*/
|
|
|
|
import {
|
|
pickQueryValue,
|
|
safeDecodeURIComponent
|
|
} from './oa-pdf-preview-query.js'
|
|
|
|
const OPEN_DOCUMENT_EXTS = {
|
|
pdf: 'pdf',
|
|
doc: 'doc',
|
|
docx: 'docx',
|
|
xls: 'xls',
|
|
xlsx: 'xlsx',
|
|
ppt: 'ppt',
|
|
pptx: 'pptx'
|
|
}
|
|
|
|
export function fileExtension(fileName) {
|
|
const match = String(fileName || '')
|
|
.trim()
|
|
.toLowerCase()
|
|
.match(/\.([a-z0-9]+)$/)
|
|
return match ? match[1] : ''
|
|
}
|
|
|
|
export function openDocumentFileType(fileName) {
|
|
const ext = fileExtension(fileName)
|
|
return OPEN_DOCUMENT_EXTS[ext] || ''
|
|
}
|
|
|
|
/**
|
|
* @returns {{ fileUrl: string, legacyUrl: string, name: string, fileType: string, rawKeys: string[] }}
|
|
*/
|
|
export function parseFilePreviewQuery(query) {
|
|
const rawKeys = Object.keys(query && typeof query === 'object' ? query : {})
|
|
const fileUrl = safeDecodeURIComponent(
|
|
pickQueryValue(query, ['fileUrl', 'fileurl', 'file_url', 'f'])
|
|
)
|
|
const legacyUrl = safeDecodeURIComponent(
|
|
pickQueryValue(query, ['url', 'downloadUrl', 'download_url'])
|
|
)
|
|
const name =
|
|
safeDecodeURIComponent(pickQueryValue(query, ['name', 'fileName', 'file_name', 'n'])) ||
|
|
'file.bin'
|
|
const fileType =
|
|
safeDecodeURIComponent(pickQueryValue(query, ['fileType', 'file_type', 't'])) ||
|
|
openDocumentFileType(name)
|
|
return { fileUrl, legacyUrl, name, fileType, rawKeys }
|
|
}
|