chat-box.vue 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352
  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. this.scrollToBottom();
  643. // 有些设备滚到底部时会莫名触发滚动到顶部的事件
  644. // 所以这里延迟100s保证能准确设置底部标志
  645. setTimeout(() => {
  646. this.isInBottom = true;
  647. this.newMessageSize = 0;
  648. }, 100)
  649. },
  650. onScroll(e) {
  651. // 记录当前滚动条高度
  652. this.scrollViewHeight = e.detail.scrollHeight;
  653. },
  654. onScrollToTop() {
  655. if (this.showMinIdx > 0) {
  656. // #ifndef H5
  657. // 防止滚动条定格在顶部,不能一直往上滚,app和小程序采用scroll-into-view定位
  658. this.scrollToMsgIdx(this.showMinIdx);
  659. // #endif
  660. // #ifdef H5
  661. // 防止滚动条定格在顶部,不能一直往上滚,h5采用scroll-top定位
  662. if (uni.getSystemInfoSync().platform == 'ios') {
  663. this.holdingScrollBar(this.scrollViewHeight);
  664. }
  665. // #endif
  666. // 多展示20条信息
  667. this.showMinIdx = this.showMinIdx > 20 ? this.showMinIdx - 20 : 0;
  668. }
  669. // 清除底部标识
  670. this.isInBottom = false;
  671. },
  672. onScrollToBottom(e) {
  673. // 设置底部标识
  674. this.isInBottom = true;
  675. this.newMessageSize = 0;
  676. },
  677. holdingScrollBar(scrollViewHeight) {
  678. // 内容高度
  679. const query = uni.createSelectorQuery().in(this);
  680. setTimeout(() => {
  681. query.select('.chat-wrap').boundingClientRect();
  682. query.exec(data => {
  683. this.scrollTop = data[0].height - scrollViewHeight;
  684. if (this.scrollTop < 10) {
  685. // 未渲染完成,重试一次
  686. this.holdingScrollBar();
  687. } else {
  688. // 让页面再滚动一下,解决部分ios手机出现白屏问题
  689. const delays = [100, 300, 1000];
  690. delays.forEach(delay => setTimeout(() => this.scrollTop += 5, delay))
  691. }
  692. });
  693. }, 10)
  694. },
  695. onShowMore() {
  696. if (this.isGroup) {
  697. uni.navigateTo({
  698. url: "/pages/group/group-info?id=" + this.group.id
  699. })
  700. } else {
  701. uni.navigateTo({
  702. url: "/pages/common/user-info?id=" + this.userInfo.id
  703. })
  704. }
  705. },
  706. onTextInput(e) {
  707. this.isEmpty = e.detail.html == '<p><br></p>'
  708. },
  709. onEditorReady() {
  710. this.$nextTick(() => {
  711. const query = uni.createSelectorQuery().in(this);
  712. query.select('#editor').context((res) => {
  713. this.editorCtx = res.context
  714. }).exec()
  715. })
  716. },
  717. onEditorFocus(e) {
  718. this.isFocus = true;
  719. this.scrollToBottom()
  720. this.switchChatTabBox('none')
  721. },
  722. onEditorBlur(e) {
  723. this.isFocus = false;
  724. },
  725. onAudioStateChange(state, msgInfo) {
  726. const playingAudio = this.$refs['message' + msgInfo.id][0]
  727. if (state == 'PLAYING' && playingAudio != this.playingAudio) {
  728. // 停止之前的录音
  729. this.playingAudio && this.playingAudio.stopPlayAudio();
  730. // 记录当前正在播放的消息
  731. this.playingAudio = playingAudio;
  732. }
  733. },
  734. loadReaded(fid) {
  735. this.$http({
  736. url: `/message/private/maxReadedId?friendId=${fid}`,
  737. method: 'get'
  738. }).then((id) => {
  739. this.chatStore.readedMessage({
  740. friendId: fid,
  741. maxId: id
  742. });
  743. });
  744. },
  745. readedMessage() {
  746. if (this.unreadCount > 0) {
  747. let url = ""
  748. if (this.isGroup) {
  749. url = `/message/group/readed?groupId=${this.chat.targetId}`
  750. } else {
  751. url = `/message/private/readed?friendId=${this.chat.targetId}`
  752. }
  753. this.$http({
  754. url: url,
  755. method: 'PUT'
  756. }).then(() => {})
  757. }
  758. this.chatStore.resetUnreadCount(this.chat)
  759. },
  760. loadGroup(groupId) {
  761. this.$http({
  762. url: `/group/find/${groupId}`,
  763. method: 'GET'
  764. }).then((group) => {
  765. this.group = group;
  766. this.chatStore.updateChatFromGroup(group);
  767. this.groupStore.updateGroup(group);
  768. });
  769. this.$http({
  770. url: `/group/members/${groupId}`,
  771. method: 'GET'
  772. }).then((groupMembers) => {
  773. this.groupMembers = groupMembers;
  774. });
  775. },
  776. updateFriendInfo() {
  777. if (this.isFriend) {
  778. // store的数据不能直接修改,深拷贝一份store的数据
  779. let friend = JSON.parse(JSON.stringify(this.friend));
  780. friend.headImage = this.userInfo.headImageThumb;
  781. friend.nickName = this.userInfo.nickName;
  782. friend.showNickName = friend.remarkNickName ? friend.remarkNickName : friend.nickName;
  783. // 更新好友列表中的昵称和头像
  784. this.friendStore.updateFriend(friend);
  785. // 更新会话中的头像和昵称
  786. this.chatStore.updateChatFromFriend(friend);
  787. } else {
  788. this.chatStore.updateChatFromUser(this.userInfo);
  789. }
  790. },
  791. loadFriend(friendId) {
  792. // 获取好友用户信息
  793. this.$http({
  794. url: `/user/find/${friendId}`,
  795. method: 'GET'
  796. }).then((userInfo) => {
  797. this.userInfo = userInfo;
  798. this.updateFriendInfo();
  799. })
  800. },
  801. rpxTopx(rpx) {
  802. // rpx转换成px
  803. let info = uni.getSystemInfoSync()
  804. let px = info.windowWidth * rpx / 750;
  805. return Math.floor(rpx);
  806. },
  807. sendMessageRequest(msgInfo) {
  808. return new Promise((resolve, reject) => {
  809. // 请求入队列,防止请求"后发先至",导致消息错序
  810. this.reqQueue.push({ msgInfo, resolve, reject });
  811. this.processReqQueue();
  812. })
  813. },
  814. processReqQueue() {
  815. if (this.reqQueue.length && !this.isSending) {
  816. this.isSending = true;
  817. const reqData = this.reqQueue.shift();
  818. this.$http({
  819. url: this.messageAction,
  820. method: 'post',
  821. data: reqData.msgInfo
  822. }).then((res) => {
  823. reqData.resolve(res)
  824. }).catch((e) => {
  825. reqData.reject(e)
  826. }).finally(() => {
  827. this.isSending = false;
  828. // 发送下一条请求
  829. this.processReqQueue();
  830. })
  831. }
  832. },
  833. reCalChatMainHeight() {
  834. let sysInfo = uni.getSystemInfoSync();
  835. let h = this.windowHeight;
  836. // 减去标题栏高度
  837. h -= 50;
  838. // 减去键盘高度
  839. if (this.isShowKeyBoard || this.chatTabBox != 'none') {
  840. // ios app的键盘高度不准,需要减去屏幕和窗口差
  841. // #ifdef APP-PLUS
  842. if (sysInfo.platform == 'ios') {
  843. h += this.screenHeight - this.windowHeight;
  844. }
  845. // #endif
  846. h -= this.keyboardHeight;
  847. this.scrollToBottom();
  848. }
  849. // APP需要减去状态栏高度
  850. // #ifdef APP-PLUS
  851. h -= sysInfo.statusBarHeight;
  852. // #endif
  853. this.chatMainHeight = h;
  854. // #ifndef APP
  855. // ios浏览器键盘把页面顶起后,页面长度不会变化,这里把页面拉到顶部适配一下
  856. if (uni.getSystemInfoSync().platform == 'ios') {
  857. // 不同手机需要的延时时间不一致,采用分段延时的方式处理
  858. const delays = [50, 100, 500];
  859. delays.forEach((delay) => {
  860. setTimeout(() => {
  861. uni.pageScrollTo({
  862. scrollTop: 0,
  863. duration: 10
  864. });
  865. }, delay);
  866. })
  867. }
  868. // #endif
  869. },
  870. listenKeyBoard() {
  871. // #ifdef H5
  872. if (navigator.platform == "Win32") {
  873. // 电脑端不需要弹出键盘
  874. console.log("navigator.platform:", navigator.platform)
  875. return;
  876. }
  877. if (uni.getSystemInfoSync().platform == 'ios') {
  878. // 监听键盘高度,ios13以上开始支持
  879. if (window.visualViewport) {
  880. window.visualViewport.addEventListener('resize', this.resizeListener);
  881. } else {
  882. // ios h5实现键盘监听
  883. window.addEventListener('focusin', this.focusInListener);
  884. window.addEventListener('focusout', this.focusOutListener);
  885. }
  886. } else {
  887. // 安卓h5实现键盘监听
  888. window.addEventListener('resize', this.resizeListener);
  889. }
  890. // #endif
  891. // #ifndef H5
  892. // app实现键盘监听
  893. uni.onKeyboardHeightChange(this.keyBoardListener);
  894. // #endif
  895. },
  896. unListenKeyboard() {
  897. // #ifdef H5
  898. window.removeEventListener('focusin', this.focusInListener);
  899. window.removeEventListener('focusout', this.focusOutListener);
  900. window.removeEventListener('resize', this.resizeListener);
  901. if (window.visualViewport) {
  902. window.visualViewport.removeEventListener('resize', this.resizeListener);
  903. }
  904. // #endif
  905. // #ifndef H5
  906. uni.offKeyboardHeightChange(this.keyBoardListener);
  907. // #endif
  908. },
  909. keyBoardListener(res) {
  910. this.isShowKeyBoard = res.height > 0;
  911. if (this.isShowKeyBoard) {
  912. this.keyboardHeight = res.height; // 获取并保存键盘高度
  913. }
  914. setTimeout(() => this.reCalChatMainHeight(), 30);
  915. },
  916. resizeListener() {
  917. let keyboardHeight = this.initHeight - window.innerHeight;
  918. // 兼容部分ios浏览器
  919. if (window.visualViewport && uni.getSystemInfoSync().platform == 'ios') {
  920. keyboardHeight = this.initHeight - window.visualViewport.height;
  921. }
  922. let isShowKeyBoard = keyboardHeight > 150;
  923. if (isShowKeyBoard) {
  924. this.keyboardHeight = keyboardHeight;
  925. }
  926. if (this.isShowKeyBoard != isShowKeyBoard) {
  927. this.isShowKeyBoard = isShowKeyBoard;
  928. setTimeout(() => this.reCalChatMainHeight(), 30);
  929. }
  930. },
  931. focusInListener() {
  932. this.isShowKeyBoard = true;
  933. setTimeout(() => this.reCalChatMainHeight(), 30);
  934. },
  935. focusOutListener() {
  936. this.isShowKeyBoard = false;
  937. setTimeout(() => this.reCalChatMainHeight(), 30);
  938. },
  939. showBannedTip() {
  940. let msgInfo = {
  941. tmpId: this.generateId(),
  942. sendId: this.mine.id,
  943. sendTime: new Date().getTime(),
  944. type: this.$enums.MESSAGE_TYPE.TIP_TEXT
  945. }
  946. if (this.isPrivate) {
  947. msgInfo.recvId = this.mine.id
  948. msgInfo.content = "该用户已被管理员封禁,原因:" + this.userInfo.reason
  949. } else {
  950. msgInfo.groupId = this.group.id;
  951. msgInfo.content = "本群聊已被管理员封禁,原因:" + this.group.reason
  952. }
  953. this.chatStore.insertMessage(msgInfo, this.chat);
  954. },
  955. buildTmpMessage(msgInfo) {
  956. let message = JSON.parse(JSON.stringify(msgInfo));
  957. message.sendId = this.mine.id;
  958. message.sendTime = new Date().getTime();
  959. message.status = this.$enums.MESSAGE_STATUS.SENDING;
  960. message.selfSend = true;
  961. if (this.isGroup) {
  962. message.readedCount = 0;
  963. }
  964. return message;
  965. },
  966. getImageSize(file) {
  967. return new Promise((resolve) => {
  968. uni.getImageInfo({
  969. src: file.path,
  970. success: (res) => {
  971. resolve(res);
  972. },
  973. fail: (err) => {
  974. console.error('获取图片信息失败', err);
  975. }
  976. });
  977. });
  978. },
  979. generateId() {
  980. // 生成临时id
  981. const id = String(new Date().getTime()) + String(Math.floor(Math.random() * 1000));
  982. // 必须保证id是递增
  983. if (this.maxTmpId > id) {
  984. return this.generateId();
  985. }
  986. this.maxTmpId = id;
  987. return id;
  988. }
  989. },
  990. computed: {
  991. mine() {
  992. return this.userStore.userInfo;
  993. },
  994. friend() {
  995. return this.friendStore.findFriend(this.userInfo.id);
  996. },
  997. title() {
  998. if (!this.chat) {
  999. return "";
  1000. }
  1001. let title = this.chat.showName;
  1002. if (this.isGroup) {
  1003. let size = this.groupMembers.filter(m => !m.quit).length;
  1004. title += `(${size})`;
  1005. }
  1006. return title;
  1007. },
  1008. messageAction() {
  1009. return `/message/${this.chat.type.toLowerCase()}/send`;
  1010. },
  1011. messageSize() {
  1012. if (!this.chat || !this.chat.messages) {
  1013. return 0;
  1014. }
  1015. return this.chat.messages.length;
  1016. },
  1017. unreadCount() {
  1018. if (!this.chat || !this.chat.unreadCount) {
  1019. return 0;
  1020. }
  1021. return this.chat.unreadCount;
  1022. },
  1023. isBanned() {
  1024. return (this.isPrivate && this.userInfo.isBanned) ||
  1025. (this.isGroup && this.group.isBanned)
  1026. },
  1027. atUserItems() {
  1028. let atUsers = [];
  1029. this.atUserIds.forEach((id) => {
  1030. if (id == -1) {
  1031. atUsers.push({
  1032. id: -1,
  1033. showNickName: "全体成员"
  1034. })
  1035. return;
  1036. }
  1037. let member = this.groupMembers.find((m) => m.userId == id);
  1038. if (member) {
  1039. atUsers.push(member);
  1040. }
  1041. })
  1042. return atUsers;
  1043. },
  1044. memberSize() {
  1045. return this.groupMembers.filter(m => !m.quit).length;
  1046. },
  1047. isGroup() {
  1048. return this.chat.type == 'GROUP';
  1049. },
  1050. isPrivate() {
  1051. return this.chat.type == 'PRIVATE';
  1052. },
  1053. loading() {
  1054. return this.chatStore.loading;
  1055. }
  1056. },
  1057. watch: {
  1058. messageSize: function(newSize, oldSize) {
  1059. // 接收到新消息
  1060. if (newSize > oldSize && oldSize > 0) {
  1061. let lastMessage = this.chat.messages[newSize - 1];
  1062. if (this.$msgType.isNormal(lastMessage.type)) {
  1063. if (this.isInBottom || lastMessage.selfSend) {
  1064. // 收到消息,则滚动至底部
  1065. this.scrollToBottom();
  1066. } else {
  1067. // 若滚动条不在底部,说明用户正在翻历史消息,此时滚动条不能动,同时增加新消息提示
  1068. this.newMessageSize++;
  1069. }
  1070. }
  1071. }
  1072. },
  1073. unreadCount: {
  1074. handler(newCount, oldCount) {
  1075. if (newCount > 0) {
  1076. // 消息已读
  1077. this.readedMessage()
  1078. }
  1079. }
  1080. },
  1081. loading: {
  1082. handler(newLoading, oldLoading) {
  1083. // 断线重连后,需要更新一下已读状态
  1084. if (!newLoading && this.isPrivate) {
  1085. this.loadReaded(this.chat.targetId)
  1086. }
  1087. }
  1088. }
  1089. },
  1090. onLoad(options) {
  1091. // 聊天数据
  1092. this.chat = this.chatStore.chats[options.chatIdx];
  1093. // 初始状态只显示20条消息
  1094. let size = this.messageSize;
  1095. this.showMinIdx = size > 20 ? size - 20 : 0;
  1096. // 消息已读
  1097. this.readedMessage()
  1098. // 加载好友或群聊信息
  1099. if (this.isGroup) {
  1100. this.loadGroup(this.chat.targetId);
  1101. } else {
  1102. this.loadFriend(this.chat.targetId);
  1103. this.loadReaded(this.chat.targetId)
  1104. }
  1105. // 激活当前会话
  1106. this.chatStore.activeChat(options.chatIdx);
  1107. // 复位回执消息
  1108. this.isReceipt = false;
  1109. // 清空底部标志
  1110. this.isInBottom = true;
  1111. this.newMessageSize = 0;
  1112. // 清空消息临时id
  1113. this.maxTmpId = 0;
  1114. // 监听键盘高度
  1115. this.listenKeyBoard();
  1116. // 计算聊天窗口高度
  1117. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  1118. this.screenHeight = uni.getSystemInfoSync().screenHeight;
  1119. this.reCalChatMainHeight();
  1120. this.$nextTick(() => {
  1121. // 上面获取的windowHeight可能不准,重新计算一次聊天窗口高度
  1122. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  1123. this.reCalChatMainHeight();
  1124. this.scrollToBottom();
  1125. // #ifdef H5
  1126. this.initHeight = window.innerHeight;
  1127. // 兼容ios的h5:禁止页面滚动
  1128. const chatBox = document.getElementById('chatBox')
  1129. chatBox.addEventListener('touchmove', e => {
  1130. e.preventDefault()
  1131. }, { passive: false });
  1132. // #endif
  1133. });
  1134. },
  1135. onUnload() {
  1136. this.unListenKeyboard();
  1137. }
  1138. }
  1139. </script>
  1140. <style lang="scss">
  1141. .chat-box {
  1142. $icon-color: rgba(0, 0, 0, 0.88);
  1143. position: relative;
  1144. background-color: #fafafa;
  1145. .header {
  1146. display: flex;
  1147. justify-content: center;
  1148. align-items: center;
  1149. height: 60rpx;
  1150. padding: 5px;
  1151. background-color: #fafafa;
  1152. line-height: 50px;
  1153. font-size: $im-font-size-large;
  1154. box-shadow: $im-box-shadow-lighter;
  1155. z-index: 1;
  1156. .btn-side {
  1157. position: absolute;
  1158. line-height: 60rpx;
  1159. cursor: pointer;
  1160. &.right {
  1161. right: 30rpx;
  1162. }
  1163. }
  1164. }
  1165. .chat-main-box {
  1166. // #ifndef APP-PLUS
  1167. top: $im-nav-bar-height;
  1168. // #endif
  1169. // #ifdef APP-PLUS
  1170. top: calc($im-nav-bar-height + var(--status-bar-height));
  1171. // #endif
  1172. position: fixed;
  1173. width: 100%;
  1174. display: flex;
  1175. flex-direction: column;
  1176. z-index: 2;
  1177. .chat-message {
  1178. flex: 1;
  1179. padding: 0;
  1180. overflow: hidden;
  1181. position: relative;
  1182. background-color: white;
  1183. .scroll-box {
  1184. height: 100%;
  1185. }
  1186. .scroll-to-bottom {
  1187. position: absolute;
  1188. right: 30rpx;
  1189. bottom: 30rpx;
  1190. font-size: $im-font-size;
  1191. color: $im-color-primary;
  1192. font-weight: 600;
  1193. background: white;
  1194. padding: 10rpx 30rpx;
  1195. border-radius: 25rpx;
  1196. box-shadow: $im-box-shadow-dark;
  1197. }
  1198. }
  1199. .chat-at-bar {
  1200. display: flex;
  1201. align-items: center;
  1202. padding: 0 10rpx;
  1203. .icon-at {
  1204. font-size: $im-font-size-larger;
  1205. color: $im-color-primary;
  1206. font-weight: bold;
  1207. }
  1208. .chat-at-scroll-box {
  1209. flex: 1;
  1210. width: 80%;
  1211. .chat-at-items {
  1212. display: flex;
  1213. align-items: center;
  1214. height: 70rpx;
  1215. .chat-at-item {
  1216. padding: 0 3rpx;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. .send-bar {
  1222. display: flex;
  1223. align-items: center;
  1224. padding: 10rpx;
  1225. border-top: $im-border solid 1px;
  1226. background-color: $im-bg;
  1227. min-height: 80rpx;
  1228. padding-bottom: 14rpx;
  1229. .iconfont {
  1230. font-size: 60rpx;
  1231. margin: 0 10rpx;
  1232. color: $icon-color;
  1233. }
  1234. .chat-record {
  1235. flex: 1;
  1236. }
  1237. .send-text {
  1238. flex: 1;
  1239. overflow: auto;
  1240. padding: 14rpx 20rpx;
  1241. background-color: #fff;
  1242. border-radius: 8rpx;
  1243. font-size: $im-font-size;
  1244. box-sizing: border-box;
  1245. margin: 0 10rpx;
  1246. position: relative;
  1247. .send-text-area {
  1248. width: 100%;
  1249. height: 100%;
  1250. min-height: 40rpx;
  1251. max-height: 200rpx;
  1252. font-size: 30rpx;
  1253. }
  1254. }
  1255. .btn-send {
  1256. margin: 5rpx;
  1257. }
  1258. }
  1259. }
  1260. .chat-tab-bar {
  1261. position: fixed;
  1262. bottom: 0;
  1263. background-color: $im-bg;
  1264. .chat-tools {
  1265. padding: 40rpx;
  1266. box-sizing: border-box;
  1267. .chat-tools-list {
  1268. display: flex;
  1269. flex-wrap: wrap;
  1270. align-content: center;
  1271. .chat-tools-item {
  1272. width: 25%;
  1273. padding: 16rpx;
  1274. box-sizing: border-box;
  1275. display: flex;
  1276. flex-direction: column;
  1277. align-items: center;
  1278. .tool-icon {
  1279. padding: 26rpx;
  1280. font-size: 54rpx;
  1281. border-radius: 20%;
  1282. background-color: white;
  1283. color: $icon-color;
  1284. &:active {
  1285. background-color: $im-bg-active;
  1286. }
  1287. }
  1288. .tool-name {
  1289. height: 60rpx;
  1290. line-height: 60rpx;
  1291. font-size: 28rpx;
  1292. }
  1293. }
  1294. }
  1295. }
  1296. .chat-emotion {
  1297. padding: 40rpx;
  1298. box-sizing: border-box;
  1299. .emotion-item-list {
  1300. display: flex;
  1301. flex-wrap: wrap;
  1302. justify-content: space-between;
  1303. align-content: center;
  1304. .emotion-item {
  1305. text-align: center;
  1306. cursor: pointer;
  1307. padding: 5px;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. }
  1313. </style>