From 54d166e290ae2a0042002ddb4684b51e4bd207d9 Mon Sep 17 00:00:00 2001 From: heimawl <1785969728@qq.com> Date: 星期三, 05 七月 2023 16:55:04 +0800 Subject: [PATCH] 11 --- src/views/shortmessage/communication/index.vue | 110 +++++++++++++++++++++++++++++++----------------------- 1 files changed, 63 insertions(+), 47 deletions(-) diff --git a/src/views/shortmessage/communication/index.vue b/src/views/shortmessage/communication/index.vue index 4bb666e..afcbac4 100644 --- a/src/views/shortmessage/communication/index.vue +++ b/src/views/shortmessage/communication/index.vue @@ -63,8 +63,8 @@ </template> <script> -import LemonMessageVoice from "./lemon-message-voice"; import EmojiData from "./database/emoji"; +import { chitchatapi } from "@/api/noteapi/chitchat"; import { sendWebsocket, websocketSend, @@ -106,6 +106,9 @@ }; export default { name: "communication", + provide: { + IMUI: "IMUI value", + }, data() { return { theme: "blue", @@ -296,19 +299,19 @@ setTimeout(() => { IMUI.changeContact("contact-1"); }, 500); - + // 宸︿晶鑱旂郴浜烘渶鏂版秷鎭� IMUI.setLastContentRender("event", (message) => { return `[鑷畾涔夐�氱煡鍐呭]`; }); - let contactList = [ { ...contactData1 }, { ...contactData2 }, { ...contactData3 }, //...Array(100).fill(contactData1) ]; - + // 鍒濆鑱旂郴浜� IMUI.initContacts(contactList); + // 鍒濆鍖栧乏渚у鑸� IMUI.initMenus([ { name: "messages", @@ -369,7 +372,7 @@ isBottom: true, }, ]); - + // 宸ュ叿鏍� IMUI.initEditorTools([ { name: "emoji", @@ -495,6 +498,7 @@ IMUI.messageViewToBottom(); } }, + // 瀹氫箟鏂版秷鎭� appendCustomMessage() { const { IMUI } = this.$refs; const message = { @@ -588,54 +592,66 @@ requstWs(message, next, file) { console.log("杩炴帴"); // 闃叉鐢ㄦ埛澶氭杩炵画鐐瑰嚮鍙戣捣璇锋眰锛屾墍浠ヨ鍏堝叧闂笂娆$殑ws璇锋眰銆� - // closeWebsocket(); + closeWebsocket(); + let formData = new FormData(); - if (file) { - const reader = new FileReader(); - console.log(reader); - console.log(file); - reader.onload = (file) => { - console.log(file); - console.log(reader); - const imageData = reader.result; - //鏂囦欢瀛楄妭澶у皬 - // const fileSize = file.loaded; - const fileSize = imageData.length; - console.log("byteLength 锛� ", fileSize); - const chunkSize = 4096; // 璁剧疆姣忎釜鏁版嵁鍧楃殑澶у皬 - let offset = 0; + // if (file) { + // const reader = new FileReader(); + // console.log(reader); + // console.log(file); + // reader.onload = (file) => { + // console.log(file); + // console.log(reader); + // const imageData = reader.result; + // //鏂囦欢瀛楄妭澶у皬 + // // const fileSize = file.loaded; + // const fileSize = imageData.length; + // console.log("byteLength 锛� ", fileSize); + // const chunkSize = 4096; // 璁剧疆姣忎釜鏁版嵁鍧楃殑澶у皬 + // let offset = 0; - // 鍒嗗潡浼犺緭鍥剧墖鏁版嵁 - while (offset < imageData.length) { - const chunk = imageData.slice(offset, offset + chunkSize); - const obj = { - type: file.type, - userId: "1", //鎺ユ敹鏁版嵁鏂� - fileSize: fileSize, - image: chunk, - }; - console.log(JSON.stringify(obj)); - // 鍙戣捣ws璇锋眰 - // sendWebsocket( - // "ws://192.168.31.121:8080/chat?userId=2", - // JSON.stringify(obj), - // this.wsMessage, - // this.wsError - // ); - websocketSend(JSON.stringify(obj)); - offset += chunkSize; + // // 鍒嗗潡浼犺緭鍥剧墖鏁版嵁 + // while (offset < imageData.length) { + // const chunk = imageData.slice(offset, offset + chunkSize); + // const obj = { + // type: file.type, + // userId: "1", //鎺ユ敹鏁版嵁鏂� + // fileSize: fileSize, + // image: chunk, + // }; + // console.log(JSON.stringify(obj)); + // // 鍙戣捣ws璇锋眰 + // // sendWebsocket( + // // "ws://192.168.31.121:8080/chat?userId=2", + // // JSON.stringify(obj), + // // this.wsMessage, + // // this.wsError + // // ); + // websocketSend(JSON.stringify(obj)); + // offset += chunkSize; - console.log("offset 锛� ", offset); - } + // console.log("offset 锛� ", offset); + // } - // 鍙戦�佸畬鎴愭爣璁� - console.log("message "); - }; + // // 鍙戦�佸畬鎴愭爣璁� + // console.log("message "); + // }; - return reader.readAsDataURL(file); - } + // return reader.readAsDataURL(file); + // } // 璺熷悗绔崗鍟嗭紝闇�瑕佷粈涔堝弬鏁版暟鎹粰鍚庡彴 + if (file) { + formData.append("files", file); + console.log(formData.get("files")); + // img.src = window.URL.createObjectURL(temp); + chitchatapi(formData).then((response) => { + console.log(response); + }); + + return console.log(formData); + } + const obj = { type: "object", userId: "1", //鎺ユ敹鏁版嵁鏂� @@ -644,7 +660,7 @@ }; // 鍙戣捣ws璇锋眰 sendWebsocket( - "ws://192.168.31.121:8080/chat?userId=2", + "ws://192.168.1.4:8080/chat?userId=2", obj, this.wsMessage, this.wsError -- Gitblit v1.9.3