123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- // 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'
- })
- }
- })
|