app.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //app.js
  2. import $api from './utils/api'
  3. import {
  4. BASEIMGURL,
  5. BASEIMGURL1
  6. } from './utils/config';
  7. import GlobalConfig from './config/index'
  8. const globalConfig = new GlobalConfig()
  9. globalConfig.init()
  10. App({
  11. onLaunch() {
  12. console.log('v1.0')
  13. const that = this;
  14. wx.getSystemInfo({
  15. success:function(res){
  16. that.globalData.systemInfo = res;
  17. }
  18. })
  19. if (wx.canIUse('getUpdateManager')) {
  20. const updateManager = wx.getUpdateManager()
  21. updateManager.onCheckForUpdate(function (res) {
  22. if (res.hasUpdate) {
  23. updateManager.onUpdateReady(function () {
  24. wx.showModal({
  25. title: '更新提示',
  26. content: '新版本已经准备好,是否重启应用?',
  27. success: function (res) {
  28. if (res.confirm) {
  29. updateManager.applyUpdate()
  30. }
  31. }
  32. })
  33. })
  34. updateManager.onUpdateFailed(function () {
  35. wx.showModal({
  36. title: '已经有新版本了哟~',
  37. content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
  38. })
  39. })
  40. }
  41. })
  42. } else {
  43. wx.showModal({
  44. title: '提示',
  45. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  46. })
  47. }
  48. this.getUserLocation();
  49. // 登录
  50. wx.login({
  51. success: res => {
  52. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  53. this.globalData.api.getOpenid({
  54. code: res.code
  55. }).then(res => {
  56. this.globalData.userInfo = res.data
  57. wx.setStorageSync('openid', res.data.openid)
  58. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  59. // 所以此处加入 callback 以防止这种情况
  60. if (this.userInfoReadyCallback) {
  61. this.userInfoReadyCallback(res.data)
  62. }
  63. })
  64. }
  65. });
  66. // 获取用户信息
  67. // wx.getSetting({
  68. // success: res => {
  69. // if (res.authSetting['scope.userInfo']) {
  70. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  71. // wx.getUserInfo({
  72. // success: res => {
  73. // // 可以将 res 发送给后台解码出 unionId
  74. // this.globalData.userInfo = res.userInfo
  75. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  76. // // 所以此处加入 callback 以防止这种情况
  77. // if (this.userInfoReadyCallback) {
  78. // this.userInfoReadyCallback(res)
  79. // }
  80. // }
  81. // })
  82. // }
  83. // }
  84. // })
  85. },
  86. // 获取用户位置
  87. getUserLocation() {
  88. let _this = this
  89. wx.getLocation({
  90. altitude: 'altitude',
  91. type: 'gcj02',
  92. success: function (res) {
  93. // const userLocation = {
  94. // longitude: res.longitude,
  95. // latitude: res.latitude
  96. // }
  97. // _this.globalData.userLocation = userLocation
  98. // _this.globalData.refuse_position = false
  99. },
  100. fail() {}
  101. })
  102. },
  103. onShareAppMessage() {
  104. const openid = wx.getStorageSync('openid')
  105. let param = openid && typeof openid === 'string' ? `pages/index/index?openid=${ openid }` : `pages/index/index`
  106. return {
  107. title: '点一杯咖啡,聚一簇伙伴,聊一片天地',
  108. desc: '快来参加活动吧~',
  109. // imageUrl: 'https://cirraybucket.oss-cn-shanghai.aliyuncs.com/nowwa-h5/aboutUs/share.jpg',
  110. path: param
  111. }
  112. },
  113. globalData: {
  114. userInfo: null,
  115. api: $api,
  116. openid: '',
  117. BASEIMGURL,
  118. BASEIMGURL1,
  119. shareOpenId: '', //是否是分享进入
  120. config: globalConfig,
  121. imgList: [],
  122. systemInfo:{}
  123. }
  124. })