|
@@ -40,6 +40,11 @@
|
|
YeIMUniSDKDefines // 预定义常量
|
|
YeIMUniSDKDefines // 预定义常量
|
|
} from 'yeim-uni-sdk'
|
|
} from 'yeim-uni-sdk'
|
|
import MescrollVue from 'mescroll.js/mescroll.vue'
|
|
import MescrollVue from 'mescroll.js/mescroll.vue'
|
|
|
|
+ import {
|
|
|
|
+ uploadImage
|
|
|
|
+ } from '@/httpApi/chat.js'
|
|
|
|
+ import md5 from 'js-md5'
|
|
|
|
+ import config from "@/config";
|
|
export default {
|
|
export default {
|
|
props: ['body'],
|
|
props: ['body'],
|
|
data() {
|
|
data() {
|
|
@@ -112,41 +117,55 @@
|
|
},
|
|
},
|
|
changeImage(e) {
|
|
changeImage(e) {
|
|
let currentfile = this.$refs.fileadd.files[0];
|
|
let currentfile = this.$refs.fileadd.files[0];
|
|
- this.$loading();
|
|
|
|
|
|
+ let _self = this;
|
|
if (currentfile) {
|
|
if (currentfile) {
|
|
- const blobUrl = URL.createObjectURL(currentfile); // 创建Blob URL
|
|
|
|
- let img = new Image();
|
|
|
|
- img.src = blobUrl;
|
|
|
|
- img.onload = () => {
|
|
|
|
- this.sendImage({
|
|
|
|
- path: blobUrl,
|
|
|
|
- width: img.width,
|
|
|
|
- height: img.height
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
|
|
+ const reader = new FileReader();
|
|
|
|
+ reader.onload = function(e) {
|
|
|
|
+ const img = new Image();
|
|
|
|
+ img.onload = () => {
|
|
|
|
+ let filename = currentfile.name;
|
|
|
|
+ let suffix = filename.substring(filename.lastIndexOf('.'));
|
|
|
|
+ let name = md5((new Date()).getTime() + '_' + filename) + '_image' + suffix;
|
|
|
|
+ const formData = new FormData();
|
|
|
|
+ formData.append('file', currentfile);
|
|
|
|
+ formData.append('key', _self.getUploadFilePath(name, 'image'));
|
|
|
|
+ _self.$loading();
|
|
|
|
+ uploadImage(formData).then(res => {
|
|
|
|
+ if (res.state) {
|
|
|
|
+ _self.sendImage(res.data, img);
|
|
|
|
+ } else {
|
|
|
|
+ _self.$loading.close();
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ };
|
|
|
|
+ img.src = e.target.result; // 设置图片源为读取的结果
|
|
|
|
+ };
|
|
|
|
+ reader.readAsDataURL(currentfile); // 读取文件内容为DataURL
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ getUploadFilePath(filename, dir = 'files') {
|
|
|
|
+ let date = new Date();
|
|
|
|
+ let dateDir = date.getFullYear() + '-' + JSON.stringify(date.getMonth() + 1).padStart(2, 0) + '-' + JSON
|
|
|
|
+ .stringify(date.getDate()).padStart(2, 0);
|
|
|
|
+ return dir + '/' + dateDir + '/' + filename;
|
|
|
|
+ },
|
|
uploadImage() {
|
|
uploadImage() {
|
|
this.$refs.fileadd.click();
|
|
this.$refs.fileadd.click();
|
|
},
|
|
},
|
|
- sendImage(option) {
|
|
|
|
|
|
+ sendImage(data, img) {
|
|
//创建图片消息
|
|
//创建图片消息
|
|
- let message = YeIMUniSDK.getInstance().createImageMessage({
|
|
|
|
|
|
+ let message = YeIMUniSDK.getInstance().createImageMessageFromUrl({
|
|
toId: this.body.conversationId, //接收者用户ID字符串
|
|
toId: this.body.conversationId, //接收者用户ID字符串
|
|
- conversationType: YeIMUniSDKDefines
|
|
|
|
- .CONVERSATION_TYPE
|
|
|
|
- .PRIVATE, //会话类型:私聊
|
|
|
|
|
|
+ conversationType: YeIMUniSDKDefines.CONVERSATION_TYPE.PRIVATE, //会话类型:私聊
|
|
body: {
|
|
body: {
|
|
- file: {
|
|
|
|
- tempFilePath: option.path, //本地图片临时路径
|
|
|
|
- width: option.width, //图片宽度
|
|
|
|
- height: option.height //图片高度
|
|
|
|
- }
|
|
|
|
|
|
+ originalUrl: 'https://www.waywish.com/im' + data.url, //原图网络Url
|
|
|
|
+ originalWidth: img.width, //原图宽度
|
|
|
|
+ originalHeight: img.height, //原图高度
|
|
|
|
+ thumbnailUrl: 'https://www.waywish.com/im' + data.thumbnailUrl, //缩略图网络Url
|
|
|
|
+ thumbnailWidth: data.thumbnailWidth, //缩略图宽度
|
|
|
|
+ thumbnailHeight: data.thumbnailHeight, //缩略图高度
|
|
},
|
|
},
|
|
- extra: "",
|
|
|
|
- onProgress: (progress) => {
|
|
|
|
- // console.log(progress);
|
|
|
|
- }
|
|
|
|
|
|
+ extra: ""
|
|
});
|
|
});
|
|
YeIMUniSDK.getInstance().sendMessage({
|
|
YeIMUniSDK.getInstance().sendMessage({
|
|
message: message,
|
|
message: message,
|
|
@@ -166,7 +185,7 @@
|
|
this.sendLoading = false;
|
|
this.sendLoading = false;
|
|
});
|
|
});
|
|
},
|
|
},
|
|
- sendSuccess(res) {
|
|
|
|
|
|
+ sendSuccess(res) {
|
|
this.$loading.close();
|
|
this.$loading.close();
|
|
this.dataList.push(res.data);
|
|
this.dataList.push(res.data);
|
|
this.sendMessage = '';
|
|
this.sendMessage = '';
|