微信小程序原生預(yù)覽文件
function previewFile(value) {
const fileExtName = `${value.ext}`;
const randFile = new Date().getTime() + fileExtName;
uni.showLoading({
title: '加載中...'
})
wx.downloadFile({
url: value.url, // 文件的本身url
filePath: wx.env.USER_DATA_PATH + '/' + randFile, // 本地自定義的文件名
success: function(res) {
// console.log("filePath", res)
let filePath = res.filePath; // 微信臨時文件路徑(這里要使用自定義的名字文件名,否則打開的文件名是亂碼)
let fileType = value.ext.substring((1));
wx.openDocument({
filePath: filePath,
fileType: fileType,
// showMenu: true, // 是否顯示右上角菜單按鈕 默認(rèn)為false(看自身需求,可要可不要。后期涉及到右上角分享功能)
success: function() {
// console.log("打開文件成功")
},
fail: function() {
// console.log("打開文件失敗,請稍后重試")
}
});
uni.hideLoading();
},
fail: function() {
// console.log("請稍后重試")
}
});
}
uniapp預(yù)覽電子文件
function previewFile(value) {
let fileType = value.ext.substring((1)); //去掉點 如下.doc=>doc
uni.showLoading({
title: '加載中...'
})
uni.downloadFile({
url: value.url,
success: function(res) {
let filePath = res.tempFilePath;
uni.openDocument({
filePath: filePath,
fileType,
success: function(res) {
// console.log('打開文檔成功');
}
});
uni.hideLoading();
}
});
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-647631.html
文章來源:http://www.zghlxwxcb.cn/news/detail-647631.html
到了這里,關(guān)于微信小程序(原生)和uniapp預(yù)覽電子文件doc/pdf/ppt/excel等的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!