index.js 3.0 KB

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