init
This commit is contained in:
@@ -1,91 +1,22 @@
|
||||
// 引入依赖
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import Vuex from 'vuex'
|
||||
import ViewUI from 'view-design'
|
||||
|
||||
|
||||
// 引入样式
|
||||
import 'view-design/dist/styles/iview.css'
|
||||
|
||||
// 引入 Admin Framework(使用本地构建的文件)
|
||||
// 引入 Admin Framework(框架内部已包含所有依赖和样式)
|
||||
import AdminFramework from '../../dist/admin-framework.js'
|
||||
|
||||
// 引入组件映射表
|
||||
import componentMap from './router/component-map.js'
|
||||
|
||||
// 【关键】先将框架暴露到全局,确保在任何代码执行前就可以访问
|
||||
window.framework = AdminFramework
|
||||
|
||||
// 使用插件
|
||||
Vue.use(ViewUI)
|
||||
|
||||
// 配置参数
|
||||
const config = {
|
||||
// 【超级简化】只需一个函数调用!
|
||||
const app = AdminFramework.createApp({
|
||||
title: 'tennis管理系统',
|
||||
apiUrl: 'http://localhost:9098/admin_api/', // 修改为你的 API 地址
|
||||
uploadUrl: 'http://localhost:9098/admin_api/upload' // 修改为你的上传地址
|
||||
}
|
||||
|
||||
// 初始化框架
|
||||
AdminFramework.install(Vue, {
|
||||
config: config,
|
||||
ViewUI: ViewUI,
|
||||
VueRouter: VueRouter,
|
||||
Vuex: Vuex,
|
||||
createPersistedState: null,
|
||||
componentMap: componentMap // 传入组件映射表,用于动态路由
|
||||
})
|
||||
|
||||
// 创建 Vue 实例
|
||||
const app = new Vue({
|
||||
router: AdminFramework.router,
|
||||
store: AdminFramework.store,
|
||||
render: h => h('router-view'),
|
||||
async created() {
|
||||
console.log('=== Admin Framework Demo 启动成功 ===')
|
||||
console.log('框架版本:', AdminFramework.version)
|
||||
console.log('配置信息:', this.$config)
|
||||
|
||||
// 刷新时恢复菜单和标题
|
||||
const token = this.$store.state.user.token
|
||||
const authorityMenus = localStorage.getItem('authorityMenus')
|
||||
|
||||
if (token && authorityMenus) {
|
||||
console.log('检测到登录状态,恢复菜单和标题...')
|
||||
try {
|
||||
// 先恢复菜单
|
||||
await this.$store.dispatch('user/setAuthorityMenus', {
|
||||
Main: AdminFramework.Main,
|
||||
ParentView: AdminFramework.ParentView,
|
||||
Page404: AdminFramework.Page404,
|
||||
authorityMenus: authorityMenus
|
||||
})
|
||||
console.log('菜单恢复成功')
|
||||
|
||||
// 再获取系统标题(已登录,会从接口获取)
|
||||
await this.$store.dispatch('app/getSysTitle', {
|
||||
defaultTitle: this.$config.title,
|
||||
defaultLogo: ''
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('恢复失败:', error)
|
||||
}
|
||||
} else {
|
||||
// 未登录,使用默认标题
|
||||
console.log('未登录,使用默认标题')
|
||||
document.title = this.$config.title
|
||||
}
|
||||
apiUrl: 'http://localhost:9098/admin_api/', // API 地址(uploadUrl 会自动设置为 apiUrl + 'upload')
|
||||
componentMap: componentMap, // 传入组件映射表,用于动态路由
|
||||
onReady() {
|
||||
// 可选:应用启动完成后的回调
|
||||
console.log('应用已准备就绪!')
|
||||
}
|
||||
})
|
||||
|
||||
// 挂载应用
|
||||
app.$mount('#app')
|
||||
|
||||
// 全局暴露 app 实例(方便调试)
|
||||
window.app = app
|
||||
window.rootVue = app
|
||||
// window.framework 已在文件开头暴露,无需重复
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user