ChatLog.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <transition name="collapse">
  3. <div class="chatlog" v-if="visible">
  4. <div class="chatlog-wrap">
  5. <div class="title">
  6. <span>聊天记录</span>
  7. <span class="close" @click="handleHistoryVisible">&times;</span>
  8. </div>
  9. <ul class="log-list">
  10. <li class="log-item" v-for="(item, index) in cloneHistory.records" :class="{'mine': item.mine}">
  11. <div class="time" v-if="handleTimeVisible(item, index)"><span>{{item.time | formatDate(true) }}</span></div>
  12. <div class="avatar">
  13. <img :src="item.avatar">
  14. </div>
  15. <div class="message message-image" v-if="item.chatlogType === 'image'">
  16. <img :src="item.content" style="width: 90%;height: auto">
  17. </div>
  18. <div class="message message-file" v-else-if="item.chatlogType === 'file'">
  19. <a class="down-link" :href="item.content.src" :download="item.content.name"><i class="fa fa-cloud-download down-link-icon"></i><span class="down-link-file">{{item.content.name}}</span></a>
  20. </div>
  21. <div class="message" v-else v-html="item.content"></div>
  22. </li>
  23. </ul>
  24. <div class="page" v-show="history.total">
  25. <el-pagination
  26. layout="prev, pager, next"
  27. :total="history.total || 0"
  28. :page-size="history.size"
  29. @current-change="handlePageChange">
  30. </el-pagination>
  31. </div>
  32. </div>
  33. </div>
  34. </transition>
  35. </template>
  36. <script>
  37. import { formatDate } from '@/filters/filters'
  38. import { deepCopy } from '@/utils/utils.js'
  39. import { getChatlog } from '@/api/webim/index.js'
  40. export default {
  41. name: 'chatlog',
  42. props: {
  43. history: Object,
  44. value: {
  45. type: Boolean,
  46. default: false
  47. },
  48. mine: Object
  49. },
  50. data () {
  51. return {
  52. visible: this.value,
  53. cloneHistory: []
  54. }
  55. },
  56. methods: {
  57. handleTimeVisible (item, index) {
  58. const self = this
  59. if (index === 0) {
  60. return true
  61. } else {
  62. return (self.history.records[index].time - self.history.records[index - 1].time > 10 * 60 * 1000)
  63. }
  64. },
  65. handleHistoryVisible () {
  66. this.visible = false
  67. this.$emit('input', this.visible)
  68. },
  69. handlePageChange (page) {
  70. this.$parent.$parent.handlePageChange(page)
  71. },
  72. makeCloneHistory () {
  73. // if (this.history && !this.history.records) return
  74. // let history = deepCopy(this.history)
  75. const self = this
  76. getChatlog(self.mine.id).then(function (response) {
  77. debugger
  78. let history =response.data
  79. history.records.forEach(item => {
  80. item.mine = item.sender == self.mine.id.toString()
  81. })
  82. return self.cloneHistory=history
  83. })
  84. }
  85. },
  86. filters: {
  87. formatDate
  88. },
  89. mounted () {
  90. this.makeCloneHistory()
  91. },
  92. watch: {
  93. value (newV) {
  94. this.visible = newV
  95. }
  96. }
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .chatlog {
  101. width: 350px;
  102. overflow: hidden;
  103. .chatlog-wrap {
  104. width: 100%;
  105. height: 100%;
  106. border-left: 1px solid rgba(0,0,0,.14);
  107. background: #fff;
  108. .title {
  109. height: 40px;
  110. line-height: 40px;
  111. background: #fff;
  112. font-size: 14px;
  113. padding: 0 15px;
  114. border-bottom: 1px solid #e7e7e7;
  115. .close {
  116. float: right;
  117. font-size: 24px;
  118. font-weight: bold;
  119. cursor: pointer;
  120. height: 30px;
  121. line-height: 30px;
  122. }
  123. }
  124. }
  125. .log-list{
  126. margin: 0 auto 30px;
  127. padding: 0 10px;
  128. height: 100%;
  129. overflow: auto;
  130. }
  131. .log-item{
  132. box-sizing: border-box;
  133. width: 100%;
  134. padding: 5px;
  135. }
  136. .avatar{
  137. float: left;
  138. width: 30px;
  139. height: 30px;
  140. img{
  141. width: 100%;
  142. height: 100%;
  143. border-radius: 50%;
  144. }
  145. }
  146. .message{
  147. display: inline-block;
  148. margin: 4px 15px;
  149. padding: 3px 5px;
  150. font-size: 14px;
  151. background: #fff;
  152. font-size: 12px;
  153. }
  154. .mine {
  155. overflow: hidden;
  156. padding-right: 10px;
  157. text-align: right;
  158. .avatar{
  159. float: right;
  160. }
  161. }
  162. .time {
  163. text-align: center;
  164. span {
  165. font-size: 12px;
  166. display: inline-block;
  167. padding: 3px 8px;
  168. color: #000;
  169. border-radius: 3px;
  170. }
  171. }
  172. .page {
  173. position: sticky;
  174. width: 100%;
  175. background: #fff;
  176. bottom: 0;
  177. height: 33px;
  178. .rs-pagination{
  179. text-align: right;
  180. }
  181. .rs-pagination .pagination{
  182. margin: 0;
  183. }
  184. }
  185. .down-link {
  186. color: #000;
  187. text-decoration: none;
  188. cursor: pointer;
  189. &:hover .down-link-file {
  190. text-decoration: underline;
  191. }
  192. }
  193. .down-link-icon {
  194. font-size: 30px;
  195. }
  196. .down-link-file {
  197. display: inline-block;
  198. margin-left: 10px;
  199. }
  200. }
  201. .collapse-enter-active, .collapse-leave-active {
  202. transition: all 0.5s;
  203. }
  204. .collapse-enter, .collapse-leave-to {
  205. width: 0;
  206. transform: translate3d(350px);
  207. }
  208. </style>