micro.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import WujieVue from 'wujie-vue3'
  2. import useMicro from '@fskj-admin/micro'
  3. import { microList } from '@/config/mainMicro'
  4. import { useUserStore } from '@/stores/user'
  5. export const plugins = [
  6. {
  7. cssBeforeLoaders: [
  8. // 强制使子利用body定位是relative
  9. { content: 'body{position: relative !important}' }
  10. ]
  11. },
  12. {
  13. jsLoader: (code: any) => {
  14. // 替换popper.js内计算偏左侧偏移量
  15. const codes = code.replace(
  16. 'left: elementRect.left - parentRect.left',
  17. 'left: fixed ? elementRect.left : elementRect.left - parentRect.left'
  18. )
  19. // 替换popper.js内右侧偏移量
  20. return codes.replace('popper.right > data.boundaries.right', 'false')
  21. }
  22. }
  23. ]
  24. // 主服务初始化
  25. export const micro = useMicro(WujieVue)
  26. export const initMicro = () => {
  27. micro.initMainMicro(microList, (bus: any) => {
  28. const userStore = useUserStore()
  29. // 监听退出登录
  30. bus.$on('logout', () => {
  31. userStore.logout()
  32. })
  33. // 监听token变化,同步给子应用
  34. watch(
  35. () => userStore.token,
  36. () => {
  37. WujieVue.bus.$emit('TOKEN', userStore.token)
  38. },
  39. {
  40. immediate: true
  41. }
  42. )
  43. })
  44. }
  45. export const isMicro = micro.isMicro
  46. export const logout = () => {
  47. if (isMicro) {
  48. window.$wujie?.bus.$emit('logout')
  49. } else {
  50. const userStore = useUserStore()
  51. userStore.logout()
  52. }
  53. }