appMixins.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import Vue from 'vue'
  2. import { mapState,mapMutations} from 'vuex'
  3. import authorize from '@/common/config/authorize.js'
  4. const appMixins = {
  5. data() {
  6. return {
  7. authParams: {
  8. code: '',
  9. encryptedData: '',
  10. iv: ''
  11. },
  12. modelMap : { // 苹果系统
  13. 'iPhone X': true,
  14. 'iPhone 11 Pro Max':true,
  15. 'iPhone 11<iPhone12,1>':true,
  16. 'iPhone 12<iPhone13,2>':true,
  17. 'iPhone 13<iPhone14,5>':true,
  18. }
  19. }
  20. },
  21. computed: {
  22. ...mapState(['hasLogin','isWxAuthorize'])
  23. },
  24. methods: {
  25. ...mapMutations(['login','logout','updateNoticeNum']),
  26. // 授权登录
  27. async authApplets() {
  28. try {
  29. const wechatCode = await authorize.getCode('weixin')
  30. const getUserInfo = await authorize.getUserInfo('weixin')
  31. this.authParams.code = wechatCode
  32. this.authParams.encryptedData = getUserInfo.encryptedData
  33. this.authParams.iv = getUserInfo.iv
  34. //授权登录
  35. const res = await this.UserService.UserLoginAuthApplets(this.authParams)
  36. this.userId = res.data.userId
  37. this.$store.commit('updateStatus', res.data)
  38. this.login(res.data)
  39. uni.setStorageSync('token', res.data.token)
  40. uni.setStorageSync('unionId', res.data.unionId)
  41. } catch (error) {
  42. this.logout()
  43. uni.setStorageSync('unionId', error.data.unionId)
  44. this.$store.commit('updateStatus', error.data)
  45. }
  46. },
  47. appUpdataRefresh(){
  48. let TIME = (20*60)*1000
  49. setInterval(()=>{
  50. this.authApplets()
  51. },TIME)
  52. },
  53. diffTime(t){
  54. let date = Date.now()
  55. return (date -t) < 2*60*1000 ? false : true
  56. },
  57. async initSetSystemInfo() {
  58. let self = this
  59. uni.getSystemInfo({
  60. success: function(e) {
  61. console.log('System',e)
  62. self.$store.dispatch('setVariableFun', self.modelMap[e.model])
  63. // #ifndef MP
  64. Vue.prototype.StatusBar = e.statusBarHeight
  65. if (e.platform == 'android') {
  66. Vue.prototype.CustomBar = e.statusBarHeight + 50
  67. Vue.prototype.platformClass = true
  68. } else {
  69. Vue.prototype.CustomBar = e.statusBarHeight + 45
  70. Vue.prototype.platformClass = false
  71. };
  72. // #endif
  73. // #ifdef MP-WEIXIN || MP-QQ
  74. console.log(e.platform)
  75. if (e.platform == 'android') {
  76. Vue.prototype.platformClass = 'left'
  77. self.$store.dispatch('setVariableFun', false)
  78. } else {
  79. Vue.prototype.platformClass = 'center'
  80. self.$store.dispatch('setIsIphoneFun', true)
  81. }
  82. Vue.prototype.StatusBar = e.statusBarHeight
  83. Vue.prototype.fontSizeSetting = e.fontSizeSetting
  84. Vue.prototype.screenWidth = e.screenWidth
  85. let capsule = wx.getMenuButtonBoundingClientRect()
  86. Vue.prototype.capsule = capsule
  87. if (capsule) {
  88. Vue.prototype.Custom = capsule
  89. Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
  90. } else {
  91. Vue.prototype.CustomBar = e.statusBarHeight + 50
  92. }
  93. // #endif
  94. // #ifdef MP-ALIPAY
  95. Vue.prototype.StatusBar = e.statusBarHeight
  96. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
  97. // #endif
  98. }
  99. })
  100. }
  101. }
  102. }
  103. export default appMixins