index.js 3.0 KB

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