appMixins.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import Vue from 'vue'
  2. import { mapState, mapMutations } from 'vuex'
  3. import authorize from '@/common/config/authorize.js'
  4. const appMixins = {
  5. computed: {
  6. ...mapState(['hasLogin', 'isWxAuthorize', 'couponEntry'])
  7. },
  8. methods: {
  9. ...mapMutations(['login', 'logout', 'updateNoticeNum', 'updateRossShow']),
  10. async getWxAuthorize() {
  11. const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  12. const getUserInfo = await authorize.getUserInfo('weixin')
  13. this.UserService.UserLoginAuthApplets({
  14. code: wechatCode,
  15. encryptedData: getUserInfo.encryptedData,
  16. iv: getUserInfo.iv
  17. })
  18. .then(response => {
  19. this.$store.commit('updateStatus', response.data)
  20. this.login(response.data)
  21. this.updateRossShow()
  22. uni.setStorageSync('token', response.data.token)
  23. uni.setStorageSync('unionId', response.data.unionId)
  24. uni.setStorageSync('spUserId', response.data.spUserId)
  25. })
  26. .catch(error => {
  27. this.logout(error.data)
  28. this.$store.commit('updateStatus', error.data)
  29. this.updateRossShow()
  30. uni.setStorageSync('unionId', error.data.unionId)
  31. // if(!this.hasLogin && this.couponEntry === 1){
  32. // if(uni.getStorageSync('isActivitySwitch')){
  33. // const lockTime = uni.getStorageSync('lockTime')
  34. // const eTime = this.diffTime(lockTime)
  35. // this.$store.dispatch('setActivityFn',eTime)
  36. // }else{
  37. // this.$store.dispatch('setActivityFn',true)
  38. // }
  39. // }
  40. })
  41. },
  42. appUpdataRefresh() {
  43. let TIME = (20 * 60) * 1000
  44. setInterval(() => {
  45. this.getWxAuthorize()
  46. }, TIME)
  47. },
  48. diffTime(t) {
  49. let date = Date.now()
  50. return (date - t) < 2 * 60 * 1000 ? false : true
  51. },
  52. async initSetSystemInfo() {
  53. const self = this
  54. // 获取系统信息
  55. const systemInfo = uni.getSystemInfoSync()
  56. console.log('用户设备信息', systemInfo)
  57. const modelmes = systemInfo.model
  58. const model = systemInfo.model
  59. const isIOS = systemInfo.platform === 'ios' || /iPhone/i.test(model)
  60. if (!isIOS) {
  61. this.$store.dispatch('setVariableFun', false)
  62. } else {
  63. // 匹配 iPhone 型号数字部分(如 "iPhone17,3" 匹配到 17)
  64. const versionMatch = model.match(/iPhone(\d+)/)
  65. const versionNumber = versionMatch ? parseInt(versionMatch[1], 10) : 0
  66. // 获取屏幕尺寸信息
  67. const screenHeight = systemInfo.screenHeight
  68. const screenWidth = systemInfo.screenWidth
  69. const screenRatio = screenHeight / screenWidth
  70. // 判断条件(支持最新机型自动适配)
  71. const isFullScreenDevice =
  72. versionNumber >= 10 || // iPhone X(10) 及后续机型
  73. screenRatio >= 2.1 || // 全面屏特征比例
  74. /iPhone1[1-9]|iPhone2\d/i.test(model) // 匹配 iPhone11-29 系列
  75. this.$store.dispatch('setVariableFun', isFullScreenDevice)
  76. }
  77. // #ifndef MP
  78. Vue.prototype.StatusBar = systemInfo.statusBarHeight
  79. if (!isIOS) {
  80. Vue.prototype.CustomBar = systemInfo.statusBarHeight + 50
  81. Vue.prototype.platformClass = true
  82. } else {
  83. Vue.prototype.CustomBar = systemInfo.statusBarHeight + 45
  84. Vue.prototype.platformClass = false
  85. };
  86. // #endif
  87. // #ifdef MP-WEIXIN || MP-QQ
  88. if (!isIOS) {
  89. Vue.prototype.platformClass = 'left'
  90. this.$store.dispatch('setVariableFun', false)
  91. } else {
  92. Vue.prototype.platformClass = 'center'
  93. this.$store.dispatch('setIsIphoneFun', true)
  94. }
  95. Vue.prototype.StatusBar = systemInfo.statusBarHeight
  96. Vue.prototype.fontSizeSetting = systemInfo.fontSizeSetting
  97. Vue.prototype.screenWidth = systemInfo.screenWidth
  98. let capsule = wx.getMenuButtonBoundingClientRect()
  99. Vue.prototype.capsule = capsule
  100. if (capsule) {
  101. Vue.prototype.Custom = capsule
  102. Vue.prototype.CustomBar = capsule.bottom + capsule.top - systemInfo.statusBarHeight
  103. } else {
  104. Vue.prototype.CustomBar = systemInfo.statusBarHeight + 50
  105. }
  106. // #endif
  107. // #ifdef MP-ALIPAY
  108. Vue.prototype.StatusBar = systemInfo.statusBarHeight
  109. Vue.prototype.CustomBar = systemInfo.statusBarHeight + systemInfo.titleBarHeight
  110. // #endif
  111. }
  112. }
  113. }
  114. export default appMixins