如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
<view class='bx'>
<text class='title'>视频</text>
<view class="page-body-info">
<block wx:if="{{v_src === ''}}">
<view class="image-plus image-plus-nb" bindtap="chooseVideo">
<view class="image-plus-text">添加视频</view>
</view>
</block>
<block wx:if="{{v_src != ''}}">
<video src="{{v_src}}" class="video"></video>
</block>
</view>
</view>
<view class='bx'>
<text class='title'>VR图</text>
<view class="page-body-info">
<block wx:if="{{vr_src === ''}}">
<view class="image-plus image-plus-nb" bindtap="chooseVR">
<view class="image-plus-text">添加Vr图</view>
</view>
</block>
<block wx:if="{{vr_src != ''}}">
<image src="{{vr_src}}"></image>
</block>
</view>
</view>
chooseVR:function(e){
var that = this;
var url = config.api_base_url + "wxapp/scrz?t=2"
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths;
wx.uploadFile({
url,
filePath: tempFilePaths[0],
name: 'file',
success(res) {
if (res == '上传失败') {
wx.showToast({
title: '上传失败',
icon: 'none',
duration: 2000
})
} else {
that.setData({
vr_src: res.data
})
}
}
})
}
})
},
chooseVideo: function () {
var that = this
wx.chooseVideo({
success: function (res) {
console.log(res.tempFilePath)
that.setData({
src: res.tempFilePath,
})
that.uploadvideo();
}
})
},
//上传视频 目前后台限制最大100M,以后如果视频太大可以在选择视频的时候进行压缩
uploadvideo: function () {
var that = this
var src = this.data.src;
console.log(src)
var url = config.api_base_url + "wxapp/scrz?t=2"
wx.uploadFile({
url: url,//服务器接口
method: 'POST',//这句话好像可以不用
filePath: src,
header: {
'content-type': 'multipart/form-data'
},
name: 'file',//服务器定义的Key值
success: function (res) {
console.log(res.data)
console.log('视频上传成功')
that.setData({
v_src:res.data
})
},
fail: function () {
console.log('接口调用失败')
}
})
},
王明昌博客
