// pages/picture/picture.js var urlPath = require('../../config.js'); Page({ // 前往下一页 picture() { wx.navigateTo({ url: '/pagesA/pages/picture/picture' }); }, again() { // wx.navigateTo({ url: '/pagesA/pages/sign/sign' }); }, /** * 页面的初始数据 */ data: { img_url:[], swiperCurrent:0, autoplay: false, interval: 3000, duration: 800, //数据 name: wx.getStorageSync('user').name, nm_number:"0", //列表 works_list:[], }, swiperChange: function (e) { // console.log(e); this.setData({ swiperCurrent: e.detail.current }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; var slide_list = []; wx.request({ url: urlPath.getSlideList, header:{ 'token': wx.getStorageSync('token') }, success(res){ if(res.data.code == 0){ if(res.data.data.length > 0){ res.data.data.forEach(function(item){ slide_list.push(urlPath.host + item.src); }); that.setData({ img_url:slide_list }); wx.setStorageSync('img_url', that.data.img_url); } }else{ console.log(res.data.msg); //失败 } } }); }, //小于10的格式化函数(2变成02) timeFormat(param) { return param < 10 ? '0' + param : param; }, //小于0的格式化函数(不会出现负数) timeFormin(param) { return param < 0 ? 0: param; }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { var that = this; var user = wx.getStorageSync('user'); that.getImgs(); }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, onShow:function(){ if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 3 }) } }, getImgs:function(){ var that = this; wx.request({ url: urlPath.getImgs, header:{ 'token': wx.getStorageSync('token') }, success(res){ if(res.data.code == 0){ if(res.data.data.length > 0){ var works_list = []; var num = 0; res.data.data.forEach(function(item, index){ works_list.push({ ids: item.id, img: urlPath.host + item.pic, text: item.explain, number: item.votes, }); num = num + item.votes; }); that.setData({ works_list: works_list, nm_number: num }); } }else{ console.log(res); //失败 } } }); } })