chat-box.vue 37 KB

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