ChatFrame.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. <template>
  2. <div>
  3. <div class="chat-wrap" v-if="selected">
  4. <div class="chat-title">
  5. {{ selected.username || selected.name }}
  6. </div>
  7. <div class="record-warp">
  8. <!-- 私聊 -->
  9. <el-scrollbar
  10. v-if="tab === 'friends'"
  11. style="height: 95%"
  12. ref="myScrollbar"
  13. >
  14. <div
  15. class="record-list"
  16. v-for="(item, i) in friend_record_list"
  17. :key="i"
  18. >
  19. <!-- receive msg record -->
  20. <div class="record-item" v-if="item.toid === socket.id">
  21. <div class="avatar">
  22. <el-avatar
  23. shape="square"
  24. src="https://img2.baidu.com/it/u=1077360284,2857506492&fm=26&fmt=auto&gp=0.jpg"
  25. ></el-avatar>
  26. </div>
  27. <div class="group-record-item">
  28. <!-- 链接 -->
  29. <a
  30. class="message-content-text receive-record-item"
  31. v-if="_isUrl(item.msg)"
  32. :href="item.msg"
  33. target="_blank"
  34. style="margin-left: 10px; margin-top: 15px;"
  35. >
  36. {{ item.msg }}
  37. </a>
  38. <!-- 文本 -->
  39. <div
  40. class="message-content-text receive-record-item"
  41. v-if="item.type === 'text'"
  42. v-html="_parseHtml(item.msg)"
  43. style="margin-left: 10px; margin-top: 15px;"
  44. ></div>
  45. <!-- 图片 -->
  46. <div
  47. class="message-content-image receive-record-item"
  48. v-if="item.type === 'image'"
  49. :style="getImageStyle(item.msg)"
  50. style="margin-left: 10px; margin-top: 15px;"
  51. >
  52. <viewer style="display: flex; align-items: center">
  53. <img :src="baseUrl + item.msg" alt="" />
  54. </viewer>
  55. </div>
  56. <!-- 视频格式文件 -->
  57. <div
  58. class="message-content-image receive-record-item"
  59. v-if="item.type === 'video'"
  60. style="margin-left: 10px; margin-top: 15px;"
  61. >
  62. <video
  63. style="width: 255px"
  64. src="https://media.w3.org/2010/05/sintel/trailer.mp4"
  65. controls="controls"
  66. >
  67. 您的浏览器不支持 video 标签。
  68. </video>
  69. </div>
  70. </div>
  71. </div>
  72. <!-- self send msg record -->
  73. <div v-if="item.toid !== socket.id" class="record-item send-record">
  74. <!-- 链接 -->
  75. <a
  76. class="message-content-text"
  77. v-if="_isUrl(item.msg)"
  78. :href="item.msg"
  79. target="_blank"
  80. >
  81. {{ item.msg }}
  82. </a>
  83. <!-- 文本 -->
  84. <div
  85. class="message-content-text"
  86. v-if="item.type === 'text'"
  87. v-html="_parseHtml(item.msg)"
  88. ></div>
  89. <!-- 图片 -->
  90. <div
  91. class="message-content-image"
  92. v-if="item.type === 'image'"
  93. :style="getImageStyle(item.msg)"
  94. >
  95. <viewer style="display: flex; align-items: center">
  96. <img :src="baseUrl + item.msg" alt="" />
  97. </viewer>
  98. </div>
  99. <!-- 附件类型消息 -->
  100. <!-- <div class="message-content-file" v-else-if="item.type === 'file'" @click="download(item)">
  101. <img class="message-content-icon" :src="getFileIcon(item)" alt="" />
  102. <div class="message-content-detail">
  103. <div class="file-name">
  104. {{ getFileName(item).name }}
  105. </div>
  106. <div class="file-size">
  107. {{ getFileName(item).size }}
  108. </div>
  109. </div>
  110. </div> -->
  111. <!-- 视频格式文件 -->
  112. <div class="message-content-image" v-if="item.type === 'video'">
  113. <video
  114. style="width: 255px"
  115. src="https://media.w3.org/2010/05/sintel/trailer.mp4"
  116. controls="controls"
  117. >
  118. 您的浏览器不支持 video 标签。
  119. </video>
  120. </div>
  121. <!-- <div class="avatar">
  122. <el-avatar
  123. shape="square"
  124. src="https://img2.baidu.com/it/u=1077360284,2857506492&fm=26&fmt=auto&gp=0.jpg"
  125. ></el-avatar>
  126. </div> -->
  127. </div>
  128. </div>
  129. </el-scrollbar>
  130. <!-- 群聊 -->
  131. <el-scrollbar
  132. v-if="tab === 'groups'"
  133. style="height: 95%"
  134. ref="myScrollbar"
  135. >
  136. <div
  137. class="record-list"
  138. v-for="(item, i) in room_record_list"
  139. :key="i"
  140. >
  141. <!-- receive msg record -->
  142. <div class="record-item" v-if="item.id !== socket.id">
  143. <div class="avatar">
  144. <el-avatar
  145. shape="square"
  146. src="https://img2.baidu.com/it/u=1077360284,2857506492&fm=26&fmt=auto&gp=0.jpg"
  147. ></el-avatar>
  148. </div>
  149. <div class="group-record-item">
  150. <div class="username">
  151. {{ item.username }}
  152. </div>
  153. <!-- 链接 -->
  154. <a
  155. class="message-content-text receive-record-item"
  156. v-if="_isUrl(item.msg)"
  157. :href="item.msg"
  158. target="_blank"
  159. >
  160. {{ item.msg }}
  161. </a>
  162. <!-- 文本 -->
  163. <div
  164. class="message-content-text receive-record-item"
  165. v-if="item.type === 'text'"
  166. v-html="_parseHtml(item.msg)"
  167. ></div>
  168. <!-- 图片 -->
  169. <div
  170. class="message-content-image receive-record-item"
  171. v-if="item.type === 'image'"
  172. :style="getImageStyle(item.msg)"
  173. >
  174. <viewer style="display: flex; align-items: center">
  175. <img :src="baseUrl + item.msg" alt="" />
  176. </viewer>
  177. </div>
  178. <!-- 附件类型消息 -->
  179. <!-- <div class="message-content-file" v-else-if="item.type === 'file'" @click="download(item)">
  180. <img class="message-content-icon" :src="getFileIcon(item)" alt="" />
  181. <div class="message-content-detail">
  182. <div class="file-name">
  183. {{ getFileName(item).name }}
  184. </div>
  185. <div class="file-size">
  186. {{ getFileName(item).size }}
  187. </div>
  188. </div>
  189. </div> -->
  190. <!-- 视频格式文件 -->
  191. <div
  192. class="message-content-image receive-record-item"
  193. v-if="item.type === 'video'"
  194. >
  195. <video
  196. style="width: 255px"
  197. src="https://media.w3.org/2010/05/sintel/trailer.mp4"
  198. controls="controls"
  199. >
  200. 您的浏览器不支持 video 标签。
  201. </video>
  202. </div>
  203. </div>
  204. </div>
  205. <!-- self send msg record -->
  206. <div v-if="item.id === socket.id" class="record-item send-record">
  207. <!-- 链接 -->
  208. <a
  209. class="message-content-text"
  210. v-if="_isUrl(item.msg)"
  211. :href="item.msg"
  212. target="_blank"
  213. >
  214. {{ item.msg }}
  215. </a>
  216. <!-- 文本 -->
  217. <div
  218. class="message-content-text"
  219. v-if="item.type === 'text'"
  220. v-html="_parseHtml(item.msg)"
  221. ></div>
  222. <!-- 图片 -->
  223. <div
  224. class="message-content-image"
  225. v-if="item.type === 'image'"
  226. :style="getImageStyle(item.msg)"
  227. >
  228. <viewer style="display: flex; align-items: center">
  229. <img :src="baseUrl + item.msg" alt="" />
  230. </viewer>
  231. </div>
  232. <!-- 附件类型消息 -->
  233. <!-- <div class="message-content-file" v-else-if="item.type === 'file'" @click="download(item)">
  234. <img class="message-content-icon" :src="getFileIcon(item)" alt="" />
  235. <div class="message-content-detail">
  236. <div class="file-name">
  237. {{ getFileName(item).name }}
  238. </div>
  239. <div class="file-size">
  240. {{ getFileName(item).size }}
  241. </div>
  242. </div>
  243. </div> -->
  244. <!-- 视频格式文件 -->
  245. <div class="message-content-image" v-if="item.type === 'video'">
  246. <video
  247. style="width: 255px"
  248. src="https://media.w3.org/2010/05/sintel/trailer.mp4"
  249. controls="controls"
  250. >
  251. 您的浏览器不支持 video 标签。
  252. </video>
  253. </div>
  254. <!-- <div class="avatar">
  255. <el-avatar
  256. shape="square"
  257. src="https://img2.baidu.com/it/u=1077360284,2857506492&fm=26&fmt=auto&gp=0.jpg"
  258. ></el-avatar>
  259. </div> -->
  260. </div>
  261. </div>
  262. </el-scrollbar>
  263. </div>
  264. <div class="send-msg-wrap">
  265. <div class="send-header">
  266. <div class="tools" style="margin: 10px">
  267. <el-popover placement="top" width="300" trigger="click" v-model="popoverShow">
  268. <Emoji @addEmoji="addEmoji" />
  269. <el-button
  270. class="iconfont open_emoji_icon"
  271. style="color:rgb(44,60,80)"
  272. type="text"
  273. slot="reference"
  274. >&#xe612;</el-button
  275. >
  276. </el-popover>
  277. <el-upload
  278. ref="upload"
  279. class="file-uploader"
  280. action="/api/upload/"
  281. :show-file-list="false"
  282. :on-success="handleSuccess"
  283. :before-upload="beforeUpload"
  284. style="display: inline"
  285. >
  286. <i
  287. id="upload-btn"
  288. class="el-icon-folder-opened"
  289. @click="upload"
  290. ></i>
  291. </el-upload>
  292. <i class="el-icon-folder-add"></i>
  293. <i class="el-icon-folder-opened"></i>
  294. </div>
  295. </div>
  296. <div class="input-box">
  297. <div
  298. id="charInput"
  299. @click="saveRangeLocal"
  300. @focus="saveRangeLocal"
  301. @input="saveRangeLocal"
  302. @keydown.enter="stopPropagation"
  303. @keyup.enter="sendMsg"
  304. class="chatframe_input_con scrollbar"
  305. contenteditable="true"
  306. ></div>
  307. <div class="send-footer">
  308. <el-button
  309. type="info"
  310. plain
  311. class="send-btn"
  312. size="small"
  313. @click="sendMsg"
  314. >发送</el-button
  315. >
  316. </div>
  317. </div>
  318. </div>
  319. </div>
  320. <div class="chat-wrap" v-if="!selected">
  321. <el-empty description="请选择聊天对象"></el-empty>
  322. </div>
  323. </div>
  324. </template>
  325. <script>
  326. import { isUrl, parseHtml } from "@/utils/common";
  327. import Emoji from "./Emoji.vue";
  328. import { mapState, mapMutations } from "vuex";
  329. import request from "@/api/require";
  330. let emojiData = require("./../assets/emoji/emoji.json");
  331. export default {
  332. name: "ChatFrame",
  333. props: ["selected", "tab"],
  334. components: {
  335. Emoji
  336. },
  337. data() {
  338. return {
  339. baseUrl: "http://192.168.100.8:3000/",
  340. emojiIcon: emojiData.icon,
  341. inputRange: "", // 光标
  342. emojiPath: new Map(), // emoji表情地址map对象,
  343. msg: "",
  344. popoverShow: false,
  345. friend_record_list: [],
  346. room_record_list: [],
  347. messageType: "",
  348. uploadProgress: false
  349. };
  350. },
  351. computed: {
  352. ...mapState({
  353. self: state => state.app.user,
  354. socket: state => state.chat.socket,
  355. friendRecord: state => state.chat.friendRecord,
  356. roomRecord: state => state.chat.roomRecord
  357. })
  358. },
  359. watch: {
  360. selected(newVal, o) {
  361. if (this.tab === "friends") {
  362. if (this.friendRecord[newVal.id]) {
  363. this.friend_record_list = this.friendRecord[newVal.id];
  364. } else {
  365. this.set_friend_record([newVal.id])
  366. this.friend_record_list = this.friendRecord[newVal.id];
  367. }
  368. } else {
  369. if (this.roomRecord[newVal.id]) {
  370. this.room_record_list = this.roomRecord[newVal.id];
  371. } else {
  372. this.set_room_record(newVal.id)
  373. this.room_record_list = this.roomRecord[newVal.id];
  374. }
  375. }
  376. this.$nextTick(() => {
  377. document.getElementById("charInput").innerText = "";
  378. this.msg = "";
  379. this.$refs["myScrollbar"].wrap.scrollTop = this.$refs[
  380. "myScrollbar"
  381. ].wrap.scrollHeight;
  382. });
  383. }
  384. },
  385. methods: {
  386. ...mapMutations('chat', [
  387. 'set_friend_record',
  388. 'set_room_record',
  389. ]),
  390. handleSuccess(res, file) {
  391. console.log(`res`, res);
  392. this.imageUrl = URL.createObjectURL(file.raw);
  393. },
  394. beforeUpload(file) {
  395. this.uploadProgress = true;
  396. this.fileData = file;
  397. // 调用函数分割文件 我这里是分割成不超过20M的文件快
  398. this.fileDataList = this.createFileChunk(file, 1024 * 1024 * 20);
  399. console.log(`this.fileDataList`, this.fileDataList);
  400. // return new Promise((reslove, reject)=>{
  401. // this.fileUpLoad(reslove, reject);
  402. // })
  403. let fd = new FormData();
  404. fd.append("filename", file);
  405. // upload_file(fd).then(
  406. request
  407. .upload_file(file)
  408. .then(res => {
  409. console.log(`res5555`, res);
  410. })
  411. .catch(err => {
  412. console.log(`err`, err);
  413. });
  414. this.$http.post(this.baseUrl + "api/upload/", fd).then(
  415. res => {
  416. if (
  417. file.type === "image/jpeg" ||
  418. file.type === "image/png" ||
  419. file.type === "image/gif"
  420. ) {
  421. this.messageType = "image";
  422. this.sendMsg(null, res.data.data);
  423. console.log(`res.data.data`, res.data.data);
  424. console.log("========is image =====");
  425. } else {
  426. this.messageType = "file";
  427. console.log("=========not image=========");
  428. }
  429. // this.importDataBtnText='导入成功';
  430. console.log(`res1111`, res);
  431. console.log("======success====");
  432. },
  433. res => {
  434. this.$message.error("文件发送失败");
  435. console.log("===========shibai====");
  436. // this.importDataBtnText='导入失败';
  437. console.log(res);
  438. }
  439. );
  440. return false;
  441. },
  442. submitUpload() {
  443. this.$refs.upload.submit();
  444. },
  445. /**
  446. * 文本转译/校验
  447. * @params text
  448. */
  449. _parseHtml(text) {
  450. const regex2 = /!!\[(.+?)\]!!/g;
  451. const codeList = text.match(regex2);
  452. let html = text;
  453. if (codeList) {
  454. codeList.map(item => {
  455. const code = item.match(/\[(.+?)\]/g)[0];
  456. html = html.replace(
  457. item,
  458. "<img style='width: 20px; height: 20px;vertical-align: sub;' src='" +
  459. this.getIconPic(code) +
  460. "' unicode = '" +
  461. code +
  462. "' alt='' >"
  463. );
  464. });
  465. }
  466. return parseHtml(html);
  467. },
  468. /**
  469. * 是否URL
  470. * @params text
  471. */
  472. _isUrl(text) {
  473. return isUrl(text);
  474. },
  475. // // 初始化上传接口的函数,再上面上传之前调用的
  476. // fileUpLoad(reslove, reject) {
  477. // const paramsData = {
  478. // multipartUpload: true, // 是否是文件分步,分块上传
  479. // name: this.fileData.name,
  480. // size: this.fileData.size,
  481. // }
  482. // initFileUpload(paramsData).then(res => {
  483. // const uploadUrl = res.data.data.uploadUrl
  484. // const completeMultipartUrl = res.data.data.completeMultipartUrl
  485. // // 文件上传的请求地址
  486. // this.uploadUrl = uploadUrl
  487. // // 合并文件上传的请求地址
  488. // this.completeMultipartUrl = completeMultipartUrl
  489. // reslove();
  490. // }).catch((err)=>{
  491. // reject(err)
  492. // })
  493. // },
  494. // 文件分割的方法
  495. createFileChunk(file, size = chunkSize) {
  496. const fileChunkList = [];
  497. let count = 0;
  498. let num = 1;
  499. while (count < file.size) {
  500. fileChunkList.push({
  501. file: file.slice(count, count + size),
  502. partNumber: num
  503. });
  504. count += size;
  505. num++;
  506. }
  507. return fileChunkList;
  508. },
  509. /**
  510. * 根据图片url设置图片框宽高, 注意是图片框
  511. */
  512. getImageStyle(src) {
  513. const arr = src.split("$");
  514. let width = Number(arr[2]);
  515. let height = Number(arr[3]);
  516. if (this.mobile) {
  517. // 如果是移动端,图片最大宽度138, 返回值加12是因为设置的是图片框的宽高要加入padding值
  518. if (width > 138) {
  519. height = (height * 138) / width;
  520. width = 138;
  521. return {
  522. width: `${width + 12}px`,
  523. height: `${height + 12}px`
  524. };
  525. }
  526. }
  527. return {
  528. width: `${width + 12}px`,
  529. height: `${height + 12}px`
  530. };
  531. },
  532. /**
  533. * 是否URL
  534. * @params text
  535. */
  536. _isUrl(text) {
  537. return isUrl(text);
  538. },
  539. upload() {},
  540. // 添加表情, 到输入框
  541. addEmoji(code) {
  542. let inputNode = document.getElementById("charInput");
  543. let html =
  544. "<img style='width: 20px; height: 20px;vertical-align: sub;' src='" +
  545. this.getIconPic(code) +
  546. "' unicode = '" +
  547. code +
  548. "' alt='' >";
  549. let sel = window.getSelection();
  550. let range = this.inputRange;
  551. let el = document.createElement("div");
  552. let frag = document.createDocumentFragment(),
  553. node,
  554. lastNode;
  555. if (!inputNode) {
  556. return;
  557. }
  558. if (!range) {
  559. inputNode.focus();
  560. range = window.getSelection().getRangeAt(0);
  561. }
  562. range.deleteContents();
  563. el.innerHTML = html;
  564. while ((node = el.firstChild)) {
  565. lastNode = frag.appendChild(node);
  566. }
  567. range.insertNode(frag);
  568. if (lastNode) {
  569. range = range.cloneRange();
  570. range.setStartAfter(lastNode);
  571. range.collapse(true);
  572. sel.removeAllRanges();
  573. sel.addRange(range);
  574. }
  575. },
  576. // 初始化emoji的map对象
  577. initEmojiPic() {
  578. let map = new Map();
  579. for (const key in emojiData.icon) {
  580. emojiData.icon[key].forEach(item => {
  581. map.set(
  582. item.unicode,
  583. require("./../assets/emoji/icon/" + item.unicode + ".png")
  584. );
  585. });
  586. }
  587. this.emojiPath = map;
  588. },
  589. // 通过Unicode码从map中获取emoji
  590. getIconPic(unicode) {
  591. return this.emojiPath.get(unicode);
  592. },
  593. // ===============================================================
  594. // 将输入框中的图片替换为emoji表情
  595. formatInputCon() {
  596. let inputValue = document.getElementById("charInput").innerHTML;
  597. inputValue = inputValue.replace(/<img.*?(?:>|\/>)/gi, val => {
  598. let unicode =
  599. "!!" + val.match(/unicode=[\'\"]?([^\'\"]*)[\'\"]?/i)[1] + "!!";
  600. return unicode;
  601. });
  602. return inputValue;
  603. },
  604. // 将emoji表情转换为图片
  605. changeEmojiCon(str) {
  606. let patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
  607. str = str.replace(patt, char => {
  608. let H, L, code;
  609. if (char.length === 2) {
  610. H = char.charCodeAt(0); // 取出高位
  611. L = char.charCodeAt(1); // 取出低位
  612. code = (H - 0xd800) * 0x400 + 0x10000 + L - 0xdc00; // 转换算法
  613. return "&#" + code + ";";
  614. } else {
  615. return char;
  616. }
  617. });
  618. str = str.replace(/&#{1}[0-9]+;{1}/gi, a => {
  619. let unicode = a.replace(/^&#{1}/gi, "");
  620. unicode = unicode.replace(/;{1}$/gi, "");
  621. unicode =
  622. "U+" +
  623. parseFloat(unicode)
  624. .toString(16)
  625. .toUpperCase();
  626. return "<img src='" + this.getIconPic(unicode) + "'/>";
  627. });
  628. return str;
  629. },
  630. // 延时记录光标到位置
  631. chartFramRange(type) {
  632. try {
  633. if (type === "click") {
  634. this.inputRange = window.getSelection().getRangeAt(0);
  635. }
  636. if (type === "focus") {
  637. this.inputRange = window.getSelection().getRangeAt(0);
  638. }
  639. } catch (err) {
  640. console.log(type);
  641. }
  642. return new Promise((resolve, reject) => {
  643. setTimeout(() => {
  644. this.inputRange = window.getSelection().getRangeAt(0);
  645. resolve(this.inputRange);
  646. }, 0);
  647. });
  648. },
  649. // 延时记录光标到位置
  650. saveRangeLocal() {
  651. setTimeout(() => {
  652. this.inputRange = window.getSelection().getRangeAt(0);
  653. }, 0);
  654. },
  655. // ================================================================
  656. // 阻止回车键默认事件
  657. stopPropagation(e) {
  658. if (e && e.keyCode === 13) {
  659. e.cancelBubble = true;
  660. e.preventDefault();
  661. e.stopPropagation();
  662. }
  663. },
  664. sendMsg(e, fileurl) {
  665. console.log(`e============`, e);
  666. if (fileurl) {
  667. // 上传文件路径
  668. this.msg = fileurl;
  669. } else {
  670. // 输入框信息
  671. this.msg = this.formatInputCon().replace(/<br>/g, "\r\n");
  672. console.log(`this.msg`, this.msg);
  673. }
  674. if (this.msg.trim() === "") {
  675. this.msg = "";
  676. return;
  677. }
  678. if (!this.messageType) {
  679. this.messageType = "text";
  680. }
  681. const msgInfo = {
  682. ...this.self,
  683. id: this.socket.id,
  684. msg: this.msg,
  685. type: this.messageType
  686. };
  687. if (this.tab === "friends") {
  688. msgInfo.toid = this.selected.id;
  689. this.socket.emit("private message", this.selected.id, msgInfo);
  690. const msgData = [this.selected.id, msgInfo];
  691. this.set_friend_record(msgData);
  692. this.friend_record_list = this.friendRecord[this.selected.id];
  693. } else {
  694. console.log("=======ROOM CHAT========");
  695. msgInfo.roomId = this.selected.id;
  696. this.socket.emit("chat-room", this.selected.id, msgInfo);
  697. this.set_room_record(msgInfo);
  698. this.room_record_list = this.roomRecord[this.selected.id];
  699. }
  700. // 发送消息后关闭表情选择弹窗
  701. this.popoverShow = false
  702. this.$nextTick(() => {
  703. // 输入enter后置空
  704. document.getElementById("charInput").innerText = "";
  705. this.msg = "";
  706. this.messageType = "";
  707. // 滚动到底部
  708. this.$refs["myScrollbar"].wrap.scrollTop = this.$refs["myScrollbar"].wrap.scrollHeight;
  709. });
  710. },
  711. },
  712. created() {
  713. },
  714. mounted() {
  715. this.initEmojiPic();
  716. }
  717. };
  718. </script>
  719. <style lang="scss" scoped>
  720. .chat-wrap {
  721. height: 90vh;
  722. border: 1px solid #ddd;
  723. border-radius: 2px;
  724. }
  725. .chat-title {
  726. padding: 20px;
  727. font-weight: 600;
  728. }
  729. .record-warp {
  730. padding: 10px;
  731. height: 63vh;
  732. background: rgb(245, 245, 245);
  733. }
  734. /* .record-list {
  735. } */
  736. .record-item {
  737. display: flex;
  738. padding: 15px 5px;
  739. margin: 5px;
  740. }
  741. .avatar {
  742. margin: 10px 5px;
  743. }
  744. .record-item > span {
  745. padding: 8px 12px;
  746. border-radius: 5px;
  747. }
  748. .username {
  749. padding: 4px;
  750. margin-bottom: 2px;
  751. font-size: 14px;
  752. color: gray;
  753. }
  754. .group-record-item > span {
  755. padding: 8px 12px;
  756. border-radius: 5px;
  757. background-color: rgb(199, 206, 200);
  758. }
  759. .send-record {
  760. position: relative;
  761. justify-content: flex-end;
  762. }
  763. .send-record > span {
  764. display: inline-block;
  765. text-align: right;
  766. }
  767. .message-content-text,
  768. .message-content-image {
  769. max-width: 600px;
  770. display: inline-block;
  771. margin-left: 35px;
  772. overflow: hidden;
  773. margin-top: 4px;
  774. padding: 6px;
  775. background: rgb(117, 197, 128);
  776. font-size: 16px;
  777. border-radius: 5px;
  778. text-align: left;
  779. word-break: break-word;
  780. }
  781. .message-content-image {
  782. max-height: 255px;
  783. max-width: 255px;
  784. background: rgb(204, 197, 197);
  785. }
  786. .message-content-image img {
  787. cursor: pointer;
  788. max-width: 225px;
  789. max-height: 225px;
  790. }
  791. .receive-record-item {
  792. margin: 2px;
  793. background: #fff;
  794. }
  795. .input-box {
  796. display: flex;
  797. overflow: hidden;
  798. position: relative;
  799. }
  800. .send-footer {
  801. position: absolute;
  802. bottom: 0;
  803. right: 20px;
  804. padding: 10px;
  805. text-align: right;
  806. }
  807. .chatframe_input_con {
  808. display: inline-block;
  809. width: 92%;
  810. height: 95px;
  811. resize: none;
  812. padding: 5px 15px;
  813. line-height: 1.5;
  814. box-sizing: border-box;
  815. font-size: inherit;
  816. color: #606266;
  817. background-color: #fff;
  818. outline: none;
  819. overflow-y: scroll;
  820. margin-bottom: 20px;
  821. // 超出自动换行 -- 火狐
  822. word-wrap: break-word;
  823. word-break: break-all;
  824. // 滚动样式 细 - 火狐
  825. scrollbar-width: thin;
  826. }
  827. .chatframe-text {
  828. min-height: 200px;
  829. width: 500px;
  830. box-sizing: border-box;
  831. padding: 10px 15px;
  832. margin-top: 5px;
  833. background: #eaedf1;
  834. color: #282828;
  835. border-radius: 4px;
  836. word-wrap: break-word;
  837. word-break: break-all;
  838. line-height: 18px;
  839. white-space: pre-wrap;
  840. position: relative;
  841. }
  842. .text_emoji {
  843. img {
  844. display: inline-block;
  845. width: 20px;
  846. height: 20px;
  847. vertical-align: bottom;
  848. }
  849. }
  850. </style>