History.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div id="history-list">
  3. <!--搜索结果面包屑-->
  4. <el-breadcrumb
  5. v-if="this.$route.path.indexOf('history') > -1"
  6. class="bread"
  7. separator-class="el-icon-arrow-right"
  8. >
  9. <el-breadcrumb-item :to="{ path: '' }"><a href="/">返回首页</a></el-breadcrumb-item>
  10. <el-breadcrumb-item>播放历史记录:共<span class="reslut">({{ totalSize }}}</span>条</el-breadcrumb-item>
  11. </el-breadcrumb>
  12. <el-row v-if="visitList.length !== 0" class="movie-list">
  13. <el-col style="text-align: center">
  14. <el-button
  15. type="danger"
  16. icon="el-icon-delete"
  17. round
  18. title="一键清空历史"
  19. @click="removeAll"
  20. >一键清空历史</el-button>
  21. </el-col>
  22. <el-col :md="8">
  23. <el-timeline :reverse="reverse">
  24. <el-timeline-item
  25. v-for="(record, index) in visitList"
  26. :key="index"
  27. :timestamp="record.createAt"
  28. placement="top"
  29. >
  30. <video-card :video="record"></video-card>
  31. <el-button
  32. type="danger"
  33. icon="el-icon-delete"
  34. circle
  35. size="small"
  36. title="移除该历史记录"
  37. @click.stop="removeHistory(record.videoId)"
  38. />
  39. </el-timeline-item>
  40. </el-timeline>
  41. </el-col>
  42. </el-row>
  43. <el-row v-else class="not-result">
  44. <el-col :span="12" :offset="6">
  45. <img src="@/assets/img/icon/not-history.png">
  46. <div>你还没有看过任何东西呢</div>
  47. </el-col>
  48. </el-row>
  49. </div>
  50. </template>
  51. <script>
  52. import VideoCard from '@/components/card/VideoCard'
  53. import { getVisitRecord } from "@/api/visit";
  54. export default {
  55. name: 'History',
  56. components: { VideoCard },
  57. data() {
  58. return {
  59. reverse: false,
  60. totalSize: 0,
  61. nextId: 0,
  62. nextId1: 0,
  63. visitList: [],
  64. showEmpty: false
  65. }
  66. },
  67. created() {
  68. document.title = '我的历史记录'
  69. this.getVisitRecordWrapper(this.nextId)
  70. },
  71. mounted() {
  72. window.addEventListener("scroll", this.handleScrollEvent);
  73. },
  74. methods: {
  75. handleScrollEvent() {
  76. if (document.body.scrollHeight <= window.screen.height + document.documentElement.scrollTop) {
  77. console.log('滚动条触底, 加载数据')
  78. if (this.nextId1 !== this.nextId) {
  79. this.nextId1 = this.nextId
  80. this.getVisitRecordWrapper(this.nextId)
  81. }
  82. }
  83. },
  84. getVisitRecordWrapper(nextId) {
  85. getVisitRecord(nextId).then(res => {
  86. if (res.code === 0) {
  87. const resData = res.data
  88. this.totalSize = resData.totalSize
  89. this.nextId = resData.nextId
  90. for (const item of resData.list) {
  91. this.visitList.push(item)
  92. }
  93. }
  94. })
  95. },
  96. // 清除当前历史记录
  97. removeHistory(videoId) {
  98. this.$confirm('确认移除吗?', '提示', {
  99. confirmButtonText: '确定',
  100. cancelButtonText: '取消',
  101. type: 'warning'
  102. }).then(() => {
  103. console.log('删除 ' + videoId + ' 这条记录')
  104. // 确认
  105. /* deleteHistory(this.uid, video.vid).then(res => {
  106. // 将要删除的当前video对象移除数组
  107. // 获取下标
  108. const index = this.videos.indexOf(video)
  109. if (index > -1) {
  110. this.videos.splice(index, 1)
  111. }
  112. })*/
  113. this.$message({
  114. type: 'success',
  115. message: '移除成功!'
  116. })
  117. }).catch(() => {
  118. this.$message({
  119. type: 'info',
  120. message: '已取消'
  121. })
  122. })
  123. },
  124. // 清空所有历史记录
  125. removeAll() {
  126. // 移除所有收藏
  127. this.$confirm('确认移除所有播放历史记录吗?', '提示', {
  128. confirmButtonText: '确定',
  129. cancelButtonText: '取消',
  130. type: 'warning'
  131. }).then(() => {
  132. console.log('删除全部记录')
  133. /*const arr = []
  134. for (const i of this.videos) {
  135. arr.push(i.vid)
  136. }*/
  137. // const vidStr = arr.join(',')
  138. // 确认
  139. /* deleteHistory(this.uid, vidStr).then(res => {
  140. this.videos = []
  141. })*/
  142. this.$message({
  143. type: 'success',
  144. message: '移除成功!'
  145. })
  146. }).catch(() => {
  147. this.$message({
  148. type: 'info',
  149. message: '已取消'
  150. })
  151. })
  152. }
  153. }
  154. }
  155. </script>
  156. <style scoped>
  157. #history-list {
  158. padding-left: 6%;
  159. padding-right: 6%;
  160. padding-top: 30px;
  161. }
  162. .bread {
  163. font-size: 15px;
  164. }
  165. .movie-list {
  166. padding-top: 15px;
  167. }
  168. .reslut {
  169. color: red;
  170. }
  171. .not-result {
  172. padding-top: 100px;
  173. padding-bottom: 100px;
  174. text-align: center;
  175. }
  176. .remove-slot {
  177. position: absolute;
  178. right: 5px;
  179. bottom: 2px;
  180. }
  181. </style>