123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import api from '../common/config/utilsTools.js'
- import authorize from '../common/config/authorize.js'
- Vue.use(Vuex)
- const store = new Vuex.Store({
- state: {
- isWxAuthorize: false, //是否授权
- hasLogin: false,
- userInfo: {}, //登录用户信息
- wechatUserInfo: {}, //用户微信相关信息
- cartNumber: 0,
- isIphoneX: false,
- isActivity: false,
- isLoginType: 0,
- isLoginProductId: 0,
- windowHeight:''
- },
- mutations: {
- login(state, provider) { //用户身份 1、协销 2、会员机构 3、供应商 4.普通机构
- state.hasLogin = true
- state.userInfo = provider
- uni.setStorage({ //缓存用户登陆状态
- key: 'userInfo',
- data: provider
- })
- },
- logout(state) {
- state.hasLogin = false
- state.userInfo = {}
- uni.removeStorage({
- key: 'userInfo'
- })
- uni.removeStorage({
- key: 'token'
- })
- },
- wxLogin(state, provider) {
- state.isWxAuthorize = true
- // console.log(state.isWxAuthorize)
- state.wechatUserInfo = provider
- uni.setStorageSync('_WX_State',true)
- uni.setStorage({ //缓存用户微信授权信息
- key: 'wechatUserInfo',
- data: provider
- })
- },
- updateStatus(state, provider) {
- let TIME = api.formatDate()
- console.log(`${TIME}`, provider)
- state.userInfo = provider
- uni.setStorage({ //缓存用户登陆状态
- key: 'userInfo',
- data: provider
- })
- },
- updateAllNum(state, num) {
- if (num >= 100) {
- uni.setTabBarBadge({
- index: 1,
- text: '99+'
- })
- } else if (num > 0) {
- uni.setTabBarBadge({
- index: 1,
- text: String(num)
- })
- } else {
- uni.removeTabBarBadge({
- index: 1,
- })
- }
- },
- setActivity(state, variable) {
- state.isActivity = variable
- },
- setChangeVar(state, variable) {
- //获取设备信息是否为IphoneX
- state.isIphoneX = variable
- },
- setIsIphone(state, variable) {
- //获取设备信息是否为IphoneX
- state.isIphone = variable
- },
- setLoginType(state, variable) {
- //获取设备信息是否为IphoneX
- state.isLoginType = variable
- console.log(state.isLoginType)
- },
- setLoginProductId(state, variable) {
- //获取设备信息是否为IphoneX
- state.isLoginProductId = variable
- console.log(state.isLoginProductId)
- },
- setLoginOrderId(state, variable) {
- //获取设备信息是否为IphoneX
- state.isLoginOrderId = variable
- console.log(state.isLoginOrderId)
- },
- setWindowHeight(state,height){
- state.windowHeight = height
- console.log(state.windowHeight)
- }
- },
- actions: {
- setVariableFun: function(context, vData) {
- context.commit('setChangeVar', vData)
- },
- setIsIphoneFun: function(context, vData) {
- context.commit('setIsIphone', vData)
- },
- setActivityFn: function(context, vData) {
- context.commit('setActivity', vData)
- },
- // setLoginTypeFn:function(context,vData){
- // context.commit('setLoginType',vData)
- // }
- }
- })
- export default store
|