/*
|
* @Author: 小明丶
|
* @Date: 2019-08-19 15:23:17
|
* @LastEditors: 小明丶
|
* @LastEditTime: 2021-01-05 15:20:51
|
* @Description:
|
*/
|
import Vue from 'vue';
|
import Vuex from "vuex";
|
import md5 from 'blueimp-md5';
|
import mutations from "./mutations";
|
import test from "./module/test";
|
// 数据持久化到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,
|
SET_BCAKCOLOR,
|
SET_BCJBCOLORF,
|
SET_BCJBCOLORB,
|
SET_DEFAULT_BG_COLOR,
|
SET_LAST_COLOR
|
} from './mutations-types';
|
|
Vue.use(Vuex);
|
|
export default new Vuex.Store({
|
plugins: [createPersistedState({ storage: window.sessionStorage })],
|
state: {
|
AppLoading: false,
|
sessionId: '',//判断是否登录
|
footerNav: [], //底部导航
|
userPage: [], //管理页面 用户有的权限页面
|
userinfo: {}, //用户信息
|
areaList: {//地区列表
|
province_list: {}, //省
|
city_list: {}, //市
|
county_list: {}, //地区、县
|
},
|
msgCount: {},
|
inviteCode: '', //邀请码
|
|
lastColor:'#423d5d',
|
backColor:'#896EDB',//主题色
|
backJbColorF:'#8F6AFF',//主题渐变色
|
backJbColorB:'#9459EC',
|
defaultBgColor:'linear-gradient(180deg, #554E7A, #423D5D)',
|
},
|
getters: {
|
orgType(state) {
|
return state.userinfo.orgType
|
},
|
orgId(state) {
|
return state.userinfo.orgId
|
}
|
},
|
mutations,
|
actions: {
|
loginByAppToken({ commit, dispatch }, { vm, appToken, backUrl, next }){
|
sessionStorage.appToken = appToken;
|
sessionStorage.backUrl = backUrl;
|
let p = new Promise(function(resolve,reject){
|
Vue.prototype.$api.loginByMerToken({
|
token:appToken
|
}).then(res=>{
|
sessionStorage.jumpUrl = res.body.clientAccessDomain;
|
let lastLoginMgrId = res.body.lastLoginMgrId
|
let sessionId = res.body.sessionId
|
commit(SET_SESSION_ID, sessionId);
|
if(lastLoginMgrId){
|
resolve(lastLoginMgrId)
|
}else{
|
next('/app/changeMer')
|
}
|
})
|
})
|
p.then(lastLoginMgrId=>{
|
sessionStorage.sid = lastLoginMgrId;
|
Vue.prototype.$api.getPowerInfo(lastLoginMgrId).then(res=>{
|
commit(SET_USER_INFO,res.body)
|
next('/app/home')
|
})
|
})
|
},
|
|
loginByToken({ commit, dispatch }, { vm, hjToken, next }) {
|
localStorage.hjToken = hjToken
|
Vue.prototype.$api.loginByToken({
|
token: hjToken
|
}).then(res => {
|
|
sessionStorage.jumpUrl = res.body.clientAccessDomain;
|
|
let lastLoginMgrId = res.body.lastLoginMgrId
|
let sessionId = res.body.sessionId
|
commit(SET_SESSION_ID, sessionId);
|
|
|
if (lastLoginMgrId) {
|
dispatch('setUserMenu', { vm, lastLoginMgrId, next })
|
} else {
|
if (next) {
|
next('/mine/toggle-identity');
|
} else {
|
vm.$router.push('/mine/toggle-identity');
|
}
|
}
|
})
|
},
|
loginByOpenId({ commit, dispatch },{ vm, loginType, verCode, mblNo,merId,wechatOpenId,userId, next}){
|
Vue.prototype.$api.loginByOpenId({
|
loginType:loginType,
|
verCode:verCode,
|
mblNo:mblNo,
|
merId:merId,
|
wechatOpenId:wechatOpenId,
|
userId:userId
|
}).then(res=>{
|
if(mblNo){
|
localStorage.sib_wx_mblNo = mblNo
|
}
|
sessionStorage.isLoginByOpenId = 1
|
localStorage.sib_wx_openId = wechatOpenId
|
localStorage.storeList = JSON.stringify(res.body.storeList)
|
// localStorage.sib_wx_mblNo = res.body.mblNo
|
// localStorage.sib_wx_userId = res.body.userId
|
commit(SET_SESSION_ID, res.body.sessionId);
|
if(res.body.isRegister == 1){
|
vm.$router.push({
|
path:'/supplement',
|
query:{
|
storeList:JSON.stringify(res.body.storeList)
|
}
|
})
|
}else{
|
if(res.body.storeList.length == 1){
|
let lastLoginMgrId = res.body.storeList[0].id
|
dispatch('setUserMenu', { vm, lastLoginMgrId, next })
|
}
|
if(res.body.storeList.length > 1){
|
vm.$router.push({
|
path:'/mine/toggle-identity',
|
query:{
|
title:'选择门店',
|
storeList:JSON.stringify(res.body.storeList)
|
}
|
})
|
}
|
|
}
|
// if(res.body.storeList.length == 1){
|
// vm.$router.push({
|
// path:'/main/mine',
|
// query:{
|
// isLoginByOpenId:1
|
// }
|
// })
|
// }
|
// if(res.body.storeList.length > 1){
|
// vm.$router.push({
|
// path:'/mine/toggle-identity',
|
// query:{
|
// title:'选择门店',
|
// storeList:res.body.storeList
|
// }
|
// })
|
// }
|
})
|
},
|
login({ commit, dispatch }, { vm, userNo, password, sib_mer_sysPlat, next }) {
|
window.localStorage.clear()
|
if(sessionStorage.isddxt == 1){
|
window.document.title = '叮咚学堂'
|
}
|
let tmpPassword = md5(userNo + password);
|
let passwordLogin = {
|
userNo: userNo,
|
password: tmpPassword
|
};
|
Vue.prototype.$api.login(passwordLogin).then(res => {
|
sessionStorage.jumpUrl = res.body.clientAccessDomain;
|
let {
|
lastLoginMgrId,
|
sessionId
|
} = res.body;
|
commit(SET_SESSION_ID, sessionId);
|
// window.sessionStorage.setItem(
|
// 'jumpUrl',
|
// res.body.clientAccessDomain
|
// );
|
// // 存储起来自动登录
|
localStorage.user_account = userNo;
|
localStorage.user_pwd = password;
|
localStorage.sib_mer_sysPlat = sib_mer_sysPlat; // 1 微信 2支付宝
|
if (lastLoginMgrId) {
|
// setUserMenu(vm, lastLoginMgrId, next);
|
dispatch('setUserMenu', { vm, lastLoginMgrId, next })
|
} else {
|
if (next) {
|
next('/mine/toggle-identity');
|
} else {
|
vm.$router.push('/mine/toggle-identity');
|
}
|
}
|
});
|
},
|
// 根据不同的权限设置用户拥有的菜单
|
setUserMenu({ commit }, { vm, lastLoginMgrId, next }) {
|
|
vm.$api.getPowerInfo(lastLoginMgrId).then(data => {
|
let {
|
powerInfoVos,
|
orgType
|
} = data.body;
|
let inviteCode = data.body.inviteCode;
|
commit(SET_INVITE_CODE, inviteCode);
|
|
let footerMenu = [
|
{
|
powerId: 100001,
|
icon: 'iconshuju_h',
|
Aicon: 'iconshuju',
|
label: '数据',
|
path: '/order/wxScore'
|
},
|
{
|
powerId: 100003,
|
icon: 'iconshenpi_h',
|
Aicon: 'iconshenpi',
|
label: '审批',
|
path: '/main/approve'
|
},
|
|
{
|
powerId: 100006,
|
icon: 'icondingdan',
|
Aicon: 'icondingdan1',
|
label: '办单',
|
path: '/main/product'
|
},
|
|
]
|
let userMenu = [
|
{
|
powerId: 100004,
|
icon: 'iconshanghuguanli',
|
label: '门店管理',
|
path: '/mine/stores'
|
},
|
{
|
powerId: 100002,
|
icon: 'iconqudaoguanli',
|
label: '渠道管理',
|
path: '/mine/channel'
|
}
|
]
|
if(!window.localStorage.hjToken && sessionStorage.isLoginByOpenId != 1){
|
userMenu.push({
|
powerId: 100005,
|
icon: 'iconzhanghaoguanli',
|
label: '账号管理',
|
path: '/mine/account'
|
})
|
}
|
|
let footernav = []
|
let userPage = []
|
let path = ''
|
|
powerInfoVos.map(item => {
|
footerMenu.map(child => {
|
if (item.powerId === child.powerId) {
|
if (child.powerId === 100001 || child.powerId === 100006) {
|
footernav.unshift(child);
|
} else {
|
footernav.push(child);
|
}
|
}
|
});
|
userMenu.map(child => {
|
if (item.powerId === child.powerId) {
|
userPage.push(child);
|
}
|
});
|
});
|
|
console.log(userPage)
|
|
|
|
footernav.push({
|
powerId: 200000,
|
icon: 'iconguanli_h',
|
Aicon: 'iconguanli',
|
label: '我的',
|
path: '/main/mine'
|
})
|
|
|
|
|
|
// 代理角色一定有商户管理、商户注册的菜单
|
if (orgType === 1 || orgType === 2) {
|
|
userPage.push({
|
icon: 'iconshanghuguanli',
|
label: '商户管理',
|
path: '/mine/mer-manager'
|
});
|
userPage.push({
|
icon: 'iconshanghuzhuce',
|
label: '商户注册',
|
path: '/user/register'
|
});
|
}
|
|
|
|
|
|
commit(SET_FOOTER_NAV, footernav);
|
commit(SET_USER_PAGE, userPage);
|
commit(SET_USER_INFO, data.body);
|
sessionStorage.sid = lastLoginMgrId;
|
// vm.$setItem('sid', mgrId);
|
if (orgType === 4) {
|
if(sessionStorage.isLoginByOpenId == 1){
|
path = '/main/mine';
|
}
|
else{
|
path = '/main/product';
|
}
|
|
} else {
|
path = '/main/mine';
|
}
|
if (next) {
|
next(path)
|
} else {
|
vm.$router.push(path)
|
}
|
});
|
},
|
// 获取地区列表
|
getArea({ commit }) {
|
Vue.prototype.$api.getArea().then((res) => {
|
let { provList } = res.body;
|
let obj = calcArea(provList)
|
commit(SET_AREA_LIST, {
|
province_list: obj.province_list,
|
city_list: obj.city_list,
|
county_list: obj.county_list
|
})
|
}).catch((err) => {
|
|
});
|
},
|
//消息count
|
getCount({ commit }) {
|
Vue.prototype.$api.indexInit().then(res => {
|
// let sum = res.body.noticeInfos.some(item => {
|
// return item.needRead === 1
|
// })
|
let notice = {};
|
notice.sum = res.body.hasNotice
|
notice.swiperList = res.body.bannerInfoVos
|
notice.messageList = res.body.noticeInfos.noticeInfos
|
commit(SET_MESSAGE_CONUT, notice)
|
})
|
},
|
// 设置主题色
|
setColor({commit},{backColor,backJbColorF,backJbColorB,defaultBgColor, lastColor}){
|
console.log('defaultBgColor:',defaultBgColor)
|
commit(SET_BCAKCOLOR,backColor)
|
commit(SET_BCJBCOLORF,backJbColorF)
|
commit(SET_BCJBCOLORB,backJbColorB)
|
commit(SET_DEFAULT_BG_COLOR,defaultBgColor)
|
commit(SET_LAST_COLOR,lastColor)
|
}
|
},
|
modules: {
|
test
|
}
|
})
|