chat-box.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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. 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. // #ifdef APP-PLUS
  914. // ios app的键盘高度不准,需要减去屏幕和窗口差
  915. let sysInfo = uni.getSystemInfoSync();
  916. if (sysInfo.platform == 'ios') {
  917. this.keyboardHeight -= this.screenHeight - this.windowHeight;
  918. }
  919. // #endif
  920. }
  921. setTimeout(() => this.reCalChatMainHeight(), 30);
  922. },
  923. resizeListener() {
  924. let keyboardHeight = this.initHeight - window.innerHeight;
  925. // 兼容部分ios浏览器
  926. if (window.visualViewport && uni.getSystemInfoSync().platform == 'ios') {
  927. keyboardHeight = this.initHeight - window.visualViewport.height;
  928. }
  929. let isShowKeyBoard = keyboardHeight > 150;
  930. if (isShowKeyBoard) {
  931. this.keyboardHeight = keyboardHeight;
  932. }
  933. if (this.isShowKeyBoard != isShowKeyBoard) {
  934. this.isShowKeyBoard = isShowKeyBoard;
  935. setTimeout(() => this.reCalChatMainHeight(), 30);
  936. }
  937. },
  938. focusInListener() {
  939. this.isShowKeyBoard = true;
  940. setTimeout(() => this.reCalChatMainHeight(), 30);
  941. },
  942. focusOutListener() {
  943. this.isShowKeyBoard = false;
  944. setTimeout(() => this.reCalChatMainHeight(), 30);
  945. },
  946. showBannedTip() {
  947. let msgInfo = {
  948. tmpId: this.generateId(),
  949. sendId: this.mine.id,
  950. sendTime: new Date().getTime(),
  951. type: this.$enums.MESSAGE_TYPE.TIP_TEXT
  952. }
  953. if (this.isPrivate) {
  954. msgInfo.recvId = this.mine.id
  955. msgInfo.content = "该用户已被管理员封禁,原因:" + this.userInfo.reason
  956. } else {
  957. msgInfo.groupId = this.group.id;
  958. msgInfo.content = "本群聊已被管理员封禁,原因:" + this.group.reason
  959. }
  960. this.chatStore.insertMessage(msgInfo, this.chat);
  961. },
  962. buildTmpMessage(msgInfo) {
  963. let message = JSON.parse(JSON.stringify(msgInfo));
  964. message.sendId = this.mine.id;
  965. message.sendTime = new Date().getTime();
  966. message.status = this.$enums.MESSAGE_STATUS.SENDING;
  967. message.selfSend = true;
  968. if (this.isGroup) {
  969. message.readedCount = 0;
  970. }
  971. return message;
  972. },
  973. getImageSize(file) {
  974. return new Promise((resolve) => {
  975. uni.getImageInfo({
  976. src: file.path,
  977. success: (res) => {
  978. resolve(res);
  979. },
  980. fail: (err) => {
  981. console.error('获取图片信息失败', err);
  982. }
  983. });
  984. });
  985. },
  986. generateId() {
  987. // 生成临时id
  988. const id = String(new Date().getTime()) + String(Math.floor(Math.random() * 1000));
  989. // 必须保证id是递增
  990. if (this.maxTmpId > id) {
  991. return this.generateId();
  992. }
  993. this.maxTmpId = id;
  994. return id;
  995. }
  996. },
  997. computed: {
  998. mine() {
  999. return this.userStore.userInfo;
  1000. },
  1001. friend() {
  1002. return this.friendStore.findFriend(this.userInfo.id);
  1003. },
  1004. title() {
  1005. if (!this.chat) {
  1006. return "";
  1007. }
  1008. let title = this.chat.showName;
  1009. if (this.isGroup) {
  1010. let size = this.groupMembers.filter(m => !m.quit).length;
  1011. title += `(${size})`;
  1012. }
  1013. return title;
  1014. },
  1015. messageAction() {
  1016. return `/message/${this.chat.type.toLowerCase()}/send`;
  1017. },
  1018. messageSize() {
  1019. if (!this.chat || !this.chat.messages) {
  1020. return 0;
  1021. }
  1022. return this.chat.messages.length;
  1023. },
  1024. unreadCount() {
  1025. if (!this.chat || !this.chat.unreadCount) {
  1026. return 0;
  1027. }
  1028. return this.chat.unreadCount;
  1029. },
  1030. isBanned() {
  1031. return (this.isPrivate && this.userInfo.isBanned) ||
  1032. (this.isGroup && this.group.isBanned)
  1033. },
  1034. atUserItems() {
  1035. let atUsers = [];
  1036. this.atUserIds.forEach((id) => {
  1037. if (id == -1) {
  1038. atUsers.push({
  1039. id: -1,
  1040. showNickName: "全体成员"
  1041. })
  1042. return;
  1043. }
  1044. let member = this.groupMembers.find((m) => m.userId == id);
  1045. if (member) {
  1046. atUsers.push(member);
  1047. }
  1048. })
  1049. return atUsers;
  1050. },
  1051. memberSize() {
  1052. return this.groupMembers.filter(m => !m.quit).length;
  1053. },
  1054. isGroup() {
  1055. return this.chat.type == 'GROUP';
  1056. },
  1057. isPrivate() {
  1058. return this.chat.type == 'PRIVATE';
  1059. },
  1060. loading() {
  1061. return this.chatStore.loading;
  1062. }
  1063. },
  1064. watch: {
  1065. messageSize: function(newSize, oldSize) {
  1066. // 接收到新消息
  1067. if (newSize > oldSize && oldSize > 0) {
  1068. let lastMessage = this.chat.messages[newSize - 1];
  1069. if (this.$msgType.isNormal(lastMessage.type)) {
  1070. if (this.isInBottom || lastMessage.selfSend) {
  1071. // 收到消息,则滚动至底部
  1072. this.scrollToBottom();
  1073. } else {
  1074. // 若滚动条不在底部,说明用户正在翻历史消息,此时滚动条不能动,同时增加新消息提示
  1075. this.newMessageSize++;
  1076. }
  1077. }
  1078. }
  1079. },
  1080. unreadCount: {
  1081. handler(newCount, oldCount) {
  1082. if (newCount > 0) {
  1083. // 消息已读
  1084. this.readedMessage()
  1085. }
  1086. }
  1087. },
  1088. loading: {
  1089. handler(newLoading, oldLoading) {
  1090. // 断线重连后,需要更新一下已读状态
  1091. if (!newLoading && this.isPrivate) {
  1092. this.loadReaded(this.chat.targetId)
  1093. }
  1094. }
  1095. }
  1096. },
  1097. onLoad(options) {
  1098. // 聊天数据
  1099. this.chat = this.chatStore.chats[options.chatIdx];
  1100. // 初始状态只显示20条消息
  1101. let size = this.messageSize;
  1102. this.showMinIdx = size > 20 ? size - 20 : 0;
  1103. // 消息已读
  1104. this.readedMessage()
  1105. // 加载好友或群聊信息
  1106. if (this.isGroup) {
  1107. this.loadGroup(this.chat.targetId);
  1108. } else {
  1109. this.loadFriend(this.chat.targetId);
  1110. this.loadReaded(this.chat.targetId)
  1111. }
  1112. // 激活当前会话
  1113. this.chatStore.activeChat(options.chatIdx);
  1114. // 复位回执消息
  1115. this.isReceipt = false;
  1116. // 清空底部标志
  1117. this.isInBottom = true;
  1118. this.newMessageSize = 0;
  1119. // 清空消息临时id
  1120. this.maxTmpId = 0;
  1121. // 监听键盘高度
  1122. this.listenKeyBoard();
  1123. // 计算聊天窗口高度
  1124. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  1125. this.screenHeight = uni.getSystemInfoSync().screenHeight;
  1126. this.reCalChatMainHeight();
  1127. this.$nextTick(() => {
  1128. // 上面获取的windowHeight可能不准,重新计算一次聊天窗口高度
  1129. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  1130. this.reCalChatMainHeight();
  1131. this.scrollToBottom();
  1132. // #ifdef H5
  1133. this.initHeight = window.innerHeight;
  1134. // 兼容ios的h5:禁止页面滚动
  1135. const chatBox = document.getElementById('chatBox')
  1136. chatBox.addEventListener('touchmove', e => {
  1137. e.preventDefault()
  1138. }, { passive: false });
  1139. // #endif
  1140. });
  1141. },
  1142. onUnload() {
  1143. this.unListenKeyboard();
  1144. }
  1145. }
  1146. </script>
  1147. <style lang="scss">
  1148. .chat-box {
  1149. $icon-color: rgba(0, 0, 0, 0.88);
  1150. position: relative;
  1151. background-color: #fafafa;
  1152. .header {
  1153. display: flex;
  1154. justify-content: center;
  1155. align-items: center;
  1156. height: 60rpx;
  1157. padding: 5px;
  1158. background-color: #fafafa;
  1159. line-height: 50px;
  1160. font-size: $im-font-size-large;
  1161. box-shadow: $im-box-shadow-lighter;
  1162. z-index: 1;
  1163. .btn-side {
  1164. position: absolute;
  1165. line-height: 60rpx;
  1166. cursor: pointer;
  1167. &.right {
  1168. right: 30rpx;
  1169. }
  1170. }
  1171. }
  1172. .chat-main-box {
  1173. // #ifndef APP-PLUS
  1174. top: $im-nav-bar-height;
  1175. // #endif
  1176. // #ifdef APP-PLUS
  1177. top: calc($im-nav-bar-height + var(--status-bar-height));
  1178. // #endif
  1179. position: fixed;
  1180. width: 100%;
  1181. display: flex;
  1182. flex-direction: column;
  1183. z-index: 2;
  1184. .chat-message {
  1185. flex: 1;
  1186. padding: 0;
  1187. overflow: hidden;
  1188. position: relative;
  1189. background-color: white;
  1190. .scroll-box {
  1191. height: 100%;
  1192. }
  1193. .scroll-to-bottom {
  1194. position: absolute;
  1195. right: 30rpx;
  1196. bottom: 30rpx;
  1197. font-size: $im-font-size;
  1198. color: $im-color-primary;
  1199. font-weight: 600;
  1200. background: white;
  1201. padding: 10rpx 30rpx;
  1202. border-radius: 25rpx;
  1203. box-shadow: $im-box-shadow-dark;
  1204. }
  1205. }
  1206. .chat-at-bar {
  1207. display: flex;
  1208. align-items: center;
  1209. padding: 0 10rpx;
  1210. .icon-at {
  1211. font-size: $im-font-size-larger;
  1212. color: $im-color-primary;
  1213. font-weight: bold;
  1214. }
  1215. .chat-at-scroll-box {
  1216. flex: 1;
  1217. width: 80%;
  1218. .chat-at-items {
  1219. display: flex;
  1220. align-items: center;
  1221. height: 70rpx;
  1222. .chat-at-item {
  1223. padding: 0 3rpx;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. .send-bar {
  1229. display: flex;
  1230. align-items: center;
  1231. padding: 10rpx;
  1232. border-top: $im-border solid 1px;
  1233. background-color: $im-bg;
  1234. min-height: 80rpx;
  1235. padding-bottom: 14rpx;
  1236. .iconfont {
  1237. font-size: 60rpx;
  1238. margin: 0 10rpx;
  1239. color: $icon-color;
  1240. }
  1241. .chat-record {
  1242. flex: 1;
  1243. }
  1244. .send-text {
  1245. flex: 1;
  1246. overflow: auto;
  1247. padding: 14rpx 20rpx;
  1248. background-color: #fff;
  1249. border-radius: 8rpx;
  1250. font-size: $im-font-size;
  1251. box-sizing: border-box;
  1252. margin: 0 10rpx;
  1253. position: relative;
  1254. .send-text-area {
  1255. width: 100%;
  1256. height: 100%;
  1257. min-height: 40rpx;
  1258. max-height: 200rpx;
  1259. font-size: 30rpx;
  1260. }
  1261. }
  1262. .btn-send {
  1263. margin: 5rpx;
  1264. }
  1265. }
  1266. }
  1267. .chat-tab-bar {
  1268. position: fixed;
  1269. bottom: 0;
  1270. background-color: $im-bg;
  1271. .chat-tools {
  1272. padding: 40rpx;
  1273. box-sizing: border-box;
  1274. .chat-tools-list {
  1275. display: flex;
  1276. flex-wrap: wrap;
  1277. align-content: center;
  1278. .chat-tools-item {
  1279. width: 25%;
  1280. padding: 16rpx;
  1281. box-sizing: border-box;
  1282. display: flex;
  1283. flex-direction: column;
  1284. align-items: center;
  1285. .tool-icon {
  1286. padding: 26rpx;
  1287. font-size: 54rpx;
  1288. border-radius: 20%;
  1289. background-color: white;
  1290. color: $icon-color;
  1291. &:active {
  1292. background-color: $im-bg-active;
  1293. }
  1294. }
  1295. .tool-name {
  1296. height: 60rpx;
  1297. line-height: 60rpx;
  1298. font-size: 28rpx;
  1299. }
  1300. }
  1301. }
  1302. }
  1303. .chat-emotion {
  1304. padding: 40rpx;
  1305. box-sizing: border-box;
  1306. .emotion-item-list {
  1307. display: flex;
  1308. flex-wrap: wrap;
  1309. justify-content: space-between;
  1310. align-content: center;
  1311. .emotion-item {
  1312. text-align: center;
  1313. cursor: pointer;
  1314. padding: 5px;
  1315. }
  1316. }
  1317. }
  1318. }
  1319. }
  1320. </style>