rkljw 3 days ago
parent
commit
10c16877c8
3 changed files with 114 additions and 70 deletions
  1. 0 61
      src/App.vue
  2. 61 3
      src/layout/index.vue
  3. 53 6
      src/views/file/index.vue

+ 0 - 61
src/App.vue

@@ -1,71 +1,10 @@
 <template>
   <div id="app">
     <router-view />
-    <ChatFloatButton ref="chatFloatButton" @showDataList="handleShowChatPanelDataList" v-show="!showChat && $store.state.user.name" @open="showChat = true" />
-    <ChatPanel
-      ref="chatPanel"
-      v-show="showChat && $store.state.user.name"
-      @close="showChat = false"
-      @showChatPanel="handleShowChatPanel"
-    />
   </div>
 </template>
-
 <script>
-import ChatFloatButton from './layout/components/Chat/ChatFloatButton.vue'
-import ChatPanel from './layout/components/Chat/ChatPanel.vue'
-import emitter from '@/eventBus';
-import wsService from '@/utils/websocketService';
 export default {
   name: 'App',
-  components: { ChatFloatButton, ChatPanel },
-  data() {
-    return {
-      showChat: false
-    }
-  },
-  mounted() {
-    emitter.on('view-group-chat', this.handleViewGroupChat);
-    const token = this.$store.state.user.token; // 或从 cookie/localStorage 获取
-    wsService.connect(token);
-    console.log('#############websocket connected:', wsService.getReadyState());
-    // 你可以在这里全局监听消息
-    wsService.addMessageListener(this.handleWsMessage);
-    setInterval(() => {
-        if (wsService.getReadyState() === 1) {
-          wsService.send({ type: 'ping' });
-        }
-    }, 10000); // 每10秒
-
-  },
-  beforeDestroy() {
-    console.log("FFFFFFFFFFFFFFFFFFFFFFFFFF");
-    emitter.off('view-group-chat', this.handleViewGroupChat);
-  },
-  methods: {
-    handleViewGroupChat(val) {
-      this.showChat = true; // 先显示 ChatPanel
-      this.$nextTick(() => {
-        if (this.$refs.chatPanel) {
-          this.$refs.chatPanel.viewGroupChat(val);// 这里调用 selectGroup 或其它弹窗方法
-        }
-      });
-    },
-    handleShowChatPanel(callback,msg) {
-    this.showChat = true;
-    this.$nextTick(() => {
-      if (typeof callback === 'function') callback(msg);
-    });
-  },
-  handleShowChatPanelDataList(data) {
-    // console.log('handleShowChatPanelDataList::::::::::::', data);
-      this.$nextTick(() => {
-          if (this.$refs.chatPanel) {
-            this.$refs.chatPanel.handleShowChatPanelDataList(data);// 这里调用 selectGroup 或其它弹窗方法
-          }
-      });
-    }
-  }
-  
 }
 </script>

+ 61 - 3
src/layout/index.vue

@@ -13,6 +13,13 @@
         <settings />
       </right-panel> -->
     </div>
+    <ChatFloatButton ref="chatFloatButton" @showDataList="handleShowChatPanelDataList" v-show="!showChat && $store.state.user.name" @open="showChat = true" />
+    <ChatPanel
+      ref="chatPanel"
+      v-show="showChat && $store.state.user.name"
+      @close="showChat = false"
+      @showChatPanel="handleShowChatPanel"
+    />
   </div>
 </template>
 
@@ -22,7 +29,10 @@ import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components'
 import ResizeMixin from './mixin/ResizeHandler'
 import { mapState } from 'vuex'
 import Breadcrumb from '@/components/Breadcrumb'
-
+import ChatFloatButton from './components/Chat/ChatFloatButton.vue'
+import ChatPanel from './components/Chat/ChatPanel.vue'
+import emitter from '@/eventBus';
+import wsService from '@/utils/websocketService';
 export default {
   name: 'Layout',
   components: {
@@ -32,7 +42,9 @@ export default {
     Settings,
     Sidebar,
     TagsView,
-    Breadcrumb
+    Breadcrumb,
+    ChatFloatButton,
+     ChatPanel
   },
   mixins: [ResizeMixin],
   computed: {
@@ -52,10 +64,56 @@ export default {
       }
     }
   },
+  data() {
+    return {
+      showChat: false
+    }
+  },
+  mounted() {
+    emitter.on('view-group-chat', this.handleViewGroupChat);
+    const token = this.$store.state.user.token; // 或从 cookie/localStorage 获取
+    wsService.connect(token);
+    console.log('#############websocket connected:', wsService.getReadyState());
+    // 你可以在这里全局监听消息
+    wsService.addMessageListener(this.handleWsMessage);
+    setInterval(() => {
+        if (wsService.getReadyState() === 1) {
+          wsService.send({ type: 'ping' });
+        }
+    }, 10000); // 每10秒
+
+  },
+  beforeDestroy() {
+    console.log("FFFFFFFFFFFFFFFFFFFFFFFFFF");
+    emitter.off('view-group-chat', this.handleViewGroupChat);
+  },
   methods: {
     handleClickOutside() {
       this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
-    }
+    },
+    handleViewGroupChat(val) {
+      this.showChat = true; // 先显示 ChatPanel
+      this.$nextTick(() => {
+        if (this.$refs.chatPanel) {
+          this.$refs.chatPanel.viewGroupChat(val);// 这里调用 selectGroup 或其它弹窗方法
+        }
+      });
+    },
+    handleShowChatPanel(callback,msg) {
+      this.showChat = true;
+      this.$nextTick(() => {
+        if (typeof callback === 'function') callback(msg);
+      });
+   },
+   handleShowChatPanelDataList(data) {
+    // console.log('handleShowChatPanelDataList::::::::::::', data);
+      this.$nextTick(() => {
+          if (this.$refs.chatPanel) {
+            this.$refs.chatPanel.handleShowChatPanelDataList(data);// 这里调用 selectGroup 或其它弹窗方法
+          }
+      });
+    },
+    
   }
 }
 </script>

+ 53 - 6
src/views/file/index.vue

@@ -2,7 +2,9 @@
   <div class="file-upload-container">
     <div class="header">
       <h2>文件上传</h2>
-      <p>选择文件后提交给小程序</p>
+      <!-- <p>选择文件后提交给小程序</p>
+      <p v-if="type" class="type-info">当前类型: {{ type }}</p>
+      <p v-else class="type-info">未设置类型参数</p> -->
     </div>
 
     <div class="upload-area" @click="triggerFileInput">
@@ -11,7 +13,7 @@
       </div>
       <div class="upload-text">
         <p>点击选择文件</p>
-        <p class="upload-hint">支持图片、文档、视频等格式</p>
+        <p class="upload-hint">支持图片、文档、压缩文件、频/音频等格式</p>
       </div>
       <input
         ref="fileInput"
@@ -64,7 +66,7 @@
         :disabled="uploadedFiles.length === 0"
         :loading="submitting"
       >
-        {{ submitting ? '提交中...' : '提交给小程序' }} ({{ uploadedFiles.length }}个文件)
+        {{ submitting ? '提交中...' : '提交文件' }} ({{ uploadedFiles.length }}个文件)
       </el-button>
     </div>
   </div>
@@ -89,9 +91,37 @@ export default {
   methods: {
     // 从URL获取type参数
     getTypeFromUrl() {
-      const urlParams = new URLSearchParams(window.location.search)
-      this.type = urlParams.get('type') || ''
-      console.log('从URL接收的type参数:', this.type)
+      try {
+        // 方法1: 使用URLSearchParams
+        const urlParams = new URLSearchParams(window.location.search)
+        this.type = urlParams.get('type') || ''
+        
+        // 如果URLSearchParams获取不到,尝试其他方法
+        if (!this.type) {
+          // 方法2: 使用正则表达式
+          const match = window.location.search.match(/[?&]type=([^&]*)/)
+          if (match) {
+            this.type = decodeURIComponent(match[1])
+          }
+        }
+        
+        // 方法3: 使用Vue Router的query参数
+        if (!this.type && this.$route && this.$route.query) {
+          this.type = this.$route.query.type || ''
+        }
+        
+        console.log('当前URL:', window.location.href)
+        console.log('URL查询参数:', window.location.search)
+        console.log('从URL接收的type参数:', this.type)
+        console.log('Vue Router query:', this.$route ? this.$route.query : '无路由信息')
+        
+        // 如果还是没有获取到,显示提示
+        if (!this.type) {
+          console.warn('未找到type参数,请检查URL格式,例如: ?type=image')
+        }
+      } catch (error) {
+        console.error('获取type参数时出错:', error)
+      }
     },
 
     // 检查微信环境
@@ -207,6 +237,13 @@ export default {
           this.$message.success('文件已提交给小程序')
           this.selectedFiles = []
           this.uploadedFiles = []
+          
+          // 延迟关闭web-view,让用户看到成功提示
+          setTimeout(() => {
+            wx.miniProgram.navigateBack({
+              delta: 1
+            })
+          }, 1500)
         } else {
           // 如果不在小程序web-view中,提示用户
           this.$message.error('请在微信小程序中打开此页面')
@@ -300,6 +337,16 @@ export default {
   font-size: 14px;
 }
 
+.type-info {
+  background: #f0f9ff;
+  border: 1px solid #409eff;
+  border-radius: 4px;
+  padding: 8px 12px;
+  margin-top: 10px;
+  font-size: 12px;
+  color: #409eff;
+}
+
 .upload-area {
   border: 2px dashed #d9d9d9;
   border-radius: 8px;