104 lines
2.4 KiB
JavaScript
104 lines
2.4 KiB
JavaScript
// template/bannerAD/bannerAD.js
|
|
var miucms = require('../../utils/miucms.js');
|
|
var app = getApp()
|
|
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
item:Object,
|
|
index:Number
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
controls:false,
|
|
// fit:'cover',
|
|
showBig:false,
|
|
isvideo:false,
|
|
height:225
|
|
},
|
|
lifetimes: {
|
|
attached: function () {
|
|
this.attachedIn()
|
|
},
|
|
},
|
|
attached: function () {
|
|
this.attachedIn()
|
|
},
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
videoID:'',
|
|
methods: {
|
|
attachedIn(){
|
|
let that = this;
|
|
let imgArr = ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tiff', '.webp'];
|
|
let videoArr = ['mp4', '3gp', 'm3u8'];
|
|
if (videoArr.indexOf(this.properties.item.annex.extension)>-1){
|
|
this.setData({
|
|
isvideo:true,
|
|
},function(){
|
|
that.observe()
|
|
that.calculate()
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
observe() {
|
|
var that = this;
|
|
this.videoID = wx.createVideoContext('video' + this.properties.index, this)
|
|
|
|
let top = -app.globalData.screen_data.totalTopHeight -100 || -168;
|
|
this.createIntersectionObserver().relativeToViewport({ top }).observe(`#video${this.properties.index}`, res => {
|
|
if (res.intersectionRatio > 0) {
|
|
that.videoID.play()
|
|
} else {
|
|
that.videoID.pause()
|
|
}
|
|
})
|
|
|
|
},
|
|
bindtimeupdate(e){
|
|
// console.log(e)
|
|
this.currentTime = e.detail.currentTime;
|
|
},
|
|
currentTime:0,
|
|
calculate(){
|
|
let that = this;
|
|
const query = this.createSelectorQuery();
|
|
query.select('#video' + this.properties.index).boundingClientRect(function (rect) {
|
|
// console.log(rect.width)
|
|
that.setData({
|
|
height: rect.width * that.properties.item.annex.height / that.properties.item.annex.width
|
|
})
|
|
|
|
}).exec();
|
|
},
|
|
topage(){
|
|
miucms.clickAD(this.properties.item.id)
|
|
if (this.properties.item.path){
|
|
wx.navigateTo({
|
|
url: '/' + this.properties.item.path,
|
|
})
|
|
}else{
|
|
// 直接将图片或者视频放大
|
|
if (this.data.isvideo) {
|
|
|
|
wx.navigateTo({
|
|
url: `/pages/video_show/video_show?loop=true&src=${this.properties.item.annex.url}`,
|
|
})
|
|
}else{
|
|
wx.previewImage({
|
|
urls: [this.properties.item.annex.url],
|
|
// current:0
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|