rt-sim-training-client/src/views/components/progressBar/index.vue

143 lines
3.3 KiB
Vue
Raw Normal View History

2019-07-25 10:32:29 +08:00
<template>
2019-08-08 16:47:34 +08:00
<div v-show="show" class="progressShade" :style="{background: background}">
<el-progress
class="progressBar"
:type="type"
:show-text="showText"
:text-inside="textInside"
:stroke-width="strokeWidth"
:percentage="percentage"
:color="color"
:status="status"
/>
</div>
2019-07-25 10:32:29 +08:00
</template>
<script>
2019-11-20 16:31:41 +08:00
// import { requestAnimationFrame, cancelRequestAnimFrame } from '@/utils/animation';
2019-07-25 10:32:29 +08:00
2019-08-08 16:47:34 +08:00
export default {
2019-11-20 16:31:41 +08:00
name: 'ProgressBar',
props: {
type: {
type: String,
default() {
return 'line';
}
},
showText: {
type: Boolean,
default() {
return true;
}
},
textInside: {
type: Boolean,
default() {
return false;
}
},
strokeWidth: {
type: Number,
default() {
return 5;
}
},
background: {
type: String,
default() {
return 'rgba(0, 0, 0, 0.8)';
}
}
},
data() {
return {
color: '#8e71c7',
status: null,
show: false,
percentage: 0,
fps: 30,
then: null,
timer: null
};
},
mounted() {
this.percentage = this.randomNum();
this.start();
},
methods: {
randomNum() {
return Math.ceil(Math.random() * 5) + 20;
},
run() {
this.timer = setInterval(() => {
this.percentage = this.percentage + 3;
// 加载到百分百完成
if (this.percentage >= 95) {
this.percentage = 95;
// 关闭定时器
clearInterval(this.timer);
return;
}
}, 50);
},
start() {
if (!this.show) {
this.status = null;
this.percentage = this.randomNum();
this.show = true;
this.run();
}
},
end(isSuccess) {
this.timer && clearInterval(this.timer);
if (this.show) {
if (isSuccess) {
this.success();
} else {
this.failed();
}
}
},
progressAt(num) {
if (num > 0 && num < 100 && num > this.percentage) {
this.percentage = num;
}
},
success() {
this.status = 'success';
this.percentage = 100;
setTimeout(() => {
this.show = false;
}, 1000 / this.fps);
},
failed() {
this.status = 'exception';
setTimeout(() => {
this.show = false;
}, 1000 / this.fps);
}
}
2019-08-08 16:47:34 +08:00
};
2019-07-25 10:32:29 +08:00
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.progressShade {
z-index: 9998;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
.progressBar {
z-index: 9999;
position: absolute;
top: 40%;
width: 50%;
left: 25%;
}
2019-07-25 10:30:30 +08:00
</style>