chatRoom.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <div class="chat-room">
  3. <!-- {{$route.params.id}} -->
  4. <div class="mini-wrap moblie-wrap">
  5. <div class="mini-body">
  6. <div class="box">
  7. <back-bar :title="isPrivate ? group.privateName : group.groupName">
  8. <span v-if="!isPrivate" class="group-set-icon el-icon-more"></span>
  9. </back-bar>
  10. <chat-pin v-bind="pinMsg" @pinMsgClose="pinMsgClose" @scrollToView="scrollToView"></chat-pin>
  11. <div class="box-bd" ref="msgBox">
  12. <div ref="scrollWrap"
  13. @scroll.prevent="handleScroll"
  14. class="scroller"
  15. >
  16. <div ref="msgWrap" class="msg-wrap">
  17. <div class="msg-top-more" v-if="lockEnd">
  18. <em>没有更多了</em>
  19. </div>
  20. <div class="msg-top-load" v-if="lockMore && !lockEnd">
  21. <i class="msg-loading-icon"></i>
  22. </div>
  23. <template v-if="group.chatList.length">
  24. <msg-item v-for="(item ,key) in group.pinList"
  25. :key="'pin' + key"
  26. v-bind="item"
  27. @quoteMsg="quoteMsg"
  28. @deleteMsg="deleteMsg"
  29. >
  30. </msg-item>
  31. </template>
  32. <msg-item v-for="item in group.chatList"
  33. :key="item.hash"
  34. v-bind="item"
  35. :msgItem="item"
  36. @quoteMsg="quoteMsg"
  37. @deleteMsg="deleteMsg"
  38. ></msg-item>
  39. </div>
  40. </div>
  41. <at-me :atList="atList" class="mini" @scrollToMsg="scrollToMsg"></at-me>
  42. <div class="msg-unread"
  43. @click="doSetRead"
  44. v-if="unreadNums > 0 && enableScroll && !isBottom">
  45. <em><i class="el-icon-d-arrow-right"></i>{{unreadNums}}条未读消息</em>
  46. </div>
  47. </div>
  48. <div class="box-ft">
  49. <chat-at
  50. ref="chatAt"
  51. v-if="atShow"
  52. @atperson="atPerson"
  53. :curInd="atInd"
  54. :filterList="filterMembers">
  55. </chat-at>
  56. <div class="input-con">
  57. <div class="more-icon" @click.stop="handleMoreClick"></div>
  58. <form class="input-wrap" @submit="handleSend">
  59. <textarea
  60. @keydown.up.prevent="handleUp"
  61. @keydown.down.prevent="handleDown"
  62. @keydown.left="handleLeft"
  63. @keydown.right="handleRight"
  64. @keydown.delete="handleDel"
  65. @keydown.esc="handleEsc"
  66. cols="1"
  67. ref="chatInput"
  68. rows="1"
  69. @keydown.enter="handleKeyDown"
  70. placeholder="Write a message"
  71. v-model="inputMsg"
  72. @focus="handleFocus"
  73. @blur="handleBlur"
  74. />
  75. </form>
  76. <div class="emoji-icon" @click.stop="handleEmojiClick"></div>
  77. <div class="btn-send" @click="handleSend">发送</div>
  78. </div>
  79. <div class="tool-wrap" @click.stop v-show="toolShow">
  80. <div class="tool-item">
  81. <div class="icon-box" @click="$packetSend">
  82. <i class="packet-icon"></i>
  83. </div>
  84. <span class="type">红包</span>
  85. </div>
  86. <div class="tool-item">
  87. <div class="icon-box">
  88. <i class="picture-icon"></i>
  89. <input type="file" ref="inputFile1" name="res" accept="image/*" @change="handleFile">
  90. </div>
  91. <span class="type">图片</span>
  92. </div>
  93. <div class="tool-item">
  94. <div class="icon-box">
  95. <i class="audio-icon"></i>
  96. <input type="file" ref="inputFile2" name="res" accept="audio/*" @change="handleFile">
  97. </div>
  98. <span class="type">音频</span>
  99. </div>
  100. <div class="tool-item">
  101. <div class="icon-box">
  102. <i class="video-icon"></i>
  103. <input type="file" ref="inputFile3" name="res" accept="video/*" @change="handleFile">
  104. </div>
  105. <span class="type">视频</span>
  106. </div>
  107. </div>
  108. <div class="emoji-wrap" v-if="emojiShow">
  109. <emoji-list @addEmoji="addEmoji"></emoji-list>
  110. </div>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. </template>
  117. <script>
  118. // import { mapState, mapMutations, mapActions } from 'vuex'
  119. import backBar from '@/components/backBar'
  120. import msgItem from '@/components/msgItem'
  121. import emojiList from '@/components/emoji'
  122. import chatAt from '@/components/chatAt'
  123. import atMe from '@/components/chatAt/atme'
  124. import chatPin from '@/components/chatPin'
  125. import { chatAtMixin, chatInputMixin } from '@/mixins'
  126. import { chatMixin, inputMixin } from '@/mixins/chat'
  127. // import API from '@/api'
  128. export default {
  129. name: 'h5ChatRoom',
  130. mixins: [chatAtMixin, chatInputMixin, chatMixin, inputMixin],
  131. components: {
  132. msgItem,
  133. emojiList,
  134. chatAt,
  135. chatPin,
  136. atMe,
  137. backBar
  138. },
  139. data () {
  140. return {
  141. emojiShow: false,
  142. toolShow: false
  143. }
  144. },
  145. methods: {
  146. handleEmojiClick () {
  147. this.toolShow = false
  148. this.emojiShow = !this.emojiShow
  149. },
  150. handleMoreClick () {
  151. this.emojiShow = false
  152. this.toolShow = !this.toolShow
  153. }
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. @charset "UTF-8";
  159. $chatBg: #34363c;
  160. $chatContBg: #eeeeee;
  161. $chatUiFont: #ffffff;
  162. $offsetBottom: 5px;
  163. $offsetRight: 5px;
  164. .group-set-icon{
  165. position: absolute;
  166. right: 0;
  167. top: 0;
  168. height: px2rem(90);
  169. width: px2rem(100);
  170. text-align: center;
  171. font-size: px2rem(42);
  172. line-height: px2rem(90);
  173. }
  174. .mini-wrap{
  175. z-index: 123456789;
  176. height: 100%;
  177. }
  178. .mini-body{
  179. height: 100%;
  180. box-sizing: border-box;
  181. }
  182. .box{
  183. position: relative;
  184. height: 100%;
  185. display: flex;
  186. flex-direction: column;
  187. }
  188. .chat-room{
  189. position: absolute;
  190. top: 0;
  191. left: 0;
  192. width: 100%;
  193. height: 100%;
  194. }
  195. .box-bd{
  196. height: 0;
  197. flex: 1;
  198. position: relative;
  199. background: $chatContBg;
  200. .msg-unread{
  201. position: absolute;
  202. width: 120px;
  203. left: 50%;
  204. bottom: 10px;
  205. border-radius: 20px;
  206. background: rgba(#000000, 0.5);
  207. padding: 0 5px;
  208. text-align: center;
  209. line-height: 32px;
  210. margin-left: -65px;
  211. cursor: pointer;
  212. &:hover{
  213. background: rgba(#000000, 0.3);
  214. }
  215. em{
  216. color: #ffffff;
  217. font-size: 14px;
  218. }
  219. i{
  220. transform: rotate(90deg);
  221. margin-right: 5px;
  222. }
  223. }
  224. }
  225. .scroller{
  226. height: 100%;
  227. overflow-y: scroll;
  228. &::-webkit-scrollbar {
  229. width: 8px;
  230. height: 6px;
  231. }
  232. &::-webkit-scrollbar-thumb {
  233. border-radius: 3px;
  234. -moz-border-radius: 3px;
  235. -webkit-border-radius: 3px;
  236. background-color: rgba($color: #8d8a8a, $alpha: 0.2);
  237. }
  238. &::-webkit-scrollbar-track {
  239. background-color: transparent;
  240. }
  241. }
  242. .box-ft{
  243. position: relative;
  244. background: $chatContBg;
  245. border-top: 1px solid #d6d6d6;
  246. .input-con{
  247. position: relative;
  248. display: flex;
  249. align-items: flex-end;
  250. background-color: #fafafa;
  251. padding: 6px 0;
  252. }
  253. .input-wrap{
  254. flex: 1;
  255. padding: 10px 0;
  256. background-color: #ffffff;
  257. border-radius: 4px;
  258. }
  259. .more-icon{
  260. width: 38px;
  261. height: 38px;
  262. background: url('../../../assets/more-icon.png') center center no-repeat;
  263. background-size: 22px 22px;
  264. cursor: pointer;
  265. &:hover{
  266. opacity: .6;
  267. }
  268. }
  269. .emoji-icon{
  270. width: 38px;
  271. height: 38px;
  272. background: url('../../../assets/m-face-icon.png') center center no-repeat;
  273. background-size: 22px 22px;
  274. cursor: pointer;
  275. &:hover{
  276. opacity: .6;
  277. }
  278. }
  279. .btn-send{
  280. margin-right: 4px;
  281. font-size: 12px;
  282. color: #ffffff;
  283. padding: 0 10px;
  284. height: 28px;
  285. line-height: 28px;
  286. margin-bottom: 3px;
  287. background: #2b9ff6;
  288. border-radius: 3px;
  289. cursor: pointer;
  290. &:hover{
  291. opacity: 0.8;
  292. }
  293. }
  294. form{
  295. @include flex(1);
  296. }
  297. textarea {
  298. display: block;
  299. width: 100%;
  300. height: 18px;
  301. max-height: 175px;
  302. font-size: 14px;
  303. color: #000000;
  304. line-height: 16px;
  305. padding: 1px;
  306. padding-left: 8px;
  307. margin: 0;
  308. border: none;
  309. outline: none;
  310. background: none;
  311. box-sizing: border-box;
  312. resize: none;
  313. }
  314. .emoji-wrap{
  315. position: absolute;
  316. left: 0;
  317. right: 0;
  318. bottom: 52px;
  319. background: #ffffff;
  320. box-shadow: 1px 1px 50px rgba(0,0,0,.3);
  321. z-index: 10;
  322. }
  323. .input-ctrl{
  324. span{
  325. width: 120px;
  326. margin: 4px auto;
  327. height: 30px;
  328. line-height: 30px;
  329. color: #ffffff;
  330. font-size: 12px;
  331. text-align: center;
  332. display: block;
  333. background-image: -webkit-linear-gradient( 90deg, rgb(25,145,235) 0%, rgb(46,161,248) 100%);
  334. border-radius: 3px;
  335. &.enable{
  336. cursor: pointer;
  337. &:hover{
  338. opacity: 0.7;
  339. }
  340. }
  341. }
  342. }
  343. }
  344. .msg-wrap{
  345. margin-bottom: 16px;
  346. }
  347. .msg-top-more{
  348. margin-top: 10px;
  349. text-align: center;
  350. i{
  351. font-size: 30px;
  352. }
  353. em{
  354. font-size: 12px;
  355. line-height: 20px;
  356. color: #999999;
  357. }
  358. }
  359. .msg-loading-icon{
  360. display: block;
  361. background: url('../../../assets/loading-icon.png') no-repeat;
  362. background-size: 100%;
  363. width: 16px;
  364. height: 16px;
  365. margin: 12px auto;
  366. animation: rotate 2s linear infinite;
  367. }
  368. .tool-wrap{
  369. background-color: #f6f6f6;
  370. display: flex;
  371. padding: 16px 0;
  372. .tool-item{
  373. flex: 1;
  374. text-align: center;
  375. }
  376. .type{
  377. font-size: 14px;
  378. color: #666666;
  379. }
  380. .icon-box{
  381. width: 58px;
  382. height: 58px;
  383. margin: 0 auto;
  384. cursor: pointer;
  385. background-color: #ffffff;
  386. border-radius: 6px;
  387. border: 1px solid #efefef;
  388. box-sizing: border-box;
  389. margin-bottom: 6px;
  390. display: flex;
  391. justify-content: center;
  392. align-items: center;
  393. position: relative;
  394. &:hover{
  395. opacity: .8;
  396. }
  397. input[type=file] {
  398. opacity: 0;
  399. position: absolute;
  400. top: 0;
  401. left: 0;
  402. width: 100%;
  403. height: 100%;
  404. cursor: pointer;
  405. z-index: 4;
  406. }
  407. i{
  408. display: inline-block;
  409. }
  410. .packet-icon{
  411. background: url('../../../assets/packet-icon.png') no-repeat;
  412. background-size: 100%;
  413. width: 21px;
  414. height: 26px;
  415. }
  416. .picture-icon{
  417. background: url('../../../assets/pic-icon.png') no-repeat;
  418. background-size: 100%;
  419. width: 27px;
  420. height: 21px;
  421. }
  422. .audio-icon{
  423. background: url('../../../assets/audio-icon.png') no-repeat;
  424. background-size: 100%;
  425. width: 18px;
  426. height: 26px;
  427. }
  428. .video-icon{
  429. background: url('../../../assets/video-icon.png') no-repeat;
  430. background-size: 100%;
  431. width: 30px;
  432. height: 18px;
  433. }
  434. }
  435. }
  436. // 手机端适配
  437. .moblie-wrap{
  438. .box-hd{
  439. height: 30px;
  440. }
  441. .box-ft{
  442. .emoji-wrap{
  443. bottom: 54px;
  444. }
  445. .btn-send{
  446. height: 36px;
  447. line-height: 36px;
  448. padding: 0 10px;
  449. font-size: 16px;
  450. margin-bottom: 0;
  451. }
  452. .input-ctrl span {
  453. height: 40px;
  454. line-height: 40px;
  455. font-size: 16px;
  456. }
  457. .input-con{
  458. padding: 8px 0;
  459. align-items: center;
  460. }
  461. .input-wrap{
  462. padding: 10px 0;
  463. margin: 0 6px;
  464. .textarea{
  465. height: 26px;
  466. line-height: 20px;
  467. }
  468. }
  469. .more-icon{
  470. background-size: 30px 30px;
  471. }
  472. .emoji-icon{
  473. background-size: 30px 30px;
  474. margin-right: 4px;
  475. }
  476. }
  477. }
  478. </style>