wxml部分:
<view class="content">
<van-cell title="{{index+1}}.{{item.descripts}}" is-link wx:for="{{helpDetail}}" wx:key="index" bindtap="goToDetail" data-id="{{item.url}}" />
</view>
js部分:
goToDetail:function(e){
if(this.data.loading){
return
}
let url = e.currentTarget.dataset.id; //pdf圖片地址
let _this = this;
if (url != "") {
if ((this.data.platform != "") && (this.data.platform != "ios")) {
//非IOS設備打開文檔
this.setData({
loading: true
}, () => {
this.openDocument(url);
})
} else {
if (this.data.platform == "") {
//未獲取到設備信息
wx.getSystemInfo({
success: function(res) {
_this.setData({
platform: res.platform
})
if (res.platform != 'ios') {
_this.setData({
loading: true
}, () => {
_this.openDocument(url);
})
}
}
})
} else {
//IOS 設備
wx.navigateTo({
url: '../questionDetail/detail?url='+url,
})
}
}
} else {
wx.showToast({
title: '無幫助文檔',
icon: false,
})
}
},
/**
* 打開文檔
*/
openDocument: function(url) {
let _this = this;
wx.downloadFile({
url: url,
success: function(res) {
console.log(res)
var Path = res.tempFilePath //返回的文件臨時地址,用於后面打開本地預覽所用
wx.openDocument({
filePath: Path,
success: function(res) {
_this.setData({
loading: false,
})
}
})
},
fail: function(res) {
wx.showToast({
title: '文檔加載失敗',
icon: 'none',
})
_this.setData({
loading: false,
})
}
})
},