index.js 2.8 KB

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