要求弹窗内显示进度条,根据接口获取当前进度值,间隔5秒调用接口获取最新进度值,当进度值为100时,允许关闭进度条弹窗

class="cancelBtn" size="small" type="warning" @click="chargeGenerate">打开进度条
- <el-dialog title="生成过程中请稍后" :visible.sync="dialogTableVisible" width="55%" top="40vh" @close="onDialogClose">
- <el-progress :text-inside="true" :stroke-width="20" :percentage="percentage" status="success">el-progress>
- el-dialog>
说明:
text-inside:进度条显示文字内置在进度条内
stroke-width:进度条的宽度,单位 px
percentage:百分比(默认设置的为0)
详细内容可查看官网:Element - The world's most popular Vue UI framework
- data() {
- return {
- dialogTableVisible: false,//弹窗默认关闭
- percentage: 0,//进度值
- timer:null,
- }
- }
- chargeGenerate(){
- //打开弹窗
- this.dialogTableVisible = true
- //进度条开始时为0
- this.percentage = 0;
- //调取进度条的接口,启动定时器,接口获取完,销毁定时器
- this.timer = setInterval(()=>{
- this.$http.get(this.$url.lifebill.getCalculateProgress).then(res=>{
- //获取接口中返回的进度值,并赋值给进度条
- this.percentage = res.data
- //满足以下条件,关闭定时器
- if ((res.code==0 && res.data == 100)||res.code==1) {
- clearInterval(this.timer); // 关闭定时器
- this.$message.success(res.msg)
- }
- })
- },5000)
- }
如果进度条在进行中,还没有达到100%时,是不能关闭进度弹窗的,给弹窗增加@close关闭事件
- onDialogClose() {
- //如果进度值小于100,弹窗不能关闭
- if(this.percentage < 100){
- this.dialogTableVisible = true
- }else{
- this.dialogTableVisible = false
- }
- },
最后,👏👏 😀😀😀 👍👍