Xiaoshu.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <!-- <LayoutExperience> -->
  3. <ContentContainer :containerStyle="containerStyle">
  4. <template v-if="!is_mounted"></template>
  5. <WujieVue
  6. v-if="is_mounted"
  7. width="100%"
  8. height="100%"
  9. name="xiaoshu"
  10. :url="xiaoshu_server_url"
  11. :sync="false"
  12. :props="props"
  13. :plugins="plugins"
  14. ></WujieVue>
  15. </ContentContainer>
  16. <!-- </LayoutExperience> -->
  17. </template>
  18. <script setup>
  19. import { ref, onMounted } from 'vue';
  20. import { useRouter } from 'vue-router';
  21. import WujieVue from 'wujie-vue3';
  22. import LayoutExperience from './layout/LayoutExperience.vue';
  23. import ContentContainer from './layout/ContentContainer.vue';
  24. import { useCurrentUserStore } from '../base/store/use-current-user';
  25. import { getConfigField } from '../config/index';
  26. const router = useRouter();
  27. const { bus } = WujieVue;
  28. const props = defineProps({});
  29. const is_mounted = ref(false);
  30. const plugins = ref([]);
  31. const xiaoshu_server_url = getConfigField('XIAOSHU_URL');
  32. const xiaoshu_websocket_url = getConfigField('WEBSOCKET_BASE_URL');
  33. const xiaoshu_assets_url = getConfigField('ASSETS_BASE_URL');
  34. const containerStyle = {
  35. padding: 0
  36. };
  37. onMounted(() => {
  38. const currentUser = useCurrentUserStore();
  39. const token = currentUser.token;
  40. const user_name = currentUser.username;
  41. const info_val = { userName: user_name, token: token };
  42. const info_str = JSON.stringify(info_val);
  43. /**
  44. * 插入到小数项目中的脚本
  45. */
  46. const insert_script_before_str = `
  47. window.WEBSOCKET_BASE_URL = '${xiaoshu_websocket_url}';
  48. window.ASSETS_BASE_URL = '${xiaoshu_assets_url}';
  49. localStorage.setItem('xintongxiaoshu', '${info_str}');
  50. `;
  51. const insert_script_after_str = `
  52. const box = document.querySelector('.xiaoshu-aside-left-menus-container');
  53. if(box){
  54. const btn = document.createElement('div');
  55. box.appendChild(btn);
  56. btn.innerHTML = '<span class="xiaoshu-aside-left-back-btn">返回</span>';
  57. btn.addEventListener('click', () => {
  58. window.$wujie?.bus.$emit("xiaoshuAsideBack");
  59. });
  60. }
  61. `;
  62. const insert_style_str = `
  63. .xiaoshu-aside-left-back-btn{
  64. width: 100%;
  65. height: 40px;
  66. line-height: 40px;
  67. text-align: center;
  68. background-color: #165dff;
  69. color: #fff;
  70. display: inline-block;
  71. cursor: pointer;
  72. }
  73. .xiaoshu-aside-left-menus-pop-container {}
  74. .xiaoshu-aside-left-menus-actions-container{
  75. display: none;
  76. }
  77. .user-popover.xiaoshu-aside-left-menus-pop-container>div.item{
  78. display: none;
  79. }
  80. .user-popover.xiaoshu-aside-left-menus-pop-container>header{
  81. padding-bottom: 0;
  82. border-bottom: none;
  83. }
  84. `;
  85. /**
  86. * 监听子系统的事件
  87. */
  88. bus.$on('xiaoshuAsideBack', function () {
  89. router.back();
  90. });
  91. plugins.value = [
  92. {
  93. /**
  94. * 在子应用所有的js之前
  95. * @see https://wujie-micro.github.io/doc/guide/plugin.html#js-before-loaders
  96. */
  97. jsBeforeLoaders: [{ content: insert_script_before_str }]
  98. },
  99. {
  100. /**
  101. * 在子应用所有的js之后
  102. * @see https://wujie-micro.github.io/doc/guide/plugin.html#js-after-loader
  103. */
  104. jsAfterLoaders: [{ content: insert_script_after_str }]
  105. },
  106. {
  107. cssAfterLoaders: [
  108. //在加载html所有样式之后添加一个内联样式
  109. { content: insert_style_str }
  110. ]
  111. }
  112. ];
  113. is_mounted.value = true;
  114. });
  115. </script>