vue前端

项目场景:

今天开发时遇到这样一个需求,在管理端用户可设置多个html样式的文本文件,然后在前端给用户提供一个dialog对话框根据按钮(要求按钮上加上计数器)依次展示这些文本内容。


需求实现

理论上是需要一个计数的参数,从0到文本文件的个数依次循环展示dialog上的内容。

<div style="alignment: center;width:  100%; text-align:center; ">
              <el-row :span="24">
                <el-button type="primary" icon="el-icon-shopping-cart-full"  @click="startTest()">开始</el-button>
              </el-row>
            </div>
<el-dialog :title="this.scoreAnalysisPayDocTitle"
               append-to-body
               :close-on-click-modal="true"
               :close-on-press-escape="true"
               :show-close="true"
               :visible.sync="isPayMessage"
               :width="width">
      <el-form>
        <div v-html="scoreAnalysisPayDoc">
          {{scoreAnalysisPayDoc}}
        </div>
      </el-form>
      <div style="alignment: center;width:  100%; text-align:center;margin-top: 20px ">
        <el-row :span="24">
          <el-checkbox v-model="selectedValue" @change="changeRadio"><span style="font-weight: bold;">同意</span></el-checkbox>  <el-button :disabled="nextStep" type="primary"   @click="handleSelectDepartment">{{buttonTitle}}</el-button>
        </el-row>
      </div>
    </el-dialog>

data 参数:

data() {
    return {
      isPayMessage:false,
      selectedValue : false,
      scoreAnalysisPayDoc:'',
      scoreAnalysisPayDocTitle:'',
      form: {
        paydocArray: [],
        textarea: "",
      },
      formRow:{
        rowId:0,
        examId:'',
      },
      count: '',
      buttonTitle:'下一步',
      timer: null,
      nextStep:true,
      iDocIndex : 0, 
    }
  },

methods 方法

methods: {
    ShowDocBody(){
      this.scoreAnalysisPayDoc=this.form.paydocArray[this.iDocIndex].docBody;
      this.scoreAnalysisPayDocTitle=this.form.paydocArray[this.iDocIndex].fileTitle;
      this.iDocIndex++;
    },
    countDown() {
      const TIME_COUNT = 20
      if (!this.timer) {
        this.count = TIME_COUNT
        this.nextStep = true
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= TIME_COUNT) {
            this.buttonTitle = '下一步('+this.count+')'
            this.count--
          } else {
            this.nextStep = false
            this.buttonTitle = '下一步'
            clearInterval(this.timer)
            this.timer = null
          }
        }, 1000)
      }
    },
    changeRadio (value) {
      this.selectedValue = value;
    },
    handleSelectDepartment(){ //处理选中的项
      if (this.selectedValue === false) {
        this.$message.warning("请阅读提示信息并进行勾选");
        return;
      }
      if (this.iDocIndex >= this.form.paydocArray.length){
        this.isPayMessage=false;
        this.scoreAnalysisPayDoc='';
        this.scoreAnalysisPayDocTitle='';
        this.toPay();
      } else {
        this.ShowDocBody();
        this.selectedValue = false;
        this.countDown();
      }
    },
    startTest(){
      this.isPayMessage=true;
      getPayDocList().then(res => {
        this.form.paydocArray = res.data.data;
        this.iDocIndex = 0;
        this.scoreAnalysisPayDoc=this.form.paydocArray[this.iDocIndex].docBody;
        this.scoreAnalysisPayDocTitle=this.form.paydocArray[this.iDocIndex].fileTitle;
        this.iDocIndex++;
        this.countDown();
      })
    },
  }

效果展示:

在这里插入图片描述
在这里插入图片描述


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值