1
This commit is contained in:
14
src/index.js
14
src/index.js
@@ -117,13 +117,12 @@ 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, homeRoute } = options
|
const { config = {}, ViewUI, VueRouter, Vuex, createPersistedState } = options
|
||||||
this.config = config
|
this.config = config
|
||||||
|
|
||||||
// 自动注册 ViewUI
|
// 自动注册 ViewUI
|
||||||
@@ -162,17 +161,6 @@ class AdminFramework {
|
|||||||
// 获取主路由配置(包含 home)
|
// 获取主路由配置(包含 home)
|
||||||
const mainRoute = this.getRoutes({ Main, ParentView, Page404 })
|
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,
|
||||||
|
|||||||
46
完整使用文档.md
46
完整使用文档.md
@@ -802,7 +802,7 @@ npm run build
|
|||||||
|
|
||||||
新版本框架会自动调用 `Vue.use(Vuex)` 和 `Vue.use(VueRouter)`,无需手动注册!
|
新版本框架会自动调用 `Vue.use(Vuex)` 和 `Vue.use(VueRouter)`,无需手动注册!
|
||||||
|
|
||||||
### Q10: `this.$store.dispatch` 报错怎么办?
|
### Q13: `this.$store.dispatch` 报错怎么办?
|
||||||
|
|
||||||
A: **常见原因和解决方案**:
|
A: **常见原因和解决方案**:
|
||||||
|
|
||||||
@@ -892,7 +892,49 @@ export default {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Q11: 需要单独引入样式文件吗?
|
### Q11: 如何自定义 home 首页路由?
|
||||||
|
|
||||||
|
A: **框架支持自定义 home 路由,在初始化时传入 `homeRoute` 参数即可。**
|
||||||
|
|
||||||
|
**默认行为**:
|
||||||
|
框架会自动创建一个默认的 home 路由,确保登录后能正常跳转:
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
path: '/home',
|
||||||
|
name: 'home',
|
||||||
|
meta: { title: '首页', notCache: true },
|
||||||
|
component: { render: h => h('div', '欢迎使用管理系统') }
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**自定义 home 路由**:
|
||||||
|
```javascript
|
||||||
|
import Vue from 'vue'
|
||||||
|
import AdminFramework from './libs/admin-framework.js'
|
||||||
|
import HomePage from './views/home.vue' // 你的自定义首页
|
||||||
|
|
||||||
|
Vue.use(AdminFramework, {
|
||||||
|
config,
|
||||||
|
ViewUI,
|
||||||
|
VueRouter,
|
||||||
|
Vuex,
|
||||||
|
createPersistedState,
|
||||||
|
// ✅ 自定义 home 路由
|
||||||
|
homeRoute: {
|
||||||
|
path: '/home',
|
||||||
|
name: 'home',
|
||||||
|
meta: { title: '工作台', notCache: true },
|
||||||
|
component: HomePage // 使用你的自定义组件
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
**说明**:
|
||||||
|
- ✅ home 路由会在创建 Router 时立即注册,确保登录后能正常跳转
|
||||||
|
- ✅ 如果提供了 `homeRoute`,会替换默认的 home 路由
|
||||||
|
- ✅ 如果后端返回的权限菜单中有 home 路由,会使用权限菜单的配置
|
||||||
|
|
||||||
|
### Q12: 需要单独引入样式文件吗?
|
||||||
|
|
||||||
A: **不需要!框架已内置所有样式。**
|
A: **不需要!框架已内置所有样式。**
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user