// pages/info/guideInfo/index.js import commonApi from "../../../utils/https/common" Page({ /** * 页面的初始数据 */ data: { info:null, images:[], page:0 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { commonApi._post("travels/getDetail",{ id:options.id }).then(res=>{ console.log(res) let images = []; //匹配图片(g表示匹配所有结果i表示区分大小写) var imgReg = /|\/>)/gi; //匹配src属性 var srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; var arr = res.data.detail.match(imgReg); for (var i = 0; i < arr.length; i++) { var src = arr[i].match(srcReg); //获取图片地址 if (src[1]) { images.push(src[1]) } } this.setData({ images:images }) }) commonApi._post("travels/addView",{ id:options.id }).then(res=>{ }) }, prevPage:function(){ if(this.data.page==0) return; this.setData({ page:this.data.page-1 }) }, nextPage:function(){ if(this.data.page==this.data.images.length-1) return; this.setData({ page:this.data.page+1 }) }, changePage:function(e){ this.setData({ page:e.detail.current }) }, showImg:function(e){ // wx.showLoading({ // title: '加载中' // }) wx.previewImage({ urls: this.data.images, current:e.currentTarget.dataset.img }) return; wx.downloadFile({ url: e.currentTarget.dataset.img, success:function(res){ if (res.statusCode === 200) { wx.previewImage({ urls: [res.tempFilePath], current:res.tempFilePath }) } }, complete:function(){ wx.hideLoading({ }) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })