Sfoglia il codice sorgente

feat: 完善小数嵌入大模型2.0项目的功能

zhupei@smartai.com 1 anno fa
parent
commit
d63ebc5f9b
1 ha cambiato i file con 50 aggiunte e 12 eliminazioni
  1. 50 12
      src/views/Xiaoshu.vue

+ 50 - 12
src/views/Xiaoshu.vue

@@ -19,6 +19,8 @@
 
 <script setup>
 import { ref, onMounted } from 'vue';
+import { useRouter } from 'vue-router';
+import WujieVue from 'wujie-vue3';
 import LayoutExperience from './layout/LayoutExperience.vue';
 import ContentContainer from './layout/ContentContainer.vue';
 
@@ -26,13 +28,17 @@ import { useCurrentUserStore } from '../base/store/use-current-user';
 
 import { getConfigField } from '../config/index';
 
+const router = useRouter();
+
+const { bus } = WujieVue;
+
 const props = defineProps({});
 
 const is_mounted = ref(false);
 
 const plugins = ref([]);
 
-const url = getConfigField('XIAOSHU_URL'); // 'http://192.168.20.119:9301/';
+const url = getConfigField('XIAOSHU_URL');
 
 const containerStyle = {
   padding: 0
@@ -47,26 +53,58 @@ onMounted(() => {
   const info_val = { userName: user_name, token: token };
   const info_str = JSON.stringify(info_val);
 
+  /**
+   * 插入到小数项目中的脚本
+   */
+  const insert_script_str = `
+    localStorage.setItem('xintongxiaoshu', '${info_str}');
+
+    const box = document.querySelector('.xiaoshu-aside-left-menus-container');
+
+    if(box){
+      const btn = document.createElement('div');
+      box.appendChild(btn);
+
+      btn.innerHTML = '<span class="xiaoshu-aside-left-back-btn">返回</span>';
+
+      btn.addEventListener('click', () => {
+        window.$wujie?.bus.$emit("xiaoshuAsideBack");
+      });
+    }
+  `;
+
+  const insert_style_str = `
+    .xiaoshu-aside-left-back-btn{
+      width: 100%;
+      height: 40px;
+      line-height: 40px;
+      text-align: center;
+      background-color: red;
+      color: #fff;
+      display: inline-block;
+      cursor: pointer;
+    }
+  `;
+
+  /**
+   * 监听子系统的事件
+   */
+  bus.$on('xiaoshuAsideBack', function () {
+    router.back();
+  });
+
   plugins.value = [
     {
       /**
        * @see https://wujie-micro.github.io/doc/guide/plugin.html#js-before-loaders
        */
-      // 在子应用所有的js之前
-      jsBeforeLoaders: [{ content: `localStorage.setItem('xintongxiaoshu', '${info_str}')` }]
-    },
-    {
-      // 对css脚本动态的进行替换
-      // code 为样式代码、url为样式的地址(内联样式为'')、base为子应用当前的地址
-      cssLoader: (code, url, base) => {
-        console.log('css-loader', url, code.slice(0, 50) + '...');
-        return code;
-      }
+      // 在子应用所有的js之后
+      jsAfterLoaders: [{ content: insert_script_str }]
     },
     {
       cssAfterLoaders: [
         //在加载html所有样式之后添加一个内联样式
-        { content: 'body{background-color: red;}' }
+        { content: insert_style_str }
       ]
     }
   ];