new_app/store/common.js

104 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {
defineStore
} from "pinia";
import {
getCommonConfig
} from '@/api/init.js'
const $map = {
882: 'isWxIosPay',
833: 'checkIosLogin',
834: 'checkIosPay',
835: 'checkWxLogin',
836: 'checkPhoneLogin',
108: 'isOpenWxWebAutoLogin',
817: 'zhengbu',
818: 'danbu',
252: 'adUnitId',
821: 'playType',
251: 'isGuanggao',
254: 'isGuanggaody',
202: 'kefu',
249: 'moreSearch', //热搜词
206: 'kefuPhone',
204: 'kefuUrl',
203: 'kefuAppId',
248: 'isVips',
49: 'AppUrl',
823: 'OfferID',
824: 'payEnv',
825: 'moneyTips',
855: 'kmPaySel',
849: 'homeTypeSel',
856: 'syPaySel',
857: 'imId',
858: 'isAccountPay',
860: 'dyadUnitId',
881: '',
109: '',
922: 'withdrawNum',
500: 'payTips',
914: 'goldBili', // 金币比例
921: 'freeDuration' //看广告免费分钟时长
}
export const useCommonStore = defineStore("common", {
state() {
return {
payTips: '付款完成后不要忘记抽红包哦',
goldBili: 0,
sysInfo: {},
isIos: false,
isExamines: 0
};
},
actions: {
async init() {
this.sysInfo = uni.getSystemInfoSync()
this.isIos = this.sysInfo.platform == 'ios'
const res = await getCommonConfig()
if (res) {
for (let i in $map) {
const key = $map[i]
if (key) {
this[key] = res[i]
uni.setStorageSync(key, res[i])
}
}
}
},
setversion(a, b) {
return new Promise(async (resolve, reject) => {
// console.log('當前版本-' + a, '接口版本-' + b, '判斷值-' + this.isExamines)
this.isExamines = await this.compare(a, b)
resolve(this.isExamines)
})
},
// 判断版本号
compare(version1, version2) {
let arr1 = version1.split(".");
let arr2 = version2.split(".");
let length = Math.max(arr1.length, arr2.length);
for (let i = 0; i < length; i++) {
const n1 = Number(arr1[i] || 0)
const n2 = Number(arr2[i] || 0)
// version1 > version2 返回1如果 version1 < version2 返回-1不然返回0
if (n1 > n2) return 1
if (n1 < n2) return -1
}
return 0
}
},
getters: {
isIosExamine: function () {
if (!this.isIos) {
return true
}
if (this.isExamines == 1) {
return false
}
return true
}
},
unistorage: true, // 开启后对 state 的数据读写都将持久化
});