feat(web): enforce server-driven GoAuto menus (#138)

This commit is contained in:
QiuSW
2026-08-28 22:16:51 +08:00
parent 9916ed5ccf
commit 5feb4e8571
7 changed files with 166 additions and 179 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ router.beforeEach(async(to, from, next) => {
next({ ...to, replace: true })
} catch (error) {
// remove token and go to login page to re-login
// await store.dispatch('user/resetToken')
await store.dispatch('user/resetToken')
ElMessage.error(error || 'Has Error')
next(`/login?redirect=${to.path}`)
NProgress.done()
-143
View File
@@ -80,149 +80,6 @@ export const constantRoutes = [
}
]
},
{
path: '/devices',
component: Layout,
redirect: '/devices/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/devices/index'),
name: 'GoAutoDeviceList',
meta: { title: '设备列表', icon: 'monitor' }
}
]
},
{
path: '/pdd-products',
component: Layout,
redirect: '/pdd-products/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/pdd-products/index'),
name: 'GoAutoPddProducts',
meta: { title: 'PDD 商品', icon: 'shopping' }
}
]
},
{
path: '/shopee-products',
component: Layout,
redirect: '/shopee-products/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/shopee-products/index'),
name: 'GoAutoShopeeProducts',
meta: { title: '虾皮商品', icon: 'goods' }
}
]
},
{
path: '/syb-products',
component: Layout,
redirect: '/syb-products/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/syb-products/index'),
name: 'GoAutoSybProducts',
meta: { title: 'SYB 商品', icon: 'tickets' }
}
]
},
{
path: '/syb-shops',
component: Layout,
redirect: '/syb-shops/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/syb-shops/index'),
name: 'GoAutoSybShops',
meta: { title: 'SYB 店铺', icon: 'shopping' }
}
]
},
{
path: '/syb-sync-runs',
component: Layout,
redirect: '/syb-sync-runs/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/syb-sync-runs/index'),
name: 'GoAutoSybSyncRuns',
meta: { title: 'SYB 同步记录', icon: 'time' }
}
]
},
{
path: '/syb-inner-codes',
component: Layout,
redirect: '/syb-inner-codes/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/syb-inner-codes/index'),
name: 'GoAutoSybInnerCodes',
meta: { title: '档口入库码', icon: 'list' }
}
]
},
{
path: '/collection-rules',
component: Layout,
redirect: '/collection-rules/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/collection-rules/index'),
name: 'GoAutoCollectionRules',
meta: { title: '采集规则', icon: 'code' }
}
]
},
{
path: '/collection-tasks',
component: Layout,
redirect: '/collection-tasks/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/collection-tasks/index'),
name: 'GoAutoCollectionTasks',
meta: { title: '采集任务', icon: 'list' }
}
]
},
{
path: '/purchase-tasks',
component: Layout,
redirect: '/purchase-tasks/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/purchase-tasks/index'),
name: 'GoAutoPurchaseTasks',
meta: { title: '采购管理', icon: 'shopping' }
}
]
},
{
path: '/ai-matching-settings',
component: Layout,
redirect: '/ai-matching-settings/index',
children: [
{
path: 'index',
component: () => import('@/views/goauto/ai-matching-settings/index'),
name: 'GoAutoAiMatchingSettings',
meta: { title: 'AI 规格匹配', icon: 'setting' }
}
]
},
{
path: '/profile',
component: Layout,
+18 -22
View File
@@ -138,34 +138,30 @@ const mutations = {
const actions = {
generateRoutes({ commit }, roles) {
return new Promise(resolve => {
return new Promise((resolve, reject) => {
const loadMenuData = []
getRoutes().then(response => {
// console.log(JSON.stringify(response))
let data = response
if (response.code !== 200) {
this.$message({
message: '菜单数据加载异常',
type: 0
})
} else {
data = response.data
Object.assign(loadMenuData, data)
const dynamicRoutes = []
generaMenu(dynamicRoutes, loadMenuData)
dynamicRoutes.push({ path: '/:pathMatch(.*)*', redirect: '/', hidden: true })
commit('SET_ROUTES', dynamicRoutes)
const sidebarRoutes = []
generaMenu(sidebarRoutes, loadMenuData)
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', sidebarRoutes)
resolve(dynamicRoutes)
reject(new Error('菜单数据加载异常'))
return
}
const data = Array.isArray(response.data) ? response.data : []
Object.assign(loadMenuData, data)
const dynamicRoutes = []
generaMenu(dynamicRoutes, loadMenuData)
dynamicRoutes.push({ path: '/:pathMatch(.*)*', redirect: '/', hidden: true })
commit('SET_ROUTES', dynamicRoutes)
const sidebarRoutes = []
generaMenu(sidebarRoutes, loadMenuData)
commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
commit('SET_DEFAULT_ROUTES', sidebarRoutes)
commit('SET_TOPBAR_ROUTES', sidebarRoutes)
resolve(dynamicRoutes)
}).catch(error => {
console.log(error)
reject(error)
})
})
}
+2
View File
@@ -89,6 +89,7 @@ const actions = {
commit('SET_PERMISSIONS', [])
removeToken()
storage.clear()
resetRouter()
resolve()
}).catch(error => {
reject(error)
@@ -114,6 +115,7 @@ const actions = {
return new Promise(resolve => {
commit('SET_TOKEN', '')
removeToken()
resetRouter()
resolve()
})
},