index.js 4.5 KB

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