init
This commit is contained in:
95
src/index.js
95
src/index.js
@@ -3,6 +3,14 @@
|
||||
* Version: 1.0.0
|
||||
*/
|
||||
|
||||
// 引入核心依赖
|
||||
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'
|
||||
import './assets/css/animate.css'
|
||||
import './assets/css/base.less'
|
||||
import './assets/css/ivewExpand.less'
|
||||
@@ -326,6 +334,93 @@ class AdminFramework {
|
||||
Vue.component(name, components[name])
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Create app with simplified API (推荐使用)
|
||||
* @param {Object} config - application config
|
||||
* @param {String} config.title - application title
|
||||
* @param {String} config.apiUrl - API base URL
|
||||
* @param {String} config.uploadUrl - upload URL (可选,默认为 apiUrl + 'upload')
|
||||
* @param {Object} config.componentMap - custom component map (optional)
|
||||
* @param {Function} config.onReady - callback when app is ready (optional)
|
||||
* @returns {Object} Vue instance
|
||||
*/
|
||||
createApp(config = {}) {
|
||||
// Auto install framework using internal dependencies
|
||||
if (!this.installed) {
|
||||
const { componentMap, ...appConfig } = config
|
||||
|
||||
// 如果没有提供 uploadUrl,自动从 apiUrl 推导
|
||||
if (!appConfig.uploadUrl && appConfig.apiUrl) {
|
||||
appConfig.uploadUrl = appConfig.apiUrl + (appConfig.apiUrl.endsWith('/') ? 'upload' : '/upload')
|
||||
}
|
||||
|
||||
this.install(Vue, {
|
||||
config: appConfig,
|
||||
ViewUI,
|
||||
VueRouter,
|
||||
Vuex,
|
||||
createPersistedState: null,
|
||||
componentMap: componentMap || {}
|
||||
})
|
||||
}
|
||||
|
||||
// Create Vue instance with auto menu/title restoration
|
||||
const app = new Vue({
|
||||
router: this.router,
|
||||
store: this.store,
|
||||
render: h => h('router-view'),
|
||||
async created() {
|
||||
console.log('=== Admin Framework App Started ===')
|
||||
console.log('Framework Version:', framework.version)
|
||||
console.log('Config:', this.$config)
|
||||
|
||||
// Auto restore menu and title on refresh
|
||||
const token = this.$store.state.user.token
|
||||
const authorityMenus = localStorage.getItem('authorityMenus')
|
||||
|
||||
if (token && authorityMenus) {
|
||||
console.log('Restoring menu and title...')
|
||||
try {
|
||||
// Restore menu
|
||||
await this.$store.dispatch('user/setAuthorityMenus', {
|
||||
Main: framework.Main,
|
||||
ParentView: framework.ParentView,
|
||||
Page404: framework.Page404,
|
||||
authorityMenus: authorityMenus
|
||||
})
|
||||
console.log('Menu restored')
|
||||
|
||||
// Get system title
|
||||
await this.$store.dispatch('app/getSysTitle', {
|
||||
defaultTitle: this.$config.title,
|
||||
defaultLogo: ''
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('Restore failed:', error)
|
||||
}
|
||||
} else {
|
||||
// Not logged in, use default title
|
||||
console.log('Not logged in, using default title')
|
||||
document.title = this.$config.title
|
||||
}
|
||||
|
||||
// Call user callback if provided
|
||||
if (config.onReady && typeof config.onReady === 'function') {
|
||||
config.onReady.call(this)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Expose to global for debugging
|
||||
if (typeof window !== 'undefined') {
|
||||
window.app = app
|
||||
window.rootVue = app
|
||||
window.framework = framework
|
||||
}
|
||||
|
||||
return app
|
||||
}
|
||||
}
|
||||
|
||||
const framework = new AdminFramework()
|
||||
|
||||
Reference in New Issue
Block a user