You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.0 KiB
81 lines
2.0 KiB
const math = require('../../utils/math') //导入模块
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
properties: {
|
|
imageList: {
|
|
type: Array,
|
|
value: []
|
|
},
|
|
clickable: {
|
|
type: Boolean,
|
|
value: false
|
|
},
|
|
column: {
|
|
type: Number,
|
|
value: 5
|
|
}
|
|
},
|
|
data: {
|
|
width: '138rpx',
|
|
heightList: []
|
|
},
|
|
observers: {
|
|
'column': function () {
|
|
var square = math.minus(math.divide(750, this.data.column), 12) + 'rpx'
|
|
this.setData({ width: square })
|
|
}
|
|
},
|
|
methods: {
|
|
viewImage: function (e) {
|
|
if (!this.data.clickable) {
|
|
return
|
|
}
|
|
var index = e.currentTarget.dataset.index
|
|
var url = this.data.imageList[index]
|
|
if (this.isPdfUrl(url)) {
|
|
var filepath = wx.env.USER_DATA_PATH + url.substring(url.lastIndexOf('/'))
|
|
// 1: 获取本地是否有文件,
|
|
wx.getFileInfo({
|
|
filePath: filepath,
|
|
success (res) {
|
|
// 2: 如果有变打开
|
|
wx.openDocument({ filePath: filepath })
|
|
},
|
|
fail: function (error) {
|
|
// 2: 没有就开始下载
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
wx.downloadFile({
|
|
url: url,
|
|
filePath: filepath,
|
|
// 3: 下载之后便打开
|
|
success: function (res) {
|
|
wx.openDocument({filePath: res.filePath})
|
|
},
|
|
complete: function (res) {
|
|
wx.hideLoading()
|
|
}
|
|
})
|
|
}
|
|
})
|
|
return
|
|
}
|
|
var imgList = []
|
|
for (let index = 0; index < this.data.imageList.length; index++) {
|
|
if(!this.isPdfUrl(this.data.imageList[index])){
|
|
imgList.push(this.data.imageList[index])
|
|
}
|
|
}
|
|
wx.previewImage({ urls: imgList, current: url })
|
|
},
|
|
isPdfUrl: function (url) {
|
|
if (url && (url.indexOf('.pdf') >= 0 || url.indexOf('.PDF') >= 0)) {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
}
|
|
})
|