appMixins.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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'])
  7. },
  8. methods: {
  9. ...mapMutations(['login','logout','isWxAuthorize']),
  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. uni.setStorageSync('token',response.data.token)
  22. uni.setStorageSync('unionId',response.data.unionId)
  23. })
  24. .catch(error =>{
  25. this.logout(error.data)
  26. uni.setStorageSync('unionId',error.data.unionId)
  27. this.$store.commit('updateStatus',error.data)
  28. if(!this.hasLogin){
  29. if(uni.getStorageSync('isActivitySwitch')){
  30. const lockTime = uni.getStorageSync('lockTime')
  31. const eTime = this.diffTime(lockTime)
  32. this.$store.dispatch('setActivityFn',eTime)
  33. }else{
  34. this.$store.dispatch('setActivityFn',true)
  35. }
  36. }
  37. })
  38. },
  39. appUpdataRefresh(){
  40. let TIME = (20*60)*1000
  41. setInterval(()=>{
  42. this.getWxAuthorize()
  43. },TIME)
  44. },
  45. diffTime(t){
  46. let date = Date.now()
  47. return (date -t) < 2*60*1000 ? false : true
  48. },
  49. initSetSystemInfo() {
  50. let self = this
  51. uni.getSystemInfo({
  52. success: function(e) {
  53. let modelmes = e.model
  54. console.log(e)
  55. if (modelmes.search('iPhone 11') !== -1 || modelmes.search('iPhone 11 Pro Max') !==
  56. -1 || modelmes.search('iPhone X') != -1) { //XS,XR,XS MAX均可以适配
  57. self.$store.dispatch('setVariableFun', true)
  58. } else {
  59. self.$store.dispatch('setVariableFun', false)
  60. }
  61. // #ifndef MP
  62. Vue.prototype.StatusBar = e.statusBarHeight
  63. if (e.platform == 'android') {
  64. Vue.prototype.CustomBar = e.statusBarHeight + 50
  65. Vue.prototype.platformClass = true
  66. } else {
  67. Vue.prototype.CustomBar = e.statusBarHeight + 45
  68. Vue.prototype.platformClass = false
  69. };
  70. // #endif
  71. // #ifdef MP-WEIXIN || MP-QQ
  72. console.log(e.platform)
  73. if (e.platform == 'android') {
  74. Vue.prototype.platformClass = 'left'
  75. self.$store.dispatch('setVariableFun', false)
  76. } else {
  77. Vue.prototype.platformClass = 'center'
  78. self.$store.dispatch('setIsIphoneFun', true)
  79. }
  80. Vue.prototype.StatusBar = e.statusBarHeight
  81. Vue.prototype.fontSizeSetting = e.fontSizeSetting
  82. Vue.prototype.screenWidth = e.screenWidth
  83. let capsule = wx.getMenuButtonBoundingClientRect()
  84. Vue.prototype.capsule = capsule
  85. if (capsule) {
  86. Vue.prototype.Custom = capsule
  87. Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
  88. } else {
  89. Vue.prototype.CustomBar = e.statusBarHeight + 50
  90. }
  91. // #endif
  92. // #ifdef MP-ALIPAY
  93. Vue.prototype.StatusBar = e.statusBarHeight
  94. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
  95. // #endif
  96. }
  97. })
  98. }
  99. }
  100. }
  101. export default appMixins