History.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. >
  29. <video-card :video="record"></video-card>
  30. </el-timeline-item>
  31. </el-timeline>
  32. </el-col>
  33. </el-row>
  34. <el-row v-else class="not-result">
  35. <el-col :span="12" :offset="6">
  36. <img src="@/assets/img/icon/not-history.png">
  37. <div>无播放历史</div>
  38. </el-col>
  39. </el-row>
  40. <el-row class="movie-list">
  41. <el-col v-for="(video,index) in videos" :key="index" :md="6" :sm="8" :xs="12">
  42. <video-card :video="video" date-tit="上次播放:">
  43. <el-button
  44. slot="remove"
  45. class="remove-slot"
  46. type="danger"
  47. icon="el-icon-delete"
  48. circle
  49. size="small"
  50. title="移除该历史记录"
  51. @click.stop="removeHistory(video)"
  52. />
  53. </video-card>
  54. </el-col>
  55. </el-row>
  56. </div>
  57. </template>
  58. <script>
  59. import VideoCard from '@/components/card/VideoCard'
  60. import { getVisitRecord } from "@/api/visit";
  61. export default {
  62. name: 'History',
  63. components: { VideoCard },
  64. data() {
  65. return {
  66. videos: [],
  67. uid: 11011,
  68. reverse: false,
  69. totalSize: 0,
  70. visitList: []
  71. }
  72. },
  73. created() {
  74. document.title = '我的历史记录'
  75. getVisitRecord(1).then(res => {
  76. if (res.code === 0) {
  77. this.totalSize = res.data.totalSize
  78. this.visitList = res.data.list
  79. }
  80. })
  81. },
  82. methods: {
  83. // 清除当前历史记录
  84. removeHistory(video) {
  85. this.$confirm('确认移除吗?', '提示', {
  86. confirmButtonText: '确定',
  87. cancelButtonText: '取消',
  88. type: 'warning'
  89. }).then(() => {
  90. // 确认
  91. /* deleteHistory(this.uid, video.vid).then(res => {
  92. // 将要删除的当前video对象移除数组
  93. // 获取下标
  94. const index = this.videos.indexOf(video)
  95. if (index > -1) {
  96. this.videos.splice(index, 1)
  97. }
  98. })*/
  99. this.$message({
  100. type: 'success',
  101. message: '移除成功!'
  102. })
  103. }).catch(() => {
  104. this.$message({
  105. type: 'info',
  106. message: '已取消'
  107. })
  108. })
  109. },
  110. // 清空所有历史记录
  111. removeAll() {
  112. // 移除所有收藏
  113. this.$confirm('确认移除所有播放历史记录吗?', '提示', {
  114. confirmButtonText: '确定',
  115. cancelButtonText: '取消',
  116. type: 'warning'
  117. }).then(() => {
  118. const arr = []
  119. for (const i of this.videos) {
  120. arr.push(i.vid)
  121. }
  122. // const vidStr = arr.join(',')
  123. // 确认
  124. /* deleteHistory(this.uid, vidStr).then(res => {
  125. this.videos = []
  126. })*/
  127. this.$message({
  128. type: 'success',
  129. message: '移除成功!'
  130. })
  131. }).catch(() => {
  132. this.$message({
  133. type: 'info',
  134. message: '已取消'
  135. })
  136. })
  137. }
  138. }
  139. }
  140. </script>
  141. <style scoped>
  142. #history-list {
  143. padding-left: 6%;
  144. padding-right: 6%;
  145. padding-top: 30px;
  146. }
  147. .bread {
  148. font-size: 15px;
  149. }
  150. .movie-list {
  151. padding-top: 15px;
  152. }
  153. .reslut {
  154. color: red;
  155. }
  156. .not-result {
  157. padding-top: 100px;
  158. padding-bottom: 100px;
  159. text-align: center;
  160. }
  161. .remove-slot {
  162. position: absolute;
  163. right: 5px;
  164. bottom: 2px;
  165. }
  166. </style>