This commit is contained in:
张成
2025-10-08 17:15:31 +08:00
parent cda6e0f222
commit 43eb9715fa
4 changed files with 99 additions and 38 deletions

View File

@@ -32,6 +32,9 @@ import { setParamSetupServer } from './store/app'
import routerConfig, { createBaseRoutes, setupRouterGuards } from './router' import routerConfig, { createBaseRoutes, setupRouterGuards } from './router'
// ==================== 系统页面 ==================== // ==================== 系统页面 ====================
// 主页
import HomePage from './views/home/index.vue'
// system 页面 // system 页面
import SysLog from './views/system/sys_log.vue' import SysLog from './views/system/sys_log.vue'
import SysParamSetup from './views/system/sys_param_setup.vue' import SysParamSetup from './views/system/sys_param_setup.vue'
@@ -95,6 +98,7 @@ class AdminFramework {
this.Page500 = Page500 this.Page500 = Page500
// 导出系统页面 // 导出系统页面
this.HomePage = HomePage
this.SysLog = SysLog this.SysLog = SysLog
this.SysParamSetup = SysParamSetup this.SysParamSetup = SysParamSetup
this.SysRole = SysRole this.SysRole = SysRole
@@ -159,8 +163,7 @@ class AdminFramework {
// 如果提供了 VueRouter自动创建 Router // 如果提供了 VueRouter自动创建 Router
if (VueRouter && !this.router) { if (VueRouter && !this.router) {
// 获取主路由配置(包含 home // 获取主路由配置(包含 home
const mainRoute = this.getRoutes({ Main, ParentView, Page404 }) const mainRoute = this.getRoutes({ Main, ParentView, Page404, HomePage })
this.router = this.createRouter(VueRouter, { this.router = this.createRouter(VueRouter, {
Main, Main,
@@ -278,14 +281,14 @@ class AdminFramework {
* @returns {Object} 主路由配置 * @returns {Object} 主路由配置
*/ */
getRoutes(components = {}) { getRoutes(components = {}) {
const { Main, ParentView, Page404 } = components const { Main, ParentView, Page404, HomePage } = components
if (!Main || !ParentView || !Page404) { if (!Main || !ParentView || !Page404) {
console.error('Missing required layout components') console.error('Missing required layout components')
return null return null
} }
return uiTool.getRoutes(Main, ParentView, Page404) return uiTool.getRoutes(Main, ParentView, Page404, HomePage)
} }
/** /**
@@ -323,6 +326,7 @@ export {
setupRouterGuards, setupRouterGuards,
// 系统页面 // 系统页面
HomePage,
SysLog, SysLog,
SysParamSetup, SysParamSetup,
SysRole, SysRole,

View File

@@ -168,7 +168,7 @@ export default class uiTool {
return [] return []
} }
static getRoutes(Main, ParentView, Page404) { static getRoutes(Main, ParentView, Page404, HomePage) {
let mainRoute = { let mainRoute = {
path: '/', path: '/',
name: '主视图', name: '主视图',
@@ -181,7 +181,7 @@ export default class uiTool {
path: '/home', path: '/home',
name: 'home', name: 'home',
meta: { title: '首页', notCache: true }, meta: { title: '首页', notCache: true },
component: { component: HomePage || {
render: h => h('div', { style: { padding: '20px' } }, '欢迎使用管理系统') render: h => h('div', { style: { padding: '20px' } }, '欢迎使用管理系统')
} }
} }

44
src/views/home/index.vue Normal file
View File

@@ -0,0 +1,44 @@
<template>
<div class="content-view">
<h1 class="home-title">
<span class="hy">欢迎登陆 </span>
{{sysFormModel.title}}
</h1>
</div>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'home',
components: {},
data() {
return {}
},
computed: {
...mapGetters({
sysFormModel: 'app/sysFormModel',
}),
},
mounted() {
//
},
}
</script>
<style scoped lang="less">
.content-view {
display: flex;
justify-content: center;
align-items: center;
.hy {
font-size: 18px;
}
.home-title {
font-size: 30px;
color: #2d8cf0;
}
}
</style>

View File

@@ -18,6 +18,7 @@
## ✨ 特性 ## ✨ 特性
**主页组件**(欢迎页面,自动显示系统标题)
**系统管理页面**sys 开头的所有页面和功能) **系统管理页面**sys 开头的所有页面和功能)
**系统 API**system 和 system_high 所有 API **系统 API**system 和 system_high 所有 API
**全局组件**Tables、Editor、Upload 等) **全局组件**Tables、Editor、Upload 等)
@@ -88,6 +89,7 @@ import AdminFramework from 'admin-framework'
**无需从原项目复制** **无需从原项目复制**
**已包含** **已包含**
- **主页组件**HomePage - 欢迎页面,显示系统标题)
- 所有系统页面system、system_high - 所有系统页面system、system_high
- 所有系统 APIsystem、system_high - 所有系统 APIsystem、system_high
- 所有全局组件Tables、Editor、Upload 等) - 所有全局组件Tables、Editor、Upload 等)
@@ -534,15 +536,20 @@ this.$store.getters['app/sysFormModel']
框架已内置所有系统管理页面,可直接从框架导入使用: 框架已内置所有系统管理页面,可直接从框架导入使用:
#### 主页
```javascript
import {
HomePage // 主页欢迎页面(显示系统标题)
} from 'admin-framework'
```
#### system 目录页面 #### system 目录页面
```javascript ```javascript
import { import {
SysLog, // 系统日志管理 SysLog, // 系统日志管理
SysParamSetup, // 参数设置 SysParamSetup, // 参数设置
SysRole, // 角色管理 SysRole, // 角色管理
SysUser, // 用户管理 SysUser // 用户管理
WchCities, // 城市管理
WchProfessions // 职业管理
} from 'admin-framework' } from 'admin-framework'
``` ```
@@ -557,9 +564,14 @@ import {
#### 在路由中使用 #### 在路由中使用
```javascript ```javascript
import { SysUser, SysRole, SysMenu } from 'admin-framework' import { HomePage, SysUser, SysRole, SysMenu } from 'admin-framework'
const routes = [ const routes = [
{
path: '/home',
name: 'home',
component: HomePage // 框架自动注册,也可手动使用
},
{ {
path: '/system/user', path: '/system/user',
name: 'sys_user', name: 'sys_user',
@@ -892,48 +904,49 @@ export default {
} }
``` ```
### Q11: 如何自定义 home 首页路由? ### Q11: 主页 HomePage 组件说明
A: **框架支持自定义 home 路由,在初始化时传入 `homeRoute` 参数即可** A: **框架已内置主页组件,自动显示系统标题欢迎信息**
**默认行为** **默认主页组件**
框架会自动创建一个默认的 home 路由,确保登录后能正常跳转: ```vue
<!-- 已内置在框架中 -->
<template>
<div class="content-view">
<h1 class="home-title">
<span class="hy">欢迎登陆 </span>
{{ sysFormModel.title }}
</h1>
</div>
</template>
```
**特性**
- ✅ 自动从 Vuex Store 获取系统标题(`app/sysFormModel`
- ✅ 优雅的欢迎页面样式
- ✅ home 路由已在创建 Router 时注册,确保登录后能正常跳转
**如何使用**
框架会自动创建 home 路由并使用内置的 HomePage 组件:
```javascript ```javascript
{ {
path: '/home', path: '/home',
name: 'home', name: 'home',
meta: { title: '首页', notCache: true }, meta: { title: '首页', notCache: true },
component: { render: h => h('div', '欢迎使用管理系统') } component: AdminFramework.HomePage // 框架内置的主页组件
} }
``` ```
**自定义 home 路由** **自定义主页**
如果后端返回的权限菜单中包含 home 路由配置,会优先使用权限菜单的配置。
**直接使用 HomePage 组件**
```javascript ```javascript
import Vue from 'vue' // 在其他地方也可以直接引用
import AdminFramework from './libs/admin-framework.js' import AdminFramework from './libs/admin-framework.js'
import HomePage from './views/home.vue' // 你的自定义首页 const HomePage = AdminFramework.HomePage
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: 需要单独引入样式文件吗? ### Q12: 需要单独引入样式文件吗?
A: **不需要!框架已内置所有样式。** A: **不需要!框架已内置所有样式。**