catchAdmin.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { createApp } from 'vue'
  2. import type { App as app } from 'vue'
  3. import App from '/admin/App.vue'
  4. import router, { bootstrapRouter } from '/admin/router'
  5. import ElementPlus from 'element-plus'
  6. import zh from 'element-plus/es/locale/lang/zh-cn'
  7. import { bootstrapStore } from '/admin/stores'
  8. import Cache from './cache'
  9. import { bootstrapI18n } from '/admin/i18n'
  10. import guard from '/admin/router/guard'
  11. /**
  12. * catchadmin
  13. */
  14. export default class CatchAdmin {
  15. protected app: app
  16. protected element: string
  17. /**
  18. * construct
  19. *
  20. * @param ele
  21. */
  22. constructor(ele: string = '#app') {
  23. this.app = createApp(App)
  24. this.element = ele
  25. }
  26. /**
  27. * admin boot
  28. */
  29. bootstrap(): void {
  30. this.useElementPlus().usePinia().useI18n().useRouter().mount()
  31. }
  32. /**
  33. * 挂载节点
  34. *
  35. * @returns
  36. */
  37. protected mount(): void {
  38. this.app.mount(this.element)
  39. }
  40. /**
  41. * 加载路由
  42. *
  43. * @returns
  44. */
  45. protected useRouter(): CatchAdmin {
  46. guard(router)
  47. bootstrapRouter(this.app)
  48. return this
  49. }
  50. /**
  51. * ui
  52. *
  53. * @returns
  54. */
  55. protected useElementPlus(): CatchAdmin {
  56. this.app.use(ElementPlus, {
  57. locale: Cache.get('language') === 'zh' && zh,
  58. })
  59. return this
  60. }
  61. /**
  62. * use pinia
  63. */
  64. protected usePinia(): CatchAdmin {
  65. bootstrapStore(this.app)
  66. return this
  67. }
  68. /**
  69. * use i18n
  70. */
  71. protected useI18n(): CatchAdmin {
  72. bootstrapI18n(this.app)
  73. return this
  74. }
  75. }