History.vue 4.8 KB

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