index.js 2.9 KB

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