index.js 2.8 KB

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