index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // pages/index/index.js
  2. var app = getApp();
  3. const request = require("../../utils/request.js");
  4. const login = require("../../utils/login.js");
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. bannerIndex: 0,
  11. bg_color: "#8D7F51",
  12. bannerData: []
  13. },
  14. toUrl(event) {
  15. let url = event.currentTarget.dataset.url;
  16. let jumpType = request.getUrlKey(url, 'jumpType');
  17. if(jumpType == 'app') {
  18. let URL = decodeURIComponent(url)
  19. let jumpUrl = request.getUrlKey(URL, 'miniptogram')
  20. wx.navigateTo({
  21. url: JSON.parse(jumpUrl).path
  22. })
  23. }else if(jumpType == 'H5') {
  24. let jumpUrl = request.getUrlKey(url, 'url')
  25. wx.navigateTo({
  26. url: '../webView/webView?url='+jumpUrl
  27. })
  28. }else if(jumpType == 'miniptogram') {
  29. let path = request.getUrlKey(url, 'path')
  30. let appId = request.getUrlKey(url, 'appId')
  31. wx.navigateToMiniProgram({
  32. appId: appId,
  33. path: path,
  34. extraData: {},
  35. envVersion: 'release',
  36. success(res) {
  37. // 打开成功
  38. }
  39. })
  40. }
  41. },
  42. bindchange(event) {
  43. if(event.detail.source == 'touch'){
  44. this.setData({
  45. bannerIndex: event.detail.current,
  46. bg_color: this.data.bannerData[event.detail.current].bgColor
  47. })
  48. }else if(event.detail.source == 'autoplay'){
  49. this.setData({
  50. bannerIndex: event.detail.current,
  51. bg_color: this.data.bannerData[event.detail.current].bgColor
  52. })
  53. }
  54. },
  55. toBeerWall() {
  56. wx.switchTab({
  57. url: '../beerWall/beerWall'
  58. })
  59. },
  60. toFactory() {
  61. wx.navigateTo({
  62. url: '../beerFactory/beerFactory'
  63. })
  64. },
  65. toBeerStore() {
  66. wx.navigateTo({
  67. url: '../beerStore/beerStore'
  68. })
  69. },
  70. getBannerData() {
  71. let that = this;
  72. request.getData(
  73. 'app/index/banner/list',{bannerType: 'Index'},
  74. res => {
  75. that.setData({
  76. bannerData: res.data.data
  77. })
  78. }
  79. )
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad: function (options) {
  85. this.getBannerData();
  86. //为了符合官方体验规范,暂时屏蔽
  87. // login.getUserInfo().then(res=>{
  88. // this.getTabBar().setData({
  89. // unreadMsgNum: app.globalData.userInfo.unreadMsgNum
  90. // })
  91. // })
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function () {
  102. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  103. this.getTabBar().setData({
  104. selected: 0,
  105. unreadMsgNum: app.globalData.userInfo?app.globalData.userInfo.unreadMsgNum:0
  106. })
  107. }
  108. },
  109. /**
  110. * 生命周期函数--监听页面隐藏
  111. */
  112. onHide: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面卸载
  116. */
  117. onUnload: function () {
  118. },
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {
  123. },
  124. /**
  125. * 页面上拉触底事件的处理函数
  126. */
  127. onReachBottom: function () {
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage: function () {
  133. },
  134. onShareTimeline() {
  135. },
  136. toWebView() {
  137. // wx.navigateTo({
  138. // url: '../webView/webView?url='+request.host+'beer-freshBucket/'
  139. // })
  140. wx.navigateTo({
  141. url: '../beerBox/beerBox'
  142. })
  143. }
  144. })