更新记录
1.0.2(2025-02-12)
下载此版本
修复已知问题
1.0.1(2025-02-12)
下载此版本
新增支持ofd文件预览(需要安装数科OFD)
1.0.0(2025-02-11)
下载此版本
1.0.0
查看更多
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 4.31,Android:不支持,iOS:不支持,HarmonyNext:支持 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
使用方式
<template>
<button @click="openFile">打开文件</button>
</template>
<script setup>
// #ifdef APP-HARMONY
// 仅鸿蒙会编译
import { previewFile } from '@/uni_modules/speed-filePreview';
// #endif
const openFile = () => {
const url = 'https://xxx.com/1.txt'; //你的文件地址
uni.downloadFile({
url: url,
success: (res) => {
const option = {
url:res.tempFilePath,
title:'1.txt'
}
// #ifdef APP-HARMONY
previewFile(option)
// #endif
}
});
}
</script>
PreviewOption 参数说明
属性 |
类型 |
默认值 |
说明 |
url |
string |
- |
文件的url,必填 |
title |
string |
- |
文件的标题名称,可选 |
width |
number |
800 |
预览窗口的宽度,单位px |
heidth |
number |
800 |
预览窗口的高度,单位px |
支持的文件类型
类型 |
文件后缀 |
MIME 类型 |
文本 |
txt、cpp、c、h、java、xhtml、xml |
text/plain、text/x-c++src、text/x-csrc、text/x-chdr、text/x-java、application/xhtml+xml、text/xml |
网页 |
html、htm |
text/html |
图片 |
jpg、png、gif、webp、bmp、svg |
image/jpeg、image/png、image/gif、image/webp、image/bmp、image/svg+xml |
音频 |
m4a、aac、mp3、ogg、wav |
audio/mp4a-latm、audio/aac、audio/mpeg、audio/ogg、audio/x-wav |
视频 |
mp4、mkv、ts |
video/mp4、video/x-matroska、video/mp2ts |
文档 |
pdf |
application/pdf |
Office 文档 |
doc、docx、xls、xlsx、ppt、pptx、csv、ofd |
application/msword、application/vnd.openxmlformats-officedocument.wordprocessingml.document、application/vnd.ms-excel、application/vnd.openxmlformats-officedocument.spreadsheetml.sheet、application/vnd.ms-powerpoint、application/vnd.openxmlformats-officedocument.presentationml.presentation、text/comma-separated-values |