index.js 1.9 KB

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