index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import {
  2. setVideoStatus,
  3. likeVideo
  4. } from '~/api/video'
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. videoInfo: {
  11. type: Object,
  12. value: {}
  13. },
  14. index: {
  15. type: Number,
  16. },
  17. currentId: {
  18. type: Number,
  19. }
  20. },
  21. data: {
  22. },
  23. methods: {
  24. // 播放视频
  25. playVideo() {
  26. this.triggerEvent('playVideo', this.properties.videoInfo.userRead.id)
  27. },
  28. // 分享视频
  29. shareVideo() {
  30. let videoInfo = this.properties.videoInfo
  31. console.log(videoInfo);
  32. },
  33. // 设置视频公开还是隐私
  34. async setVideoPublic() {
  35. let info = this.properties.videoInfo.userRead
  36. let data = {
  37. id: info.id,
  38. status: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
  39. }
  40. let res = await setVideoStatus(data)
  41. if (res.status == 'DISABLE') {
  42. wx.showToast({
  43. title: '该作品仅自己可见',
  44. icon: 'none',
  45. duration: 2000
  46. })
  47. }
  48. let index = this.properties.index
  49. let status = `list[${index}].userRead.status`;
  50. let val = info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
  51. let options = {
  52. [status]: val
  53. }
  54. this.triggerEvent('changStatus', options)
  55. },
  56. // 点赞
  57. async likeVideo() {
  58. let {
  59. id
  60. } = this.properties.videoInfo.userRead
  61. if (this.properties.videoInfo.isLike) {
  62. return
  63. }
  64. await likeVideo(id)
  65. let index = this.properties.index
  66. let likeStr = `list[${index}].isLike`;
  67. let likeNumStr = `list[${index}].userRead.likeAmount`;
  68. let options = {
  69. [likeStr]: true,
  70. [likeNumStr]: this.properties.videoInfo.userRead.likeAmount + 1
  71. }
  72. this.triggerEvent('changStatus', options)
  73. },
  74. // 下载视频
  75. download() {
  76. wx.showLoading({
  77. title: '保存到本地',
  78. mask: true
  79. })
  80. const url = this.properties.videoInfo.userRead.markPath || ''
  81. wx.downloadFile({
  82. url,
  83. success(res) {
  84. if (res.statusCode === 200) {
  85. wx.saveVideoToPhotosAlbum({
  86. filePath: res.tempFilePath,
  87. success(res) {
  88. wx.hideLoading()
  89. wx.showToast({
  90. title: '成功保存到相册!',
  91. duration: 3000,
  92. icon: 'success',
  93. mask: true
  94. })
  95. },
  96. fail() {
  97. wx.hideLoading()
  98. wx.showToast({
  99. title: '网络不给力',
  100. icon: 'error',
  101. duration: 3000,
  102. mask: true
  103. })
  104. }
  105. })
  106. }
  107. },
  108. fail() {
  109. wx.hideLoading()
  110. wx.showToast({
  111. title: '网络不给力',
  112. icon: 'error',
  113. duration: 3000,
  114. mask: true
  115. })
  116. }
  117. })
  118. },
  119. //评论
  120. openComment() {},
  121. // 删除
  122. delete() {
  123. let {
  124. id
  125. } = this.properties.videoInfo.userRead
  126. wx.showModal({
  127. title: '确认删除吗?',
  128. content: '作品将被永久删除,无法找回。',
  129. confirmText: '确认',
  130. cancelText: '取消',
  131. success: async (res) => {
  132. if (res.confirm) {
  133. let data = {
  134. id,
  135. status: 'DEL'
  136. }
  137. await setVideoStatus(data)
  138. wx.showToast({
  139. title: '删除成功!',
  140. icon: "none"
  141. })
  142. this.triggerEvent('getList')
  143. }
  144. }
  145. })
  146. },
  147. }
  148. })