appMixins.js 4.0 KB

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