zhaoxiaoqiang
2022-08-05 0eb1ac5a76afcad261caa4c2d50c5ac5aae2704b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * @Author: 小明丶
 * @Date: 2019-08-19 15:23:17
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-11-01 11:01:36
 * @Description:
 */
import Vue from 'vue';
import Vuex from "vuex";
import md5 from 'blueimp-md5';
import mutations from "./mutations";
// 数据持久化到session的插件
import createPersistedState from 'vuex-persistedstate';
import {calcArea} from '@/utils/index';
 
import {
    SET_SESSION_ID,
    SET_FOOTER_NAV,
    SET_USER_PAGE,
    SET_USER_INFO,
    SET_AREA_LIST,
    SET_MESSAGE_CONUT,
    SET_INVITE_CODE,
} from './mutations-types';
 
Vue.use(Vuex);
 
export default new Vuex.Store({
    plugins: [createPersistedState({ storage: window.sessionStorage })],
    state: {
        AppLoading: false,//加载
        sessionId: '',//判断是否登录
        userinfo: {}, //用户信息
        footerNav:[],//底部导航
        areaList:[],
        msgCount: {},
    },
    getters: {
        orgType(state){
            return state.userinfo.orgType
        },
        orgId(state) {
            return state.userinfo.orgId
        }
    },
    mutations,
    actions: {
        openIdLogin({ commit, dispatch }, { vm, openId, next }){
            let passwordLogin = {
               openId:openId
            };
            //dispatch('getWechatUserInfo',{vm,openId,next})
            Vue.prototype.$api.openIdLogin(passwordLogin).then(res=>{
                if(res.body){
                    let userInfo = {}
                    userInfo.mblNo = res.body.account;//手机号修改成账号
                    userInfo.hasBankCard = res.body.hasBankCard;//1标识有我的银行卡0未绑定银行卡
                    commit(SET_USER_INFO,userInfo)
                    commit(SET_SESSION_ID, res.body.sessionId);//存储sessionId用于判断是否登录
                    dispatch('setUserMenu',{ vm, next })
                    vm.$router.push('/home/index')//跳转到指定页面
                }else{
                    vm.$router.push('/login')
                }
            }).catch(err=>{
                //vm.$router.push('/login')
            })
        },
        login({ commit, dispatch }, { vm, mblNo, verCode, openId, next }) {
            let tmpCode = md5(mblNo + verCode);
            let passwordLogin = {
                mblNo: mblNo,
                verCode: verCode,
                openId:openId
            };
            //dispatch('getWechatUserInfo',{vm,openId,next})
            Vue.prototype.$api.login(passwordLogin).then(res => {
                // sessionStorage.jumpUrl = res.body.clientAccessDomain;
                let {
                    sessionId,
                    mblNo
                } = res.body;
                let userInfo = {}
                userInfo.mblNo = res.body.account;//手机号修改成账号
                userInfo.hasBankCard = res.body.hasBankCard;//1标识有我的银行卡0未绑定银行卡
                commit(SET_SESSION_ID, sessionId);//存储sessionId用于判断是否登录
                commit(SET_USER_INFO,userInfo)
                dispatch('setUserMenu',{ vm, next })
                vm.$router.push('/home/index')//跳转到指定页面
            });
        },
         // 获取微信用户信息
        getWechatUserInfo({commit},{vm,openId,next}){
            Vue.prototype.$api.wechatGetUserInfo({
                openId:openId
            }).then(res=>{
                let obj = {}
                obj = res.body
            })
        },
        // 根据不同的权限设置用户拥有的菜单
        setUserMenu({ commit }, { vm, lastLoginMgrId, next }) {
            var arr = [
                {
                    icon:'iconshouye',
                    icon_h:'iconshouye_h',
                    title:'首页',
                    to:'/home/index'
                },
                {
                    icon:'icongerenzhongxin',
                    icon_h:'icongerenzhongxin_h',
                    title:'我的',
                    to:'/home/personal'
                }
            ] 
            commit(SET_FOOTER_NAV, arr);
        },
        // 获取验证码
        getVercode({ commit },obj){
            let form = {
                mblNo:obj.mblNo,
                verCodeType:obj.verCodeType
            } 
            Vue.prototype.$api.getVerCode(form).then(res=>{
                obj.vm.$tool.toast('验证码获取成功')
            })
        },
        // 获取地区列表
        getArea({commit}) {
            Vue.prototype.$api.areaOptions().then((res) => {
                let  provList  = res.body;
                commit(SET_AREA_LIST,provList)
            }).catch((err) => {
 
            });
        },
        //消息count
        getCount({commit}) {
            
        }
    },
    modules: {
        
    }
})