123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import Vue from 'vue'
- import { mapState, mapMutations } from 'vuex'
- import authorize from '@/common/config/authorize.js'
- const appMixins = {
- computed: {
- ...mapState(['hasLogin', 'isWxAuthorize', 'couponEntry'])
- },
- methods: {
- ...mapMutations(['login', 'logout', 'updateNoticeNum', 'updateRossShow']),
- async getWxAuthorize() {
- const wechatCode = await authorize.getCode('weixin') // 根据微信的code获取用户登录状态:1已登录过 -1未登录过
- const getUserInfo = await authorize.getUserInfo('weixin')
- this.UserService.UserLoginAuthApplets({
- code: wechatCode,
- encryptedData: getUserInfo.encryptedData,
- iv: getUserInfo.iv
- })
- .then(response => {
- this.$store.commit('updateStatus', response.data)
- this.login(response.data)
- this.updateRossShow()
- uni.setStorageSync('token', response.data.token)
- uni.setStorageSync('unionId', response.data.unionId)
- uni.setStorageSync('spUserId', response.data.spUserId)
- })
- .catch(error => {
- this.logout(error.data)
- this.$store.commit('updateStatus', error.data)
- this.updateRossShow()
- uni.setStorageSync('unionId', error.data.unionId)
- // if(!this.hasLogin && this.couponEntry === 1){
- // if(uni.getStorageSync('isActivitySwitch')){
- // const lockTime = uni.getStorageSync('lockTime')
- // const eTime = this.diffTime(lockTime)
- // this.$store.dispatch('setActivityFn',eTime)
- // }else{
- // this.$store.dispatch('setActivityFn',true)
- // }
- // }
- })
- },
- appUpdataRefresh() {
- let TIME = (20 * 60) * 1000
- setInterval(() => {
- this.getWxAuthorize()
- }, TIME)
- },
- diffTime(t) {
- let date = Date.now()
- return (date - t) < 2 * 60 * 1000 ? false : true
- },
- async initSetSystemInfo() {
- const self = this
- // 获取系统信息
- const systemInfo = uni.getSystemInfoSync()
- console.log('用户设备信息', systemInfo)
- const modelmes = systemInfo.model
- const model = systemInfo.model
- const isIOS = systemInfo.platform === 'ios' || /iPhone/i.test(model)
- if (!isIOS) {
- this.$store.dispatch('setVariableFun', false)
- } else {
- // 匹配 iPhone 型号数字部分(如 "iPhone17,3" 匹配到 17)
- const versionMatch = model.match(/iPhone(\d+)/)
- const versionNumber = versionMatch ? parseInt(versionMatch[1], 10) : 0
- // 获取屏幕尺寸信息
- const screenHeight = systemInfo.screenHeight
- const screenWidth = systemInfo.screenWidth
- const screenRatio = screenHeight / screenWidth
- // 判断条件(支持最新机型自动适配)
- const isFullScreenDevice =
- versionNumber >= 10 || // iPhone X(10) 及后续机型
- screenRatio >= 2.1 || // 全面屏特征比例
- /iPhone1[1-9]|iPhone2\d/i.test(model) // 匹配 iPhone11-29 系列
- this.$store.dispatch('setVariableFun', isFullScreenDevice)
- }
- // #ifndef MP
- Vue.prototype.StatusBar = systemInfo.statusBarHeight
- if (!isIOS) {
- Vue.prototype.CustomBar = systemInfo.statusBarHeight + 50
- Vue.prototype.platformClass = true
- } else {
- Vue.prototype.CustomBar = systemInfo.statusBarHeight + 45
- Vue.prototype.platformClass = false
- };
- // #endif
- // #ifdef MP-WEIXIN || MP-QQ
- if (!isIOS) {
- Vue.prototype.platformClass = 'left'
- this.$store.dispatch('setVariableFun', false)
- } else {
- Vue.prototype.platformClass = 'center'
- this.$store.dispatch('setIsIphoneFun', true)
- }
- Vue.prototype.StatusBar = systemInfo.statusBarHeight
- Vue.prototype.fontSizeSetting = systemInfo.fontSizeSetting
- Vue.prototype.screenWidth = systemInfo.screenWidth
- let capsule = wx.getMenuButtonBoundingClientRect()
- Vue.prototype.capsule = capsule
- if (capsule) {
- Vue.prototype.Custom = capsule
- Vue.prototype.CustomBar = capsule.bottom + capsule.top - systemInfo.statusBarHeight
- } else {
- Vue.prototype.CustomBar = systemInfo.statusBarHeight + 50
- }
- // #endif
- // #ifdef MP-ALIPAY
- Vue.prototype.StatusBar = systemInfo.statusBarHeight
- Vue.prototype.CustomBar = systemInfo.statusBarHeight + systemInfo.titleBarHeight
- // #endif
- }
- }
- }
- export default appMixins
|