index.js 5.5 KB

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