1
This commit is contained in:
24
src/index.js
24
src/index.js
@@ -117,12 +117,13 @@ class AdminFramework {
|
|||||||
* @param {Object} options.VueRouter - VueRouter 实例(可选)
|
* @param {Object} options.VueRouter - VueRouter 实例(可选)
|
||||||
* @param {Object} options.Vuex - Vuex 实例(可选)
|
* @param {Object} options.Vuex - Vuex 实例(可选)
|
||||||
* @param {Function} options.createPersistedState - vuex-persistedstate(可选)
|
* @param {Function} options.createPersistedState - vuex-persistedstate(可选)
|
||||||
|
* @param {Object} options.homeRoute - 自定义 home 路由配置(可选,用于覆盖默认 home)
|
||||||
*/
|
*/
|
||||||
install(Vue, options = {}) {
|
install(Vue, options = {}) {
|
||||||
if (this.installed) return
|
if (this.installed) return
|
||||||
this.installed = true
|
this.installed = true
|
||||||
|
|
||||||
const { config = {}, ViewUI, VueRouter, Vuex, createPersistedState } = options
|
const { config = {}, ViewUI, VueRouter, Vuex, createPersistedState, homeRoute } = options
|
||||||
this.config = config
|
this.config = config
|
||||||
|
|
||||||
// 自动注册 ViewUI
|
// 自动注册 ViewUI
|
||||||
@@ -158,6 +159,21 @@ class AdminFramework {
|
|||||||
|
|
||||||
// 如果提供了 VueRouter,自动创建 Router
|
// 如果提供了 VueRouter,自动创建 Router
|
||||||
if (VueRouter && !this.router) {
|
if (VueRouter && !this.router) {
|
||||||
|
// 获取主路由配置(包含 home)
|
||||||
|
const mainRoute = this.getRoutes({ Main, ParentView, Page404 })
|
||||||
|
|
||||||
|
// 如果外部提供了自定义 homeRoute,合并到主路由的 children 中
|
||||||
|
if (homeRoute && mainRoute && mainRoute.children) {
|
||||||
|
// 查找并替换默认的 home 路由
|
||||||
|
const homeIndex = mainRoute.children.findIndex(route => route.name === 'home')
|
||||||
|
if (homeIndex !== -1) {
|
||||||
|
mainRoute.children[homeIndex] = homeRoute
|
||||||
|
} else {
|
||||||
|
// 如果没找到,添加到开头
|
||||||
|
mainRoute.children.unshift(homeRoute)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.router = this.createRouter(VueRouter, {
|
this.router = this.createRouter(VueRouter, {
|
||||||
Main,
|
Main,
|
||||||
ParentView,
|
ParentView,
|
||||||
@@ -165,11 +181,7 @@ class AdminFramework {
|
|||||||
Page401,
|
Page401,
|
||||||
Page404,
|
Page404,
|
||||||
Page500
|
Page500
|
||||||
}, [], ViewUI)
|
}, mainRoute ? [mainRoute] : [], ViewUI)
|
||||||
|
|
||||||
// 自动添加动态路由
|
|
||||||
const mainRoutes = this.getRoutes({ Main, ParentView, Page404 })
|
|
||||||
this.router.addRoutes([mainRoutes])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,10 +73,6 @@ export default {
|
|||||||
let token = res.data.token
|
let token = res.data.token
|
||||||
let name = res.data.user.name.trim()
|
let name = res.data.user.name.trim()
|
||||||
|
|
||||||
if (res.data.shop) {
|
|
||||||
let shopId = res.data.shop.id
|
|
||||||
commit('shop/setShopId', shopId, { root: true })
|
|
||||||
}
|
|
||||||
|
|
||||||
commit('setUserName', name)
|
commit('setUserName', name)
|
||||||
commit('setToken', token)
|
commit('setToken', token)
|
||||||
@@ -93,9 +89,6 @@ export default {
|
|||||||
async handleLogOut({ state, commit }, vue) {
|
async handleLogOut({ state, commit }, vue) {
|
||||||
commit('setToken', '')
|
commit('setToken', '')
|
||||||
commit('setAuthorityMenus', '[]')
|
commit('setAuthorityMenus', '[]')
|
||||||
if (state.shop) {
|
|
||||||
commit('shop/setShopId', '', { root: true })
|
|
||||||
}
|
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,17 @@ export default class uiTool {
|
|||||||
redirect: '/home',
|
redirect: '/home',
|
||||||
component: Main,
|
component: Main,
|
||||||
meta: { title: '首页', notCache: true },
|
meta: { title: '首页', notCache: true },
|
||||||
children: []
|
children: [
|
||||||
|
// 默认 home 路由,确保登录后能跳转
|
||||||
|
{
|
||||||
|
path: '/home',
|
||||||
|
name: 'home',
|
||||||
|
meta: { title: '首页', notCache: true },
|
||||||
|
component: {
|
||||||
|
render: h => h('div', { style: { padding: '20px' } }, '欢迎使用管理系统')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -188,7 +198,17 @@ export default class uiTool {
|
|||||||
let menus = uiTool.transformTree(authorityMenus)
|
let menus = uiTool.transformTree(authorityMenus)
|
||||||
let curRoutes = uiTool.menuToRoute(menus, ParentView, Page404)
|
let curRoutes = uiTool.menuToRoute(menus, ParentView, Page404)
|
||||||
|
|
||||||
mainRoute.children = curRoutes
|
// 合并权限路由,保留默认 home 路由
|
||||||
|
const homeRoute = mainRoute.children.find(r => r.name === 'home')
|
||||||
|
const hasHome = curRoutes.some(r => r.name === 'home')
|
||||||
|
|
||||||
|
if (hasHome) {
|
||||||
|
// 如果权限路由中有 home,使用权限路由的 home
|
||||||
|
mainRoute.children = curRoutes
|
||||||
|
} else {
|
||||||
|
// 如果权限路由中没有 home,保留默认 home 并添加其他路由
|
||||||
|
mainRoute.children = [homeRoute, ...curRoutes]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ window.addEventListener('resize', AdminFramework.uiTool.setRem)
|
|||||||
- ✅ 注册 Vuex(自动调用 `Vue.use(Vuex)`)
|
- ✅ 注册 Vuex(自动调用 `Vue.use(Vuex)`)
|
||||||
- ✅ 创建 Store(包含用户、应用模块)
|
- ✅ 创建 Store(包含用户、应用模块)
|
||||||
- ✅ 创建 Router(包含所有基础路由和动态路由)
|
- ✅ 创建 Router(包含所有基础路由和动态路由)
|
||||||
|
- ✅ **提前注册 home 路由**(确保登录后能正常跳转)
|
||||||
- ✅ 初始化 HTTP
|
- ✅ 初始化 HTTP
|
||||||
- ✅ 设置 API 服务
|
- ✅ 设置 API 服务
|
||||||
- ✅ 注册全局组件
|
- ✅ 注册全局组件
|
||||||
|
|||||||
Reference in New Issue
Block a user