|
| 1 | +import { MENU_LIST } from '../mutations' |
| 2 | + |
| 3 | +const state = { |
| 4 | + list: [ |
| 5 | + { moduleName: '学校管理', menuList: []}, |
| 6 | + { moduleName: '教务管理', menuList: [ |
| 7 | + { index: '1', label: '学生管理', children: [ |
| 8 | + { index: '1-1', label: '学生信息', name: 'demoList', path: '/demo/list' }, // 注意:必须与路由router的name、path对应 |
| 9 | + { index: '1-2', label: 'test', children: [ |
| 10 | + { index: '1-2-1', label: 'test_1', name: 'test_1', path: '/demo/test_1' } |
| 11 | + ]}] |
| 12 | + } |
| 13 | + ]}, |
| 14 | + { moduleName: '教职工管理', menuList: [ |
| 15 | + { index: '1', label: '学生管理', children: [ |
| 16 | + { index: '1-1', label: 'test_2', name: 'test_2', path: '/demo/test_2' }] |
| 17 | + } |
| 18 | + ]}, |
| 19 | + { moduleName: '行政办公', menuList: []}, |
| 20 | + ], |
| 21 | + activeModuleName: '', |
| 22 | + activeMenuIndex: '-1' |
| 23 | + |
| 24 | +} |
| 25 | + |
| 26 | +const getters = { |
| 27 | + // 模块名数组 |
| 28 | + modules: () => { |
| 29 | + return state.list.map(item => item.moduleName) |
| 30 | + }, |
| 31 | + // 获取相应模块下的菜单列表 |
| 32 | + menuList: () => { |
| 33 | + let current = state.list.filter(item => item.moduleName === state.activeModuleName); |
| 34 | + return current.length ? current[0].menuList : []; |
| 35 | + }, |
| 36 | +} |
| 37 | + |
| 38 | +const mutations = { |
| 39 | + // 设置当前的模块名 |
| 40 | + [MENU_LIST.SET_ACTICE_MODULE_NAME] (state, moduleName) { |
| 41 | + state.activeModuleName = moduleName; |
| 42 | + }, |
| 43 | + // 设置当前菜单的index |
| 44 | + [MENU_LIST.SET_ACTICE_MENU_INDEX] (state, menuIndex) { |
| 45 | + state.activeMenuIndex = menuIndex; |
| 46 | + }, |
| 47 | + } |
| 48 | + |
| 49 | +export default { |
| 50 | + state, |
| 51 | + getters, |
| 52 | + mutations |
| 53 | +} |
0 commit comments