修改七牛上传
parent
162da8b1d1
commit
ce5e3b7d80
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<view class="">
|
||||
<view class="disjbac fw">
|
||||
<view @tap="goDetail(item.id)" class="radius8 bacf pad12 boxshow1 width48_6 mar-s20" v-for="(item,index) in list" :key="index">
|
||||
<view @tap="goDetail(item.id,item.is_buy)" class="radius8 bacf pad12 boxshow1 width48_6 mar-s20" v-for="(item,index) in list" :key="index">
|
||||
<image :src="item.cover" style="height: 226rpx;" mode="aspectFill" class="width100 animated fadeIn" lazy-load></image>
|
||||
<view class="fon24 pad-zy8 disjb fc" style="color: #262626;">
|
||||
<view class="clips2 mar-sx10" style="height: 64rpx;">{{item.name}}</view>
|
||||
|
@ -33,8 +33,8 @@
|
|||
};
|
||||
},
|
||||
methods:{
|
||||
goDetail(id){
|
||||
this.$emit('goDetail',id);
|
||||
goDetail(id,is_buy){
|
||||
this.$emit('goDetail',id,is_buy);
|
||||
},
|
||||
// 调起弹框
|
||||
buyPopu(id,is_buy){
|
||||
|
@ -44,7 +44,7 @@
|
|||
this.$refs.refbuy.isLoading = true;
|
||||
this.$refs.refbuy.getSpec(id);
|
||||
} else {
|
||||
this.$emit('goDetail',id);
|
||||
this.$emit('goDetail',id,is_buy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,117 @@
|
|||
// created by gpake
|
||||
(function() {
|
||||
|
||||
var config = {
|
||||
qiniuUploadURL: '',
|
||||
qiniuImageURLPrefix: '',
|
||||
qiniuUploadToken: '',
|
||||
qiniuUploadTokenURL: '',
|
||||
qiniuUploadTokenFunction: null
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
upload: upload,
|
||||
}
|
||||
|
||||
// 在整个程序生命周期中,只需要 init 一次即可
|
||||
// 如果需要变更参数,再调用 init 即可
|
||||
function init(options) {
|
||||
config = {
|
||||
qiniuUploadURL: '',
|
||||
qiniuImageURLPrefix: '',
|
||||
qiniuUploadToken: '',
|
||||
qiniuUploadTokenURL: '',
|
||||
qiniuUploadTokenFunction: null
|
||||
};
|
||||
updateConfigWithOptions(options);
|
||||
}
|
||||
|
||||
function updateConfigWithOptions(options) {
|
||||
if (options.uploadURL) {
|
||||
config.qiniuUploadURL = options.uploadURL;
|
||||
} else {
|
||||
console.error('qiniu uploader need uploadURL');
|
||||
}
|
||||
if (options.uptoken) {
|
||||
config.qiniuUploadToken = options.uptoken;
|
||||
} else if (options.uptokenURL) {
|
||||
config.qiniuUploadTokenURL = options.uptokenURL;
|
||||
} else if(options.uptokenFunc) {
|
||||
config.qiniuUploadTokenFunction = options.uptokenFunc;
|
||||
}
|
||||
if (options.domain) {
|
||||
config.qiniuImageURLPrefix = options.domain;
|
||||
}
|
||||
}
|
||||
|
||||
function upload(filePath, success, fail, options) {
|
||||
if (null == filePath) {
|
||||
console.error('qiniu uploader need filePath to upload');
|
||||
return;
|
||||
}
|
||||
if (options) {
|
||||
init(options);
|
||||
}
|
||||
if (config.qiniuUploadToken) {
|
||||
doUpload(filePath, success, fail, options);
|
||||
} else if (config.qiniuUploadTokenURL) {
|
||||
getQiniuToken(function() {
|
||||
doUpload(filePath, success, fail, options);
|
||||
});
|
||||
} else if (config.qiniuUploadTokenFunction) {
|
||||
config.qiniuUploadToken = config.qiniuUploadTokenFunction();
|
||||
} else {
|
||||
console.error('qiniu uploader need one of [uptoken, uptokenURL, uptokenFunc]');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function doUpload(filePath, success, fail, options) {
|
||||
var url = config.qiniuUploadURL;
|
||||
var fileName = filePath.split('//')[1];
|
||||
if (options && options.key) {
|
||||
fileName = options.key;
|
||||
}
|
||||
var formData = {
|
||||
'token': config.qiniuUploadToken,
|
||||
'key': fileName
|
||||
};
|
||||
wx.uploadFile({
|
||||
url: url,
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
formData: formData,
|
||||
success: function (res) {
|
||||
var dataString = res.data
|
||||
var dataObject = JSON.parse(dataString);
|
||||
//do something
|
||||
var imageUrl = config.qiniuImageURLPrefix + dataObject.key;
|
||||
dataObject.imageURL = imageUrl;
|
||||
console.log(dataObject);
|
||||
success(dataObject);
|
||||
},
|
||||
fail: function (error) {
|
||||
console.log(error);
|
||||
fail(error);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function getQiniuToken(callback) {
|
||||
wx.request({
|
||||
url: config.qiniuUploadTokenURL,
|
||||
success: function (res) {
|
||||
var token = res.data.uptoken;
|
||||
config.qiniuUploadToken = token;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
fail: function (error) {
|
||||
console.log(error);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
})();
|
|
@ -16,7 +16,7 @@
|
|||
<swiper-tab id="tab" :list="dataList" v-model="current" @changeEv="clickTab" :itemColor="'#e42417'" :lineColor="'#e42417'"></swiper-tab>
|
||||
</view>
|
||||
<view class="pad-zy20">
|
||||
<list ref="refcourse" @goDetail="goDetail"></list>
|
||||
<list ref="refcourse" @goDetail="goDetail(arguments)"></list>
|
||||
<view class="" v-if="loading">
|
||||
<pitera :textStr="`${noMore && total > $refs.refcourse.list.length?'上滑加载更多':'到底了'}~~`" textColor="#b0aaa9" paddingStr="40rpx 0 20rpx 0"></pitera>
|
||||
</view>
|
||||
|
@ -112,11 +112,20 @@
|
|||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 去课程详情
|
||||
goDetail(id){
|
||||
goDetail(data){
|
||||
let id = data[0],
|
||||
is_buy = data[1];
|
||||
if(is_buy == 0) {
|
||||
uni.navigateTo({
|
||||
url:`/pagesB/course-detail/course-detail?id=${id}&category_id=${this.classId}`
|
||||
})
|
||||
}else {
|
||||
uni.navigateTo({
|
||||
url:`/pagesB/course-list/course-list?id=${id}`
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
<pitera textStr="查询课程列表无果o(╥﹏╥)o" textColor="#b0aaa9" paddingStr="40rpx 0 20rpx 0"></pitera>
|
||||
</view>
|
||||
<!-- 两列列表 start -->
|
||||
<list ref="refcourse" @goDetail="goCourseDetail"></list>
|
||||
<list ref="refcourse" @goDetail="goCourseDetail(arguments)"></list>
|
||||
<!-- 两列列表 end -->
|
||||
<!-- 推荐视频 start -->
|
||||
<view class="disjb ae mar-s40 mar-x20" v-if="parseInt(show_video)!==0">
|
||||
|
@ -180,7 +180,11 @@
|
|||
// 大图点击事件
|
||||
goBigCourse(id,category_id,is_buy){
|
||||
if(this.$toolAll.tools.judgeAuth()) {
|
||||
if(is_buy == 0) {
|
||||
this.$toolAll.tools.goPage(`/pagesB/course-detail/course-detail?id=${id}&category_id=${category_id}`);
|
||||
}else {
|
||||
this.$toolAll.tools.goPage(`/pagesB/course-list/course-list?id=${id}&category_id=${category_id}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
// 获取课程列表
|
||||
|
@ -272,11 +276,20 @@
|
|||
})
|
||||
},
|
||||
// 去课程详情
|
||||
goCourseDetail(id){
|
||||
goCourseDetail(data){
|
||||
if(this.$toolAll.tools.judgeAuth()) {
|
||||
let id = data[0],
|
||||
is_buy = data[1];
|
||||
if(is_buy == 0) {
|
||||
uni.navigateTo({
|
||||
url:`/pagesB/course-detail/course-detail?id=${id}`
|
||||
})
|
||||
}else {
|
||||
uni.navigateTo({
|
||||
url:`/pagesB/course-list/course-list?id=${id}`
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
// 去商品详情
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<view class="fon32 bold colb">推荐课程</view>
|
||||
<view class="fon20" style="color: #bbb4b3;" @tap="$toolAll.tools.goPage('/pages/tabbar/course/course')">更多+</view>
|
||||
</view>
|
||||
<list ref="refcourse" @goDetail="goDetail"></list>
|
||||
<list ref="refcourse" @goDetail="goDetail(arguments)"></list>
|
||||
</view>
|
||||
<!-- 登录弹框 start -->
|
||||
<view class="posAll disjc" v-if="ifLogin">
|
||||
|
@ -163,10 +163,18 @@
|
|||
},
|
||||
|
||||
// 去课程详情
|
||||
goDetail(id){
|
||||
goDetail(data){
|
||||
let id = data[0],
|
||||
is_buy = data[1];
|
||||
if(is_buy == 0) {
|
||||
uni.navigateTo({
|
||||
url:`/pagesB/course-detail/course-detail?id=${id}&category_id=${this.classId}`
|
||||
})
|
||||
}else {
|
||||
uni.navigateTo({
|
||||
url:`/pagesB/course-list/course-list?id=${id}`
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 播放视频
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
course_id:this.course_id,
|
||||
}
|
||||
this.$requst.post('/api/course/get-course-video',params).then(res=>{
|
||||
this.total = res.data.list;
|
||||
this.total = res.data.total;
|
||||
if(this.page==1){this.dataList=[];}
|
||||
this.dataList = [...this.dataList,...res.data.list];
|
||||
if(this.total==this.dataList.length && this.page!=1){
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<video :id="`video${index}`" :ref="`refvideo_${index}`" style="width: 100%;" :style="{height:newHeight+'px'}" :autoplay="item.autoplay"
|
||||
:src="item.src" :enable-play-gesture="dans"
|
||||
:controls="item.isControls" :show-center-play-btn="isCenterImg" :show-play-btn="isBottomImg" :show-fullscreen-btn="isFull"
|
||||
@play="comePlay(index)" @pause="comePause(index)" @timeupdate='timeupdate'></video>
|
||||
@play="comePlay(index)" @pause="comePause(index)" @timeupdate='videoTimeUpdateEvent' :enable-progress-gesture="isBottomImg"></video>
|
||||
<!-- 封面图 -->
|
||||
<image v-if="item.isPlayImg" @tap.stop="playEv(index)" src="/static/tabbar/icon-play.png" style="position: fixed;top: 50%;left: 50%;
|
||||
width: 126rpx;height: 126rpx;transform: translate(-50%, -50%);" mode="aspectFill"></image>
|
||||
|
@ -34,7 +34,10 @@
|
|||
isBottomImg:true,//是否显示视频底部控制栏的播放按钮
|
||||
isFull:true,//是否显示全屏按钮
|
||||
count:0,
|
||||
currentTime:'' //记录观看时长
|
||||
currentTime:'' ,//记录观看时长
|
||||
duration:'',//视频总时长
|
||||
video_real_time: 0,
|
||||
nitial_time: ''
|
||||
}
|
||||
},
|
||||
onReady: (res)=> {
|
||||
|
@ -133,10 +136,41 @@
|
|||
this.videoList[index].isControls = false;
|
||||
},
|
||||
//记录观看时长
|
||||
timeupdate(e) {
|
||||
this.currentTime = Number(e.detail.currentTime);
|
||||
videoTimeUpdateEvent(e) {
|
||||
var isReady = 1; // 是否开启可以视频快进 1 禁止开启
|
||||
//跳转到指定播放位置 initial-time 时间为秒
|
||||
let that = this;
|
||||
//播放的总时长
|
||||
var duration = e.detail.duration;
|
||||
//实时播放进度 秒数
|
||||
var currentTime = parseInt(e.detail.currentTime);
|
||||
//当前视频进度
|
||||
// console.log("视频播放到第" + currentTime + "秒")//查看正在播放时间,以秒为单位
|
||||
if (that.video_real_time == 0) {
|
||||
var jump_time = parseInt(that.initial_time) + parseInt(that.video_real_time);
|
||||
} else {
|
||||
var jump_time = parseInt(that.video_real_time);
|
||||
}
|
||||
if (isReady == 1) {
|
||||
if (currentTime > jump_time && currentTime - jump_time > 3) {
|
||||
let videoContext = wx.createVideoContext('video0');
|
||||
videoContext.seek(that.video_real_time);
|
||||
}
|
||||
}
|
||||
|
||||
that.video_real_time = currentTime; //实时播放进度
|
||||
that.currentTime = Math.ceil(e.detail.currentTime);
|
||||
that.duration = parseInt(e.detail.duration - 1);
|
||||
if(that.currentTime >= that.duration) {
|
||||
setTimeout(()=>{
|
||||
uni.navigateBack({
|
||||
delta:1
|
||||
})
|
||||
},200)
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<view class="radius8 bacf pad-sx40 pad-zy40 boxshow2 col26 fon24">
|
||||
<view class="">视频标题</view>
|
||||
<input v-model="title" class="width100 radius4 mar-s20 pad-zy20" type="text" style="border: 2rpx solid #ececec;background-color: #f5f5f5;height: 70rpx;box-sizing: border-box;">
|
||||
<view class="mar-s40">视频上传</view>
|
||||
<view class="mar-s40">视频上传:温馨提示:请上传像素720P,规格100M以内的视频。</view>
|
||||
<input @tap="uploadVideo" class="width100 radius4 mar-s20 pad-zy20 tcenter" type="text" placeholder="浏览..." disabled
|
||||
style="border: 2rpx solid #ececec;background-color: #f5f5f5;height: 70rpx;box-sizing: border-box;">
|
||||
<view class="pad-s20" v-if="videoInfo.full_src">
|
||||
|
@ -31,29 +31,81 @@
|
|||
full_src:'',
|
||||
src:''
|
||||
},
|
||||
flag:true
|
||||
flag:true,
|
||||
qiniuToken:'',
|
||||
qiniuFilename:'',
|
||||
hostapi:'',
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.hostapi = getApp().globalData.hostapiQi;
|
||||
this.getQiniu();
|
||||
},
|
||||
methods: {
|
||||
getQiniu() {
|
||||
this.$requst.post('/api/common/qiniuToken').then(res=>{
|
||||
if(res.code==0){
|
||||
console.log(res,'qiniu token')
|
||||
this.qiniuToken = res.data.token;
|
||||
this.qiniuFilename = res.data.filename + '.mp4';
|
||||
}
|
||||
|
||||
}).catch(err=>{
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
// 上传视频
|
||||
uploadVideo(){
|
||||
uni.chooseMedia({
|
||||
sourceType:['album','camera'],
|
||||
maxDuration: 60,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title:'正在上传...',
|
||||
title:'正在上传,请勿关闭页面和退出',
|
||||
icon:'none',
|
||||
duration:100000
|
||||
})
|
||||
uploadFile({path:res.tempFiles[0].tempFilePath}).then(res=>{
|
||||
if(res.code==0){
|
||||
this.videoInfo = res.data;
|
||||
this.$toolAll.tools.showToast('上传视频成功(*^▽^*)');
|
||||
}
|
||||
let file = res.tempFiles[0].tempFilePath;
|
||||
let key = this.qiniuFilename;
|
||||
let token = this.qiniuToken;
|
||||
|
||||
uni.uploadFile({
|
||||
url: "https://up-z1.qiniup.com",//华北地区上传
|
||||
filePath: file,
|
||||
name: 'file',
|
||||
method: "POST",
|
||||
formData: {
|
||||
'key': key,//key值
|
||||
'token': token //七牛云token值
|
||||
},
|
||||
success: uploadFileRes => {
|
||||
//uploadFileRes 返回了data是一个json字符串
|
||||
//拿到里面的key拼接上域名,再反出去就ok了
|
||||
let strToObj=JSON.parse(uploadFileRes.data),
|
||||
backUrl = this.hostapi+ '/' + strToObj.key,
|
||||
uploadUrl = '/' + strToObj.key;
|
||||
this.videoInfo.full_src = backUrl;
|
||||
this.videoInfo.src = uploadUrl;
|
||||
console.log(this.videoInfo)
|
||||
setTimeout(()=>{
|
||||
uni.hideToast();
|
||||
},1500)
|
||||
},500)
|
||||
},
|
||||
fail: fail => {
|
||||
uni.showToast({ title: "网络错误", icon: "none" });
|
||||
}
|
||||
})
|
||||
|
||||
// uploadFile({path:res.tempFiles[0].tempFilePath}).then(res=>{
|
||||
// if(res.code==0){
|
||||
// this.videoInfo = res.data;
|
||||
// this.$toolAll.tools.showToast('上传视频成功(*^▽^*)');
|
||||
// }
|
||||
// setTimeout(()=>{
|
||||
// uni.hideToast();
|
||||
// },1500)
|
||||
// })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -86,7 +138,7 @@
|
|||
}
|
||||
setTimeout(()=>{
|
||||
uni.hideToast();
|
||||
},1500)
|
||||
},500)
|
||||
}).catch(err=>{
|
||||
this.flag = true;
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue