|
@@ -2,7 +2,8 @@ import {
|
|
|
getSelfRead
|
|
|
} from '~/api/user'
|
|
|
import {
|
|
|
- setVideoStatus
|
|
|
+ setVideoStatus,
|
|
|
+ likeVideo
|
|
|
} from '~/api/video'
|
|
|
let videoContext = null
|
|
|
Page({
|
|
@@ -101,7 +102,13 @@ Page({
|
|
|
status: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
|
|
|
}
|
|
|
let res = await setVideoStatus(data)
|
|
|
- this.getSelfRead()
|
|
|
+ let index = this.data.list.findIndex(item => {
|
|
|
+ return item.userRead.id == info.id
|
|
|
+ })
|
|
|
+ let status = `list[${index}].userRead.status`;
|
|
|
+ this.setData({
|
|
|
+ [status]: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
|
|
|
+ })
|
|
|
if (res.status == 'DISABLE') {
|
|
|
wx.showToast({
|
|
|
title: '该作品仅自己可见',
|
|
@@ -110,6 +117,69 @@ Page({
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
+ // 下载视频
|
|
|
+ download: function ({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '保存到本地',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ const {
|
|
|
+ url
|
|
|
+ } = currentTarget.dataset;
|
|
|
+ wx.downloadFile({
|
|
|
+ url,
|
|
|
+ success(res) {
|
|
|
+ // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
|
|
|
+ if (res.statusCode === 200) {
|
|
|
+ wx.saveVideoToPhotosAlbum({
|
|
|
+ filePath: res.tempFilePath,
|
|
|
+ success(res) {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '成功保存到相册!',
|
|
|
+ duration: 3000,
|
|
|
+ icon: 'success',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail() {
|
|
|
+ wx.hideLoading()
|
|
|
+ wx.showToast({
|
|
|
+ title: '网络不给力',
|
|
|
+ icon: 'error',
|
|
|
+ duration: 3000,
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 点赞
|
|
|
+ async likeVideo({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ let {
|
|
|
+ id,
|
|
|
+ like
|
|
|
+ } = currentTarget.dataset;
|
|
|
+ if (like) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ await likeVideo(id)
|
|
|
+ let index = this.data.list.findIndex(item => {
|
|
|
+ return item.userRead.id == id
|
|
|
+ })
|
|
|
+ let likeStr = `list[${index}].isLike`;
|
|
|
+ let likeNumStr = `list[${index}].userRead.likeAmount`;
|
|
|
+ this.setData({
|
|
|
+ [likeStr]: true,
|
|
|
+ [likeNumStr]: this.data.list[index].userRead.likeAmount + 1
|
|
|
+ })
|
|
|
+ },
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|