app.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. const WXAPI = require('apifm-wxapi')
  2. const CONFIG = require('config.js')
  3. const AUTH = require('utils/auth')
  4. App({
  5. onLaunch: function() {
  6. const subDomain = wx.getExtConfigSync().subDomain
  7. if (subDomain) {
  8. WXAPI.init(subDomain)
  9. } else {
  10. WXAPI.init(CONFIG.subDomain)
  11. WXAPI.setMerchantId(CONFIG.merchantId)
  12. }
  13. const that = this;
  14. // 检测新版本
  15. const updateManager = wx.getUpdateManager()
  16. updateManager.onUpdateReady(function () {
  17. wx.showModal({
  18. title: '更新提示',
  19. content: '新版本已经准备好,是否重启应用?',
  20. success(res) {
  21. if (res.confirm) {
  22. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  23. updateManager.applyUpdate()
  24. }
  25. }
  26. })
  27. })
  28. /**
  29. * 初次加载判断网络情况
  30. * 无网络状态下根据实际情况进行调整
  31. */
  32. wx.getNetworkType({
  33. success(res) {
  34. const networkType = res.networkType
  35. if (networkType === 'none') {
  36. that.globalData.isConnected = false
  37. wx.showToast({
  38. title: '当前无网络',
  39. icon: 'loading',
  40. duration: 2000
  41. })
  42. }
  43. }
  44. });
  45. /**
  46. * 监听网络状态变化
  47. * 可根据业务需求进行调整
  48. */
  49. wx.onNetworkStatusChange(function(res) {
  50. if (!res.isConnected) {
  51. that.globalData.isConnected = false
  52. wx.showToast({
  53. title: '网络已断开',
  54. icon: 'loading',
  55. duration: 2000
  56. })
  57. } else {
  58. that.globalData.isConnected = true
  59. wx.hideToast()
  60. }
  61. })
  62. // WXAPI.queryConfigBatch('mallName,WITHDRAW_MIN,ALLOW_SELF_COLLECTION,order_hx_uids,subscribe_ids,share_profile,adminUserIds,goodsDetailSkuShowType,shopMod,needIdCheck,balance_pay_pwd,shipping_address_gps,shipping_address_region_level,shopping_cart_vop_open,cps_open,recycle_open,categoryMod,hide_reputation,show_seller_number,show_goods_echarts,show_buy_dynamic,goods_search_show_type,show_3_seller,show_quan_exchange_score,show_score_exchange_growth,show_score_sign,fx_subscribe_ids,share_pic,orderPeriod_open,order_pay_user_balance,wxpay_api_url,sphpay_open,fx_type').then(res => {
  63. // if (res.code == 0) {
  64. // res.data.forEach(config => {
  65. // wx.setStorageSync(config.key, config.value);
  66. // })
  67. // if (this.configLoadOK) {
  68. // this.configLoadOK()
  69. // }
  70. // // wx.setStorageSync('shopMod', '1') // 测试用,不要取消注释
  71. // }
  72. // })
  73. // ---------------检测navbar高度
  74. let menuButtonObject = wx.getMenuButtonBoundingClientRect();
  75. console.log("小程序胶囊信息",menuButtonObject)
  76. wx.getSystemInfo({
  77. success: res => {
  78. let statusBarHeight = res.statusBarHeight,
  79. navTop = menuButtonObject.top,//胶囊按钮与顶部的距离
  80. navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight)*2;//导航高度
  81. this.globalData.navHeight = navHeight;
  82. this.globalData.navTop = navTop;
  83. this.globalData.windowHeight = res.windowHeight;
  84. this.globalData.menuButtonObject = menuButtonObject;
  85. console.log("navHeight",navHeight);
  86. },
  87. fail(err) {
  88. console.log(err);
  89. }
  90. })
  91. },
  92. onShow (e) {
  93. // 保存邀请人
  94. if (e && e.query && e.query.inviter_id) {
  95. wx.setStorageSync('referrer', e.query.inviter_id)
  96. if (e.shareTicket) {
  97. wx.getShareInfo({
  98. shareTicket: e.shareTicket,
  99. success: res => {
  100. wx.login({
  101. success(loginRes) {
  102. if (loginRes.code) {
  103. WXAPI.shareGroupGetScore(
  104. loginRes.code,
  105. e.query.inviter_id,
  106. res.encryptedData,
  107. res.iv
  108. ).then(_res => {
  109. console.log(_res)
  110. }).catch(err => {
  111. console.error(err)
  112. })
  113. } else {
  114. console.error('登录失败!' + loginRes.errMsg)
  115. }
  116. }
  117. })
  118. }
  119. })
  120. }
  121. }
  122. 自动登录
  123. AUTH.checkHasLogined().then(isLogined => {
  124. if (!isLogined) {
  125. AUTH.authorize().then( aaa => {
  126. AUTH.bindSeller()
  127. })
  128. } else {
  129. AUTH.bindSeller()
  130. }
  131. })
  132. },
  133. globalData: {
  134. isConnected: true,
  135. sdkAppID: CONFIG.sdkAppID
  136. }
  137. })