appMixins.js 4.5 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. computed: {
  6. ...mapState(['hasLogin','isWxAuthorize'])
  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. })
  25. .catch(error =>{
  26. this.logout(error.data)
  27. this.$store.commit('updateStatus',error.data)
  28. this.updateRossShow()
  29. uni.setStorageSync('unionId',error.data.unionId)
  30. if(!this.hasLogin){
  31. if(uni.getStorageSync('isActivitySwitch')){
  32. const lockTime = uni.getStorageSync('lockTime')
  33. const eTime = this.diffTime(lockTime)
  34. this.$store.dispatch('setActivityFn',eTime)
  35. }else{
  36. this.$store.dispatch('setActivityFn',true)
  37. }
  38. }
  39. })
  40. },
  41. appUpdataRefresh(){
  42. let TIME = (20*60)*1000
  43. setInterval(()=>{
  44. this.getWxAuthorize()
  45. },TIME)
  46. },
  47. diffTime(t){
  48. let date = Date.now()
  49. return (date -t) < 2*60*1000 ? false : true
  50. },
  51. initSetSystemInfo() {
  52. let self = this
  53. uni.getSystemInfo({
  54. success: function(e) {
  55. let modelmes = e.model
  56. console.log(e)
  57. if (modelmes.search('iPhone 11') !== -1 || modelmes.search('iPhone 11 Pro Max') !==
  58. -1 || modelmes.search('iPhone X') != -1) { //XS,XR,XS MAX均可以适配
  59. self.$store.dispatch('setVariableFun', true)
  60. } else {
  61. self.$store.dispatch('setVariableFun', false)
  62. }
  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