appMixins.js 4.0 KB

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