You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import Vue from 'vue' ;
export default {
// Vuex模块启用命名空间
namespaced : true ,
// Vuex的state, 用来存储应用状态
state : {
// 账户类型, 映射数字ID到账户类型名称
ACCOUNT _TYPES : {
1 : '订阅号' ,
2 : '服务号'
} ,
// 存储账户列表
accountList : [ ] ,
// 当前选中的Appid, 用来标识选择的账号
selectedAppid : ''
} ,
// Vuex的mutations, 用来修改state
mutations : {
// 更新账户列表
updateAccountList ( state , list ) {
// 更新state中的accountList
state . accountList = list ;
// 如果列表为空,直接返回
if ( ! list . length ) return ;
// 如果当前没有选中的Appid, 则从cookie或列表中选择一个默认Appid
if ( ! state . selectedAppid ) {
let appidCookie = Vue . cookie . get ( 'appid' ) ;
// 获取cookie中的appid, 如果有则使用cookie中的appid, 否则使用列表中的第一个Appid
let selectedAppid = appidCookie ? appidCookie : list [ 0 ] . appid ;
// 通过commit调用mutation更新选中的账号
this . commit ( 'wxAccount/selectAccount' , selectedAppid ) ;
}
} ,
// 选择某个账号( 切换Appid)
selectAccount ( state , appid ) {
// 更新cookie中的appid, 保存选中的Appid
Vue . cookie . set ( 'appid' , appid ) ;
// 记录上一个选中的Appid
let oldAppid = state . selectedAppid ;
// 更新当前选中的Appid
state . selectedAppid = appid ;
// 如果选中的Appid发生变化, 则刷新页面
if ( oldAppid ) {
location . reload ( ) ;
}
}
}
} ;