// pages/index/index.js var app = getApp(); const request = require("../../utils/request.js"); const login = require("../../utils/login.js"); Page({ /** * 页面的初始数据 */ data: { bannerIndex: 0, bg_color: "#8D7F51", bannerData: [] }, toUrl(event) { let url = event.currentTarget.dataset.url; let jumpType = request.getUrlKey(url, 'jumpType'); if(jumpType == 'app') { let URL = decodeURIComponent(url) let jumpUrl = request.getUrlKey(URL, 'miniptogram') wx.navigateTo({ url: JSON.parse(jumpUrl).path }) }else if(jumpType == 'H5') { let jumpUrl = request.getUrlKey(url, 'url') wx.navigateTo({ url: '../webView/webView?url='+jumpUrl }) }else if(jumpType == 'miniptogram') { let path = request.getUrlKey(url, 'path') let appId = request.getUrlKey(url, 'appId') wx.navigateToMiniProgram({ appId: appId, path: path, extraData: {}, envVersion: 'release', success(res) { // 打开成功 } }) } }, bindchange(event) { if(event.detail.source == 'touch'){ this.setData({ bannerIndex: event.detail.current, bg_color: this.data.bannerData[event.detail.current].bgColor }) }else if(event.detail.source == 'autoplay'){ this.setData({ bannerIndex: event.detail.current, bg_color: this.data.bannerData[event.detail.current].bgColor }) } }, toBeerWall() { wx.switchTab({ url: '../beerWall/beerWall' }) }, toFactory() { wx.navigateTo({ url: '../beerFactory/beerFactory' }) }, toBeerStore() { wx.navigateTo({ url: '../beerStore/beerStore' }) }, getBannerData() { let that = this; request.getData( 'app/index/banner/list',{bannerType: 'Index'}, res => { that.setData({ bannerData: res.data.data }) } ) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getBannerData(); login.getUserInfo().then(res=>{ this.getTabBar().setData({ unreadMsgNum: app.globalData.userInfo.unreadMsgNum }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 0, unreadMsgNum: app.globalData.userInfo?app.globalData.userInfo.unreadMsgNum:0 }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, onShareTimeline() { }, toWebView() { // wx.navigateTo({ // url: '../webView/webView?url='+request.host+'beer-freshBucket/' // }) wx.navigateTo({ url: '../beerBox/beerBox' }) } })