chat.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. <template>
  2. <view>
  3. <view class="content" id="content" @touchstart="hideDrawer">
  4. <scroll-view id="scrollview" class="msg-list" :class="{'chat-h':popupLayerClass === 'showLayer'}" scroll-y="true"
  5. :scroll-with-animation="scrollAnimation" :scroll-top="scrollTop" :scroll-into-view="scrollToView" @scrolltoupper="loadHistory"
  6. upper-threshold="80">
  7. <view id="msglistview" class="row" v-for="(row,index) in msgList" :key="index" :id="'msg'+row.id">
  8. <!-- 系统通知的消息 -->
  9. <system-bubble :row="row"></system-bubble>
  10. <!-- 别人发出的消息 -->
  11. <left-bubble @openLeft="openLeft" :lClickId="lClickId" :row="row" :index="index"
  12. @openRedPacket="openRedPacket"></left-bubble>
  13. <!-- 自己发出的消息 -->
  14. <right-bubble @sendMsg="sendMsg" @openRight="openRight" :rClickId="rClickId"
  15. :index="index" @openRedPacket="openRedPacket" :row="row" ></right-bubble>
  16. </view>
  17. </scroll-view>
  18. </view>
  19. <!-- 抽屉栏 -->
  20. <im-drawer @addEmoji="addEmoji" @sendMsg="sendMsg" @getImage="getImage"
  21. @redShow="redFlag = true" :hideMore="hideMore" :hideEmoji="hideEmoji" :popupLayerClass="popupLayerClass"></im-drawer>
  22. <!-- 底部输入框 -->
  23. <footer-input @textMsgFunc="textMsgFunc" @switchVoice="switchVoice" @chooseEmoji="chooseEmoji" @sendMsg="sendMsg"
  24. @showMore="showMore" @textareaFocus="textareaFocus" @hideDrawer="hideDrawer" @openDrawer="openDrawer"
  25. :disabledSay="disabledSay" :textMsg2="textMsg" :popupLayerClass="popupLayerClass"
  26. :inputOffsetBottom="inputOffsetBottom" :isVoice="isVoice"></footer-input>
  27. <!-- 红包卡片弹窗 -->
  28. <red-card @robRed="robRed" @closeRed="closeRed" :winState="winState"></red-card>
  29. <!-- 发红包弹窗 -->
  30. <u-popup v-model="redFlag" mode="bottom" length="50%">
  31. <red-envelope @sendRedPacket="sendRedPacket">
  32. </red-envelope>
  33. </u-popup>
  34. </view>
  35. </template>
  36. <script>
  37. import ImDrawer from '@/components/chat/im-drawer.vue'
  38. import RedCard from '@/components/chat/red-card.vue'
  39. import RedEnvelope from "@/components/redenvelope"
  40. import emojiData from "@/pageC/static/emoji/emojiData.js"
  41. import ImgCache from '@/components/img-cache/img-cache.vue'
  42. import RightBubble from '@/components/chat/right-bubble.vue'
  43. import LeftBubble from '@/components/chat/left-bubble.vue'
  44. import FooterInput from '@/components/chat/footer-input.vue'
  45. import SystemBubble from '@/components/chat/system-bubble.vue'
  46. import { openMsgSqlite, createMsgSQL, selectMsgSQL, addMsgSQL } from '../../util/msg.js'
  47. import { queryData, upData, initData, upRedData, upCanceData } from '../../util/dbUtil.js'
  48. export default {
  49. components: {
  50. ImDrawer,
  51. RedCard,
  52. ImgCache,
  53. RightBubble,
  54. LeftBubble,
  55. SystemBubble,
  56. RedEnvelope,
  57. FooterInput
  58. },
  59. data() {
  60. return {
  61. isHistoryLoading:false,
  62. textMsg: '',
  63. redFlag: false,
  64. calls:[],
  65. myGroupInfo:{},
  66. memberFlag: false,
  67. memberData:{},
  68. forwardData:{},
  69. forwardFlag: false,
  70. rClickId:0,
  71. lClickId:0,
  72. pageNum:1,
  73. disabledSay:0,
  74. rightClickFlag: false,
  75. scrollAnimation:false,
  76. scrollTop:0,
  77. scrollToView:'',
  78. msgList:[],
  79. isVoice:false,
  80. groupInfo:{},
  81. playMsgid:null,
  82. popupLayerClass:'',
  83. hideMore:true,
  84. hideEmoji:true,
  85. emojiList:[{}],
  86. emojiPath:'',
  87. winState:'',
  88. message:{},
  89. sel: '' ,
  90. inputOffsetBottom: 0,
  91. viewOffsetBottom: 0
  92. };
  93. },
  94. //头部按钮监听
  95. onNavigationBarButtonTap({ index }) {
  96. if (index == 0) {
  97. let url = this.chatObj.chatType==1?'groupDetail':'userDetail'
  98. this.$u.route({
  99. url: 'pages/chat/' + url
  100. });
  101. //用户详情 设置
  102. } else if (index == 1) {
  103. //返回按钮
  104. this.$u.route({
  105. type: 'switchTab',
  106. url: 'pages/home/home'
  107. });
  108. }
  109. },
  110. onUnload(){
  111. },
  112. onHide(){
  113. },
  114. onLoad(option) {
  115. this.emojiList =emojiData.imgArr[1].emojiList;
  116. },
  117. onShow(){
  118. this.disabledSay = 0
  119. this.scrollTop = 9999999;
  120. this.sendMsg(0,'');
  121. this.getMsgItem();
  122. this.openConver();
  123. this.hideDrawer();
  124. },
  125. onReady() {
  126. // #ifdef H5
  127. const icon = document.getElementsByClassName('uni-page-head-btn')[0];
  128. icon.style.display = 'none';
  129. // #endif
  130. uni.setNavigationBarTitle({
  131. title: this.chatObj.chatName
  132. });
  133. //h5暂不支持键盘的高度监听
  134. uni.onKeyboardHeightChange(res => {
  135. this.inputOffsetBottom = res.height;
  136. this.viewOffsetBottom = res.height + uni.upx2px(100);
  137. if (res.height == 0) {
  138. // #ifndef MP-WEIXIN
  139. this.showInput = false;
  140. // #endif
  141. }
  142. });
  143. },
  144. watch: {
  145. inputOffsetBottom: {
  146. handler(val) {
  147. if (val != 0) {
  148. this.$nextTick(() => {
  149. //暂时不支持h5的滚动方式 因为h5不支持键盘的高度监听
  150. //微信小程序会把input的焦点和placeholder顶起,正在寻找解决方案
  151. // #ifndef MP-WEIXIN || H5
  152. this.bindScroll(this.sel, 100);
  153. // #endif
  154. });
  155. }
  156. }
  157. }
  158. },
  159. methods:{
  160. textMsgFunc(t){
  161. this.textMsg = t;
  162. },
  163. // 切换语音/文字输入
  164. switchVoice(){
  165. this.hideDrawer();
  166. this.isVoice = this.isVoice?false:true;
  167. },
  168. //添加表情
  169. addEmoji(em, del){
  170. if (em.emoticonFlag){
  171. this.sendMsg(1,em.avatar);
  172. } else {
  173. //判断删除按钮
  174. if(del){
  175. var str;
  176. var msglen = this.textMsg.length - 1;
  177. let start = this.textMsg.lastIndexOf("[");
  178. let end = this.textMsg.lastIndexOf("]");
  179. let len = end - start;
  180. if(end != -1 && end === msglen && len >= 2 && len <= 4){
  181. // 表情字符
  182. str = this.textMsg.slice(0, start);
  183. }else{
  184. // 普通键盘输入汉字 或者字符
  185. str = this.textMsg.slice(0, msglen);
  186. }
  187. this.textMsg = str
  188. return;
  189. }
  190. this.emojiList =emojiData.imgArr[em.groupIndex].emojiList
  191. this.emojiPath =emojiData.imgArr[em.groupIndex].emojiPath
  192. console.log(this.emojiPath)
  193. if(!em.minEmoji){
  194. this.sendBigEmoji(em.emojiItem.url)
  195. }else{
  196. console.log(em.emojiItem.alt)
  197. this.textMsg+=em.emojiItem.alt;
  198. }
  199. }
  200. },
  201. // 发送大表情
  202. sendBigEmoji(url){
  203. this.hideDrawer();//隐藏抽屉
  204. if(!url){
  205. return;
  206. }
  207. let imgstr = '<img style="width:48px;height:48px;" src="'+ this.emojiPath + url +'">';
  208. let content = '<div style="align-items: center;word-wrap:break-word;">'
  209. + imgstr
  210. + '</div>';
  211. let msg = {text:content}
  212. this.sendMsg(1, msg);
  213. //清空输入框
  214. this.textMsg = '';
  215. },
  216. openLeft(row){
  217. this.lClickId = row.id;
  218. },
  219. openRight(row){
  220. this.rClickId = row.id;
  221. },
  222. // 关闭红包弹窗
  223. closeRed(){
  224. this.winState = 'hide';
  225. setTimeout(()=>{
  226. this.winState = '';
  227. },200)
  228. },
  229. // 打开红包
  230. openRedPacket(msg){
  231. this.winState = 'show'
  232. this.message = msg
  233. this.$u.vuex('packet',this.red_process(msg.msgContext));
  234. },
  235. // 开始抢红包
  236. robRed(){
  237. console.log(1);
  238. this.sendMsg(8, this.message.id);
  239. },
  240. //处理红包数据
  241. red_process(msgContext){
  242. let packets = JSON.parse(msgContext).Packets;
  243. let msg = {
  244. description:'红包异常',
  245. money:0,
  246. number:0,
  247. userAvatar:'defalut.jpg',
  248. }
  249. if(packets===undefined)
  250. return msg;
  251. return packets[0];
  252. },
  253. hideRed(){
  254. this.redFlag = false;
  255. },
  256. //更多功能(点击+弹出)
  257. showMore(){
  258. uni.hideKeyboard()
  259. this.isVoice = false;
  260. this.hideEmoji = true;
  261. if(this.hideMore){
  262. this.hideMore = false;
  263. this.openDrawer();
  264. }else{
  265. this.hideDrawer();
  266. }
  267. },
  268. // 打开抽屉
  269. openDrawer(){
  270. this.popupLayerClass = 'showLayer';
  271. this.scrollAnimation = false
  272. this.$nextTick(() => {
  273. if(this.msgList.length>0){
  274. this.scrollToView = 'msg' + this.msgList[this.msgList.length-1].id
  275. this.scrollAnimation = true;
  276. }
  277. });
  278. },
  279. // 隐藏抽屉
  280. hideDrawer(){
  281. this.popupLayerClass = '';
  282. // setTimeout(()=>{
  283. // },150);
  284. this.hideMore = true;
  285. this.hideEmoji = true;
  286. this.rClickId = 0;
  287. this.lClickId = 0;
  288. },
  289. // 置底
  290. scrollToBottom(t) {
  291. let that = this
  292. let query = uni.createSelectorQuery()
  293. query.select('#scrollview').boundingClientRect()
  294. query.select('#msglistview').boundingClientRect()
  295. query.exec((res) => {
  296. if(res[1].height > res[0].height){
  297. that.scrollTop = res[1].height - res[0].height
  298. }
  299. })
  300. },
  301. //删除
  302. deleteFunc(id,index){
  303. this.msgList.splice(index,1);
  304. },
  305. //处理红包数据
  306. red_process(msgContext){
  307. let packets = JSON.parse(msgContext).Packets;
  308. let msg = {
  309. description:'红包异常',
  310. money:0,
  311. number:0,
  312. userAvatar:'defalut.jpg',
  313. surplusMoney:0,
  314. Records:[]
  315. }
  316. if(packets==undefined){
  317. return msg;
  318. }
  319. if(packets.length==0){
  320. return msg;
  321. }
  322. return packets[0];
  323. },
  324. //发送红包
  325. sendRedPacket(packet){
  326. if(this.chatObj.chatType==0){
  327. uni.showToast({
  328. title:'暂不支持私发红包'
  329. })
  330. return;
  331. }
  332. this.sendMsg(7, packet)
  333. this.redFlag = false;
  334. },
  335. //暂时不适配微信小程序,正在解决此bug
  336. bindScroll(sel, duration = 0) {
  337. uni.createSelectorQuery()
  338. .select('#content')
  339. .boundingClientRect(data => {
  340. console.log(data)
  341. //最外层盒子节点
  342. uni.createSelectorQuery()
  343. .select(sel)
  344. .boundingClientRect(res => {
  345. console.log(res)
  346. if (!res) return;
  347. //选中的节点
  348. let windowHeight = 0;
  349. uni.getSystemInfo({
  350. success: system => {
  351. windowHeight = system.windowHeight;
  352. }
  353. });
  354. const inputKeyBoardHeight = uni.upx2px(100) + this.inputOffsetBottom; //input输入框和键盘的高度
  355. const contentHeight = windowHeight - inputKeyBoardHeight; //可视内容的高度(除去input输入框和键盘)
  356. let scrollTop = 0;
  357. scrollTop = res.top - data.top - contentHeight + res.height; //滚动到实际距离是元素距离顶部的距离减去最外层盒子的滚动距离再减去可视内容的高度然后再加上此元素的高度
  358. console.log(scrollTop)
  359. uni.pageScrollTo({ duration, scrollTop });
  360. })
  361. .exec();
  362. })
  363. .exec();
  364. },
  365. //@共功能
  366. processFunc(){
  367. this.scrollAnimation = false;
  368. if(this.calls.length>0){
  369. this.scrollToView = 'msg'+this.calls[0];
  370. this.$nextTick(function() {
  371. this.bindScroll(this.scrollToView)
  372. this.scrollAnimation = true;
  373. });
  374. this.calls.splice(0, 1)
  375. this.$u.vuex('_call_s',this.calls)
  376. }
  377. },
  378. //监听输入框
  379. Input(e){
  380. if(this.textMsg.indexOf('@')!=-1){
  381. if (this.chatObj.chatType==1){
  382. this.$u.route({
  383. url:'pages/chat/remind',
  384. params:{ msg :this.textMsg }
  385. });
  386. }
  387. }
  388. },
  389. //获取群成员
  390. queryMembers () {
  391. if (this.chatObj.chatType == 1) {
  392. this.$socket.queryMembers(this.chatObj.chatId, this.userData.user.operId, (res) => {
  393. this.$u.vuex('memberItem', res.memberResponse);
  394. this.myGroupInfo = {
  395. groupUser: res.groupUser,
  396. group: res.group
  397. }
  398. })
  399. }
  400. },
  401. //消费消息
  402. openConver () {
  403. let _this = this
  404. this.$socket.openChat(this.chatObj.chatId, this.userData.user.operId, this.chatObj.chatType, res => {
  405. if (res.success) {
  406. if (_this.chatObj.chatType == 1) {
  407. if (res.groupUser === undefined) {
  408. _this.disabledSay = 1
  409. } else {
  410. _this.disabledSay = res.groupUser.status
  411. }
  412. }
  413. }
  414. })
  415. },
  416. // localStorage版本获取消息列表
  417. getMsgItem(){
  418. uni.showLoading({
  419. title: '正在加载',
  420. mask:true
  421. })
  422. if(this.chatObj.chatType==0){
  423. this.scrollAnimation = false;
  424. this.$socket.queryFriendMessages(this.chatObj.chatId, this.userData.user.operId,1, (res) => {
  425. this.msgList = res.response.data;
  426. console.log(this.msgList)
  427. this.scrollTop = 9999;
  428. this.scrollAnimation = true;
  429. uni.hideLoading()
  430. });
  431. }else {
  432. this.scrollAnimation = false;
  433. queryData(this.chatObj.chatId).then(res=>{
  434. this.msgList = res;
  435. this.$nextTick(function() {
  436. this.scrollTop = 9999;
  437. this.scrollAnimation = true;
  438. });
  439. uni.hideLoading()
  440. });
  441. }
  442. },
  443. // sqlite版本获取消息列表
  444. getMsgList2(){
  445. this.scrollAnimation = false;
  446. selectMsgSQL(this.chatObj.chatId).then(res=>{
  447. this.msgList = res
  448. this.$nextTick(function() {
  449. this.scrollTop = 9999;
  450. this.$nextTick(function() {
  451. this.scrollAnimation = true;
  452. });
  453. });
  454. });
  455. },
  456. //触发滑动到顶部(加载历史信息记录)
  457. loadHistory(e){
  458. uni.showLoading({
  459. title:"加载中...",
  460. mask:true
  461. })
  462. //参数作为进入请求标识,防止重复请求
  463. this.scrollAnimation = false;
  464. //关闭滑动动画
  465. let arr = ['queryFriendMessages','queryGroupMessages'];
  466. let i = this.chatObj.chatType
  467. this.$socket[arr[i]](this.chatObj.chatId, this.userData.user.operId, this.pageNum, res => {
  468. let message = res.response.data;
  469. if(message.length>0){
  470. message.forEach(m=>{
  471. if (!this.msgList.map(v => v.id).includes(m.id)) {
  472. this.msgList.push(m)
  473. }
  474. })
  475. this.msgList.sort((a, b) => { return a.id - b.id })
  476. this.$nextTick(() => {
  477. //this.scrollToView = 'msg' + this.msgList[0].id
  478. this.scrollAnimation = true;
  479. this.pageNum++
  480. });
  481. }
  482. uni.hideLoading();
  483. //this.scrollAnimation = true;
  484. });
  485. },
  486. //处理图片尺寸,如果不处理宽高,新进入页面加载图片时候会闪
  487. setPicSize(content){
  488. // 让图片最长边等于设置的最大长度,短边等比例缩小,图片控件真实改变,区别于aspectFit方式。
  489. let maxW = uni.upx2px(350);//350是定义消息图片最大宽度
  490. let maxH = uni.upx2px(350);//350是定义消息图片最大高度
  491. if(content.w>maxW||content.h>maxH){
  492. let scale = content.w/content.h;
  493. content.w = scale>1?maxW:maxH*scale;
  494. content.h = scale>1?maxW/scale:maxH;
  495. }
  496. return content;
  497. },
  498. // 选择图片发送
  499. chooseImage(){
  500. this.getImage('album');
  501. },
  502. //拍照发送
  503. camera(){
  504. this.getImage('camera');
  505. },
  506. //发红包
  507. handRedEnvelopes(){
  508. this.hideDrawer();
  509. },
  510. //选照片 or 拍照
  511. getImage(type){
  512. let that=this;
  513. this.hideDrawer();
  514. uni.chooseImage({
  515. sourceType:[type],
  516. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  517. success: (res)=>{
  518. for(let i=0;i<res.tempFilePaths.length;i++){
  519. uni.getImageInfo({
  520. src: res.tempFilePaths[i],
  521. success: (image)=>{
  522. uni.uploadFile({
  523. url: this.$uploadUrl, //仅为示例,非真实的接口地址
  524. filePath: res.tempFilePaths[i],
  525. header: {
  526. 'merchcode':'md5'
  527. },
  528. name: 'file',
  529. formData: {
  530. 'user': 'test'
  531. },
  532. success: (res) => {
  533. let data = JSON.parse(res.data)
  534. this.sendMsg(1, data.data)
  535. }
  536. });
  537. }
  538. });
  539. }
  540. }
  541. });
  542. },
  543. // 选择表情
  544. chooseEmoji(){
  545. this.hideMore = true;
  546. if(this.hideEmoji){
  547. this.hideEmoji = false;
  548. this.openDrawer();
  549. }else{
  550. this.hideDrawer();
  551. }
  552. },
  553. //获取焦点,如果不是选表情ing,则关闭抽屉
  554. textareaFocus(){
  555. // if(this.popupLayerClass=='showLayer' && this.hideMore == false){
  556. this.hideDrawer();
  557. // }
  558. },
  559. //发送消息
  560. sendMsg (msgType, text) {
  561. if (this.disabledSay == 1) {
  562. uni.showToast({
  563. title:'你已经被管理员禁言'
  564. });
  565. return;
  566. }
  567. if(text!=''){
  568. this.$socket.createChatList(this.userData.user.operId, this.chatObj.chatId, text, msgType, res => {});
  569. }
  570. let arr = ['send2Friend','send2Group'];
  571. let _this = this;
  572. this.scrollAnimation = false;
  573. this.$socket[arr[this.chatObj.chatType]](this.chatObj.chatId, this.userData.user.operId, text, msgType, res => {
  574. if (res.success) {
  575. console.log(res)
  576. if (res.response!==undefined) {
  577. console.log(res)
  578. console.log("send2Friend res.response.data ",res.response.data)
  579. const data = res.response.data
  580. if(res.msgType===8){
  581. _this.addRobEnvelope(res);
  582. }else if(res.msgType===6){
  583. _this.addRevoke(res);
  584. }else {
  585. if(_this.chatObj.chatType===1){
  586. if(data!==undefined){
  587. if (data.groupId === this.chatObj.chatId) {
  588. _this.addMsg(data);
  589. }
  590. upData(data, _this.chatObj.chatId);
  591. }
  592. }else {
  593. if( _this.chatObj.chatId === data.sendUid || _this.chatObj.chatId === data.receiveUid ){
  594. _this.addMsg(data);
  595. }
  596. }
  597. }
  598. }
  599. }
  600. });
  601. this.textMsg = ''
  602. },
  603. // 接受消息(筛选处理)
  604. addMsg(msg){
  605. // 用户消息
  606. switch (msg.msgType){
  607. case 0:
  608. this.addTextMsg(msg);
  609. break;
  610. case 1:
  611. this.addImgMsg(msg);
  612. break;
  613. case 3:
  614. this.addVoiceMsg(msg);
  615. break;
  616. case 7:
  617. this.addRedEnvelopeMsg(msg);
  618. break;
  619. default:
  620. }
  621. this.$nextTick(() => {
  622. this.scrollTop = 9999;
  623. this.scrollToView = 'msg' + this.msgList[this.msgList.length-1].id
  624. this.scrollAnimation = true;
  625. });
  626. //非自己的消息震动
  627. if(msg.sendUid!==this.userData.user.operId){
  628. uni.vibrateLong();
  629. }
  630. },
  631. //增加撤销
  632. addRevoke(res){
  633. if (res.chatId != undefined) {
  634. for(var index in this.msgList){
  635. if(this.msgList[index].id==res.chatId){
  636. this.msgList.splice(index,1);
  637. upCanceData(res.chatId,this.chatObj.chatId,this.msgList[index]);
  638. }
  639. }
  640. }
  641. },
  642. // 增加红包
  643. addRobEnvelope(res){
  644. if (res.msgId != undefined && res.message != undefined) {
  645. this.$u.vuex('packet',this.red_process(res.message));
  646. for(var index in this.msgList){
  647. if(this.msgList[index].id==res.msgId){
  648. this.msgList[index].msgContext = res.message;
  649. }
  650. }
  651. upRedData(res.msgId,this.chatObj.chatId,res.message);
  652. }
  653. },
  654. //@功能处理
  655. process(msg) {
  656. // let groupNickName = this.myGroupInfo.groupUser.groupNickName || ''
  657. // let msgContext = msg.msgContext || ''
  658. // //包含自己
  659. // if(msgContext.indexOf('@')!=-1){
  660. // if(msgContext.includes('@'+groupNickName)||
  661. // msgContext.includes('@all')||
  662. // msgContext.includes('@All')){
  663. // this.calls.push(msg.id);
  664. // } else if (msgContext.includes('@'+this._user_info.nickName)){
  665. // this.calls.push(msg.id);
  666. // }
  667. // this.$u.vuex('_call_s',this.calls)
  668. // }
  669. },
  670. //替换表情符号为图片
  671. replaceEmoji(str){
  672. // 正则表达式匹配内容
  673. let replacedStr = str.replace(/\[([^(\]|\[)]*)\]/g,(item, index)=>{
  674. // console.log("item: " + item);
  675. for(let i=0;i<this.emojiList.length;i++){
  676. let row = this.emojiList[i];
  677. for(let j=0;j<row.length;j++){
  678. let EM = row[j];
  679. if(EM.alt==item){
  680. let onlinePath=this.emojiPath
  681. let imgstr = '<img style="width:24px;height:24px;" src="'+onlinePath+EM.url+'">';
  682. return imgstr;
  683. }
  684. }
  685. }
  686. });
  687. return '<div style="align-items: center;word-wrap:break-word;">'+replacedStr+'</div>';
  688. },
  689. // 添加文字消息到列表
  690. addTextMsg(msg){
  691. this.msgList.push(msg);
  692. },
  693. // 添加语音消息到列表
  694. addVoiceMsg(msg){
  695. this.msgList.push(msg);
  696. },
  697. // 添加图片消息到列表
  698. addImgMsg(msg){
  699. this.msgList.push(msg);
  700. },
  701. addRedEnvelopeMsg(msg){
  702. this.msgList.push(msg);
  703. },
  704. // 添加系统文字消息到列表
  705. addSystemTextMsg(msg){
  706. this.msgList.push(msg);
  707. },
  708. // 添加系统红包消息到列表
  709. addSystemRedEnvelopeMsg(msg){
  710. this.msgList.push(msg);
  711. },
  712. discard(){
  713. return;
  714. },
  715. }
  716. }
  717. </script>
  718. <style lang="scss">
  719. @import "./style.scss";
  720. </style>