2021-06-10

import axios from ‘axios’
export default {
name: “Compute”,

data:function(){
return{
total:5,
good_count:0,
bad_count:0,
score:0,
result:[],
last_result:[],
good_img:require("…/assets/good.png"),
bad_img:require("…/assets/bad.png"),
null_img:require("…/assets/null.png"),
option:{
add:true,
dec:true,
chen:false,
chu:false,
}
}
},
methods:{
generate:function(){
document.getElementById(“div_score”).style.display=“none”
//let _this = this
let opt ="";
if(this.option.add){
opt = opt + “0”;
}
if(this.option.dec) {
opt = opt + “1”;
}
if(this.option.chen) {
opt = opt + “2”;
}
if(this.option.chu) {
opt = opt + “3”;
}
//清空提示图片
for(let i=0;i<this.result.length;i++){
let img_name = “img” + i;
let input_name = “input” +i;
this. r e f s [ i m g n a m e ] . s r c = t h i s . n u l l i m g ; t h i s . refs[img_name].src = this.null_img; this. refs[imgname].src=this.nullimg;this.refs[input_name].value = “”;
}

    axios
      .post('http://localhost:8888/compute/index',{
        total:this.total,
        option: opt
      })
      .then((data)=>{
        //console.log(data.data)
        this.result = data.data
      })
      .catch(function (err){
        console.log(err)
      })


},


finish:function (){

  //将用户填写的结果写入到JSON数据内
  for(let i=0;i<this.total;i++){
    let input_name = "input" +i;
    //console.log(this.$refs[input_name].value);
    this.result[i].answer = this.$refs[input_name].value;
    parseInt(this.result[i].answer);
  }
  console.log(this.result)
  axios
      .post('http://localhost:8888/compute/test',{
        t:this.result
      })
      .then()
      .catch(function (err){
        console.log(err)
      })

  //判断结果是否正确并添加图片
  this.setImg();
},

loadLastFinish:function (){

  let date = document.getElementById("txtDate").value

  axios
      .post('http://localhost:8888/compute/loadLastFinish',{
        date:date
      })
      .then((data)=>{
        this.result = data.data;
        if(data.data == null){
          alert("这一天的信息成绩");
        }
        //console.log(this.result);
      })
      .catch(function (err){
        console.log(err)
      });

  this.setImg();

},

//添加判断图片
setImg:function (){
  let count = 0;
  for(let i=0;i<this.result.length;i++){
    let input_name = "input" +i;
    let img_name = "img" + i;
    let input_val = this.$refs[input_name].value;
    if(input_val != "" && input_val != null && input_val == this.result[i].result) {
      count++;
      this.$refs[img_name].src = this.good_img;
    }else {
      this.$refs[img_name].src = this.bad_img;
    }
  }

  this.score = (count/this.result.length * 100).toFixed(1);
  this.good_count = count;
  this.bad_count = this.result.length - count;
  document.getElementById("div_score").style.display="inline"

}

}

}在这里插入代码片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值