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"
}
}
}在这里插入代码片