ChatItem.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div class="chat-item" :class="active ? 'active' : ''" @contextmenu.prevent="showRightMenu($event)">
  3. <div class="chat-left">
  4. <head-image :url="chat.headImage" :name="chat.showName" :size="45"
  5. :id="chat.type=='PRIVATE'?chat.targetId:0"></head-image>
  6. <div v-show="chat.unreadCount>0" class="unread-text">{{chat.unreadCount}}</div>
  7. </div>
  8. <div class="chat-right">
  9. <div class="chat-name">
  10. <div class="chat-tag" v-if="chat.type=='GROUP'">
  11. <el-tag size="mini" >群</el-tag>
  12. </div>
  13. <div class="chat-name-text">{{chat.showName}}</div>
  14. <div class="chat-time-text">{{showTime}}</div>
  15. </div>
  16. <div class="chat-content">
  17. <div class="chat-at-text">{{atText}}</div>
  18. <div class="chat-send-name" v-show="isShowSendName">{{chat.sendNickName+':&nbsp;'}}</div>
  19. <div class="chat-content-text" v-html="$emo.transform(chat.lastContent)"></div>
  20. </div>
  21. </div>
  22. <right-menu v-show="rightMenu.show" :pos="rightMenu.pos" :items="rightMenu.items" @close="rightMenu.show=false"
  23. @select="onSelectMenu"></right-menu>
  24. </div>
  25. </template>
  26. <script>
  27. import HeadImage from '../common/HeadImage.vue';
  28. import RightMenu from '../common/RightMenu.vue';
  29. export default {
  30. name: "chatItem",
  31. components: {
  32. HeadImage,
  33. RightMenu
  34. },
  35. data() {
  36. return {
  37. rightMenu: {
  38. show: false,
  39. pos: {
  40. x: 0,
  41. y: 0
  42. },
  43. items: [{
  44. key: 'TOP',
  45. name: '置顶',
  46. icon: 'el-icon-top'
  47. }, {
  48. key: 'DELETE',
  49. name: '删除',
  50. icon: 'el-icon-delete'
  51. }]
  52. }
  53. }
  54. },
  55. props: {
  56. chat: {
  57. type: Object
  58. },
  59. active: {
  60. type: Boolean
  61. },
  62. index: {
  63. type: Number
  64. }
  65. },
  66. methods: {
  67. showRightMenu(e) {
  68. this.rightMenu.pos = {
  69. x: e.x,
  70. y: e.y
  71. };
  72. this.rightMenu.show = "true";
  73. },
  74. onSelectMenu(item) {
  75. this.$emit(item.key.toLowerCase(), this.msgInfo);
  76. }
  77. },
  78. computed: {
  79. isShowSendName() {
  80. if (!this.chat.sendNickName) {
  81. return false;
  82. }
  83. let size = this.chat.messages.length;
  84. if (size == 0) {
  85. return false;
  86. }
  87. // 只有群聊的普通消息需要显示名称
  88. let lastMsg = this.chat.messages[size - 1];
  89. return this.$msgType.isNormal(lastMsg.type)
  90. },
  91. showTime() {
  92. return this.$date.toTimeText(this.chat.lastSendTime, true)
  93. },
  94. atText() {
  95. if (this.chat.atMe) {
  96. return "[有人@我]"
  97. } else if (this.chat.atAll) {
  98. return "[@全体成员]"
  99. }
  100. return "";
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss">
  106. .chat-item {
  107. height: 50px;
  108. display: flex;
  109. margin-bottom: 1px;
  110. position: relative;
  111. padding: 5px 10px;
  112. align-items: center;
  113. background-color: white;
  114. white-space: nowrap;
  115. color: black;
  116. cursor: pointer;
  117. &:hover {
  118. background-color: #F8FAFF;
  119. }
  120. &.active {
  121. background-color: #F4F9FF;
  122. }
  123. .chat-left {
  124. position: relative;
  125. display: flex;
  126. width: 45px;
  127. height: 45x;
  128. .unread-text {
  129. position: absolute;
  130. background-color: #f56c6c;
  131. right: -5px;
  132. top: -5px;
  133. color: white;
  134. border-radius: 30px;
  135. padding: 1px 5px;
  136. font-size: 10px;
  137. text-align: center;
  138. white-space: nowrap;
  139. border: 1px solid #f1e5e5;
  140. }
  141. }
  142. .chat-right {
  143. flex: 1;
  144. display: flex;
  145. flex-direction: column;
  146. padding-left: 10px;
  147. text-align: left;
  148. overflow: hidden;
  149. .chat-name {
  150. display: flex;
  151. line-height: 25px;
  152. height: 25px;
  153. .chat-tag {
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. margin-right: 1px;
  158. }
  159. .chat-name-text {
  160. flex: 1;
  161. font-size: 15px;
  162. font-weight: 600;
  163. white-space: nowrap;
  164. overflow: hidden;
  165. }
  166. .chat-time-text {
  167. font-size: 13px;
  168. text-align: right;
  169. color: #888888;
  170. white-space: nowrap;
  171. overflow: hidden;
  172. padding-left: 10px;
  173. }
  174. }
  175. .chat-content {
  176. display: flex;
  177. line-height: 22px;
  178. .chat-at-text {
  179. color: #c70b0b;
  180. font-size: 12px;
  181. }
  182. .chat-send-name {
  183. font-size: 13px;
  184. }
  185. .chat-content-text {
  186. flex: 1;
  187. white-space: nowrap;
  188. overflow: hidden;
  189. text-overflow: ellipsis;
  190. font-size: 13px;
  191. img {
  192. width: 20px !important;
  193. height: 20px !important;
  194. vertical-align: bottom;
  195. }
  196. }
  197. }
  198. }
  199. }
  200. </style>