appMixins.js 4.1 KB

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