123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import { createApp } from 'vue';
- import type { App as app } from 'vue';
- import App from '@/App.vue';
- import router, { bootstrapRouter } from '@/router';
- import ElementPlus from 'element-plus';
- import zh from 'element-plus/es/locale/lang/zh-cn';
- import { bootstrapStore } from '@/stores';
- import Cache from './cache';
- import { bootstrapI18n } from '@/i18n';
- import guard from '@/router/guard';
- import { bootstrapDirectives } from '@/directives';
- import svgIcon from '@/components/SvgIcon/index.vue';
- /**
- * catchadmin
- */
- export default class CatchAdmin {
- protected app: app;
- protected element: string;
- /**
- * construct
- *
- * @param ele
- */
- constructor(ele = '#app') {
- this.app = createApp(App);
- this.element = ele;
- }
- /**
- * admin boot
- */
- bootstrap(): void {
- this.useElementPlus()
- .usePinia()
- .useI18n()
- .useRouter()
- .installDirectives()
- .installSvgComponent()
- .mount();
- }
- /**
- * 挂载节点
- *
- * @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 {
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- this.app.use(ElementPlus, {
- // locale: Cache.get('language') === 'zh' && zh
- locale: zh
- });
- return this;
- }
- /**
- * use pinia
- */
- protected usePinia(): CatchAdmin {
- bootstrapStore(this.app);
- return this;
- }
- /**
- * use i18n
- */
- protected useI18n(): CatchAdmin {
- bootstrapI18n(this.app);
- return this;
- }
- /**
- * install directives
- *
- * @protected
- */
- protected installDirectives(): CatchAdmin {
- bootstrapDirectives(this.app);
- return this;
- }
- /**
- * install -g svg-component
- *
- * @protected
- */
- protected installSvgComponent(): CatchAdmin {
- this.app.component('svg-icon', svgIcon);
- return this;
- }
- }
|