index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. login.getUserInfo().then(res=>{
  87. this.getTabBar().setData({
  88. unreadMsgNum: app.globalData.userInfo.unreadMsgNum
  89. })
  90. })
  91. },
  92. /**
  93. * 生命周期函数--监听页面初次渲染完成
  94. */
  95. onReady: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  102. this.getTabBar().setData({
  103. selected: 0,
  104. unreadMsgNum: app.globalData.userInfo?app.globalData.userInfo.unreadMsgNum:0
  105. })
  106. }
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide: function () {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload: function () {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh: function () {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage: function () {
  132. },
  133. onShareTimeline() {
  134. },
  135. toWebView() {
  136. // wx.navigateTo({
  137. // url: '../webView/webView?url='+request.host+'beer-freshBucket/'
  138. // })
  139. wx.navigateTo({
  140. url: '../beerBox/beerBox'
  141. })
  142. }
  143. })