dl_site_nuxt/store/index.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

const routeMap = {
'dym': 'separate', // 单页面
'xp': 'inquiry', // 询盘栏目
'wz': 'article-page', // 文章栏目
'cp': 'products' // 产品栏目
}
export const state = () => ({
locales: ['en', 'zh'],
locale: 'en',
menuTree: [],
footerInfo: {}
})
export const mutations = {
SET_LANG (state, locale) {
if (state.locales.includes(locale)) {
state.locale = locale
}
},
SET_FOOTER_INFO (state, info) {
state.footerInfo = info
},
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]
}
}
export const actions = {
}