chat-box.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. <template>
  2. <view class="page chat-box">
  3. <view class="header">
  4. <uni-icons class="btn-side left" type="back" size="30" @click="onNavBack()"></uni-icons>
  5. <text class="title">{{title}}</text>
  6. <uni-icons class="btn-side right" type="more-filled" size="30" @click="onShowMore()"></uni-icons>
  7. </view>
  8. <view class="chat-msg" @click="switchChatTabBox('none',true)">
  9. <scroll-view class="scroll-box" scroll-y="true" @scrolltoupper="onScrollToTop"
  10. :scroll-into-view="'chat-item-'+scrollMsgIdx">
  11. <view v-for="(msgInfo,idx) in chat.messages" :key="idx">
  12. <chat-message-item v-if="idx>=showMinIdx" :headImage="headImage(msgInfo)"
  13. @call="onRtCall(msgInfo)"
  14. :showName="showName(msgInfo)" @recall="onRecallMessage" @delete="onDeleteMessage"
  15. @longPressHead="onLongPressHead(msgInfo)" @download="onDownloadFile" :id="'chat-item-'+idx"
  16. :msgInfo="msgInfo" :groupMembers="groupMembers">
  17. </chat-message-item>
  18. </view>
  19. </scroll-view>
  20. </view>
  21. <view v-if="atUserIds.length>0" class="chat-at-bar" @click="openAtBox()">
  22. <view class="iconfont icon-at">:&nbsp;</view>
  23. <scroll-view v-if="atUserIds.length>0" class="chat-at-scroll-box" scroll-x="true" scroll-left="120">
  24. <view class="chat-at-items">
  25. <view v-for="m in atUserItems" class="chat-at-item">
  26. <head-image :name="m.aliasName" :url="m.headImage" :size="50"></head-image>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. <view class="send-bar">
  32. <view class="send-text">
  33. <textarea class="send-text-area" v-model="sendText" auto-height :show-confirm-bar="false"
  34. :placeholder="isReceipt?'[回执消息]':''" :adjust-position="false" @confirm="sendTextMessage()"
  35. @keyboardheightchange="onKeyboardheightchange" @input="onTextInput" confirm-type="send" confirm-hold
  36. :hold-keyboard="true"></textarea>
  37. </view>
  38. <view v-if="chat.type=='GROUP'" class="iconfont icon-at" @click="openAtBox()"></view>
  39. <view class="iconfont icon-icon_emoji" @click="switchChatTabBox('emo',true)"></view>
  40. <view v-if="sendText==''" class="iconfont icon-add" @click="switchChatTabBox('tools',true)">
  41. </view>
  42. <button v-if="sendText!=''||atUserIds.length>0" class="btn-send" type="primary"
  43. @touchend.prevent="sendTextMessage()" size="mini">发送</button>
  44. </view>
  45. <view class="chat-tab-bar" v-show="chatTabBox!='none' ||showKeyBoard " :style="{height:`${keyboardHeight}px`}">
  46. <view v-if="chatTabBox == 'tools'" class="chat-tools">
  47. <view class="chat-tools-item">
  48. <image-upload :maxCount="9" sourceType="album" :onBefore="onUploadImageBefore"
  49. :onSuccess="onUploadImageSuccess" :onError="onUploadImageFail">
  50. <view class="tool-icon iconfont icon-picture"></view>
  51. </image-upload>
  52. <view class="tool-name">相册</view>
  53. </view>
  54. <view class="chat-tools-item">
  55. <image-upload sourceType="camera" :onBefore="onUploadImageBefore" :onSuccess="onUploadImageSuccess"
  56. :onError="onUploadImageFail">
  57. <view class="tool-icon iconfont icon-camera"></view>
  58. </image-upload>
  59. <view class="tool-name">拍摄</view>
  60. </view>
  61. <!-- #ifndef APP-PLUS -->
  62. <!-- APP 暂时不支持选择文件 -->
  63. <view class="chat-tools-item">
  64. <file-upload :onBefore="onUploadFileBefore" :onSuccess="onUploadFileSuccess"
  65. :onError="onUploadFileFail">
  66. <view class="tool-icon iconfont icon-folder"></view>
  67. </file-upload>
  68. <view class="tool-name">文件</view>
  69. </view>
  70. <!-- #endif -->
  71. <view class="chat-tools-item" @click="showTip()">
  72. <view class="tool-icon iconfont icon-microphone"></view>
  73. <view class="tool-name">语音输入</view>
  74. </view>
  75. <view v-if="chat.type == 'GROUP'" class="chat-tools-item" @click="switchReceipt()">
  76. <view class="tool-icon iconfont icon-receipt" :class="isReceipt?'active':''"></view>
  77. <view class="tool-name">回执消息</view>
  78. </view>
  79. <view v-if="chat.type == 'PRIVATE'" class="chat-tools-item" @click="onVideoCall()">
  80. <view class="tool-icon iconfont icon-video"></view>
  81. <view class="tool-name">视频通话</view>
  82. </view>
  83. <view v-if="chat.type == 'PRIVATE'" class="chat-tools-item" @click="onVoiceCall()">
  84. <view class="tool-icon iconfont icon-call"></view>
  85. <view class="tool-name">语音通话</view>
  86. </view>
  87. </view>
  88. <scroll-view v-if="chatTabBox==='emo'" class="chat-emotion" scroll-y="true">
  89. <view class="emotion-item-list">
  90. <image class="emotion-item" :title="emoText" :src="$emo.textToPath(emoText)"
  91. v-for="(emoText, i) in $emo.emoTextList" :key="i" @click="selectEmoji(emoText)" mode="aspectFit"
  92. lazy-load="true"></image>
  93. </view>
  94. </scroll-view>
  95. <view v-if="showKeyBoard"></view>
  96. </view>
  97. <chat-at-box ref="atBox" :ownerId="group.ownerId" :members="groupMembers"
  98. @complete="onAtComplete"></chat-at-box>
  99. </view>
  100. </template>
  101. <script>
  102. export default {
  103. data() {
  104. return {
  105. chat: {},
  106. friend: {},
  107. group: {},
  108. groupMembers: [],
  109. sendText: "",
  110. isReceipt: false, // 是否回执消息
  111. showVoice: false, // 是否显示语音录制弹窗
  112. scrollMsgIdx: 0, // 滚动条定位为到哪条消息
  113. chatTabBox: 'none',
  114. showKeyBoard: false,
  115. keyboardHeight: 322,
  116. atUserIds: [],
  117. showMinIdx: 0 // 下标小于showMinIdx的消息不显示,否则可能很卡
  118. }
  119. },
  120. methods: {
  121. showTip() {
  122. uni.showToast({
  123. title: "暂未支持...",
  124. icon: "none"
  125. })
  126. },
  127. onRtCall(msgInfo){
  128. if(msgInfo.type == this.$enums.MESSAGE_TYPE.RT_VOICE){
  129. this.onVoiceCall();
  130. }else if(msgInfo.type == this.$enums.MESSAGE_TYPE.RT_VIDEO){
  131. this.onVideoCall();
  132. }
  133. },
  134. onVideoCall(){
  135. const friendInfo = encodeURIComponent(JSON.stringify(this.friend));
  136. uni.navigateTo({
  137. url: `/pages/chat/chat-video?mode=video&friend=${friendInfo}&isHost=true`
  138. })
  139. },
  140. onVoiceCall(){
  141. const friendInfo = encodeURIComponent(JSON.stringify(this.friend));
  142. uni.navigateTo({
  143. url: `/pages/chat/chat-video?mode=voice&friend=${friendInfo}&isHost=true`
  144. })
  145. },
  146. moveChatToTop() {
  147. let chatIdx = this.$store.getters.findChatIdx(this.chat);
  148. this.$store.commit("moveTop", chatIdx);
  149. },
  150. switchReceipt() {
  151. this.isReceipt = !this.isReceipt;
  152. },
  153. openAtBox() {
  154. this.$refs.atBox.init(this.atUserIds);
  155. this.$refs.atBox.open();
  156. },
  157. onAtComplete(atUserIds) {
  158. this.atUserIds = atUserIds;
  159. },
  160. onLongPressHead(msgInfo) {
  161. if (!msgInfo.selfSend && this.chat.type == "GROUP" && this.atUserIds.indexOf(msgInfo.sendId) < 0) {
  162. this.atUserIds.push(msgInfo.sendId);
  163. }
  164. },
  165. headImage(msgInfo) {
  166. if (this.chat.type == 'GROUP') {
  167. let member = this.groupMembers.find((m) => m.userId == msgInfo.sendId);
  168. return member ? member.headImage : "";
  169. } else {
  170. return msgInfo.selfSend ? this.mine.headImageThumb : this.chat.headImage
  171. }
  172. },
  173. showName(msgInfo) {
  174. if (this.chat.type == 'GROUP') {
  175. let member = this.groupMembers.find((m) => m.userId == msgInfo.sendId);
  176. return member ? member.aliasName : "";
  177. } else {
  178. return msgInfo.selfSend ? this.mine.nickName : this.chat.showName
  179. }
  180. },
  181. sendTextMessage() {
  182. if (!this.sendText.trim() && this.atUserIds.length == 0) {
  183. return uni.showToast({
  184. title: "不能发送空白信息",
  185. icon: "none"
  186. });
  187. }
  188. let receiptText = this.isReceipt ? "【回执消息】" : "";
  189. let atText = this.createAtText();
  190. let msgInfo = {
  191. content: receiptText + this.sendText + atText,
  192. atUserIds: this.atUserIds,
  193. receipt: this.isReceipt,
  194. type: 0
  195. }
  196. // 填充对方id
  197. this.fillTargetId(msgInfo, this.chat.targetId);
  198. this.sendText = "";
  199. this.$http({
  200. url: this.messageAction,
  201. method: 'POST',
  202. data: msgInfo
  203. }).then((id) => {
  204. msgInfo.id = id;
  205. msgInfo.sendTime = new Date().getTime();
  206. msgInfo.sendId = this.$store.state.userStore.userInfo.id;
  207. msgInfo.selfSend = true;
  208. msgInfo.readedCount = 0,
  209. msgInfo.status = this.$enums.MESSAGE_STATUS.UNSEND;
  210. this.$store.commit("insertMessage", msgInfo);
  211. // 会话置顶
  212. this.moveChatToTop();
  213. this.sendText = "";
  214. }).finally(() => {
  215. // 滚动到底部
  216. this.scrollToBottom();
  217. // 清空@用户列表
  218. this.atUserIds = [];
  219. this.isReceipt = false;
  220. });
  221. },
  222. createAtText() {
  223. let atText = "";
  224. this.atUserIds.forEach((id) => {
  225. if (id == -1) {
  226. atText += ` @全体成员`;
  227. } else {
  228. let member = this.groupMembers.find((m) => m.userId == id);
  229. if (member) {
  230. atText += ` @${member.aliasName}`;
  231. }
  232. }
  233. })
  234. return atText;
  235. },
  236. fillTargetId(msgInfo, targetId) {
  237. if (this.chat.type == "GROUP") {
  238. msgInfo.groupId = targetId;
  239. } else {
  240. msgInfo.recvId = targetId;
  241. }
  242. },
  243. scrollToBottom() {
  244. let size = this.chat.messages.length;
  245. if (size > 0) {
  246. this.scrollToMsgIdx(size - 1);
  247. }
  248. },
  249. scrollToMsgIdx(idx) {
  250. // 如果scrollMsgIdx值没变化,滚动条不会移动
  251. if (idx == this.scrollMsgIdx && idx > 0) {
  252. this.$nextTick(() => {
  253. // 先滚动到上一条
  254. this.scrollMsgIdx = idx - 1;
  255. // 再滚动目标位置
  256. this.scrollToMsgIdx(idx);
  257. });
  258. return;
  259. }
  260. this.$nextTick(() => {
  261. this.scrollMsgIdx = idx;
  262. });
  263. },
  264. switchChatTabBox(chatTabBox, hideKeyBoard) {
  265. this.chatTabBox = chatTabBox;
  266. if (hideKeyBoard) {
  267. uni.hideKeyboard();
  268. }
  269. },
  270. selectEmoji(emoText) {
  271. this.sendText += `#${emoText};`;
  272. },
  273. onNavBack() {
  274. uni.switchTab({
  275. url: "/pages/chat/chat"
  276. })
  277. },
  278. onKeyboardheightchange(e) {
  279. if (e.detail.height > 0) {
  280. this.showKeyBoard = true;
  281. this.switchChatTabBox('none', false)
  282. this.keyboardHeight = this.rpxTopx(e.detail.height);
  283. } else {
  284. this.showKeyBoard = false;
  285. }
  286. },
  287. onUploadImageBefore(file) {
  288. let data = {
  289. originUrl: file.path,
  290. thumbUrl: file.path
  291. }
  292. let msgInfo = {
  293. id: 0,
  294. fileId: file.uid,
  295. sendId: this.mine.id,
  296. content: JSON.stringify(data),
  297. sendTime: new Date().getTime(),
  298. selfSend: true,
  299. type: this.$enums.MESSAGE_TYPE.IMAGE,
  300. readedCount: 0,
  301. loadStatus: "loading",
  302. status: this.$enums.MESSAGE_STATUS.UNSEND
  303. }
  304. // 填充对方id
  305. this.fillTargetId(msgInfo, this.chat.targetId);
  306. // 插入消息
  307. this.$store.commit("insertMessage", msgInfo);
  308. // 会话置顶
  309. this.moveChatToTop();
  310. // 借助file对象保存
  311. file.msgInfo = msgInfo;
  312. // 滚到最低部
  313. this.scrollToBottom();
  314. return true;
  315. },
  316. onUploadImageSuccess(file, res) {
  317. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  318. msgInfo.content = JSON.stringify(res.data);
  319. msgInfo.receipt = this.isReceipt
  320. this.$http({
  321. url: this.messageAction,
  322. method: 'POST',
  323. data: msgInfo
  324. }).then((id) => {
  325. msgInfo.loadStatus = 'ok';
  326. msgInfo.id = id;
  327. this.isReceipt = false;
  328. this.$store.commit("insertMessage", msgInfo);
  329. })
  330. },
  331. onUploadImageFail(file, err) {
  332. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  333. msgInfo.loadStatus = 'fail';
  334. this.$store.commit("insertMessage", msgInfo);
  335. },
  336. onUploadFileBefore(file) {
  337. let data = {
  338. name: file.name,
  339. size: file.size,
  340. url: file.path
  341. }
  342. let msgInfo = {
  343. id: 0,
  344. sendId: this.mine.id,
  345. content: JSON.stringify(data),
  346. sendTime: new Date().getTime(),
  347. selfSend: true,
  348. type: this.$enums.MESSAGE_TYPE.FILE,
  349. readedCount: 0,
  350. loadStatus: "loading",
  351. status: this.$enums.MESSAGE_STATUS.UNSEND
  352. }
  353. // 填充对方id
  354. this.fillTargetId(msgInfo, this.chat.targetId);
  355. // 插入消息
  356. this.$store.commit("insertMessage", msgInfo);
  357. // 会话置顶
  358. this.moveChatToTop();
  359. // 借助file对象保存
  360. file.msgInfo = msgInfo;
  361. // 滚到最低部
  362. this.scrollToBottom();
  363. return true;
  364. },
  365. onUploadFileSuccess(file, res) {
  366. let data = {
  367. name: file.name,
  368. size: file.size,
  369. url: res.data
  370. }
  371. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  372. msgInfo.content = JSON.stringify(data);
  373. msgInfo.receipt = this.isReceipt
  374. this.$http({
  375. url: this.messageAction,
  376. method: 'POST',
  377. data: msgInfo
  378. }).then((id) => {
  379. msgInfo.loadStatus = 'ok';
  380. msgInfo.id = id;
  381. this.isReceipt = false;
  382. this.$store.commit("insertMessage", msgInfo);
  383. })
  384. },
  385. onUploadFileFail(file, res) {
  386. let msgInfo = JSON.parse(JSON.stringify(file.msgInfo));
  387. msgInfo.loadStatus = 'fail';
  388. this.$store.commit("insertMessage", msgInfo);
  389. },
  390. onDeleteMessage(msgInfo) {
  391. uni.showModal({
  392. title: '删除消息',
  393. content: '确认删除消息?',
  394. success: (res) => {
  395. if (!res.cancel) {
  396. this.$store.commit("deleteMessage", msgInfo);
  397. uni.showToast({
  398. title: "删除成功",
  399. icon: "none"
  400. })
  401. }
  402. }
  403. })
  404. },
  405. onRecallMessage(msgInfo) {
  406. uni.showModal({
  407. title: '撤回消息',
  408. content: '确认撤回消息?',
  409. success: (res) => {
  410. if (!res.cancel) {
  411. let url = `/message/${this.chat.type.toLowerCase()}/recall/${msgInfo.id}`
  412. this.$http({
  413. url: url,
  414. method: 'DELETE'
  415. }).then(() => {
  416. msgInfo = JSON.parse(JSON.stringify(msgInfo));
  417. msgInfo.type = this.$enums.MESSAGE_TYPE.RECALL;
  418. msgInfo.content = '你撤回了一条消息';
  419. msgInfo.status = this.$enums.MESSAGE_STATUS.RECALL;
  420. this.$store.commit("insertMessage", msgInfo);
  421. })
  422. }
  423. }
  424. })
  425. },
  426. onDownloadFile(msgInfo) {
  427. let url = JSON.parse(msgInfo.content).url;
  428. uni.downloadFile({
  429. url: url,
  430. success(res) {
  431. if (res.statusCode === 200) {
  432. var filePath = encodeURI(res.tempFilePath);
  433. uni.openDocument({
  434. filePath: filePath,
  435. showMenu: true
  436. });
  437. }
  438. },
  439. fail(e) {
  440. console.log(e);
  441. uni.showToast({
  442. title: "文件下载失败",
  443. icon: "none"
  444. })
  445. }
  446. });
  447. },
  448. onScrollToTop() {
  449. // #ifdef MP
  450. // 防止滚动条定格在顶部,不能一直往上滚
  451. this.scrollToMsgIdx(this.showMinIdx);
  452. // #endif
  453. // 多展示10条信息
  454. this.showMinIdx = this.showMinIdx > 10 ? this.showMinIdx - 10 : 0;
  455. },
  456. onShowMore() {
  457. if (this.chat.type == "GROUP") {
  458. uni.navigateTo({
  459. url: "/pages/group/group-info?id=" + this.group.id
  460. })
  461. } else {
  462. uni.navigateTo({
  463. url: "/pages/common/user-info?id=" + this.friend.id
  464. })
  465. }
  466. },
  467. onTextInput(e) {
  468. let idx = e.detail.cursor - 1;
  469. if (this.chat.type == 'GROUP' && e.detail.value[idx] == '@') {
  470. this.openAtBox();
  471. let sendText = e.detail.value.replace("@", '');
  472. this.$nextTick(() => {
  473. this.sendText = sendText;
  474. })
  475. }
  476. },
  477. loadReaded(fId) {
  478. this.$http({
  479. url: `/message/private/maxReadedId?friendId=${fId}`,
  480. method: 'get'
  481. }).then((id) => {
  482. this.$store.commit("readedMessage", {
  483. friendId: fId,
  484. maxId: id
  485. });
  486. });
  487. },
  488. readedMessage() {
  489. if (this.chat.type == "GROUP") {
  490. var url = `/message/group/readed?groupId=${this.chat.targetId}`
  491. } else {
  492. url = `/message/private/readed?friendId=${this.chat.targetId}`
  493. }
  494. this.$http({
  495. url: url,
  496. method: 'PUT'
  497. }).then(() => {
  498. this.$store.commit("resetUnreadCount", this.chat)
  499. this.scrollToBottom();
  500. })
  501. },
  502. loadGroup(groupId) {
  503. this.$http({
  504. url: `/group/find/${groupId}`,
  505. method: 'GET'
  506. }).then((group) => {
  507. this.group = group;
  508. this.$store.commit("updateChatFromGroup", group);
  509. this.$store.commit("updateGroup", group);
  510. });
  511. this.$http({
  512. url: `/group/members/${groupId}`,
  513. method: 'get'
  514. }).then((groupMembers) => {
  515. this.groupMembers = groupMembers;
  516. });
  517. },
  518. loadFriend(friendId) {
  519. // 获取对方最新信息
  520. this.$http({
  521. url: `/user/find/${friendId}`,
  522. method: 'GET'
  523. }).then((friend) => {
  524. this.friend = friend;
  525. this.$store.commit("updateChatFromFriend", friend);
  526. this.$store.commit("updateFriend", friend);
  527. })
  528. },
  529. rpxTopx(rpx) {
  530. // px转换成rpx
  531. let info = uni.getSystemInfoSync()
  532. let px = info.windowWidth * rpx / 750;
  533. return Math.floor(rpx);
  534. }
  535. },
  536. computed: {
  537. mine() {
  538. return this.$store.state.userStore.userInfo;
  539. },
  540. title() {
  541. if (!this.chat) {
  542. return "";
  543. }
  544. let title = this.chat.showName;
  545. if (this.chat.type == "GROUP") {
  546. let size = this.groupMembers.filter(m => !m.quit).length;
  547. title += `(${size})`;
  548. }
  549. return title;
  550. },
  551. messageAction() {
  552. return `/message/${this.chat.type.toLowerCase()}/send`;
  553. },
  554. messageSize() {
  555. if (!this.chat || !this.chat.messages) {
  556. return 0;
  557. }
  558. return this.chat.messages.length;
  559. },
  560. unreadCount() {
  561. return this.chat.unreadCount;
  562. },
  563. atUserItems() {
  564. let atUsers = [];
  565. this.atUserIds.forEach((id) => {
  566. if (id == -1) {
  567. atUsers.push({
  568. id: -1,
  569. aliasName: "全体成员"
  570. })
  571. return;
  572. }
  573. let member = this.groupMembers.find((m) => m.userId == id);
  574. if (member) {
  575. atUsers.push(member);
  576. }
  577. })
  578. return atUsers;
  579. }
  580. },
  581. watch: {
  582. messageSize: function(newSize, oldSize) {
  583. // 接收到消息时滚动到底部
  584. if (newSize > oldSize) {
  585. this.scrollToBottom();
  586. }
  587. },
  588. unreadCount: {
  589. handler(newCount, oldCount) {
  590. if (newCount > 0) {
  591. // 消息已读
  592. this.readedMessage()
  593. }
  594. }
  595. }
  596. },
  597. onLoad(options) {
  598. // 聊天数据
  599. this.chat = this.$store.state.chatStore.chats[options.chatIdx];
  600. // 初始状态只显示30条消息
  601. let size = this.chat.messages.length;
  602. this.showMinIdx = size > 30 ? size - 30 : 0;
  603. // 激活当前会话
  604. this.$store.commit("activeChat", options.chatIdx);
  605. // 消息已读
  606. this.readedMessage()
  607. // 加载好友或群聊信息
  608. if (this.chat.type == "GROUP") {
  609. this.loadGroup(this.chat.targetId);
  610. } else {
  611. this.loadFriend(this.chat.targetId);
  612. this.loadReaded(this.chat.targetId)
  613. }
  614. // 复位回执消息
  615. this.isReceipt = false;
  616. },
  617. onShow() {
  618. // 页面滚到底部
  619. this.scrollToBottom();
  620. },
  621. onUnload() {
  622. this.$store.commit("activeChat", -1);
  623. }
  624. }
  625. </script>
  626. <style lang="scss" scoped>
  627. .chat-box {
  628. position: relative;
  629. border: #dddddd solid 1px;
  630. display: flex;
  631. flex-direction: column;
  632. .header {
  633. display: flex;
  634. justify-content: center;
  635. align-items: center;
  636. height: 60rpx;
  637. padding: 5px;
  638. background-color: white;
  639. line-height: 50px;
  640. font-size: 40rpx;
  641. font-weight: 600;
  642. border: #dddddd solid 1px;
  643. .btn-side {
  644. position: absolute;
  645. line-height: 60rpx;
  646. font-size: 28rpx;
  647. cursor: pointer;
  648. &.left {
  649. left: 30rpx;
  650. }
  651. &.right {
  652. right: 30rpx;
  653. }
  654. }
  655. }
  656. .chat-msg {
  657. flex: 1;
  658. padding: 0;
  659. border: #dddddd solid 1px;
  660. overflow: hidden;
  661. position: relative;
  662. background-color: #f8f8f8;
  663. .scroll-box {
  664. height: 100%;
  665. }
  666. }
  667. .chat-at-bar {
  668. display: flex;
  669. align-items: center;
  670. padding: 0 10rpx;
  671. border: #dddddd solid 1px;
  672. .icon-at {
  673. font-size: 35rpx;
  674. color: darkblue;
  675. font-weight: 600;
  676. }
  677. .chat-at-scroll-box {
  678. flex: 1;
  679. width: 80%;
  680. .chat-at-items {
  681. display: flex;
  682. align-items: center;
  683. height: 70rpx;
  684. .chat-at-item {
  685. padding: 0 3rpx;
  686. }
  687. }
  688. }
  689. }
  690. .send-bar {
  691. display: flex;
  692. align-items: center;
  693. padding: 10rpx;
  694. margin-bottom: 10rpx;
  695. border: #dddddd solid 1px;
  696. background-color: white;
  697. .iconfont {
  698. font-size: 60rpx;
  699. margin: 3rpx;
  700. }
  701. .send-text {
  702. flex: 1;
  703. background-color: #f8f8f8 !important;
  704. overflow: auto;
  705. padding: 20rpx;
  706. background-color: #fff;
  707. border-radius: 20rpx;
  708. max-height: 300rpx;
  709. min-height: 85rpx;
  710. font-size: 30rpx;
  711. box-sizing: border-box;
  712. .send-text-area {
  713. width: 100%;
  714. }
  715. }
  716. .btn-send {
  717. margin: 5rpx;
  718. }
  719. }
  720. .chat-tab-bar {
  721. height: 500rpx;
  722. padding: 20rpx;
  723. background-color: whitesmoke;
  724. .chat-tools {
  725. display: flex;
  726. flex-wrap: wrap;
  727. .chat-tools-item {
  728. width: 140rpx;
  729. padding: 16rpx;
  730. display: flex;
  731. flex-direction: column;
  732. align-items: center;
  733. .tool-icon {
  734. padding: 28rpx;
  735. font-size: 60rpx;
  736. background-color: white;
  737. border-radius: 20%;
  738. &.active {
  739. background-color: #ddd;
  740. }
  741. }
  742. .tool-name {
  743. height: 60rpx;
  744. line-height: 60rpx;
  745. font-size: 25rpx;
  746. }
  747. }
  748. }
  749. .chat-emotion {
  750. height: 100%;
  751. .emotion-item-list {
  752. display: flex;
  753. flex-wrap: wrap;
  754. .emotion-item {
  755. width: 40px;
  756. height: 40px;
  757. text-align: center;
  758. cursor: pointer;
  759. padding: 6px;
  760. }
  761. }
  762. }
  763. }
  764. }
  765. </style>