小程序体验
js逻辑
var services = require('../../lib/service')
var ReceiverOptions = null;
Page({
data: {
loading: false,
videoInfo: {},
searchLoadingStatus: 2,
typeCode: 0,
searchKeyWord: '',
systemInfo: {},
videoDownLoadStatus: 0,
videoDownProgress: 0,
videoPlayCoverList: [],
showDownLoadBtn: false,
showShareVideoBtn: false,
showOnlineKf: false,
creditsAmountSum: 0,
downLoadVideoUrl: '',
downloadVideoWaitRemindText: '正在生成视频地址,请稍后...'
},
onLoad(options) {
var that = this;
wx.getSystemInfo({
success: function(res) {
that.setData({
systemInfo: res
});
console.log(res);
}
});
getApp().getWxLoginInfo(function() {
that.loadSupportPlat(true);
that.videoSystemSetting();
});
},
onShow() {
var that = this;
var userLoginStatus = getApp().globalData.UserInfo.UserLoginStatus;
if (userLoginStatus) {
that.loadSupportPlat(false);
}
wx.getClipboardData({
success(res) {
console.log(res.data);
var linkStr = res.data;
if (linkStr.indexOf('http:') >= 0 || linkStr.indexOf('https:') >= 0) {
wx.setClipboardData({
data: ' ',
success(clearRes) {
wx.hideToast();
}
})
wx.showModal({
title: '是否粘贴剪切板中的链接地址',
content: linkStr,
success(res) {
if (res.confirm) {
that.setData({
searchKeyWord: linkStr
});
}
}
})
}
}
})
that.setData({
searchLoadingStatus: 2
});
},
loadSupportPlat: function(loading) {
var that = this;
services.service('minivideo/getplatlist', {
"WxUserId": 0
},
function(res) {
console.log(res);
that.setData({
videoPlayCoverList: res.data.Data
});
}, null, null, loading);
},
loadShareVideo: function() {
let that = this;
var videoId = that.data.videoInfo.videoId;
if (videoId > 0) {
services.service('minivideo/getvideoinfo', {
"WxUserId": 0,
"VideoId": videoId
},
function(res) {
console.log(res);
if (res.data.Status) {
var analysisStatus = res.data.Data.AnalysisStatus;
var showDownLoadBtn = false;
if (analysisStatus == 3) {
showDownLoadBtn = true;
}
that.setData({
downloadVideoWaitRemindText: '',
showDownLoadBtn: showDownLoadBtn,
showShareVideoBtn: true,
videoInfo: {
videoId: videoId,
videourl: res.data.Data.VideoUrl
},
downLoadVideoUrl: res.data.Data.VideoUrl
});
}
}, null, null, true);
} else {
}
},
videoSystemSetting: function() {
let that = this;
services.service('minivideo/getconfig', {},
function(res) {
console.log(res);
if (res.data.Status) {
that.setData({
showShareVideoBtn: res.data.Data.ShowShareVideo,
showOnlineKf: res.data.Data.ShowOnlineKf
});
}
}, null, null, false);
},
btnSaveVideo: function() {
var that = this;
wx.authorize({
scope: "scope.writePhotosAlbum",
success: function() {
var downLoadStatus = that.data.videoDownLoadStatus;
if (downLoadStatus == 0) {
var videourl = that.data.downLoadVideoUrl;
if (videourl == null || videourl == '') {
that.showToast('请先提取视频');
return;
}
that.setData({
videoDownLoadStatus: 1,
videoDownProgress: 0
})
const downloadTask = wx.downloadFile({
url: videourl,
success(res) {
if (res.statusCode === 200) {
wx.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
that.showSuccessToast('已保存到相册');
},
fail(res) {
console.log(res);
that.showToast('保存失败');
}
})
}
},
fail(res) {
that.showToast('下载视频失败');
},
complete(res) {
that.setData({
videoDownLoadStatus: 0
})
}
})
downloadTask.onProgressUpdate(function(res) {
that.setData({
videoDownProgress: res.progress
})
})
}
},
fail: function() {
that.showToast('授权保存视频到相册失败,请删除该小程序重新授权');
}
});
},
copyVideoLink: function() {
var that = this;
var videoUrl = that.data.videoInfo.videourl;
wx.setClipboardData({
data: videoUrl,
success(res) {
that.showToast('复制成功')
}
});
},
bindSearchTap: function(e) {
console.log('开始提取视频')
console.log(e);
var that = this;
var searchLoadingStatus = that.data.searchLoadingStatus;
if (searchLoadingStatus != 1) {
that.setData({
searchLoadingStatus: 1
});
var _userInfo = e.detail.userInfo;
if (_userInfo != null && _userInfo != undefined) {
getApp().authorUserInfo(_userInfo, function(data) {
that.getVideoPlayUrl();
}, false);
} else {
that.showToast("请先允许微信授权");
that.setData({
searchLoadingStatus: 2
});
}
}
},
bindUseCourse: function(e) {
wx.navigateTo({
url: '../useCourse/useCourse'
});
},
navigateToLocationMiniProgram: function(e) {
var wxUserId = getApp().globalData.UserInfo.WxUserId;
wx.navigateToMiniProgram({
appId: 'wxb91f7b85c23f0624',
path: 'pages/home/home?skip=' + wxUserId,
envVersion: 'release',
success(res) {
},
fail(res) {
that.showToast('调起小程序失败,请稍后重试');
}
})
},
clearInput: function() {
var that = this;
that.setData({
searchKeyWord: ''
});
},
searchInputMonitor: function(e) {
var that = this;
that.setData({
searchKeyWord: e.detail.value
});
},
getVideoPlayUrl: function() {
var that = this;
that.startGetVideoPlayUrl();
},
startGetVideoPlayUrl: function() {
var that = this;
var wxUserId = getApp().globalData.UserInfo.WxUserId;
var keyword = that.data.searchKeyWord;
services.service('minivideo/addvideourl', {
WxUserId: wxUserId,
OriginalUrl: keyword,
XcxTypeCode: 1
},
function(res) {
if (res.data.Status) {
var videoUrl = res.data.Data.VideoUrl;
var videoRecordId = res.data.Data.VideoRecordId;
var videoImgs = res.data.Data.Imgs;
that.setData({
videoInfo: {
videoId: videoRecordId,
videourl: videoUrl,
title: '',
imgs: videoImgs
}
});
var needDownLoadToServer = res.data.Data.NeedDownLoadToServer;
if (needDownLoadToServer) {
if (videoUrl != null && videoUrl != '') {
that.downLoadVideoToServer(wxUserId, videoUrl, videoRecordId);
}
} else {
that.setData({
downLoadVideoUrl: videoUrl,
showDownLoadBtn: true
});
}
} else {
wx.showModal({
content: res.data.Msg,
showCancel: false
})
}
}, null,
function() {
that.setData({
searchLoadingStatus: 2
});
})
},
downLoadVideoToServer: function(wxUserId, videoUrl, videoRecordId) {
var that = this;
that.setData({
showDownLoadBtn: false,
downloadVideoWaitRemindText: '正在生成视频地址,请稍后...'
});
services.service('minivideo/downloadvideo', {
"WxUserId": wxUserId,
"VideoUrl": videoUrl,
"VideoRecordId": videoRecordId
},
function(res) {
if (res.data.Status) {
var url = res.data.Data.Url;
that.setData({
downLoadVideoUrl: url,
showDownLoadBtn: true
});
} else {
that.showToast(res.data.Msg);
that.setData({
showDownLoadBtn: false,
downloadVideoWaitRemindText: res.data.Msg
});
}
}, null, null, false);
},
getTimesMore: function() {
wx.navigateTo({
url: '../getTimesMore/getTimesMore'
});
},
showToast(title) {
wx.showToast({
title: title,
icon: 'none',
duration: 2000
})
},
onShareAppMessage: function(res) {
let that = this;
return {
path: '/pages/home/home'
}
}
});