index.js 2.5 KB

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