|
|
@ -4,7 +4,7 @@ |
|
|
<text class="title">{{title}}</text> |
|
|
<text class="title">{{title}}</text> |
|
|
<uni-icons class="btn-side" type="more-filled" size="30"></uni-icons> |
|
|
<uni-icons class="btn-side" type="more-filled" size="30"></uni-icons> |
|
|
</view> |
|
|
</view> |
|
|
<view class="chat-msg" @click="switchChatTabBox('none',false)"> |
|
|
<view class="chat-msg" @click="switchChatTabBox('none',true)"> |
|
|
<scroll-view class="scroll-box" scroll-y="true" :scroll-into-view="'chat-item-'+scrollMsgIdx"> |
|
|
<scroll-view class="scroll-box" scroll-y="true" :scroll-into-view="'chat-item-'+scrollMsgIdx"> |
|
|
<view v-for="(msgInfo,idx) in chat.messages" :key="idx"> |
|
|
<view v-for="(msgInfo,idx) in chat.messages" :key="idx"> |
|
|
<chat-message-item :headImage="headImage(msgInfo)" :showName="showName(msgInfo)" |
|
|
<chat-message-item :headImage="headImage(msgInfo)" :showName="showName(msgInfo)" |
|
|
@ -16,16 +16,21 @@ |
|
|
<view class="send-bar"> |
|
|
<view class="send-bar"> |
|
|
<view class="iconfont icon-voice-circle"></view> |
|
|
<view class="iconfont icon-voice-circle"></view> |
|
|
<view class="send-text"> |
|
|
<view class="send-text"> |
|
|
<textarea class="send-text-area" v-model="sendText" auto-height :show-confirm-bar="false" :focus="sendTextFocus" |
|
|
<textarea class="send-text-area" v-model="sendText" auto-height |
|
|
@focus="onSendTextFoucs()" cursor-spacing="20" @keydown.enter="sendTextMessage()" @click="switchChatTabBox('none',true)" :hold-keyboard="sendTextFocus"></textarea> |
|
|
:show-confirm-bar="false" :adjust-position="false" |
|
|
|
|
|
@focus="onSendTextFoucs" @confirm="sendTextMessage()" |
|
|
|
|
|
@keyboardheightchange="onKeyboardheightchange" |
|
|
|
|
|
confirm-type="send" @blur="onSendTextBlur" |
|
|
|
|
|
confirm-hold :hold-keyboard="true"></textarea> |
|
|
|
|
|
</view> |
|
|
|
|
|
<view class="iconfont icon-icon_emoji" @touchend.prevent="switchChatTabBox('emo',true)"></view> |
|
|
|
|
|
<view v-show="sendText==''" class="iconfont icon-add-circle" @touchend.prevent="switchChatTabBox('tools',true)"> |
|
|
</view> |
|
|
</view> |
|
|
<view class="iconfont icon-icon_emoji" @click="switchChatTabBox('emo',false)"></view> |
|
|
|
|
|
<view v-show="sendText==''" class="iconfont icon-add-circle" @click="switchChatTabBox('tools',false)"></view> |
|
|
|
|
|
<button v-show="sendText!=''" class="btn-send" type="primary" @touchend.prevent="sendTextMessage()" |
|
|
<button v-show="sendText!=''" class="btn-send" type="primary" @touchend.prevent="sendTextMessage()" |
|
|
size="mini">发送</button> |
|
|
size="mini">发送</button> |
|
|
</view> |
|
|
</view> |
|
|
|
|
|
|
|
|
<view class="chat-tab-bar" v-show="chatTabBox!='none'"> |
|
|
<view class="chat-tab-bar" v-show="chatTabBox!='none' ||showKeyBoard " :style="{height:`${keyboardHeight}px`}"> |
|
|
<view v-if="chatTabBox == 'tools'" class="chat-tools"> |
|
|
<view v-if="chatTabBox == 'tools'" class="chat-tools"> |
|
|
<view class="chat-tools-item"> |
|
|
<view class="chat-tools-item"> |
|
|
<image-upload :onBefore="onUploadImageBefore" :onSuccess="onUploadImageSuccess" |
|
|
<image-upload :onBefore="onUploadImageBefore" :onSuccess="onUploadImageSuccess" |
|
|
@ -34,7 +39,7 @@ |
|
|
</image-upload> |
|
|
</image-upload> |
|
|
<view class="tool-name">相册</view> |
|
|
<view class="tool-name">相册</view> |
|
|
</view> |
|
|
</view> |
|
|
<view class="chat-tools-item" v-for="(tool, idx) in tools" @click="onClickTool(tool)"> |
|
|
<view class="chat-tools-item" v-for="(tool, idx) in tools" @click.stop="onClickTool(tool)"> |
|
|
<view class="tool-icon iconfont" :class="tool.icon"></view> |
|
|
<view class="tool-icon iconfont" :class="tool.icon"></view> |
|
|
<view class="tool-name">{{ tool.name }}</view> |
|
|
<view class="tool-name">{{ tool.name }}</view> |
|
|
</view> |
|
|
</view> |
|
|
@ -46,8 +51,9 @@ |
|
|
:key="i" @click="selectEmoji(emoText)" mode="aspectFit" lazy-load="true"></image> |
|
|
:key="i" @click="selectEmoji(emoText)" mode="aspectFit" lazy-load="true"></image> |
|
|
</view> |
|
|
</view> |
|
|
</scroll-view> |
|
|
</scroll-view> |
|
|
|
|
|
<view v-if="showKeyBoard"></view> |
|
|
</view> |
|
|
</view> |
|
|
|
|
|
|
|
|
</view> |
|
|
</view> |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
@ -63,7 +69,8 @@ |
|
|
showVoice: false, // 是否显示语音录制弹窗 |
|
|
showVoice: false, // 是否显示语音录制弹窗 |
|
|
scrollMsgIdx: 0, // 滚动条定位为到哪条消息 |
|
|
scrollMsgIdx: 0, // 滚动条定位为到哪条消息 |
|
|
chatTabBox: 'none', |
|
|
chatTabBox: 'none', |
|
|
sendTextFocus: false, |
|
|
showKeyBoard:false, |
|
|
|
|
|
keyboardHeight: 322, |
|
|
tools: [{ |
|
|
tools: [{ |
|
|
name: "拍摄", |
|
|
name: "拍摄", |
|
|
icon: "icon-camera" |
|
|
icon: "icon-camera" |
|
|
@ -129,8 +136,6 @@ |
|
|
}).finally(() => { |
|
|
}).finally(() => { |
|
|
// 滚动到底部 |
|
|
// 滚动到底部 |
|
|
this.scrollToBottom(); |
|
|
this.scrollToBottom(); |
|
|
// 重新获得输入焦点 |
|
|
|
|
|
//this.sendTextFocus = true; |
|
|
|
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
fillTargetId(msgInfo, targetId) { |
|
|
fillTargetId(msgInfo, targetId) { |
|
|
@ -142,16 +147,16 @@ |
|
|
}, |
|
|
}, |
|
|
scrollToBottom() { |
|
|
scrollToBottom() { |
|
|
let size = this.chat.messages.length; |
|
|
let size = this.chat.messages.length; |
|
|
if(size>0){ |
|
|
if (size > 0) { |
|
|
this.scrollToMsgIdx(size-1); |
|
|
this.scrollToMsgIdx(size - 1); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
scrollToMsgIdx(idx){ |
|
|
scrollToMsgIdx(idx) { |
|
|
// 踩坑:如果scrollMsgIdx值没变化,滚动条不会移动 |
|
|
// 踩坑:如果scrollMsgIdx值没变化,滚动条不会移动 |
|
|
if(idx == this.scrollMsgIdx && idx>0){ |
|
|
if (idx == this.scrollMsgIdx && idx > 0) { |
|
|
this.$nextTick(() => { |
|
|
this.$nextTick(() => { |
|
|
// 先滚动到上一条 |
|
|
// 先滚动到上一条 |
|
|
this.scrollMsgIdx = idx-1; |
|
|
this.scrollMsgIdx = idx - 1; |
|
|
// 再滚动目标位置 |
|
|
// 再滚动目标位置 |
|
|
this.scrollToMsgIdx(idx); |
|
|
this.scrollToMsgIdx(idx); |
|
|
}); |
|
|
}); |
|
|
@ -160,21 +165,39 @@ |
|
|
this.$nextTick(() => { |
|
|
this.$nextTick(() => { |
|
|
this.scrollMsgIdx = idx; |
|
|
this.scrollMsgIdx = idx; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
switchChatTabBox(chatTabBox,sendTextFocus) { |
|
|
switchChatTabBox(chatTabBox,hideKeyBoard) { |
|
|
console.log("switchChatTabBox") |
|
|
console.log("switchChatTabBox") |
|
|
this.chatTabBox = chatTabBox; |
|
|
this.chatTabBox = chatTabBox; |
|
|
this.sendTextFocus = sendTextFocus |
|
|
|
|
|
this.scrollToBottom(); |
|
|
this.scrollToBottom(); |
|
|
console.log(this.sendTextFocus) |
|
|
if(hideKeyBoard){ |
|
|
|
|
|
uni.hideKeyboard(); |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
selectEmoji(emoText) { |
|
|
selectEmoji(emoText) { |
|
|
this.sendText += `#${emoText};`; |
|
|
this.sendText += `#${emoText};`; |
|
|
}, |
|
|
}, |
|
|
onSendTextFoucs(){ |
|
|
onSendTextFoucs(e) { |
|
|
console.log("onSendTextFoucs") |
|
|
// 更新键盘高度 |
|
|
this.scrollToBottom(); |
|
|
// if (e && e.detail && e.detail.height) { |
|
|
|
|
|
// this.switchChatTabBox('keyboard') |
|
|
|
|
|
// this.keyboardHeight = this.rpxTopx(e.detail.height); |
|
|
|
|
|
// console.log(this.keyboardHeight) |
|
|
|
|
|
// } |
|
|
|
|
|
}, |
|
|
|
|
|
onKeyboardheightchange(e){ |
|
|
|
|
|
console.log(e); |
|
|
|
|
|
if(e.detail.height >0){ |
|
|
|
|
|
this.showKeyBoard = true; |
|
|
|
|
|
this.switchChatTabBox('none',false) |
|
|
|
|
|
this.keyboardHeight = this.rpxTopx(e.detail.height); |
|
|
|
|
|
}else{ |
|
|
|
|
|
this.showKeyBoard = false; |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
onSendTextBlur() { |
|
|
|
|
|
//this.switchChatTabBox("none") |
|
|
}, |
|
|
}, |
|
|
onUploadImageBefore(file) { |
|
|
onUploadImageBefore(file) { |
|
|
let data = { |
|
|
let data = { |
|
|
@ -225,7 +248,7 @@ |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
loadGroup(groupId) { |
|
|
loadGroup(groupId) { |
|
|
this.$http({ |
|
|
this.$http({ |
|
|
@ -235,9 +258,9 @@ |
|
|
this.group = group; |
|
|
this.group = group; |
|
|
this.$store.commit("updateChatFromGroup", group); |
|
|
this.$store.commit("updateChatFromGroup", group); |
|
|
this.$store.commit("updateGroup", group); |
|
|
this.$store.commit("updateGroup", group); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.$http({ |
|
|
this.$http({ |
|
|
url: `/group/members/${groupId}`, |
|
|
url: `/group/members/${groupId}`, |
|
|
method: 'get' |
|
|
method: 'get' |
|
|
@ -256,6 +279,12 @@ |
|
|
this.$store.commit("updateFriend", friend); |
|
|
this.$store.commit("updateFriend", friend); |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
|
|
|
rpxTopx(rpx) { |
|
|
|
|
|
// px转换成rpx |
|
|
|
|
|
let info = uni.getSystemInfoSync() |
|
|
|
|
|
let px = info.windowWidth * rpx / 750; |
|
|
|
|
|
return Math.floor(rpx); |
|
|
|
|
|
} |
|
|
}, |
|
|
}, |
|
|
computed: { |
|
|
computed: { |
|
|
mine() { |
|
|
mine() { |
|
|
@ -293,6 +322,7 @@ |
|
|
onUnload() { |
|
|
onUnload() { |
|
|
console.log("onShow") |
|
|
console.log("onShow") |
|
|
this.$store.commit("activeChat", -1); |
|
|
this.$store.commit("activeChat", -1); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|
@ -303,6 +333,7 @@ |
|
|
border: #dddddd solid 1px; |
|
|
border: #dddddd solid 1px; |
|
|
display: flex; |
|
|
display: flex; |
|
|
flex-direction: column; |
|
|
flex-direction: column; |
|
|
|
|
|
|
|
|
.header { |
|
|
.header { |
|
|
display: flex; |
|
|
display: flex; |
|
|
justify-content: center; |
|
|
justify-content: center; |
|
|
@ -333,6 +364,7 @@ |
|
|
overflow: hidden; |
|
|
overflow: hidden; |
|
|
position: relative; |
|
|
position: relative; |
|
|
background-color: white; |
|
|
background-color: white; |
|
|
|
|
|
|
|
|
.scroll-box { |
|
|
.scroll-box { |
|
|
height: 100%; |
|
|
height: 100%; |
|
|
} |
|
|
} |
|
|
@ -362,7 +394,7 @@ |
|
|
min-height: 85rpx; |
|
|
min-height: 85rpx; |
|
|
font-size: 30rpx; |
|
|
font-size: 30rpx; |
|
|
box-sizing: border-box; |
|
|
box-sizing: border-box; |
|
|
|
|
|
|
|
|
.send-text-area { |
|
|
.send-text-area { |
|
|
width: 100%; |
|
|
width: 100%; |
|
|
} |
|
|
} |
|
|
@ -411,6 +443,7 @@ |
|
|
|
|
|
|
|
|
.chat-emotion { |
|
|
.chat-emotion { |
|
|
height: 100%; |
|
|
height: 100%; |
|
|
|
|
|
|
|
|
.emotion-item-list { |
|
|
.emotion-item-list { |
|
|
display: flex; |
|
|
display: flex; |
|
|
flex-wrap: wrap; |
|
|
flex-wrap: wrap; |
|
|
|