const routeMap = { 'dym': 'separate', // 单页面 'xp': 'inquiry', // 询盘栏目 'wz': 'article-page', // 文章栏目 'cp': 'products' // 产品栏目 } export const state = () => ({ locales: ['en', 'zh'], locale: 'en', menuTree: [], footerInfo: {}, footerPordCategory: [], device: '' }) export const mutations = { SET_LANG (state, locale) { if (state.locales.includes(locale)) { state.locale = locale this.$cookies.set('lang', locale) } }, SET_FOOTER_INFO (state, info) { state.footerInfo = info }, SET_FOOTER_PRODCAT (state, list) { state.footerPordCategory = list }, SET_MENU_TREE (state, tree) { state.menuTree = [ {label:'Home', to: '/', children: []} ] const fn = (list) => { list.forEach(item => { if (item.catgLevel===1) { item.to = `/${routeMap[item.catgType]}?maxCatgId=${item.id}&title=${item.label}` } else { item.to = `/${routeMap[item.catgType]}?&catgId=${item.id}&maxCatgId=${item.maxParentId}&title=${item.label}` } if (item.children.length) { fn(item.children) } }) } fn(tree) state.menuTree = [...state.menuTree, ...tree] }, SET_DEVICE (state, isMob) { state.device = isMob ? '移动端' : '电脑端' } } export const actions = { }