main.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { createApp } from 'vue'
  2. import ElementPlus from 'element-plus'
  3. import zhCn from 'element-plus/es/locale/lang/zh-cn'
  4. import CacpUI from '@cacp/ui'
  5. import 'normalize.css/normalize.css'
  6. import 'element-plus/dist/index.css' //先引入element plus样式
  7. import '@cacp/ui/dist/index.css' //后引入@cacp/ui样式
  8. import './assets/main.less'
  9. import App from './App.vue'
  10. import router from './router'
  11. import plugins from './plugins'
  12. import directives from './directives'
  13. import { pinia } from './stores'
  14. import { addEventListener } from './utils/frame'
  15. import { BridgeCore } from '@cacp/bridge-core'
  16. import DictTag from '@/components/DictTag/dictTag.vue'
  17. import { getDict } from '@/utils/dict'
  18. // 初始化通信实例
  19. const bridge = new BridgeCore({
  20. allowedOrigins: [], //门户地址
  21. source: 'subApp'
  22. })
  23. const app = createApp(App)
  24. // 注册全局字典属性
  25. app.config.globalProperties.$dict = {
  26. get: getDict,
  27. type: async (dictType: string) => {
  28. return await getDict(dictType)
  29. }
  30. }
  31. // 声明全局属性类型
  32. declare module 'vue' {
  33. interface ComponentCustomProperties {
  34. $dict: {
  35. get: (dictType: string) => Promise<any[]>
  36. type: (dictType: string) => Promise<any[]>
  37. }
  38. }
  39. }
  40. app.use(router)
  41. app.use(plugins)
  42. app.use(directives)
  43. app.use(pinia)
  44. app.component('DictTag', DictTag)
  45. // 绑定message监听,addEventListener中调用了store,所以需要放在app.use(pinia)之后调用。
  46. addEventListener(bridge)
  47. app.use(ElementPlus, {
  48. locale: zhCn
  49. })
  50. app.use(CacpUI)
  51. app.mount('#app')