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.
152 lines
4.4 KiB
152 lines
4.4 KiB
const float = require('../../utils/floatObj');
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true
|
|
},
|
|
properties: {
|
|
// 数据源
|
|
imgList: {
|
|
type: Array,
|
|
value: [],
|
|
observer: "dataChange"
|
|
}
|
|
},
|
|
data: {
|
|
videoContext: null,
|
|
imageHeight: 0,
|
|
visible: false,
|
|
videoUrl: null
|
|
},
|
|
methods: {
|
|
/**
|
|
* 初始化函数
|
|
*/
|
|
init() {
|
|
this.setData({
|
|
imageHeight: float.accDiv(float.accMul(750, 9), 16),
|
|
})
|
|
this.data.videoContext = wx.createVideoContext('video', this)
|
|
},
|
|
isVideoUrl: function (url) {
|
|
if (url && url.indexOf('.mp4') >= 0) {
|
|
return true
|
|
}
|
|
return false
|
|
},
|
|
dataChange(newVal, oldVal) {
|
|
var vindex = -1
|
|
var vurl = null
|
|
var imgList = []
|
|
for (let index = 0; index < newVal.length; index++) {
|
|
const element = newVal[index]
|
|
if (this.isVideoUrl(element)) {
|
|
vindex = index
|
|
vurl = element
|
|
break
|
|
}
|
|
}
|
|
|
|
if (vindex >= 1) {
|
|
newVal.splice(vindex, 1)
|
|
imgList = newVal
|
|
imgList.unshift(vurl)
|
|
this.data.videoContext = wx.createVideoContext('video', this)
|
|
} else if (vindex == 0) {
|
|
imgList = newVal
|
|
this.data.videoContext = wx.createVideoContext('video', this)
|
|
} else {
|
|
imgList = newVal
|
|
}
|
|
this.setData({
|
|
videoUrl: vurl,
|
|
imgList: imgList
|
|
})
|
|
},
|
|
// bindchange: function (event) {
|
|
// if (this.data.videoContext && this.data.status == 1) {
|
|
// this.data.videoContext.pause()
|
|
// }
|
|
// },
|
|
// videoTouch: function () {
|
|
|
|
// if (this.data.timeout) {
|
|
// return
|
|
// }
|
|
// if (!this.data.controls && this.data.status == 1) {
|
|
// this.setData({
|
|
// controls: true
|
|
// })
|
|
// this.data.timeout = setTimeout(() => {
|
|
// this.setData({
|
|
// controls: false
|
|
// })
|
|
// this.data.timeout = null
|
|
// }, 1000)
|
|
// }
|
|
// },
|
|
videoTap: function () {
|
|
this.setData({
|
|
visible: true,
|
|
})
|
|
if (this.data.videoContext) {
|
|
this.data.videoContext.play()
|
|
}
|
|
},
|
|
onClose: function() {
|
|
this.setData({
|
|
visible: false,
|
|
})
|
|
if (this.data.videoContext) {
|
|
this.data.videoContext.pause()
|
|
}
|
|
},
|
|
// bindplay: function () {
|
|
// this.setData({
|
|
// status: 1
|
|
// })
|
|
// this.data.timeout = setTimeout(() => {
|
|
// this.setData({
|
|
// controls: false
|
|
// })
|
|
// this.data.timeout = null
|
|
// }, 1500)
|
|
// },
|
|
// bindpause: function () {
|
|
// this.setData({
|
|
// status: 0,
|
|
// controls: true
|
|
// })
|
|
// if (this.data.timeout) {
|
|
// clearTimeout(this.data.timeout)
|
|
// this.data.timeout = null
|
|
// }
|
|
// },
|
|
bindended: function () {
|
|
this.data.videoContext.exitFullScreen()
|
|
this.setData({
|
|
visible: false
|
|
})
|
|
},
|
|
// 图片查看
|
|
viewImage: function (e) {
|
|
if (e.currentTarget.dataset.url.indexOf('.mp4') >= 0) {
|
|
return
|
|
}
|
|
var imgList = []
|
|
for (let index = 0; index < this.data.imgList.length; index++) {
|
|
if (this.data.imgList[index].indexOf('.mp4') >= 0) {
|
|
continue
|
|
}
|
|
imgList.push(this.data.imgList[index])
|
|
}
|
|
wx.previewImage({
|
|
urls: imgList,
|
|
current: e.currentTarget.dataset.url
|
|
});
|
|
},
|
|
},
|
|
ready() {
|
|
this.init();
|
|
}
|
|
})
|