123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import api from '../common/config/caimeiApi.js'
- import authorize from '../common/config/authorize.js'
- import * as caimeiApi from '@/common/config/caimeiApi.js'
- import ajaxService from '@/services/ajax.service.js'
- import UserService from '@/services/user.service.js'
- const getUserService = new UserService(ajaxService)
- Vue.use(Vuex)
- const store = new Vuex.Store({
- state: {
- isWxAuthorize: false,
- hasLogin: false,
- userInfo: {},
- identity: 0,
- noticeNum:0,
- clubType: 0, // 1: 医美机构 2:生美机构 (医美、生美机构类型)
- wechatUserInfo: {},
- cartNumber: 0,
- isIphoneX: false,
- isActivity: false,
- isLoginType: 0,
- isLoginProductId: 0,
- isManage: false,// 是否是管理员或者小组长
- isRossShow:false // 是否显示ross广告图
- },
- mutations: {
- login(state, provider) { //用户身份 1、协销 2、资质机构 3、供应商 4.个人机构
- state.hasLogin = true
- state.userInfo = provider
- uni.setStorage({ //缓存用户登陆状态
- key: 'userInfo',
- data: provider
- })
- },
- logout(state,provider) {
- state.hasLogin = false
- state.userInfo = provider
- uni.removeStorage({
- key: 'userInfo'
- })
- uni.removeStorage({
- key: 'token'
- })
- },
- wxLogin(state, provider) {
- state.isWxAuthorize = true
- state.wechatUserInfo = provider
- uni.setStorage({ //缓存用户登陆状态
- key: 'wechatUserInfo',
- data: provider
- })
- uni.setStorageSync('_WX_State', 1)
- },
- updateStatus(state, provider) {
- let TIME = api.formatDate()
- console.log(`${TIME}`, provider)
- state.userInfo = provider
- uni.setStorage({ //缓存用户登陆状态
- key: 'userInfo',
- data: provider
- })
- },
- async updateNoticeNum(state) { // 更新通知消息数量
- const userInfo = await caimeiApi.getStorage()
- const commonId = userInfo.clubId ? userInfo.clubId : 0
- getUserService.getAuthClubCount({ commonId: commonId })
- .then(response => {
- state.noticeNum = response.data.count
- if (state.noticeNum >= 100) {
- uni.setTabBarBadge({
- index: 2,
- text: '99+'
- })
- } else if (state.noticeNum > 0) {
- uni.setTabBarBadge({
- index: 2,
- text: String(state.noticeNum)
- })
- } else {
- uni.removeTabBarBadge({
- index: 2,
- })
- }
- })
- .catch(error => {
- uni.removeTabBarBadge({
- index: 2,
- })
- })
- },
- 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) {
- state.isIphoneX = variable
- },
- setIsIphone(state, variable) { // 记录设备信息是否为IphoneX
- state.isIphone = variable
- },
- setLoginType(state, variable) { // 记录登录跳转类型
- state.isLoginType = variable
- console.log(state.isLoginType)
- },
- setLoginProductId(state, variable) { // 记录跳转商品ID
- state.isLoginProductId = variable
- console.log(state.isLoginProductId)
- },
- setLoginOrderId(state, variable) { // 记录跳转订单ID
- state.isLoginOrderId = variable
- console.log(state.isLoginOrderId)
- }
- },
- 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
|