123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import Vue from 'vue'
- import { mapState,mapMutations} from 'vuex'
- import authorize from '@/common/config/authorize.js'
- const appMixins = {
- data() {
- return {
- authParams: {
- code: '',
- encryptedData: '',
- iv: ''
- },
- modelMap : { // 苹果系统
- 'iPhone X': true,
- 'iPhone 11 Pro Max':true,
- 'iPhone 11<iPhone12,1>':true,
- 'iPhone 12<iPhone13,2>':true,
- 'iPhone 13<iPhone14,5>':true,
- }
- }
- },
- computed: {
- ...mapState(['hasLogin','isWxAuthorize'])
- },
- methods: {
- ...mapMutations(['login','logout','updateNoticeNum']),
- // 授权登录
- async authApplets() {
- try {
- const wechatCode = await authorize.getCode('weixin')
- const getUserInfo = await authorize.getUserInfo('weixin')
- this.authParams.code = wechatCode
- this.authParams.encryptedData = getUserInfo.encryptedData
- this.authParams.iv = getUserInfo.iv
- //授权登录
- const res = await this.UserService.UserLoginAuthApplets(this.authParams)
- this.userId = res.data.userId
- this.$store.commit('updateStatus', res.data)
- this.login(res.data)
- uni.setStorageSync('token', res.data.token)
- uni.setStorageSync('unionId', res.data.unionId)
- } catch (error) {
- this.logout()
- uni.setStorageSync('unionId', error.data.unionId)
- this.$store.commit('updateStatus', error.data)
- }
- },
- appUpdataRefresh(){
- let TIME = (20*60)*1000
- setInterval(()=>{
- this.authApplets()
- },TIME)
- },
- diffTime(t){
- let date = Date.now()
- return (date -t) < 2*60*1000 ? false : true
- },
- async initSetSystemInfo() {
- let self = this
- uni.getSystemInfo({
- success: function(e) {
- console.log('System',e)
- self.$store.dispatch('setVariableFun', self.modelMap[e.model])
- // #ifndef MP
- Vue.prototype.StatusBar = e.statusBarHeight
- if (e.platform == 'android') {
- Vue.prototype.CustomBar = e.statusBarHeight + 50
- Vue.prototype.platformClass = true
- } else {
- Vue.prototype.CustomBar = e.statusBarHeight + 45
- Vue.prototype.platformClass = false
- };
- // #endif
- // #ifdef MP-WEIXIN || MP-QQ
- console.log(e.platform)
- if (e.platform == 'android') {
- Vue.prototype.platformClass = 'left'
- self.$store.dispatch('setVariableFun', false)
- } else {
- Vue.prototype.platformClass = 'center'
- self.$store.dispatch('setIsIphoneFun', true)
- }
- Vue.prototype.StatusBar = e.statusBarHeight
- Vue.prototype.fontSizeSetting = e.fontSizeSetting
- Vue.prototype.screenWidth = e.screenWidth
- let capsule = wx.getMenuButtonBoundingClientRect()
- Vue.prototype.capsule = capsule
- if (capsule) {
- Vue.prototype.Custom = capsule
- Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
- } else {
- Vue.prototype.CustomBar = e.statusBarHeight + 50
- }
- // #endif
- // #ifdef MP-ALIPAY
- Vue.prototype.StatusBar = e.statusBarHeight
- Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
- // #endif
- }
- })
- }
- }
- }
- export default appMixins
|