diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index fc94f96..2e57e5e 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -1,18 +1,193 @@ \ No newline at end of file diff --git a/im-uniapp/common/emotion.js b/im-uniapp/common/emotion.js index 1caa481..9e6917c 100644 --- a/im-uniapp/common/emotion.js +++ b/im-uniapp/common/emotion.js @@ -1,21 +1,55 @@ -const emoTextList = ['微笑', '撇嘴', '色', '发呆', '得意', '流泪', '害羞', '闭嘴', '睡', '大哭', '尴尬', '发怒', '调皮', '呲牙', '惊讶', '难过', '酷', '冷汗', '抓狂', '吐', '偷笑', '可爱', '白眼', '傲慢', '饥饿', '困', '惊恐', '流汗', '憨笑', '大兵', '奋斗', '咒骂', '疑问', '嘘', '晕', '折磨', '衰', '骷髅', '敲打', '再见', '擦汗', '抠鼻', '鼓掌', '糗大了', '坏笑', '左哼哼', '右哼哼', '哈欠', '鄙视', '委屈', '快哭了', '阴险', '亲亲', '吓', '可怜', '菜刀', '西瓜', '啤酒', '篮球', '乒乓', '咖啡', '饭', '猪头', '玫瑰', '凋谢', '示爱', '爱心', '心碎', '蛋糕', '闪电', '炸弹', '刀', '足球', '瓢虫', '便便', '月亮', '太阳', '礼物', '拥抱', '强', '弱', '握手', '胜利', '抱拳', '勾引', '拳头', '差劲', '爱你', 'NO', 'OK', '爱情', '飞吻', '跳跳', '发抖', '怄火', '转圈', '磕头', '回头', '跳绳', '挥手', '激动', '街舞', '献吻', '左太极', '右太极']; +const emoTextList = ['微笑', '撇嘴', '色', '发呆', '得意', '流泪', '害羞', '闭嘴', '睡', '大哭', '尴尬', '发怒', '调皮', '呲牙', '惊讶', '难过', '酷', + '冷汗', '抓狂', '吐', '偷笑', '可爱', '白眼', '傲慢', '饥饿', '困', '惊恐', '流汗', '憨笑', '大兵', '奋斗', '咒骂', '疑问', '嘘', '晕', '折磨', + '衰', '骷髅', '敲打', '再见', '擦汗', '抠鼻', '鼓掌', '糗大了', '坏笑', '左哼哼', '右哼哼', '哈欠', '鄙视', '委屈', '快哭了', '阴险', '亲亲', '吓', + '可怜', '菜刀', '西瓜', '啤酒', '篮球', '乒乓', '咖啡', '饭', '猪头', '玫瑰', '凋谢', '示爱', '爱心', '心碎', '蛋糕', '闪电', '炸弹', '刀', '足球', + '瓢虫', '便便', '月亮', '太阳', '礼物', '拥抱', '强', '弱', '握手', '胜利', '抱拳', '勾引', '拳头', '差劲', '爱你', 'NO', 'OK', '爱情', '飞吻', + '跳跳', '发抖', '怄火', '转圈', '磕头', '回头', '跳绳', '挥手', '激动', '街舞', '献吻', '左太极', '右太极' +]; + +let emoImageUrlList = []; + +// 备注:经过测试,小程序的无法显示相对路径的图片,所以在这里对图片提前全部转成绝对路径 +// 提前初始化图片的url +for (let i = 0; i < emoTextList.length; i++) { + let path = `/static/emoji/${i}.gif`; + uni.getImageInfo({ + src: path, + success(res) { + emoImageUrlList[i] = res.path + }, + fail(res) { + emoImageUrlList = path; + } + }); +} let transform = (content) => { return content.replace(/\#[\u4E00-\u9FA5]{1,3}\;/gi, textToImg); } + + // 将匹配结果替换表情图片 let textToImg = (emoText) => { let word = emoText.replace(/\#|\;/gi, ''); let idx = emoTextList.indexOf(word); - let url = `/static/emoji/${idx}.gif`; - return `` + let img = ``; + return img; +} + + +let textToPath = (emoText) => { + let word = emoText.replace(/\#|\;/gi, ''); + let idx = emoTextList.indexOf(word); + return `/static/emoji/${idx}.gif`; } + export default { emoTextList, transform, - textToImg -} + textToImg, + textToPath +} \ No newline at end of file diff --git a/im-uniapp/components/chat-item/chat-item.vue b/im-uniapp/components/chat-item/chat-item.vue index 488abdb..97a086a 100644 --- a/im-uniapp/components/chat-item/chat-item.vue +++ b/im-uniapp/components/chat-item/chat-item.vue @@ -45,12 +45,12 @@ .chat-item { height: 120rpx; display: flex; - margin-bottom: 1rpx; + margin-bottom: 2rpx; position: relative; padding-left: 30rpx; align-items: center; padding-right: 10rpx; - background-color: #fafafa; + background-color: white; white-space: nowrap; &:hover { background-color: #eeeeee; @@ -76,9 +76,9 @@ right: -12rpx; top: -12rpx; color: white; - border-radius: 30rpx; - padding: 5rpx 6rpx; - font-size: 10px; + border-radius: 16rpx; + padding: 4rpx 12rpx; + font-size: 20rpx; text-align: center; white-space: nowrap; } diff --git a/im-uniapp/components/friend-item/friend-item.vue b/im-uniapp/components/friend-item/friend-item.vue index 2708a1d..9e93998 100644 --- a/im-uniapp/components/friend-item/friend-item.vue +++ b/im-uniapp/components/friend-item/friend-item.vue @@ -48,7 +48,7 @@ padding-left: 30rpx; align-items: center; padding-right: 10rpx; - background-color: #fafafa; + background-color: white; white-space: nowrap; &:hover { background-color: #eeeeee; diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 271fcec..60f66a2 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -1,10 +1,10 @@ @@ -59,11 +61,9 @@ groupMembers: [], sendText: "", showVoice: false, // 是否显示语音录制弹窗 - showSide: false, // 是否显示群聊信息栏 - showEmotion: false, // 是否显示emoji表情 - showHistory: false, // 是否显示历史聊天记录 scrollMsgIdx: 0, // 滚动条定位为到哪条消息 - showTools: false, + chatTabBox: 'none', + sendTextFocus: false, tools: [{ name: "拍摄", icon: "icon-camera" @@ -125,13 +125,12 @@ msgInfo.sendId = this.$store.state.userStore.userInfo.id; msgInfo.selfSend = true; this.$store.commit("insertMessage", msgInfo); - uni.showToast({ - title: "发送成功", - icon: "none" - }) + this.sendText = ""; }).finally(() => { // 滚动到底部 this.scrollToBottom(); + // 重新获得输入焦点 + this.sendTextFocus = true; }); }, fillTargetId(msgInfo, targetId) { @@ -142,13 +141,40 @@ } }, scrollToBottom() { + let size = this.chat.messages.length; + if(size>0){ + this.scrollToMsgIdx(size-1); + } + }, + scrollToMsgIdx(idx){ + // 踩坑:如果scrollMsgIdx值没变化,滚动条不会移动 + if(idx == this.scrollMsgIdx && idx>0){ + this.$nextTick(() => { + // 先滚动到上一条 + this.scrollMsgIdx = idx-1; + // 再滚动目标位置 + this.scrollToMsgIdx(idx); + }); + return; + } this.$nextTick(() => { - this.scrollMsgIdx = this.chat.messages.length - 1; - }) - + this.scrollMsgIdx = idx; + }); + + }, + switchChatTabBox(v) { + this.chatTabBox = v; + this.scrollToBottom(); + }, + selectEmoji(emoText) { + this.sendText += `#${emoText};`; + }, + onSendTextBlur(){ + this.sendTextFocus=false; }, - showToolBox(v){ - this.showTools = v; + onSendTextFoucs(){ + console.log("onSendTextFoucs") + this.scrollToBottom(); }, onUploadImageBefore(file) { let data = { @@ -176,7 +202,6 @@ return true; }, onUploadImageSuccess(file, res) { - console.log("onUploadImageSuccess") let msgInfo = JSON.parse(JSON.stringify(file.msgInfo)); msgInfo.content = JSON.stringify(res.data); this.$http({ @@ -200,7 +225,7 @@ break; } - console.log(tool); + } }, computed: { @@ -223,7 +248,6 @@ } }, onLoad(options) { - console.log("onLoad") let chatIdx = options.chatIdx; this.chat = this.$store.state.chatStore.chats[chatIdx]; this.scrollToBottom(); @@ -234,12 +258,9 @@ \ No newline at end of file diff --git a/im-uniapp/pages/chat/chat.vue b/im-uniapp/pages/chat/chat.vue index bbe6b4f..a5d8a56 100644 --- a/im-uniapp/pages/chat/chat.vue +++ b/im-uniapp/pages/chat/chat.vue @@ -1,5 +1,5 @@