index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import behavior from '~/mixins/video'
  2. import {
  3. submitPlayLog
  4. } from '~/api/video'
  5. let _observer
  6. let timer;
  7. let preId = ''
  8. Component({
  9. behaviors: [behavior],
  10. properties: {
  11. worksList: {
  12. type: Array,
  13. value: [],
  14. observer(newVal) {
  15. this.setData({
  16. worksListCopy: newVal
  17. })
  18. if (this.properties.autoPlay) {
  19. // 自动播放
  20. this._observer = this.createIntersectionObserver({
  21. observeAll: true
  22. })
  23. this._observer.relativeTo('.playLine')
  24. .observe('.videoPreview', (res) => {
  25. let intersectionRatio = res.intersectionRatio
  26. if (intersectionRatio > 0 && preId != res.dataset.id) {
  27. clearTimeout(timer);
  28. timer = setTimeout(() => {
  29. preId = res.dataset.id
  30. submitPlayLog({
  31. userReadId: res.dataset.id,
  32. playStopTime: 1000
  33. })
  34. // 0视频1音频
  35. if (res.dataset.type == 0) {
  36. this.resetAudio();
  37. this.setData({
  38. currentId: res.dataset.id,
  39. })
  40. } else {
  41. this.playAudio({
  42. currentTarget: {
  43. dataset: res.dataset
  44. }
  45. })
  46. }
  47. }, 600);
  48. }
  49. })
  50. }
  51. }
  52. },
  53. // 是否自动播放
  54. autoPlay: {
  55. type: Boolean,
  56. value: true
  57. },
  58. videoType: {
  59. type: String,
  60. // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,collection为收藏时的样式,
  61. value: 'public',
  62. },
  63. // 是否在tabbar页面使用
  64. tabBarPadding: {
  65. type: Boolean,
  66. value: false,
  67. }
  68. },
  69. data: {
  70. worksListCopy: {}
  71. },
  72. lifetimes: {
  73. detached: function () {
  74. // 在组件实例被从页面节点树移除时执行
  75. this.resetAudio()
  76. },
  77. },
  78. methods: {
  79. setListFans({
  80. detail
  81. }) {
  82. let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
  83. worksListCopy.forEach(item => {
  84. if (item.user.uid == detail) {
  85. item.isFans = true
  86. }
  87. })
  88. this.setData({
  89. worksListCopy
  90. })
  91. },
  92. addCommentNum({
  93. detail
  94. }) {
  95. let worksListCopy = this.data.worksListCopy
  96. let index = worksListCopy.findIndex(item => {
  97. return item.userRead.id == detail
  98. })
  99. if (index != -1) {
  100. this.setData({
  101. [`worksListCopy[${index}].userRead.commentAmount`]: ++worksListCopy[index].userRead.commentAmount
  102. })
  103. }
  104. },
  105. deleteVideo({
  106. detail
  107. }) {
  108. let worksListCopy = this.properties.worksListCopy.filter(item => {
  109. return item.userRead.id != detail
  110. })
  111. this.setData({
  112. worksListCopy
  113. })
  114. },
  115. },
  116. })