Răsfoiți Sursa

部分兼容h5

imndx 2 ani în urmă
părinte
comite
bbc401a498
2 a modificat fișierele cu 81 adăugiri și 23 ștergeri
  1. 50 19
      App.vue
  2. 31 4
      pages/conversation/MessageInputView.vue

+ 50 - 19
App.vue

@@ -1,27 +1,58 @@
 <script>
 import store from "./store";
+import {getItem} from "./pages/util/storageHelper";
 import wfc from "./wfc/client/wfc";
 
 export default {
-  onLaunch: function () {
-    console.log("App Launch");
-      plus.push.getClientInfoAsync((info) => {
-          let cid = info["clientid"];
-          if (cid){
-              console.log('push clientId', cid);
-              wfc.setDeviceToken(7, cid);
-          }
-      });
-  },
-  onShow: function () {
-    console.log("App Show");
-      store.state.misc.isAppHidden = false;
-  },
-  onHide: function () {
-    console.log("App Hide");
-    store.state.misc.isAppHidden = true;
-  },
-};
+    onLaunch: function () {
+        console.log("App Launch");
+        // #ifdef APP-PLUS
+        plus.push.getClientInfoAsync((info) => {
+            let cid = info["clientid"];
+            if (cid) {
+                console.log('push clientId', cid);
+                wfc.setDeviceToken(7, cid);
+            }
+        });
+        // #endif
+    },
+    onShow: function () {
+        console.log("App Show");
+        store.state.misc.isAppHidden = false;
+        // #ifdef H5
+        let userId = getItem('userId');
+        let token = getItem('token')
+        if (token) {
+            wfc.connect(userId, token);
+            this.go2ConversationList();
+        } else {
+            uni.redirectTo({
+                url: '/pages/login/LoginPage',
+            })
+        }
+        // #endif
+    },
+    onHide: function () {
+        console.log("App Hide");
+        store.state.misc.isAppHidden = true;
+    },
+    methods: {
+        go2ConversationList() {
+            uni.switchTab({
+                url: '/pages/conversationList/ConversationListPage',
+                success: () => {
+                    console.log('to conversation list success');
+                },
+                fail: e => {
+                    console.log('to conversation list error', e);
+                },
+                complete: () => {
+                    console.log('switch tab complete')
+                }
+            });
+        }
+    }
+}
 </script>
 
 <style>

+ 31 - 4
pages/conversation/MessageInputView.vue

@@ -192,7 +192,7 @@ export default {
             }
         },
 
-        mention(){
+        mention() {
 
         },
         send() {
@@ -331,13 +331,22 @@ export default {
                 sizeType: ['original', 'compressed'],
                 success: (e) => {
                     console.log('choose image', e.tempFilePaths);
-                    e.tempFilePaths.forEach(path => {
+                    e.tempFilePaths.forEach(async path => {
                         let filePath;
+                        // #ifdef APP-PLUS
                         if (path.startsWith('file://')) {
                             filePath = path.substring('file://'.length);
                         } else {
                             filePath = plus.io.convertLocalFileSystemURL(path)
                         }
+                        // #endif
+                        // #ifdef H5
+                        filePath = await fetch(path).then(res => res.blob())
+                            .then(blob => {
+                                let name = `${new Date().getTime()}.${blob.type.substring(blob.type.lastIndexOf('/') + 1)}`;
+                                return new File([blob], name)
+                            })
+                        // #endif
                         store.sendFile(this.conversationInfo.conversation, filePath);
                     })
                 }
@@ -372,31 +381,49 @@ export default {
                 // count: _self.limit ? _self.limit  - _self.fileList.length : 999,
                 sourceType: ['camera'],
                 sizeType: ['original', 'compressed'],
-                success: (e) => {
+                success: async (e) => {
                     console.log('choose video', e);
                     let duration = e.duration;
                     let path = e.tempFilePath;
                     let filePath;
+                    // #ifdef APP-PLUS
                     if (path.startsWith('file://')) {
                         filePath = path.substring('file://'.length);
                     } else {
                         filePath = plus.io.convertLocalFileSystemURL(path)
                     }
+                    // #endif
+                    // #ifdef H5
+                    filePath = await fetch(path).then(res => res.blob())
+                        .then(blob => {
+                            let name = `${new Date().getTime()}.${blob.type.substring(blob.type.lastIndexOf('/') + 1)}`;
+                            return new File([blob], name)
+                        })
+                    // #endif
                     store.sendFile(this.conversationInfo.conversation, filePath, duration);
                 }
             })
         },
 
         chooseFile() {
-            wfc.chooseFile('all', (file) => {
+            wfc.chooseFile('all', async (file) => {
                     console.log('choose file', file);
                     let path = file.path;
                     let filePath;
+                    // #ifdef APP-PLUS
                     if (path.startsWith('file://')) {
                         filePath = path.substring('file://'.length);
                     } else {
                         filePath = plus.io.convertLocalFileSystemURL(path)
                     }
+                    // #endif
+                    // #ifdef H5
+                    filePath = await fetch(path).then(res => res.blob())
+                        .then(blob => {
+                            let name = `${new Date().getTime()}.${blob.type.substring(blob.type.lastIndexOf('/') + 1)}`;
+                            return new File([blob], name)
+                        })
+                    // #endif
                     file.path = filePath;
                     store.sendFile(this.conversationInfo.conversation, file);
                 }