appMixins.js 5.4 KB

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