117 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-12-05 23:01:12 +08:00
import { createApp } from 'vue'
import type { App as app } from 'vue'
import App from '/admin/App.vue'
import router, { bootstrapRouter } from '/admin/router'
import ElementPlus from 'element-plus'
import zh from 'element-plus/es/locale/lang/zh-cn'
2024-01-24 11:49:22 +08:00
import en from 'element-plus/es/locale/lang/en'
2022-12-05 23:01:12 +08:00
import { bootstrapStore } from '/admin/stores'
import Cache from './cache'
import { bootstrapI18n } from '/admin/i18n'
import guard from '/admin/router/guard'
2023-03-11 15:05:46 +08:00
import { bootstrapDirectives } from '/admin/directives'
2024-01-24 11:49:22 +08:00
import { Language } from 'element-plus/es/locale'
2024-04-23 13:12:36 +08:00
import { bootstrapCatchForm } from '/admin/components/catchForm'
import http from '/admin/support/http'
2022-12-05 23:01:12 +08:00
/**
* catchadmin
*/
export default class CatchAdmin {
protected app: app
protected element: string
/**
* construct
*
* @param ele
*/
constructor(ele: string = '#app') {
this.app = createApp(App)
this.element = ele
}
/**
* admin boot
*/
bootstrap(): void {
2024-04-23 13:12:36 +08:00
this.useElementPlus().usePinia().useI18n().installDirectives().bootstrapCatchForm().useRouter().mount()
2022-12-05 23:01:12 +08:00
}
/**
*
*
* @returns
*/
protected mount(): void {
this.app.mount(this.element)
}
/**
*
*
* @returns
*/
protected useRouter(): CatchAdmin {
guard(router)
bootstrapRouter(this.app)
return this
}
/**
* ui
*
* @returns
*/
protected useElementPlus(): CatchAdmin {
2024-01-24 11:51:49 +08:00
const languages: Record<string, Language> = {
2024-01-24 11:49:22 +08:00
zh, en
}
const language = Cache.get('language') || 'zh'
2022-12-05 23:01:12 +08:00
this.app.use(ElementPlus, {
2024-01-24 11:49:22 +08:00
locale: languages[language]
2022-12-05 23:01:12 +08:00
})
return this
}
/**
* use pinia
*/
protected usePinia(): CatchAdmin {
bootstrapStore(this.app)
return this
}
/**
* use i18n
*/
protected useI18n(): CatchAdmin {
bootstrapI18n(this.app)
return this
}
2023-03-11 15:05:46 +08:00
/**
* install directives
*
* @protected
*/
protected installDirectives(): CatchAdmin {
bootstrapDirectives(this.app)
return this
}
2024-04-23 13:12:36 +08:00
protected bootstrapCatchForm(): CatchAdmin {
bootstrapCatchForm(this.app, {http: http})
return this
}
2022-12-05 23:01:12 +08:00
}