Browse Source

Merge branch 'master' of http://git.cc-lotus.info/pointToNetwork/point-app

guhongwei 2 years ago
parent
commit
01eec366f3
2 changed files with 35 additions and 23 deletions
  1. 21 9
      pagesMessage/message/components/submit_1.vue
  2. 14 14
      pagesMessage/message/info.vue

+ 21 - 9
pagesMessage/message/components/submit_1.vue

@@ -3,7 +3,7 @@
 		<view class="submit">
 			<view class="submit-chat">
 				<!-- 文本框 -->
-				<textarea auto-height="true" class="chat-send btn" @confirm="inputs" @focus="focus"
+				<textarea auto-height="true" fixed="true" class="chat-send btn" @confirm="inputs" @focus="focus"
 					v-model="msg"></textarea>
 				<view class="bt-img" @tap="more">
 					<text class="iconfont icon-gengduoneirong"></text>
@@ -61,15 +61,27 @@
 			},
 			//图片发送
 			sendImg(e) {
+				const that = this;
+				let serverUrl = that.$config.serverUrl;
 				uni.chooseImage({
-					count: 9, //默认9
-					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
-					sourceType: [e], //从相册选择
-					// success: function (res) { //用function的方式会找不到send方法
-					success: (res) => {
-						const filePaths = res.tempFilePaths;
-						for (let i = 0; i < filePaths.length; i++) {
-							this.send(filePaths[i], 1)
+					count: 1,
+					sizeType: ['original', 'compressed'],
+					sourceType: ['album', 'camera'],
+					success: async function(res) {
+						let tempFile = JSON.parse(JSON.stringify(res.tempFilePaths));
+						const arr = await that.$apifile(`/point/upload`, 'file', tempFile[0], 'file');
+						if (arr.errcode == '0') {
+							let filePaths = {
+								name: arr.name,
+								uri: arr.uri,
+								url: serverUrl + arr.uri
+							}
+							that.send([filePaths], 1)
+						} else {
+							uni.showToast({
+								title: arr.errmsg,
+								icon: 'none'
+							})
 						}
 					}
 				});

+ 14 - 14
pagesMessage/message/info.vue

@@ -17,8 +17,9 @@
 									<view class="msg-text">{{item.content}}</view>
 								</view>
 								<!-- 图像 -->
-								<view class="message" v-else @tap="previewImg(item.content)">
-									<image :src="item.content" class="msg-img" mode="widthFix"></image>
+								<view class="message img" v-else @tap="previewImg(item.content)">
+									<image :src="item.content&&item.content.length>0?item.content[0].url:''"
+										class="msg-img" mode="widthFix"></image>
 								</view>
 							</view>
 							<view class="msg-m msg-right" v-if="item.speaker == friendName">
@@ -29,8 +30,9 @@
 									<view class="msg-text">{{item.content}}</view>
 								</view>
 								<!-- 图像 -->
-								<view class="message" v-else @tap="previewImg(item.content)">
-									<image :src="item.content" class="msg-img" mode="widthFix"></image>
+								<view class="message img" v-else @tap="previewImg(item.content)">
+									<image :src="item.content&&item.content.length>0?item.content[0].url:''"
+										class="msg-img" mode="widthFix"></image>
 								</view>
 							</view>
 						</view>
@@ -158,17 +160,11 @@
 			// 进行图片的预览
 			previewImg(e) {
 				const that = this;
-				let index = 0;
-				for (let i = 0; i < that.imgMsg.length; i++) {
-					if (that.imgMsg[i] == e) {
-						index = i;
-					}
-				}
-				console.log("index", index)
+				let urls = e && e[0] && e[0].url;
 				// 预览图片
 				uni.previewImage({
-					current: index,
-					urls: that.imgMsg,
+					current: 0,
+					urls: [urls],
 					longPressActions: {
 						itemList: ['发送给朋友', '保存图片', '收藏'],
 						success: function(data) {
@@ -194,7 +190,7 @@
 				// 发送给服务器消息
 				// onSendWS(JSON.stringify(data));
 
-				thatthat.unshiftmsg.push(data);
+				that.unshiftmsg.push(data);
 				// 跳转到最后一条数据 与前面的:id进行对照
 				that.$nextTick(function() {
 					that.scrollToView = 'msg' + (that.unshiftmsg.length - 1)
@@ -267,6 +263,10 @@
 							max-width: 480rpx;
 						}
 
+						.img {
+							margin: 0 20rpx 0 0;
+						}
+
 						.msg-text {
 							font-size: 32rpx;
 							color: rgba(39, 40, 50, 1);