chat.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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="50">
  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" :playMsgId="playMsgid" :index="index"
  12. @openRedPacket="openRedPacket"></left-bubble>
  13. <!-- 自己发出的消息 -->
  14. <right-bubble @sendMsg="sendMsg" @openRight="openRight" :rClickId="rClickId"
  15. :index="index" @openRedPacket="openRedPacket" :row="row" :playMsgid="playMsgid"></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 "../../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. if(!em.minEmoji){
  193. this.sendBigEmoji(em.emojiItem.url)
  194. }else{
  195. console.log(em.emojiItem.alt)
  196. this.textMsg+=em.emojiItem.alt;
  197. }
  198. }
  199. },
  200. // 发送大表情
  201. sendBigEmoji(url){
  202. this.hideDrawer();//隐藏抽屉
  203. if(!url){
  204. return;
  205. }
  206. let imgstr = '<img style="width:48px;height:48px;" src="'+ this.emojiPath + url +'">';
  207. let content = '<div style="align-items: center;word-wrap:break-word;">'
  208. + imgstr
  209. + '</div>';
  210. let msg = {text:content}
  211. this.sendMsg(1, msg);
  212. //清空输入框
  213. this.textMsg = '';
  214. },
  215. openLeft(row){
  216. this.lClickId = row.id;
  217. },
  218. openRight(row){
  219. this.rClickId = row.id;
  220. },
  221. // 关闭红包弹窗
  222. closeRed(){
  223. this.winState = 'hide';
  224. setTimeout(()=>{
  225. this.winState = '';
  226. },200)
  227. },
  228. // 打开红包
  229. openRedPacket(msg){
  230. this.winState = 'show'
  231. this.message = msg
  232. this.$u.vuex('packet',this.red_process(msg.msgContext));
  233. },
  234. // 开始抢红包
  235. robRed(){
  236. console.log(1);
  237. this.sendMsg(8, this.message.id);
  238. },
  239. //处理红包数据
  240. red_process(msgContext){
  241. let packets = JSON.parse(msgContext).Packets;
  242. let msg = {
  243. description:'红包异常',
  244. money:0,
  245. number:0,
  246. userAvatar:'defalut.jpg',
  247. }
  248. if(packets===undefined)
  249. return msg;
  250. return packets[0];
  251. },
  252. hideRed(){
  253. this.redFlag = false;
  254. },
  255. //更多功能(点击+弹出)
  256. showMore(){
  257. this.isVoice = false;
  258. this.hideEmoji = true;
  259. if(this.hideMore){
  260. this.hideMore = false;
  261. this.openDrawer();
  262. }else{
  263. this.hideDrawer();
  264. }
  265. },
  266. // 打开抽屉
  267. openDrawer(){
  268. this.popupLayerClass = 'showLayer';
  269. this.scrollAnimation = false
  270. this.$nextTick(() => {
  271. if(this.msgList.length>0){
  272. this.scrollToView = 'msg' + this.msgList[this.msgList.length-1].id
  273. this.scrollAnimation = true;
  274. }
  275. });
  276. },
  277. // 隐藏抽屉
  278. hideDrawer(){
  279. this.popupLayerClass = '';
  280. setTimeout(()=>{
  281. this.hideMore = true;
  282. this.hideEmoji = true;
  283. this.rClickId = 0;
  284. this.lClickId = 0;
  285. },150);
  286. },
  287. // 置底
  288. scrollToBottom(t) {
  289. let that = this
  290. let query = uni.createSelectorQuery()
  291. query.select('#scrollview').boundingClientRect()
  292. query.select('#msglistview').boundingClientRect()
  293. query.exec((res) => {
  294. if(res[1].height > res[0].height){
  295. that.scrollTop = res[1].height - res[0].height
  296. }
  297. })
  298. },
  299. //删除
  300. deleteFunc(id,index){
  301. this.msgList.splice(index,1);
  302. },
  303. //处理红包数据
  304. red_process(msgContext){
  305. let packets = JSON.parse(msgContext).Packets;
  306. let msg = {
  307. description:'红包异常',
  308. money:0,
  309. number:0,
  310. userAvatar:'defalut.jpg',
  311. surplusMoney:0,
  312. Records:[]
  313. }
  314. if(packets==undefined){
  315. return msg;
  316. }
  317. if(packets.length==0){
  318. return msg;
  319. }
  320. return packets[0];
  321. },
  322. //发送红包
  323. sendRedPacket(packet){
  324. if(this.chatObj.chatType==0){
  325. uni.showToast({
  326. title:'暂不支持私发红包'
  327. })
  328. return;
  329. }
  330. this.sendMsg(7, packet)
  331. this.redFlag = false;
  332. },
  333. //暂时不适配微信小程序,正在解决此bug
  334. bindScroll(sel, duration = 0) {
  335. uni.createSelectorQuery()
  336. .select('#content')
  337. .boundingClientRect(data => {
  338. console.log(data)
  339. //最外层盒子节点
  340. uni.createSelectorQuery()
  341. .select(sel)
  342. .boundingClientRect(res => {
  343. console.log(res)
  344. if (!res) return;
  345. //选中的节点
  346. let windowHeight = 0;
  347. uni.getSystemInfo({
  348. success: system => {
  349. windowHeight = system.windowHeight;
  350. }
  351. });
  352. const inputKeyBoardHeight = uni.upx2px(100) + this.inputOffsetBottom; //input输入框和键盘的高度
  353. const contentHeight = windowHeight - inputKeyBoardHeight; //可视内容的高度(除去input输入框和键盘)
  354. let scrollTop = 0;
  355. scrollTop = res.top - data.top - contentHeight + res.height; //滚动到实际距离是元素距离顶部的距离减去最外层盒子的滚动距离再减去可视内容的高度然后再加上此元素的高度
  356. console.log(scrollTop)
  357. uni.pageScrollTo({ duration, scrollTop });
  358. })
  359. .exec();
  360. })
  361. .exec();
  362. },
  363. //@共功能
  364. processFunc(){
  365. this.scrollAnimation = false;
  366. if(this.calls.length>0){
  367. this.scrollToView = 'msg'+this.calls[0];
  368. this.$nextTick(function() {
  369. this.bindScroll(this.scrollToView)
  370. this.scrollAnimation = true;
  371. });
  372. this.calls.splice(0, 1)
  373. this.$u.vuex('_call_s',this.calls)
  374. }
  375. },
  376. //监听输入框
  377. Input(e){
  378. if(this.textMsg.indexOf('@')!=-1){
  379. if (this.chatObj.chatType==1){
  380. this.$u.route({
  381. url:'pages/chat/remind',
  382. params:{ msg :this.textMsg }
  383. });
  384. }
  385. }
  386. },
  387. //获取群成员
  388. queryMembers () {
  389. if (this.chatObj.chatType == 1) {
  390. this.$socket.queryMembers(this.chatObj.chatId, this.userData.user.operId, (res) => {
  391. this.$u.vuex('memberItem', res.memberResponse);
  392. this.myGroupInfo = {
  393. groupUser: res.groupUser,
  394. group: res.group
  395. }
  396. })
  397. }
  398. },
  399. //消费消息
  400. openConver () {
  401. let _this = this
  402. this.$socket.openChat(this.chatObj.chatId, this.userData.user.operId, this.chatObj.chatType, res => {
  403. if (res.success) {
  404. if (_this.chatObj.chatType == 1) {
  405. if (res.groupUser === undefined) {
  406. _this.disabledSay = 1
  407. } else {
  408. _this.disabledSay = res.groupUser.status
  409. }
  410. }
  411. }
  412. })
  413. },
  414. // localStorage版本获取消息列表
  415. getMsgItem(){
  416. if(this.chatObj.chatType==0){
  417. this.scrollAnimation = false;
  418. this.$socket.queryFriendMessages(this.chatObj.chatId, this.userData.user.operId,1, (res) => {
  419. this.msgList = res.response.data;
  420. console.log(this.msgList)
  421. this.scrollTop = 9999;
  422. this.scrollAnimation = true;
  423. });
  424. }else {
  425. this.scrollAnimation = false;
  426. queryData(this.chatObj.chatId).then(res=>{
  427. this.msgList = res;
  428. this.$nextTick(function() {
  429. this.scrollTop = 9999;
  430. this.scrollAnimation = true;
  431. });
  432. });
  433. }
  434. },
  435. // sqlite版本获取消息列表
  436. getMsgList2(){
  437. this.scrollAnimation = false;
  438. selectMsgSQL(this.chatObj.chatId).then(res=>{
  439. this.msgList = res
  440. this.$nextTick(function() {
  441. this.scrollTop = 9999;
  442. this.$nextTick(function() {
  443. this.scrollAnimation = true;
  444. });
  445. });
  446. });
  447. },
  448. //触发滑动到顶部(加载历史信息记录)
  449. loadHistory(e){
  450. uni.showLoading({
  451. title:"加载中..."
  452. })
  453. //参数作为进入请求标识,防止重复请求
  454. this.scrollAnimation = false;
  455. //关闭滑动动画
  456. let arr = ['queryFriendMessages','queryGroupMessages'];
  457. let i = this.chatObj.chatType
  458. this.$socket[arr[i]](this.chatObj.chatId, this.userData.user.operId, this.pageNum, res => {
  459. let message = res.response.data;
  460. if(message.length>0){
  461. message.forEach(m=>{
  462. if (!this.msgList.map(v => v.id).includes(m.id)) {
  463. this.msgList.push(m)
  464. }
  465. })
  466. this.msgList.sort((a, b) => { return a.id - b.id })
  467. this.$nextTick(() => {
  468. //this.scrollToView = 'msg' + this.msgList[0].id
  469. this.scrollAnimation = true;
  470. this.pageNum++
  471. });
  472. }
  473. uni.hideLoading();
  474. //this.scrollAnimation = true;
  475. });
  476. },
  477. //处理图片尺寸,如果不处理宽高,新进入页面加载图片时候会闪
  478. setPicSize(content){
  479. // 让图片最长边等于设置的最大长度,短边等比例缩小,图片控件真实改变,区别于aspectFit方式。
  480. let maxW = uni.upx2px(350);//350是定义消息图片最大宽度
  481. let maxH = uni.upx2px(350);//350是定义消息图片最大高度
  482. if(content.w>maxW||content.h>maxH){
  483. let scale = content.w/content.h;
  484. content.w = scale>1?maxW:maxH*scale;
  485. content.h = scale>1?maxW/scale:maxH;
  486. }
  487. return content;
  488. },
  489. // 选择图片发送
  490. chooseImage(){
  491. this.getImage('album');
  492. },
  493. //拍照发送
  494. camera(){
  495. this.getImage('camera');
  496. },
  497. //发红包
  498. handRedEnvelopes(){
  499. this.hideDrawer();
  500. },
  501. //选照片 or 拍照
  502. getImage(type){
  503. let that=this;
  504. this.hideDrawer();
  505. uni.chooseImage({
  506. sourceType:[type],
  507. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  508. success: (res)=>{
  509. for(let i=0;i<res.tempFilePaths.length;i++){
  510. uni.getImageInfo({
  511. src: res.tempFilePaths[i],
  512. success: (image)=>{
  513. uni.uploadFile({
  514. url: this.$uploadUrl, //仅为示例,非真实的接口地址
  515. filePath: res.tempFilePaths[i],
  516. header: {
  517. 'merchcode':'md5'
  518. },
  519. name: 'file',
  520. formData: {
  521. 'user': 'test'
  522. },
  523. success: (res) => {
  524. let data = JSON.parse(res.data)
  525. this.sendMsg(1, data.data)
  526. }
  527. });
  528. }
  529. });
  530. }
  531. }
  532. });
  533. },
  534. // 选择表情
  535. chooseEmoji(){
  536. this.hideMore = true;
  537. if(this.hideEmoji){
  538. this.hideEmoji = false;
  539. this.openDrawer();
  540. }else{
  541. this.hideDrawer();
  542. }
  543. },
  544. //获取焦点,如果不是选表情ing,则关闭抽屉
  545. textareaFocus(){
  546. if(this.popupLayerClass=='showLayer' && this.hideMore == false){
  547. this.hideDrawer();
  548. }
  549. },
  550. //发送消息
  551. sendMsg (msgType, text) {
  552. if (this.disabledSay == 1) {
  553. uni.showToast({
  554. title:'你已经被管理员禁言'
  555. });
  556. return;
  557. }
  558. if(text!=''){
  559. this.$socket.createChatList(this.userData.user.operId, this.chatObj.chatId, text, msgType, res => {});
  560. }
  561. let arr = ['send2Friend','send2Group'];
  562. let _this = this;
  563. this.scrollAnimation = false;
  564. this.$socket[arr[this.chatObj.chatType]](this.chatObj.chatId, this.userData.user.operId, text, msgType, res => {
  565. if (res.success) {
  566. if (res.response!==undefined) {
  567. const data = res.response.data
  568. if(res.msgType===8){
  569. _this.addRobEnvelope(res);
  570. }else if(res.msgType===6){
  571. _this.addRevoke(res);
  572. }else {
  573. if(_this.chatObj.chatType===1){
  574. if(data!==undefined){
  575. if (data.groupId === this.chatObj.chatId) {
  576. _this.addMsg(data);
  577. }
  578. upData(data, _this.chatObj.chatId);
  579. }
  580. }else {
  581. _this.addMsg(data);
  582. }
  583. }
  584. }
  585. }
  586. });
  587. this.textMsg = ''
  588. },
  589. // 接受消息(筛选处理)
  590. addMsg(msg){
  591. // 用户消息
  592. switch (msg.msgType){
  593. case 0:
  594. this.addTextMsg(msg);
  595. break;
  596. case 1:
  597. this.addImgMsg(msg);
  598. break;
  599. case 3:
  600. this.addVoiceMsg(msg);
  601. break;
  602. case 7:
  603. this.addRedEnvelopeMsg(msg);
  604. break;
  605. default:
  606. }
  607. this.$nextTick(() => {
  608. this.scrollTop = 9999;
  609. this.scrollToView = 'msg' + this.msgList[this.msgList.length-1].id
  610. this.scrollAnimation = true;
  611. });
  612. //非自己的消息震动
  613. if(msg.sendUid!==this.userData.user.operId){
  614. uni.vibrateLong();
  615. }
  616. },
  617. //增加撤销
  618. addRevoke(res){
  619. if (res.msgId != undefined && res.message == undefined) {
  620. for(var index in this.msgList){
  621. if(this.msgList[index].id==res.msgId){
  622. this.msgList.splice(index,1);
  623. upCanceData(res.msgId,this.chatObj.chatId,this.msgList[index]);
  624. }
  625. }
  626. }
  627. },
  628. // 增加红包
  629. addRobEnvelope(res){
  630. if (res.msgId != undefined && res.message != undefined) {
  631. this.$u.vuex('packet',this.red_process(res.message));
  632. for(var index in this.msgList){
  633. if(this.msgList[index].id==res.msgId){
  634. this.msgList[index].msgContext = res.message;
  635. }
  636. }
  637. upRedData(res.msgId,this.chatObj.chatId,res.message);
  638. }
  639. },
  640. //@功能处理
  641. process(msg) {
  642. // let groupNickName = this.myGroupInfo.groupUser.groupNickName || ''
  643. // let msgContext = msg.msgContext || ''
  644. // //包含自己
  645. // if(msgContext.indexOf('@')!=-1){
  646. // if(msgContext.includes('@'+groupNickName)||
  647. // msgContext.includes('@all')||
  648. // msgContext.includes('@All')){
  649. // this.calls.push(msg.id);
  650. // } else if (msgContext.includes('@'+this._user_info.nickName)){
  651. // this.calls.push(msg.id);
  652. // }
  653. // this.$u.vuex('_call_s',this.calls)
  654. // }
  655. },
  656. //替换表情符号为图片
  657. replaceEmoji(str){
  658. // 正则表达式匹配内容
  659. let replacedStr = str.replace(/\[([^(\]|\[)]*)\]/g,(item, index)=>{
  660. // console.log("item: " + item);
  661. for(let i=0;i<this.emojiList.length;i++){
  662. let row = this.emojiList[i];
  663. for(let j=0;j<row.length;j++){
  664. let EM = row[j];
  665. if(EM.alt==item){
  666. let onlinePath=this.emojiPath
  667. let imgstr = '<img style="width:24px;height:24px;" src="'+onlinePath+EM.url+'">';
  668. return imgstr;
  669. }
  670. }
  671. }
  672. });
  673. return '<div style="align-items: center;word-wrap:break-word;">'+replacedStr+'</div>';
  674. },
  675. // 添加文字消息到列表
  676. addTextMsg(msg){
  677. this.msgList.push(msg);
  678. },
  679. // 添加语音消息到列表
  680. addVoiceMsg(msg){
  681. this.msgList.push(msg);
  682. },
  683. // 添加图片消息到列表
  684. addImgMsg(msg){
  685. this.msgList.push(msg);
  686. },
  687. addRedEnvelopeMsg(msg){
  688. this.msgList.push(msg);
  689. },
  690. // 添加系统文字消息到列表
  691. addSystemTextMsg(msg){
  692. this.msgList.push(msg);
  693. },
  694. // 添加系统红包消息到列表
  695. addSystemRedEnvelopeMsg(msg){
  696. this.msgList.push(msg);
  697. },
  698. discard(){
  699. return;
  700. },
  701. }
  702. }
  703. </script>
  704. <style lang="scss">
  705. @import "./style.scss";
  706. </style>