// miniprogram/pages/marvellous/index.js; const app = getApp(); Page({ imgList: [], downCount: 0, /** * 页面的初始数据 */ data: { pageList: [], select: { count: 0 }, pageType: "", showVideo: "", showAnVideo: true }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.setNavigationBarTitle({ title: options.title || "精彩瞬间" }) this.init(options); }, init(options) { app.globalData.origin[options.type].map(v=> this.imgList.push(v.url)) console.log( app.globalData.origin,options.type) this.setData({ pageList: app.globalData.origin[options.type], pageType: options.type || "img", showAnVideo: options.type === "video" }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, showImg(e) { if (this.data.pageType === "video") return this.showVideo(e); if (this.data.pageType === "img") return this.showImage(e); }, showVideo: function (e) { this.setData({ showVideo: this.imgList[e.currentTarget.dataset.o] }) }, showImage: function (e) { wx.previewImage({ urls: this.imgList, current: this.imgList[e.currentTarget.dataset.o], }) }, longtap: function (e) { // this.setData({ // showSelect: true // }) }, longClose: function (e) { let pageList = this.data.pageList; let select = this.data.select; let keys = Object.keys(select); for (let i = 0; i < keys.length; i++) { let v = keys[i]; if (v === 'count') continue; let li = v.split("-"); pageList[li[0]].list[li[1]].select = false; } this.setData({ pageList, select: { count: 0 } }) }, format: function (res) { if (!res) return "" let T = new Date(res || 0); let year = T.getFullYear(); let month = T.getMonth() + 1; let day = T.getDate(); let hour = T.getHours(); let min = T.getMinutes() + 1; let sec = T.getSeconds(); return year + "-" + (month > 9 ? month : "0" + month) + "-" + day + " " + (hour > 9 ? hour : '0' + hour) + ":" + (min > 9 ? min : '0' + min) + ":" + (sec > 9 ? sec : '0' + sec); }, downEnd: function () { this.downCount--; if (this.downCount <= 0) { wx.hideLoading(); } }, closeVideo: function () { this.setData({ showVideo: "" }) }, closeAnvido: function () { this.setData({ showAnVideo: false }) } })