手册版本 V3.0
GraceUI - 进度按钮组件可以用于各种大文件下载/上传等进度展示;
组件名称
graceProgressButton : /graceUI/组件目录/graceProgressButton
组件属性
height : {type : Number, default : 88}// 组件高度,单位 rpx
fontSize : { type : Number, default : 30} // 文字大小,单位 rpx
val : {type : Number, default : 0} // 当前进度值
buttonText : { type : String, default : ""} // 按钮文本
color : { type : String, default : "#FFFFFF"} // 文本颜色
background:{ type : String, default : "#5CC72F"} // 背景颜色
borderRadius : { type : String, default : "6rpx"} // 圆角大小
progressText : { type : String, default : "已下载 : "} // 进度附加文本演示代码
UNI 普通版本
NVUE 版本
微信小程序独立版本
<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body"></view>
<view slot="gFooter" class="concerns-footer" @tap="download">
<graceProgressButton :buttonText="buttonText" borderRadius="50rpx" :val="progress"></graceProgressButton>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/components/gracePage.vue";
import graceProgressButton from "../../graceUI/components/graceProgressButton.vue";
export default{
data() {
return {
progress : 0,
buttonText : "下载视频",
fileUrl : ''
}
},
components:{
gracePage,
graceProgressButton
},
methods:{
download : function(){
console.log(this.progress);
// 根据进度判断要做什么
// 0 下载
if(this.progress == 0){
const downloadTask = uni.downloadFile({
url : 'https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/%E7%AC%AC1%E8%AE%B2%EF%BC%88uni-app%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D%EF%BC%89-%20DCloud%E5%AE%98%E6%96%B9%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B@20181126.mp4',
success : (res) => {
if (res.statusCode === 200) {
this.progress = 100;
this.buttonText = '下载完成';
this.fileUrl = res.tempFilePath;
}
}
});
downloadTask.onProgressUpdate((res) => {
console.log(res);
console.log('下载进度' + res.progress);
console.log('已经下载的数据长度' + res.totalBytesWritten);
console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
this.progress = res.progress;
});
}
// 下载完成播放
else if(this.progress == 100){
var videoContext = uni.createVideoContext('myVideo')
videoContext.play();
}
}
}
}
</script>
<style>
.concerns-footer{padding:10rpx 20rpx; background-color:#F4F5F6;}
#myVideo{width:100%;}
</style>
<template>
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body" style="padding-bottom:150rpx;">
</view>
<view slot="gFooter" class="concerns-footer" @tap="download">
<graceProgressButton :buttonText="buttonText" borderRadius="50rpx" :val="progress"></graceProgressButton>
</view>
</gracePage>
</template>
<script>
import gracePage from "../../graceUI/weexComponents/gracePage.nvue";
import graceProgressButton from "../../graceUI/weexComponents/graceProgressButton.vue";
export default{
data() {
return {
progress : 0,
buttonText : "下载视频",
fileUrl : ''
}
},
components:{
gracePage,
graceProgressButton
},
methods:{
download : function(){
// 根据进度判断要做什么
// 0 下载
if(this.progress == 0){
const downloadTask = uni.downloadFile({
url : 'https://img.cdn.aliyun.dcloud.net.cn/guide/uniapp/%E7%AC%AC1%E8%AE%B2%EF%BC%88uni-app%E4%BA%A7%E5%93%81%E4%BB%8B%E7%BB%8D%EF%BC%89-%20DCloud%E5%AE%98%E6%96%B9%E8%A7%86%E9%A2%91%E6%95%99%E7%A8%8B@20181126.mp4',
success : (res) => {
if (res.statusCode === 200) {
this.progress = 100;
this.buttonText = '下载完成';
this.fileUrl = res.tempFilePath;
console.log(this.fileUrl);
}
}
});
downloadTask.onProgressUpdate((res) => {
console.log(res);
console.log('下载进度' + res.progress);
console.log('已经下载的数据长度' + res.totalBytesWritten);
console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
this.progress = res.progress;
});
}
// 下载完成播放
else if(this.progress == 100){
var videoContext = uni.createVideoContext('myVideo')
videoContext.play();
}
}
}
}
</script>
<style>
.concerns-footer{padding:10rpx 20rpx; background-color:#F4F5F6;}
</style>
.wxml
<gracePage :customHeader="false">
<view slot="gBody" class="grace-body" style="padding-bottom:150rpx;">
<view>
<video src="{{fileUrl}}" controls id="myVideo"></video>
</view>
</view>
<view slot="gFooter" class="concerns-footer" catchtap="download">
<graceProgressButton buttonText="{{buttonText}}" borderRadius="50rpx" val="{{progress}}"></graceProgressButton>
</view>
</gracePage>.json
{
"usingComponents": {
"gracePage": "../../graceUI/components/gracePage",
"graceProgressButton": "../../graceUI/components/graceProgressButton"
}
}.wxss
.concerns-footer{padding:10rpx 20rpx; background-color:#F4F5F6;}
#myVideo{width:100%;}.js
Page({
data: {
progress: 0,
buttonText: "下载视频",
fileUrl: ''
},
onLoad: function () {
},
download: function () {
// 根据进度判断要做什么
// 0 下载
if (this.data.progress == 0) {
const downloadTask = wx.downloadFile({
url: 'http://dcloud-img.oss-cn-hangzhou.aliyuncs.com/video/uni-app20190127.mp4',
success: (res) => {
if (res.statusCode === 200) {
this.setData({ progress: 100, buttonText: '播放视频', fileUrl:res.tempFilePath});
}
}
});
downloadTask.onProgressUpdate((res) => {
this.setData({ progress : res.progress });
});
}
// 下载完成播放
else if (this.data.progress == 100) {
var videoContext = wx.createVideoContext('myVideo')
videoContext.play();
}
}
})