chat-box.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. <template>
  2. <view class="page chat-box" id="chatBox">
  3. <nav-bar back more @more="onShowMore">{{ title }}</nav-bar>
  4. <view class="chat-main-box" :style="{height: chatMainHeight+'px'}">
  5. <view class="chat-message" @click="switchChatTabBox('none')">
  6. <scroll-view class="scroll-box" scroll-y="true" upper-threshold="200" @scrolltoupper="onScrollToTop"
  7. @scroll="onScroll" :scroll-into-view="'chat-item-' + scrollMsgIdx" :scroll-top="scrollTop">
  8. <view v-if="chat" class="chat-wrap">
  9. <view v-for="(msgInfo, idx) in chat.messages" :key="idx">
  10. <chat-message-item :ref="'message'+msgInfo.id" v-if="idx >= showMinIdx"
  11. :headImage="headImage(msgInfo)" @call="onRtCall(msgInfo)" :showName="showName(msgInfo)"
  12. @resend="onResendMessage" @recall="onRecallMessage" @delete="onDeleteMessage"
  13. @copy="onCopyMessage" @longPressHead="onLongPressHead(msgInfo)"
  14. @download="onDownloadFile" @audioStateChange="onAudioStateChange"
  15. :id="'chat-item-' + idx" :msgInfo="msgInfo" :groupMembers="groupMembers">
  16. </chat-message-item>
  17. </view>
  18. </view>
  19. </scroll-view>
  20. <view v-if="!isInBottom" class="scroll-to-bottom" @click="onClickToBottom">
  21. {{ newMessageSize > 0 ? newMessageSize+'条新消息' :'回到底部'}}
  22. </view>
  23. </view>
  24. <view v-if="atUserIds.length > 0" class="chat-at-bar" @click="openAtBox()">
  25. <view class="iconfont icon-at">&nbsp;</view>
  26. <scroll-view v-if="atUserIds.length > 0" class="chat-at-scroll-box" scroll-x="true" scroll-left="120">
  27. <view class="chat-at-items">
  28. <view v-for="m in atUserItems" class="chat-at-item" :key="m.userId">
  29. <head-image :name="m.showNickName" :url="m.headImage" size="minier"></head-image>
  30. </view>
  31. </view>
  32. </scroll-view>
  33. </view>
  34. <view class="send-bar">
  35. <view v-if="!showRecord" class="iconfont icon-voice-circle" @click="onRecorderInput()"></view>
  36. <view v-else class="iconfont icon-keyboard" @click="onKeyboardInput()"></view>
  37. <chat-record v-if="showRecord" class="chat-record" @send="onSendRecord"></chat-record>
  38. <view v-else class="send-text">
  39. <editor id="editor" class="send-text-area" :placeholder="isReceipt ? '[回执消息]' : ''"
  40. :read-only="isReadOnly" @focus="onEditorFocus" @blur="onEditorBlur" @ready="onEditorReady"
  41. @input="onTextInput">
  42. </editor>
  43. </view>
  44. <view v-if="chat && chat.type == 'GROUP'" class="iconfont icon-at" @click="openAtBox()"></view>
  45. <view class="iconfont icon-icon_emoji" @click="onShowEmoChatTab()"></view>
  46. <view v-if="isEmpty" class="iconfont icon-add" @click="onShowToolsChatTab()">
  47. </view>
  48. <button v-if="!isEmpty || atUserIds.length" class="btn-send" type="primary"
  49. @touchend.prevent="sendTextMessage()" size="mini">发送</button>
  50. </view>
  51. </view>
  52. <view class="chat-tab-bar">
  53. <view v-if="chatTabBox == 'tools'" class="chat-tools" :style="{height: keyboardHeight+'px'}">
  54. <view class="chat-tools-item">
  55. <file-upload ref="fileUpload" :onBefore="onUploadFileBefore" :onSuccess="onUploadFileSuccess"
  56. :onError="onUploadFileFail">
  57. <view class="tool-icon iconfont icon-folder"></view>
  58. </file-upload>
  59. <view class="tool-name">文件</view>
  60. </view>
  61. <view class="chat-tools-item">
  62. <image-upload :maxCount="9" sourceType="album" :onBefore="onUploadImageBefore"
  63. :onSuccess="onUploadImageSuccess" :onError="onUploadImageFail">
  64. <view class="tool-icon iconfont icon-picture"></view>
  65. </image-upload>
  66. <view class="tool-name">相册</view>
  67. </view>
  68. <view class="chat-tools-item">
  69. <image-upload sourceType="camera" :onBefore="onUploadImageBefore" :onSuccess="onUploadImageSuccess"
  70. :onError="onUploadImageFail">
  71. <view class="tool-icon iconfont icon-camera"></view>
  72. </image-upload>
  73. <view class="tool-name">拍摄</view>
  74. </view>
  75. <view class="chat-tools-item" @click="onRecorderInput()">
  76. <view class="tool-icon iconfont icon-microphone"></view>
  77. <view class="tool-name">语音消息</view>
  78. </view>
  79. <view v-if="chat.type == 'GROUP' && memberSize<=500" class="chat-tools-item" @click="switchReceipt()">
  80. <view class="tool-icon iconfont icon-receipt" :class="isReceipt ? 'active' : ''"></view>
  81. <view class="tool-name">回执消息</view>
  82. </view>
  83. <!-- #ifndef MP-WEIXIN -->
  84. <!-- 音视频不支持小程序 -->
  85. <view v-if="chat.type == 'PRIVATE'" class="chat-tools-item" @click="onPriviteVideo()">
  86. <view class="tool-icon iconfont icon-video"></view>
  87. <view class="tool-name">视频通话</view>
  88. </view>
  89. <view v-if="chat.type == 'PRIVATE'" class="chat-tools-item" @click="onPriviteVoice()">
  90. <view class="tool-icon iconfont icon-call"></view>
  91. <view class="tool-name">语音通话</view>
  92. </view>
  93. <view v-if="chat.type == 'GROUP'" class="chat-tools-item" @click="onGroupVideo()">
  94. <view class="tool-icon iconfont icon-call"></view>
  95. <view class="tool-name">语音通话</view>
  96. </view>
  97. <!-- #endif -->
  98. </view>
  99. <scroll-view v-if="chatTabBox === 'emo'" class="chat-emotion" scroll-y="true"
  100. :style="{height: keyboardHeight+'px'}">
  101. <view class="emotion-item-list">
  102. <image class="emotion-item emoji-large" :title="emoText" :src="$emo.textToPath(emoText)"
  103. v-for="(emoText, i) in $emo.emoTextList" :key="i" @click="selectEmoji(emoText)" mode="aspectFit"
  104. lazy-load="true"></image>
  105. </view>
  106. </scroll-view>
  107. </view>
  108. <!-- @用户时选择成员 -->
  109. <chat-at-box ref="atBox" :ownerId="group.ownerId" :members="groupMembers"
  110. @complete="onAtComplete"></chat-at-box>
  111. <!-- 群语音通话时选择成员 -->
  112. <!-- #ifndef MP-WEIXIN -->
  113. <group-member-selector ref="selBox" :members="groupMembers" :maxSize="configStore.webrtc.maxChannel"
  114. @complete="onInviteOk"></group-member-selector>
  115. <group-rtc-join ref="rtcJoin" :groupId="group.id"></group-rtc-join>
  116. <!-- #endif -->
  117. </view>
  118. </template>
  119. <script>
  120. import UNI_APP from '@/.env.js';
  121. export default {
  122. data() {
  123. return {
  124. chat: {},
  125. userInfo: {},
  126. group: {},
  127. groupMembers: [],
  128. isReceipt: false, // 是否回执消息
  129. scrollMsgIdx: 0, // 滚动条定位为到哪条消息
  130. chatTabBox: 'none',
  131. showRecord: false,
  132. chatMainHeight: 800, // 聊天窗口高度
  133. keyboardHeight: 290, // 键盘高度
  134. windowHeight: 1000, // 窗口高度
  135. initHeight: 1000, // h5初始高度
  136. atUserIds: [],
  137. showMinIdx: 0, // 下标小于showMinIdx的消息不显示,否则可能很卡
  138. reqQueue: [], // 请求队列
  139. isSending: false, // 是否正在发送请求
  140. isShowKeyBoard: false, // 键盘是否正在弹起
  141. editorCtx: null, // 编辑器上下文
  142. isEmpty: true, // 编辑器是否为空
  143. isFocus: false, // 编辑器是否焦点
  144. isReadOnly: false, // 编辑器是否只读
  145. playingAudio: null, // 当前正在播放的录音消息
  146. isInBottom: true, // 滚动条是否在底部
  147. newMessageSize: 0, // 滚动条不在底部时新的消息数量
  148. scrollTop: 0, // 用于ios h5定位滚动条
  149. scrollViewHeight: 0 // 滚动条总长度
  150. }
  151. },
  152. methods: {
  153. onRecorderInput() {
  154. this.showRecord = true;
  155. this.switchChatTabBox('none');
  156. },
  157. onKeyboardInput() {
  158. this.showRecord = false;
  159. this.switchChatTabBox('none');
  160. },
  161. onSendRecord(data) {
  162. // 检查是否被封禁
  163. if (this.isBanned) {
  164. this.showBannedTip();
  165. return;
  166. }
  167. let msgInfo = {
  168. tmpId: this.generateId(),
  169. content: JSON.stringify(data),
  170. type: this.$enums.MESSAGE_TYPE.AUDIO,
  171. receipt: this.isReceipt
  172. }
  173. // 填充对方id
  174. this.fillTargetId(msgInfo, this.chat.targetId);
  175. // 防止发送期间用户切换会话导致串扰
  176. const chat = this.chat;
  177. // 消息回显
  178. let tmpMessage = this.buildTmpMessage(msgInfo);
  179. this.chatStore.insertMessage(tmpMessage, chat);
  180. this.moveChatToTop();
  181. this.sendMessageRequest(msgInfo).then((m) => {
  182. // 更新消息
  183. tmpMessage.id = m.id;
  184. tmpMessage.status = m.status;
  185. this.chatStore.insertMessage(tmpMessage, chat);
  186. // 会话置顶
  187. this.moveChatToTop();
  188. // 滚动到底部
  189. this.scrollToBottom();
  190. this.isReceipt = false;
  191. })
  192. },
  193. onRtCall(msgInfo) {
  194. if (msgInfo.type == this.$enums.MESSAGE_TYPE.ACT_RT_VOICE) {
  195. this.onPriviteVoice();
  196. } else if (msgInfo.type == this.$enums.MESSAGE_TYPE.ACT_RT_VIDEO) {
  197. this.onPriviteVideo();
  198. }
  199. },
  200. onPriviteVideo() {
  201. const friendInfo = encodeURIComponent(JSON.stringify(this.friend));
  202. uni.navigateTo({
  203. url: `/pages/chat/chat-private-video?mode=video&friend=${friendInfo}&isHost=true`
  204. })
  205. },
  206. onPriviteVoice() {
  207. const friendInfo = encodeURIComponent(JSON.stringify(this.friend));
  208. uni.navigateTo({
  209. url: `/pages/chat/chat-private-video?mode=voice&friend=${friendInfo}&isHost=true`
  210. })
  211. },
  212. onGroupVideo() {
  213. // 邀请成员发起通话
  214. let ids = [this.mine.id];
  215. this.$refs.selBox.init(ids, ids, []);
  216. this.$refs.selBox.open();
  217. },
  218. onInviteOk(ids) {
  219. if (ids.length < 2) {
  220. return;
  221. }
  222. let users = [];
  223. ids.forEach(id => {
  224. let m = this.groupMembers.find(m => m.userId == id);
  225. // 只取部分字段,压缩url长度
  226. users.push({
  227. id: m.userId,
  228. nickName: m.showNickName,
  229. headImage: m.headImage,
  230. isCamera: false,
  231. isMicroPhone: true
  232. })
  233. })
  234. const groupId = this.group.id;
  235. const inviterId = this.mine.id;
  236. const userInfos = encodeURIComponent(JSON.stringify(users));
  237. uni.navigateTo({
  238. url: `/pages/chat/chat-group-video?groupId=${groupId}&isHost=true
  239. &inviterId=${inviterId}&userInfos=${userInfos}`
  240. })
  241. },
  242. moveChatToTop() {
  243. let chatIdx = this.chatStore.findChatIdx(this.chat);
  244. this.chatStore.moveTop(chatIdx);
  245. },
  246. switchReceipt() {
  247. this.isReceipt = !this.isReceipt;
  248. },
  249. openAtBox() {
  250. this.$refs.atBox.init(this.atUserIds);
  251. this.$refs.atBox.open();
  252. },
  253. onAtComplete(atUserIds) {
  254. this.atUserIds = atUserIds;
  255. },
  256. onLongPressHead(msgInfo) {
  257. if (!msgInfo.selfSend && this.chat.type == "GROUP" && this.atUserIds.indexOf(msgInfo.sendId) < 0) {
  258. this.atUserIds.push(msgInfo.sendId);
  259. }
  260. },
  261. headImage(msgInfo) {
  262. if (this.chat.type == 'GROUP') {
  263. let member = this.groupMembers.find((m) => m.userId == msgInfo.sendId);
  264. return member ? member.headImage : "";
  265. } else {
  266. return msgInfo.selfSend ? this.mine.headImageThumb : this.chat.headImage
  267. }
  268. },
  269. showName(msgInfo) {
  270. if (this.chat.type == 'GROUP') {
  271. let member = this.groupMembers.find((m) => m.userId == msgInfo.sendId);
  272. return member ? member.showNickName : "";
  273. } else {
  274. return msgInfo.selfSend ? this.mine.nickName : this.chat.showName
  275. }
  276. },
  277. sendTextMessage() {
  278. this.editorCtx.getContents({
  279. success: (e) => {
  280. // 清空编辑框数据
  281. this.editorCtx.clear();
  282. // 检查是否被封禁
  283. if (this.isBanned) {
  284. this.showBannedTip();
  285. return;
  286. }
  287. let sendText = "";
  288. e.delta.ops.forEach((op) => {
  289. if (op.insert.image) {
  290. // emo表情
  291. sendText += `#${op.attributes.alt};`
  292. } else(
  293. // 文字
  294. sendText += op.insert
  295. )
  296. })
  297. // 去除最后的换行符
  298. sendText = sendText.trim();
  299. if (!sendText && this.atUserIds.length == 0) {
  300. return uni.showToast({
  301. title: "不能发送空白信息",
  302. icon: "none"
  303. });
  304. }
  305. let receiptText = this.isReceipt ? "【回执消息】" : "";
  306. let atText = this.createAtText();
  307. let msgInfo = {
  308. tmpId: this.generateId(),
  309. content: receiptText + sendText + atText,
  310. atUserIds: this.atUserIds,
  311. receipt: this.isReceipt,
  312. type: this.$enums.MESSAGE_TYPE.TEXT
  313. }
  314. // 清空@成员和回执标记
  315. this.atUserIds = [];
  316. this.isReceipt = false;
  317. // 填充对方id
  318. this.fillTargetId(msgInfo, this.chat.targetId);
  319. // 防止发送期间用户切换会话导致串扰
  320. const chat = this.chat;
  321. // 回显消息
  322. let tmpMessage = this.buildTmpMessage(msgInfo);
  323. this.chatStore.insertMessage(tmpMessage, chat);
  324. this.moveChatToTop();
  325. this.sendMessageRequest(msgInfo).then((m) => {
  326. // 更新消息
  327. tmpMessage = JSON.parse(JSON.stringify(tmpMessage));
  328. tmpMessage.id = m.id;
  329. tmpMessage.status = m.status;
  330. tmpMessage.content = m.content;
  331. this.chatStore.insertMessage(tmpMessage, chat);
  332. }).catch(() => {
  333. // 更新消息
  334. tmpMessage = JSON.parse(JSON.stringify(tmpMessage));
  335. tmpMessage.status = this.$enums.MESSAGE_STATUS.FAILED;
  336. this.chatStore.insertMessage(tmpMessage, chat);
  337. })
  338. }
  339. })
  340. },
  341. createAtText() {
  342. let atText = "";
  343. this.atUserIds.forEach((id) => {
  344. if (id == -1) {
  345. atText += ` @全体成员`;
  346. } else {
  347. let member = this.groupMembers.find((m) => m.userId == id);
  348. if (member) {
  349. atText += ` @${member.showNickName}`;
  350. }
  351. }
  352. })
  353. return atText;
  354. },
  355. fillTargetId(msgInfo, targetId) {
  356. if (this.chat.type == "GROUP") {
  357. msgInfo.groupId = targetId;
  358. } else {
  359. msgInfo.recvId = targetId;
  360. }
  361. },
  362. scrollToBottom() {
  363. let size = this.messageSize;
  364. if (size > 0) {
  365. this.scrollToMsgIdx(size - 1);
  366. }
  367. },
  368. scrollToMsgIdx(idx) {
  369. // 如果scrollMsgIdx值没变化,滚动条不会移动
  370. if (idx == this.scrollMsgIdx && idx > 0) {
  371. this.$nextTick(() => {
  372. // 先滚动到上一条
  373. this.scrollMsgIdx = idx - 1;
  374. // 再滚动目标位置
  375. this.scrollToMsgIdx(idx);
  376. });
  377. return;
  378. }
  379. this.$nextTick(() => {
  380. this.scrollMsgIdx = idx;
  381. });
  382. },
  383. onShowEmoChatTab() {
  384. this.showRecord = false;
  385. this.switchChatTabBox('emo')
  386. },
  387. onShowToolsChatTab() {
  388. this.showRecord = false;
  389. this.switchChatTabBox('tools')
  390. },
  391. switchChatTabBox(chatTabBox) {
  392. this.chatTabBox = chatTabBox;
  393. this.reCalChatMainHeight();
  394. if (chatTabBox != 'tools' && this.$refs.fileUpload) {
  395. this.$refs.fileUpload.hide()
  396. }
  397. },
  398. selectEmoji(emoText) {
  399. let path = this.$emo.textToPath(emoText)
  400. // 先把键盘禁用了,否则会重新弹出键盘
  401. this.isReadOnly = true;
  402. this.isEmpty = false;
  403. this.$nextTick(() => {
  404. this.editorCtx.insertImage({
  405. src: path,
  406. alt: emoText,
  407. extClass: 'emoji-small',
  408. nowrap: true,
  409. complete: () => {
  410. this.isReadOnly = false;
  411. this.editorCtx.blur();
  412. }
  413. });
  414. })
  415. },
  416. onUploadImageBefore(file) {
  417. // 检查是否被封禁
  418. if (this.isBanned) {
  419. this.showBannedTip();
  420. return;
  421. }
  422. let data = {
  423. originUrl: file.path,
  424. thumbUrl: file.path
  425. }
  426. let msgInfo = {
  427. tmpId: this.generateId(),
  428. fileId: file.uid,
  429. sendId: this.mine.id,
  430. content: JSON.stringify(data),
  431. sendTime: new Date().getTime(),
  432. selfSend: true,
  433. type: this.$enums.MESSAGE_TYPE.IMAGE,
  434. readedCount: 0,
  435. status: this.$enums.MESSAGE_STATUS.SENDING
  436. }
  437. // 填充对方id
  438. this.fillTargetId(msgInfo, this.chat.targetId);
  439. // 插入消息
  440. this.chatStore.insertMessage(msgInfo, this.chat);
  441. // 会话置顶
  442. this.moveChatToTop();
  443. // 借助file对象保存
  444. file.msgInfo = msgInfo;
  445. file.chat = this.chat;
  446. // 更新图片宽高
  447. let chat = this.chat;
  448. this.getImageSize(file).then(size => {
  449. msgInfo = JSON.parse(JSON.stringify(msgInfo))
  450. data.width = size.width;
  451. data.height = size.height;
  452. msgInfo.content = JSON.stringify(data)
  453. this.chatStore.insertMessage(msgInfo, chat);
  454. this.scrollToBottom();
  455. })
  456. return true;
  457. },
  458. onUploadImageSuccess(file, res) {
  459. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  460. msgInfo.content = JSON.stringify(res.data);
  461. msgInfo.receipt = this.isReceipt
  462. this.sendMessageRequest(msgInfo).then((m) => {
  463. msgInfo.id = m.id;
  464. msgInfo.status = m.status;
  465. this.isReceipt = false;
  466. this.chatStore.insertMessage(msgInfo, file.chat);
  467. })
  468. },
  469. onUploadImageFail(file, err) {
  470. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  471. msgInfo.status = this.$enums.MESSAGE_STATUS.FAILED;
  472. this.chatStore.insertMessage(msgInfo, file.chat);
  473. },
  474. onUploadFileBefore(file) {
  475. // 检查是否被封禁
  476. if (this.isBanned) {
  477. this.showBannedTip();
  478. return;
  479. }
  480. let data = {
  481. name: file.name,
  482. size: file.size,
  483. url: file.path
  484. }
  485. let msgInfo = {
  486. tmpId: this.generateId(),
  487. sendId: this.mine.id,
  488. content: JSON.stringify(data),
  489. sendTime: new Date().getTime(),
  490. selfSend: true,
  491. type: this.$enums.MESSAGE_TYPE.FILE,
  492. readedCount: 0,
  493. status: this.$enums.MESSAGE_STATUS.SENDING
  494. }
  495. // 填充对方id
  496. this.fillTargetId(msgInfo, this.chat.targetId);
  497. // 插入消息
  498. this.chatStore.insertMessage(msgInfo, this.chat);
  499. // 会话置顶
  500. this.moveChatToTop();
  501. // 借助file对象保存
  502. file.msgInfo = msgInfo;
  503. file.chat = this.chat;
  504. return true;
  505. },
  506. onUploadFileSuccess(file, res) {
  507. let data = {
  508. name: file.name,
  509. size: file.size,
  510. url: res.data
  511. }
  512. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  513. msgInfo.content = JSON.stringify(data);
  514. msgInfo.receipt = this.isReceipt
  515. this.sendMessageRequest(msgInfo).then((m) => {
  516. msgInfo.id = m.id;
  517. msgInfo.status = m.status;
  518. this.isReceipt = false;
  519. this.chatStore.insertMessage(msgInfo, file.chat);
  520. })
  521. },
  522. onUploadFileFail(file, res) {
  523. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  524. msgInfo.status = this.$enums.MESSAGE_STATUS.FAILED;
  525. this.chatStore.insertMessage(msgInfo, file.chat);
  526. },
  527. onResendMessage(msgInfo) {
  528. if (msgInfo.type != this.$enums.MESSAGE_TYPE.TEXT) {
  529. uni.showToast({
  530. title: "该消息不支持自动重新发送,建议手动重新发送",
  531. icon: "none"
  532. })
  533. return;
  534. }
  535. // 防止发送期间用户切换会话导致串扰
  536. const chat = this.chat;
  537. // 删除旧消息
  538. this.chatStore.deleteMessage(msgInfo, chat);
  539. // 重新发送
  540. msgInfo.tmpId = this.generateId();
  541. let tmpMessage = this.buildTmpMessage(msgInfo);
  542. this.chatStore.insertMessage(tmpMessage, chat);
  543. this.moveChatToTop();
  544. this.sendMessageRequest(msgInfo).then(m => {
  545. // 更新消息
  546. tmpMessage = JSON.parse(JSON.stringify(tmpMessage));
  547. tmpMessage.id = m.id;
  548. tmpMessage.status = m.status;
  549. tmpMessage.content = m.content;
  550. this.chatStore.insertMessage(tmpMessage, chat);
  551. }).catch(() => {
  552. // 更新消息
  553. tmpMessage = JSON.parse(JSON.stringify(tmpMessage));
  554. tmpMessage.status = this.$enums.MESSAGE_STATUS.FAILED;
  555. this.chatStore.insertMessage(tmpMessage, chat);
  556. })
  557. },
  558. onDeleteMessage(msgInfo) {
  559. uni.showModal({
  560. title: '删除消息',
  561. content: '确认删除消息?',
  562. success: (res) => {
  563. if (!res.cancel) {
  564. this.chatStore.deleteMessage(msgInfo, this.chat);
  565. uni.showToast({
  566. title: "删除成功",
  567. icon: "none"
  568. })
  569. }
  570. }
  571. })
  572. },
  573. onRecallMessage(msgInfo) {
  574. uni.showModal({
  575. title: '撤回消息',
  576. content: '确认撤回消息?',
  577. success: (res) => {
  578. if (!res.cancel) {
  579. let url = `/message/${this.chat.type.toLowerCase()}/recall/${msgInfo.id}`
  580. this.$http({
  581. url: url,
  582. method: 'DELETE'
  583. }).then((m) => {
  584. m.selfSend = true;
  585. this.chatStore.recallMessage(m, this.chat);
  586. })
  587. }
  588. }
  589. })
  590. },
  591. onCopyMessage(msgInfo) {
  592. uni.setClipboardData({
  593. data: msgInfo.content,
  594. success: () => {
  595. uni.showToast({ title: '复制成功' });
  596. },
  597. fail: () => {
  598. uni.showToast({ title: '复制失败', icon: 'none' });
  599. }
  600. });
  601. },
  602. onDownloadFile(msgInfo) {
  603. let url = JSON.parse(msgInfo.content).url;
  604. uni.downloadFile({
  605. url: url,
  606. success(res) {
  607. if (res.statusCode === 200) {
  608. var filePath = encodeURI(res.tempFilePath);
  609. uni.openDocument({
  610. filePath: filePath,
  611. showMenu: true
  612. });
  613. }
  614. },
  615. fail(e) {
  616. uni.showToast({
  617. title: "文件下载失败",
  618. icon: "none"
  619. })
  620. }
  621. });
  622. },
  623. onClickToBottom() {
  624. this.scrollToBottom();
  625. // 有些设备滚到底部时会莫名触发滚动到顶部的事件
  626. // 所以这里延迟100s保证能准确设置底部标志
  627. setTimeout(() => {
  628. this.isInBottom = true;
  629. this.newMessageSize = 0;
  630. }, 100)
  631. },
  632. onScroll(e) {
  633. // 记录当前滚动条高度
  634. this.scrollViewHeight = e.detail.scrollHeight;
  635. },
  636. onScrollToTop() {
  637. if (this.showMinIdx > 0) {
  638. // #ifndef H5
  639. // 防止滚动条定格在顶部,不能一直往上滚,app和小程序采用scroll-into-view定位
  640. this.scrollToMsgIdx(this.showMinIdx);
  641. // #endif
  642. // #ifdef H5
  643. // 防止滚动条定格在顶部,不能一直往上滚,h5采用scroll-top定位
  644. if (uni.getSystemInfoSync().platform == 'ios') {
  645. this.holdingScrollBar(this.scrollViewHeight);
  646. }
  647. // #endif
  648. // 多展示20条信息
  649. this.showMinIdx = this.showMinIdx > 20 ? this.showMinIdx - 20 : 0;
  650. }
  651. // 清除底部标识
  652. this.isInBottom = false;
  653. },
  654. onScrollToBottom(e) {
  655. // 设置底部标识
  656. this.isInBottom = true;
  657. this.newMessageSize = 0;
  658. },
  659. holdingScrollBar(scrollViewHeight) {
  660. // 内容高度
  661. const query = uni.createSelectorQuery().in(this);
  662. setTimeout(() => {
  663. query.select('.chat-wrap').boundingClientRect();
  664. query.exec(data => {
  665. this.scrollTop = data[0].height - scrollViewHeight;
  666. if (this.scrollTop < 10) {
  667. // 未渲染完成,重试一次
  668. this.holdingScrollBar();
  669. }
  670. });
  671. }, 50)
  672. },
  673. onShowMore() {
  674. if (this.chat.type == "GROUP") {
  675. uni.navigateTo({
  676. url: "/pages/group/group-info?id=" + this.group.id
  677. })
  678. } else {
  679. uni.navigateTo({
  680. url: "/pages/common/user-info?id=" + this.userInfo.id
  681. })
  682. }
  683. },
  684. onTextInput(e) {
  685. this.isEmpty = e.detail.html == '<p><br></p>'
  686. },
  687. onEditorReady() {
  688. this.$nextTick(() => {
  689. const query = uni.createSelectorQuery().in(this);
  690. query.select('#editor').context((res) => {
  691. this.editorCtx = res.context
  692. }).exec()
  693. })
  694. },
  695. onEditorFocus(e) {
  696. this.isFocus = true;
  697. this.scrollToBottom()
  698. this.switchChatTabBox('none')
  699. },
  700. onEditorBlur(e) {
  701. this.isFocus = false;
  702. },
  703. onAudioStateChange(state, msgInfo) {
  704. const playingAudio = this.$refs['message' + msgInfo.id][0]
  705. if (state == 'PLAYING' && playingAudio != this.playingAudio) {
  706. // 停止之前的录音
  707. this.playingAudio && this.playingAudio.stopPlayAudio();
  708. // 记录当前正在播放的消息
  709. this.playingAudio = playingAudio;
  710. }
  711. },
  712. loadReaded(fid) {
  713. this.$http({
  714. url: `/message/private/maxReadedId?friendId=${fid}`,
  715. method: 'get'
  716. }).then((id) => {
  717. this.chatStore.readedMessage({
  718. friendId: fid,
  719. maxId: id
  720. });
  721. });
  722. },
  723. readedMessage() {
  724. if (this.unreadCount > 0) {
  725. let url = ""
  726. if (this.chat.type == "GROUP") {
  727. url = `/message/group/readed?groupId=${this.chat.targetId}`
  728. } else {
  729. url = `/message/private/readed?friendId=${this.chat.targetId}`
  730. }
  731. this.$http({
  732. url: url,
  733. method: 'PUT'
  734. }).then(() => {})
  735. }
  736. this.chatStore.resetUnreadCount(this.chat)
  737. },
  738. loadGroup(groupId) {
  739. this.$http({
  740. url: `/group/find/${groupId}`,
  741. method: 'GET'
  742. }).then((group) => {
  743. this.group = group;
  744. this.chatStore.updateChatFromGroup(group);
  745. this.groupStore.updateGroup(group);
  746. });
  747. this.$http({
  748. url: `/group/members/${groupId}`,
  749. method: 'GET'
  750. }).then((groupMembers) => {
  751. this.groupMembers = groupMembers;
  752. });
  753. },
  754. updateFriendInfo() {
  755. if (this.isFriend) {
  756. // store的数据不能直接修改,深拷贝一份store的数据
  757. let friend = JSON.parse(JSON.stringify(this.friend));
  758. friend.headImage = this.userInfo.headImageThumb;
  759. friend.nickName = this.userInfo.nickName;
  760. friend.showNickName = friend.remarkNickName ? friend.remarkNickName : friend.nickName;
  761. // 更新好友列表中的昵称和头像
  762. this.friendStore.updateFriend(friend);
  763. // 更新会话中的头像和昵称
  764. this.chatStore.updateChatFromFriend(friend);
  765. } else {
  766. this.chatStore.updateChatFromUser(this.userInfo);
  767. }
  768. },
  769. loadFriend(friendId) {
  770. // 获取好友用户信息
  771. this.$http({
  772. url: `/user/find/${friendId}`,
  773. method: 'GET'
  774. }).then((userInfo) => {
  775. this.userInfo = userInfo;
  776. this.updateFriendInfo();
  777. })
  778. },
  779. rpxTopx(rpx) {
  780. // rpx转换成px
  781. let info = uni.getSystemInfoSync()
  782. let px = info.windowWidth * rpx / 750;
  783. return Math.floor(rpx);
  784. },
  785. sendMessageRequest(msgInfo) {
  786. return new Promise((resolve, reject) => {
  787. // 请求入队列,防止请求"后发先至",导致消息错序
  788. this.reqQueue.push({ msgInfo, resolve, reject });
  789. this.processReqQueue();
  790. })
  791. },
  792. processReqQueue() {
  793. if (this.reqQueue.length && !this.isSending) {
  794. this.isSending = true;
  795. const reqData = this.reqQueue.shift();
  796. this.$http({
  797. url: this.messageAction,
  798. method: 'post',
  799. data: reqData.msgInfo
  800. }).then((res) => {
  801. reqData.resolve(res)
  802. }).catch((e) => {
  803. reqData.reject(e)
  804. }).finally(() => {
  805. this.isSending = false;
  806. // 发送下一条请求
  807. this.processReqQueue();
  808. })
  809. }
  810. },
  811. reCalChatMainHeight() {
  812. setTimeout(() => {
  813. let h = this.windowHeight;
  814. // 减去标题栏高度
  815. h -= 50;
  816. // 减去键盘高度
  817. if (this.isShowKeyBoard || this.chatTabBox != 'none') {
  818. h -= this.keyboardHeight;
  819. this.scrollToBottom();
  820. }
  821. // #ifndef H5
  822. // h5需要减去状态栏高度
  823. h -= uni.getSystemInfoSync().statusBarHeight;
  824. // #endif
  825. this.chatMainHeight = h;
  826. if (this.isShowKeyBoard || this.chatTabBox != 'none') {
  827. this.scrollToBottom();
  828. }
  829. // ios浏览器键盘把页面顶起后,页面长度不会变化,这里把页面拉到顶部适配一下
  830. // #ifdef H5
  831. if (uni.getSystemInfoSync().platform == 'ios') {
  832. // 不同手机需要的延时时间不一致,采用分段延时的方式处理
  833. const delays = [50, 100, 500];
  834. delays.forEach((delay) => {
  835. setTimeout(() => {
  836. uni.pageScrollTo({
  837. scrollTop: 0,
  838. duration: 10
  839. });
  840. }, delay);
  841. })
  842. }
  843. // #endif
  844. }, 30)
  845. },
  846. listenKeyBoard() {
  847. // #ifdef H5
  848. if (navigator.platform == "Win32") {
  849. // 电脑端不需要弹出键盘
  850. console.log("navigator.platform:", navigator.platform)
  851. return;
  852. }
  853. if (uni.getSystemInfoSync().platform == 'ios') {
  854. // ios h5实现键盘监听
  855. window.addEventListener('focusin', this.focusInListener);
  856. window.addEventListener('focusout', this.focusOutListener);
  857. // 监听键盘高度,ios13以上开始支持
  858. if (window.visualViewport) {
  859. window.visualViewport.addEventListener('resize', this.resizeListener);
  860. }
  861. } else {
  862. // 安卓h5实现键盘监听
  863. window.addEventListener('resize', this.resizeListener);
  864. }
  865. // #endif
  866. // #ifndef H5
  867. // app实现键盘监听
  868. uni.onKeyboardHeightChange(this.keyBoardListener);
  869. // #endif
  870. },
  871. unListenKeyboard() {
  872. // #ifdef H5
  873. window.removeEventListener('resize', this.resizeListener);
  874. window.removeEventListener('focusin', this.focusInListener);
  875. window.removeEventListener('focusout', this.focusOutListener);
  876. // #endif
  877. // #ifndef H5
  878. uni.offKeyboardHeightChange(this.keyBoardListener);
  879. // #endif
  880. },
  881. keyBoardListener(res) {
  882. this.isShowKeyBoard = res.height > 0;
  883. if (this.isShowKeyBoard) {
  884. this.keyboardHeight = res.height; // 获取并保存键盘高度
  885. }
  886. this.reCalChatMainHeight();
  887. },
  888. resizeListener() {
  889. let keyboardHeight = this.initHeight - window.innerHeight;
  890. // 兼容部分ios浏览器
  891. if (window.visualViewport && uni.getSystemInfoSync().platform == 'ios') {
  892. keyboardHeight = this.initHeight - window.visualViewport.height;
  893. }
  894. console.log("resizeListener:", window.visualViewport.height)
  895. this.isShowKeyBoard = keyboardHeight > 150;
  896. if (this.isShowKeyBoard) {
  897. this.keyboardHeight = keyboardHeight;
  898. }
  899. this.reCalChatMainHeight();
  900. },
  901. focusInListener() {
  902. this.isShowKeyBoard = true;
  903. this.reCalChatMainHeight();
  904. },
  905. focusOutListener() {
  906. this.isShowKeyBoard = false;
  907. this.reCalChatMainHeight();
  908. },
  909. showBannedTip() {
  910. let msgInfo = {
  911. tmpId: this.generateId(),
  912. sendId: this.mine.id,
  913. sendTime: new Date().getTime(),
  914. type: this.$enums.MESSAGE_TYPE.TIP_TEXT
  915. }
  916. if (this.chat.type == "PRIVATE") {
  917. msgInfo.recvId = this.mine.id
  918. msgInfo.content = "该用户已被管理员封禁,原因:" + this.userInfo.reason
  919. } else {
  920. msgInfo.groupId = this.group.id;
  921. msgInfo.content = "本群聊已被管理员封禁,原因:" + this.group.reason
  922. }
  923. this.chatStore.insertMessage(msgInfo, this.chat);
  924. },
  925. buildTmpMessage(msgInfo) {
  926. let message = JSON.parse(JSON.stringify(msgInfo));
  927. message.sendId = this.mine.id;
  928. message.sendTime = new Date().getTime();
  929. message.status = this.$enums.MESSAGE_STATUS.SENDING;
  930. message.selfSend = true;
  931. if (this.isGroup) {
  932. message.readedCount = 0;
  933. }
  934. return message;
  935. },
  936. getImageSize(file) {
  937. return new Promise((resolve) => {
  938. uni.getImageInfo({
  939. src: file.path,
  940. success: (res) => {
  941. resolve(res);
  942. },
  943. fail: (err) => {
  944. console.error('获取图片信息失败', err);
  945. }
  946. });
  947. });
  948. },
  949. generateId() {
  950. // 生成临时id
  951. return String(new Date().getTime()) + String(Math.floor(Math.random() * 1000));
  952. }
  953. },
  954. computed: {
  955. mine() {
  956. return this.userStore.userInfo;
  957. },
  958. friend() {
  959. return this.friendStore.findFriend(this.userInfo.id);
  960. },
  961. title() {
  962. if (!this.chat) {
  963. return "";
  964. }
  965. let title = this.chat.showName;
  966. if (this.chat.type == "GROUP") {
  967. let size = this.groupMembers.filter(m => !m.quit).length;
  968. title += `(${size})`;
  969. }
  970. return title;
  971. },
  972. messageAction() {
  973. return `/message/${this.chat.type.toLowerCase()}/send`;
  974. },
  975. messageSize() {
  976. if (!this.chat || !this.chat.messages) {
  977. return 0;
  978. }
  979. return this.chat.messages.length;
  980. },
  981. unreadCount() {
  982. if (!this.chat || !this.chat.unreadCount) {
  983. return 0;
  984. }
  985. return this.chat.unreadCount;
  986. },
  987. isBanned() {
  988. return (this.chat.type == "PRIVATE" && this.userInfo.isBanned) ||
  989. (this.chat.type == "GROUP" && this.group.isBanned)
  990. },
  991. atUserItems() {
  992. let atUsers = [];
  993. this.atUserIds.forEach((id) => {
  994. if (id == -1) {
  995. atUsers.push({
  996. id: -1,
  997. showNickName: "全体成员"
  998. })
  999. return;
  1000. }
  1001. let member = this.groupMembers.find((m) => m.userId == id);
  1002. if (member) {
  1003. atUsers.push(member);
  1004. }
  1005. })
  1006. return atUsers;
  1007. },
  1008. memberSize() {
  1009. return this.groupMembers.filter(m => !m.quit).length;
  1010. }
  1011. },
  1012. watch: {
  1013. messageSize: function(newSize, oldSize) {
  1014. // 接收到新消息
  1015. if (newSize > oldSize && oldSize > 0) {
  1016. let lastMessage = this.chat.messages[newSize - 1];
  1017. if (this.$msgType.isNormal(lastMessage.type)) {
  1018. if (this.isInBottom || lastMessage.selfSend) {
  1019. // 收到消息,则滚动至底部
  1020. this.scrollToBottom();
  1021. } else {
  1022. // 若滚动条不在底部,说明用户正在翻历史消息,此时滚动条不能动,同时增加新消息提示
  1023. this.newMessageSize++;
  1024. }
  1025. }
  1026. }
  1027. },
  1028. unreadCount: {
  1029. handler(newCount, oldCount) {
  1030. if (newCount > 0) {
  1031. // 消息已读
  1032. this.readedMessage()
  1033. }
  1034. }
  1035. }
  1036. },
  1037. onLoad(options) {
  1038. // 聊天数据
  1039. this.chat = this.chatStore.chats[options.chatIdx];
  1040. // 初始状态只显示20条消息
  1041. let size = this.messageSize;
  1042. this.showMinIdx = size > 20 ? size - 20 : 0;
  1043. // 消息已读
  1044. this.readedMessage()
  1045. // 加载好友或群聊信息
  1046. if (this.chat.type == "GROUP") {
  1047. this.loadGroup(this.chat.targetId);
  1048. } else {
  1049. this.loadFriend(this.chat.targetId);
  1050. this.loadReaded(this.chat.targetId)
  1051. }
  1052. // 激活当前会话
  1053. this.chatStore.activeChat(options.chatIdx);
  1054. // 复位回执消息
  1055. this.isReceipt = false;
  1056. // 清空底部标志
  1057. this.isInBottom = true;
  1058. this.newMessageSize = 0;
  1059. // 监听键盘高度
  1060. this.listenKeyBoard();
  1061. // 计算聊天窗口高度
  1062. this.$nextTick(() => {
  1063. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  1064. this.reCalChatMainHeight();
  1065. this.scrollToBottom();
  1066. // #ifdef H5
  1067. this.initHeight = window.innerHeight;
  1068. // 兼容ios的h5:禁止页面滚动
  1069. const chatBox = document.getElementById('chatBox')
  1070. chatBox.addEventListener('touchmove', e => {
  1071. e.preventDefault()
  1072. }, { passive: false });
  1073. // #endif
  1074. });
  1075. },
  1076. onUnload() {
  1077. this.unListenKeyboard();
  1078. }
  1079. }
  1080. </script>
  1081. <style lang="scss">
  1082. .chat-box {
  1083. $icon-color: rgba(0, 0, 0, 0.88);
  1084. position: relative;
  1085. background-color: #fafafa;
  1086. .header {
  1087. display: flex;
  1088. justify-content: center;
  1089. align-items: center;
  1090. height: 60rpx;
  1091. padding: 5px;
  1092. background-color: #fafafa;
  1093. line-height: 50px;
  1094. font-size: $im-font-size-large;
  1095. box-shadow: $im-box-shadow-lighter;
  1096. z-index: 1;
  1097. .btn-side {
  1098. position: absolute;
  1099. line-height: 60rpx;
  1100. cursor: pointer;
  1101. &.right {
  1102. right: 30rpx;
  1103. }
  1104. }
  1105. }
  1106. .chat-main-box {
  1107. // #ifdef H5
  1108. top: $im-nav-bar-height;
  1109. // #endif
  1110. // #ifndef H5
  1111. top: calc($im-nav-bar-height + var(--status-bar-height));
  1112. // #endif
  1113. position: fixed;
  1114. width: 100%;
  1115. display: flex;
  1116. flex-direction: column;
  1117. z-index: 2;
  1118. .chat-message {
  1119. flex: 1;
  1120. padding: 0;
  1121. overflow: hidden;
  1122. position: relative;
  1123. background-color: white;
  1124. .scroll-box {
  1125. height: 100%;
  1126. }
  1127. .scroll-to-bottom {
  1128. position: absolute;
  1129. right: 30rpx;
  1130. bottom: 30rpx;
  1131. font-size: $im-font-size;
  1132. color: $im-color-primary;
  1133. font-weight: 600;
  1134. background: white;
  1135. padding: 10rpx 30rpx;
  1136. border-radius: 25rpx;
  1137. box-shadow: $im-box-shadow-dark;
  1138. }
  1139. }
  1140. .chat-at-bar {
  1141. display: flex;
  1142. align-items: center;
  1143. padding: 0 10rpx;
  1144. .icon-at {
  1145. font-size: $im-font-size-larger;
  1146. color: $im-color-primary;
  1147. font-weight: bold;
  1148. }
  1149. .chat-at-scroll-box {
  1150. flex: 1;
  1151. width: 80%;
  1152. .chat-at-items {
  1153. display: flex;
  1154. align-items: center;
  1155. height: 70rpx;
  1156. .chat-at-item {
  1157. padding: 0 3rpx;
  1158. }
  1159. }
  1160. }
  1161. }
  1162. .send-bar {
  1163. display: flex;
  1164. align-items: center;
  1165. padding: 10rpx;
  1166. border-top: $im-border solid 1px;
  1167. background-color: $im-bg;
  1168. min-height: 80rpx;
  1169. margin-bottom: 14rpx;
  1170. .iconfont {
  1171. font-size: 60rpx;
  1172. margin: 0 10rpx;
  1173. color: $icon-color;
  1174. }
  1175. .chat-record {
  1176. flex: 1;
  1177. }
  1178. .send-text {
  1179. flex: 1;
  1180. overflow: auto;
  1181. padding: 14rpx 20rpx;
  1182. background-color: #fff;
  1183. border-radius: 8rpx;
  1184. font-size: $im-font-size;
  1185. box-sizing: border-box;
  1186. margin: 0 10rpx;
  1187. position: relative;
  1188. .send-text-area {
  1189. width: 100%;
  1190. height: 100%;
  1191. min-height: 40rpx;
  1192. max-height: 200rpx;
  1193. font-size: 30rpx;
  1194. }
  1195. }
  1196. .btn-send {
  1197. margin: 5rpx;
  1198. }
  1199. }
  1200. }
  1201. .chat-tab-bar {
  1202. position: fixed;
  1203. bottom: 0;
  1204. background-color: $im-bg;
  1205. .chat-tools {
  1206. display: flex;
  1207. flex-wrap: wrap;
  1208. align-items: top;
  1209. height: 310px;
  1210. padding: 40rpx;
  1211. box-sizing: border-box;
  1212. .chat-tools-item {
  1213. width: 25%;
  1214. padding: 16rpx;
  1215. box-sizing: border-box;
  1216. display: flex;
  1217. flex-direction: column;
  1218. align-items: center;
  1219. .tool-icon {
  1220. padding: 26rpx;
  1221. font-size: 54rpx;
  1222. border-radius: 20%;
  1223. background-color: white;
  1224. color: $icon-color;
  1225. &:active {
  1226. background-color: $im-bg-active;
  1227. }
  1228. }
  1229. .tool-name {
  1230. height: 60rpx;
  1231. line-height: 60rpx;
  1232. font-size: 28rpx;
  1233. }
  1234. }
  1235. }
  1236. .chat-emotion {
  1237. height: 310px;
  1238. padding: 20rpx;
  1239. box-sizing: border-box;
  1240. .emotion-item-list {
  1241. display: flex;
  1242. flex-wrap: wrap;
  1243. justify-content: space-between;
  1244. align-content: center;
  1245. .emotion-item {
  1246. text-align: center;
  1247. cursor: pointer;
  1248. padding: 5px;
  1249. }
  1250. }
  1251. }
  1252. }
  1253. }
  1254. </style>