index.js 2.8 KB

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