start.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const WXAPI = require('apifm-wxapi')
  2. const CONFIG = require('../../config.js')
  3. //获取应用实例
  4. var app = getApp();
  5. Page({
  6. data: {
  7. banners:[],
  8. swiperMaxNumber: 0,
  9. swiperCurrent: 0
  10. },
  11. onLoad:function(){
  12. const _this = this
  13. wx.setNavigationBarTitle({
  14. title: wx.getStorageSync('mallName')
  15. })
  16. let shopMod = wx.getStorageSync('shopMod')
  17. if (!shopMod) {
  18. shopMod = 0
  19. }
  20. const app_show_pic_version = wx.getStorageSync('app_show_pic_version')
  21. if (app_show_pic_version && app_show_pic_version == CONFIG.version) {
  22. if (shopMod==1) {
  23. wx.redirectTo({
  24. url: '/pages/shop/select',
  25. });
  26. } else {
  27. wx.switchTab({
  28. url: '/pages/index/index',
  29. });
  30. }
  31. } else {
  32. // 展示启动页
  33. WXAPI.banners({
  34. type: 'app'
  35. }).then(function (res) {
  36. if (res.code == 700) {
  37. if (shopMod==1) {
  38. wx.redirectTo({
  39. url: '/pages/shop/select',
  40. });
  41. } else {
  42. wx.switchTab({
  43. url: '/pages/index/index',
  44. });
  45. }
  46. } else {
  47. _this.setData({
  48. banners: res.data,
  49. swiperMaxNumber: res.data.length
  50. });
  51. }
  52. }).catch(function (e) {
  53. if (shopMod==1) {
  54. wx.redirectTo({
  55. url: '/pages/shop/select',
  56. });
  57. } else {
  58. wx.switchTab({
  59. url: '/pages/index/index',
  60. });
  61. }
  62. })
  63. }
  64. },
  65. onShow:function(){
  66. },
  67. swiperchange: function (e) {
  68. //console.log(e.detail.current)
  69. this.setData({
  70. swiperCurrent: e.detail.current
  71. })
  72. },
  73. goToIndex: function (e) {
  74. let shopMod = wx.getStorageSync('shopMod')
  75. if (!shopMod) {
  76. shopMod = 0
  77. }
  78. if (app.globalData.isConnected) {
  79. wx.setStorage({
  80. key: 'app_show_pic_version',
  81. data: CONFIG.version
  82. })
  83. if (shopMod == 1) {
  84. wx.redirectTo({
  85. url: '/pages/shop/select',
  86. });
  87. } else {
  88. wx.switchTab({
  89. url: '/pages/index/index',
  90. });
  91. }
  92. } else {
  93. wx.showToast({
  94. title: '当前无网络',
  95. icon: 'none',
  96. })
  97. }
  98. },
  99. imgClick(){
  100. if (this.data.swiperCurrent + 1 != this.data.swiperMaxNumber) {
  101. wx.showToast({
  102. title: '左滑进入',
  103. icon: 'none',
  104. })
  105. }
  106. }
  107. });