index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.setData({
  24. currentId: res.dataset.id
  25. })
  26. } else {
  27. this.playAudio({
  28. currentTarget: {
  29. dataset: res.dataset
  30. }
  31. })
  32. }
  33. }
  34. })
  35. }
  36. }
  37. },
  38. // 是否自动播放
  39. autoPlay: {
  40. type: Boolean,
  41. value: true
  42. },
  43. videoType: {
  44. type: String,
  45. // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案,collection为收藏时的样式,excellent优秀作品展播
  46. value: 'public'
  47. },
  48. // 是否在tabbar页面使用
  49. tabBarPadding: {
  50. type: Boolean,
  51. value: false
  52. }
  53. },
  54. data: {
  55. worksListCopy: {}
  56. },
  57. methods: {
  58. setListFans({
  59. detail
  60. }) {
  61. let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
  62. worksListCopy.forEach(item => {
  63. if (item.user.uid == detail) {
  64. item.isFans = true
  65. }
  66. })
  67. this.setData({
  68. worksListCopy
  69. })
  70. },
  71. addCommentNum({
  72. detail
  73. }) {
  74. let worksListCopy = JSON.parse(JSON.stringify(this.data.worksListCopy))
  75. worksListCopy.forEach(item => {
  76. if (item.userRead.id == detail) {
  77. item.userRead.commentAmount = ++item.userRead.commentAmount
  78. }
  79. })
  80. this.setData({
  81. worksListCopy
  82. })
  83. }
  84. },
  85. })