app.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {
  2. GetQueryString
  3. } from 'utils/util'
  4. import {
  5. userLogin
  6. } from '~/api/user'
  7. // const Towxml = require('/towxml/main');
  8. App({
  9. watch(method) {
  10. let obj = this.globalData
  11. // 这里监听 openId
  12. Object.defineProperty(obj, "openId", {
  13. configurable: true,
  14. enumerable: true,
  15. set: function (value) {
  16. console.log('zzeweqweqw', value);
  17. method(value) // 触发页面回调函数
  18. }
  19. })
  20. },
  21. async onLaunch(options) {
  22. wx.login({
  23. success(res) {
  24. if (res.code) {
  25. console.log(res.code);
  26. // 获取openid
  27. userLogin({
  28. code: res.code,
  29. grade: null
  30. }).then(res => {
  31. console.log(res);
  32. })
  33. }
  34. }
  35. })
  36. // 判断设备是否为 iPhone X
  37. this.checkIsIPhoneX()
  38. options.referrerInfo.extraData && (this.globalData.upgradeHide = options.referrerInfo.extraData.upgrade)
  39. },
  40. globalData: {
  41. isIPX: false, // 当前设备是否为 iPhone X
  42. isIOS: false, // 判断设备是否为苹果
  43. userInfo: null,
  44. statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
  45. userGrade: '二年级',
  46. upgradeHide: true,
  47. openId: null
  48. },
  49. checkIsIPhoneX: function () {
  50. const self = this
  51. wx.getSystemInfo({
  52. success: function (res) {
  53. // 根据 model 进行判断
  54. console.log(res)
  55. console.log(res.system.search('iOS'))
  56. if (res.model.search('iPhone X') != -1) {
  57. self.globalData.isIPX = true
  58. }
  59. if (res.system.search('iOS') != -1) {
  60. self.globalData.isIOS = true
  61. }
  62. }
  63. })
  64. },
  65. // towxml: new Towxml()
  66. })