index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. nextvideo: res.dataset.nextvideo || ""
  40. })
  41. } else {
  42. this.playAudio({
  43. currentTarget: {
  44. dataset: res.dataset
  45. }
  46. })
  47. this.setData({
  48. nextvideo: res.dataset.nextvideo || ""
  49. })
  50. }
  51. }, 600);
  52. }
  53. })
  54. }
  55. }
  56. },
  57. // 是否自动播放
  58. autoPlay: {
  59. type: Boolean,
  60. value: true
  61. },
  62. videoType: {
  63. type: String,
  64. // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,collection为收藏时的样式,
  65. value: 'public',
  66. },
  67. // 是否在tabbar页面使用
  68. tabBarPadding: {
  69. type: Boolean,
  70. value: false,
  71. }
  72. },
  73. data: {
  74. worksListCopy: {},
  75. nextvideo: ''
  76. },
  77. lifetimes: {
  78. detached: function () {
  79. // 在组件实例被从页面节点树移除时执行
  80. this.resetAudio()
  81. },
  82. },
  83. methods: {
  84. setListFans({
  85. detail
  86. }) {
  87. let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
  88. worksListCopy.forEach(item => {
  89. if (item.user.uid == detail) {
  90. item.isFans = true
  91. }
  92. })
  93. this.setData({
  94. worksListCopy
  95. })
  96. },
  97. addCommentNum({
  98. detail
  99. }) {
  100. let worksListCopy = this.data.worksListCopy
  101. let index = worksListCopy.findIndex(item => {
  102. return item.userRead.id == detail
  103. })
  104. if (index != -1) {
  105. this.setData({
  106. [`worksListCopy[${index}].userRead.commentAmount`]: ++worksListCopy[index].userRead.commentAmount
  107. })
  108. }
  109. },
  110. deleteVideo({
  111. detail
  112. }) {
  113. let worksListCopy = this.properties.worksListCopy.filter(item => {
  114. return item.userRead.id != detail
  115. })
  116. this.setData({
  117. worksListCopy
  118. })
  119. },
  120. },
  121. })