123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- import {
- storeBindingsBehavior
- } from 'mobx-miniprogram-bindings'
- import {
- store
- } from '~/store/index'
- import {
- setVideoStatus,
- likeVideo,
- collectVideo,
- } from '~/api/video'
- import {
- setFans
- } from '~/api/user'
- Component({
- behaviors: [storeBindingsBehavior],
- storeBindings: {
- store,
- fields: {
- pkData: 'pkData'
- },
- actions: {
- setPkData: 'setPkData'
- }
- },
- /**
- * 组件的属性列表
- */
- properties: {
- videoInfo: {
- type: Object,
- value: {},
- observer(newVal) {
- this.setData({
- videoInfoCopy: newVal
- })
- }
- },
- videoType: {
- type: String,
- // value 为public时是默认公共样式,为my时为“我的”样式,展示下载删除是否公开,pk为pk的样式文案
- value: 'public'
- },
- currentId: {
- type: Number,
- }
- },
- data: {
- selfUid: wx.getStorageSync('uid'),
- videoInfoCopy: {}
- },
- methods: {
- // 播放视频
- playVideo() {
- this.triggerEvent('playVideo', this.properties.videoInfo.userRead.id)
- },
- // 设置视频公开还是隐私
- async setVideoPublic() {
- let info = this.properties.videoInfo.userRead
- let data = {
- id: info.id,
- status: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
- }
- let res = await setVideoStatus(data)
- if (res.status == 'DISABLE') {
- wx.showToast({
- title: '该作品仅自己可见',
- icon: 'none',
- duration: 2000
- })
- }
- this.setData({
- ['videoInfoCopy.userRead.status']: info.status === 'NORMAL' ? 'DISABLE' : 'NORMAL'
- })
- },
- // 点赞
- async likeVideo() {
- let {
- id
- } = this.properties.videoInfo.userRead
- if (this.properties.videoInfo.isLike) {
- return
- }
- await likeVideo(id)
- this.setData({
- ['videoInfoCopy.isLike']: true,
- ['videoInfoCopy.userRead.likeAmount']: this.data.videoInfoCopy.userRead.likeAmount + 1
- })
- },
- // 下载视频
- download() {
- wx.showLoading({
- title: '保存到本地',
- mask: true
- })
- const url = this.properties.videoInfo.userRead.markPath || ''
- wx.downloadFile({
- url,
- success(res) {
- 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
- })
- }
- })
- }
- },
- fail() {
- wx.hideLoading()
- wx.showToast({
- title: '网络不给力',
- icon: 'error',
- duration: 3000,
- mask: true
- })
- }
- })
- },
- //评论
- openComment() {
- this.triggerEvent('openComment')
- },
- // 删除
- delete() {
- let {
- id
- } = this.properties.videoInfo.userRead
- wx.showModal({
- title: '确认删除吗?',
- content: '作品将被永久删除,无法找回。',
- confirmText: '确认',
- cancelText: '取消',
- success: async (res) => {
- if (res.confirm) {
- let data = {
- id,
- status: 'DEL'
- }
- await setVideoStatus(data)
- wx.showToast({
- title: '删除成功!',
- icon: "none"
- })
- this.triggerEvent('getList')
- }
- }
- })
- },
- // 收藏课程
- async collect() {
- let {
- id,
- type,
- uid
- } = this.properties.videoInfo.userRead
- if (wx.getStorageSync('uid') == uid) {
- return
- }
- await collectVideo({
- targetCode: id,
- favoritesType: type
- })
- this.setData({
- ['videoInfoCopy.isFavorites']: !this.data.videoInfoCopy.isFavorites
- })
- },
- // 关注
- async setFans() {
- if (this.properties.videoInfo.isFans) {
- return
- }
- await setFans({
- uid: this.properties.videoInfo.user.uid
- })
- this.triggerEvent('setListFans', this.properties.videoInfo.user.uid)
- },
- toPkPage() {
- let videoInfo = this.data.videoInfoCopy
- if (this.properties.videoType == 'pk') {
- console.log(videoInfo);
- this.setPkData({
- nickName: videoInfo.user.nickName || videoInfo.user.eid,
- avatar: videoInfo.user.avatar,
- score: videoInfo.userRead.score,
- audioPath: videoInfo.userRead.audioPath,
- exampleId: videoInfo.userRead.exampleId
- })
- }
- let readId = videoInfo.userRead.id
- let url = this.properties.videoType == 'public' ? `/pages/pkPage/index?videoId=${readId}` : `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&readingType=pk`
- wx.navigateTo({
- url
- })
- },
- jumpUserInfo() {
- wx.navigateTo({
- url: `/pages/personal/index?uid=${this.data.videoInfoCopy.user.uid}`,
- })
- },
- // 控制音频播放
- audioPlay() {
- this.triggerEvent('playAudio')
- }
- }
- })
|