index.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. methods: {
  59. setListFans({
  60. detail
  61. }) {
  62. let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
  63. worksListCopy.forEach(item => {
  64. if (item.user.uid == detail) {
  65. item.isFans = true
  66. }
  67. })
  68. this.setData({
  69. worksListCopy
  70. })
  71. },
  72. addCommentNum({
  73. detail
  74. }) {
  75. let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
  76. worksListCopy.forEach(item => {
  77. if (item.userRead.id == detail) {
  78. item.userRead.commentAmount = ++item.userRead.commentAmount
  79. }
  80. })
  81. this.setData({
  82. worksListCopy
  83. })
  84. }
  85. },
  86. })