ans_question.vue
8.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<template>
<div class="bck">
<div class="title">
<div>单向选择</div>
<div>
{{ dataObj.curNum }}<span>/{{ dataObj.totalNum }}</span>
</div>
</div>
<div class="ans">
{{ dataObj.title }}
</div>
<div class="ans_card" v-for="(v, i) in contentJsonArray" :key="i">
<div
class="ans_item grey"
:class="checkIndex === i ? 'yellow' : 'grey'"
@click="subAns(v.k, i)"
>
{{ v.k + " . " + v.v }}
</div>
<!-- <div class="ans_item grey">B.水性</div>
<div class="ans_item yellow">C.绍兴</div> -->
</div>
<div class="whiteLine"></div>
<div class="reply" v-if="rightData.isShow">
<div class="reply_title">正确答案:{{ rightData.rightAnswer }}</div>
<div class="reply_text">解析:{{ rightData.remark }}</div>
</div>
<div
class="btn blue"
v-if="dataObj.curNum != 0 && dataObj.curNum == dataObj.totalNum"
@click="toEnd"
>
完成
</div>
<div class="btn" v-else @click="toNext">下一题</div>
</div>
</template>
<script>
export default {
data() {
return {
categoryId: 0,
dataObj: {
answer: null,
contentJsonArray: null,
curNum: 0,
id: 0,
itemCategoryId: 0,
remark: null,
score: 0,
sort: 0,
status: 0,
title: "",
totalNum: 0,
version: 0,
},
contentJsonArray: [], //选项
checkIndex: "",
//答案-解析
rightData: {
rightAnswer: "",
remark: "",
isShow: false,
},
//答题时间
answerUseTime: 0,
timer: null, //计时器
};
},
methods: {
//获取题目-开始答题
toBank() {
if (!this.categoryId) return this.$toast.fail("题库Id为空");
this.yxAxios
.get(
`${
this.kqUrl
}/item/getItemBank?travelerNum=${localStorage.getItem(
"travelerNum"
)}&categoryId=${this.categoryId}`
)
.then((res) => {
if (res.data.code == 200) {
this.dataObj = res.data.data;
this.contentJsonArray = JSON.parse(
this.dataObj.contentJsonArray
);
this.hanleTime();
} else {
this.$toast.fail(res.data.message);
}
});
},
//提交答案
subAns(val, index) {
this.checkIndex = index;
this.yxAxios
.get(
`${
this.kqUrl
}/item/submit?travelerNum=${localStorage.getItem(
"travelerNum"
)}&itemBankId=${
this.dataObj.id
}&answer=${val}&answerUseTime=${this.answerUseTime}`
)
.then((res) => {
if (res.data.code == 200) {
const data = res.data.data;
this.rightData = {
rightAnswer: data.rightAnswer,
remark: data.remark,
isShow: true,
};
} else {
this.$toast.fail(res.data.message);
}
clearInterval(this.timer);
});
},
//下一题
toNext() {
this.yxAxios
.get(
`${
this.kqUrl
}/item/nextOne?travelerNum=${localStorage.getItem(
"travelerNum"
)}&curItemBankId=${this.dataObj.id}&categoryId=${
this.categoryId
}`
)
.then((res) => {
if (res.data.code == 200) {
this.remakeData();
this.dataObj = res.data.data;
this.contentJsonArray = JSON.parse(
this.dataObj.contentJsonArray
);
//计时器
this.hanleTime();
} else {
this.$toast.fail(res.data.message);
}
});
},
//完成
toEnd() {
this.yxAxios
.get(
`${
this.kqUrl
}/item/finish?travelerNum=${localStorage.getItem(
"travelerNum"
)}&categoryId=${this.categoryId}`
)
.then((res) => {
if (res.data.code == 200) {
this.$dialog
.alert({
title: "完成答题",
message: "您的分数是:" + res.data.data,
theme: "round-button",
})
.then(() => {
let index = this.$route.query.index;
this.$router.push({
name: "stars",
query: {
index: index,
},
});
});
} else {
this.$toast.fail(res.data.message);
}
});
},
//重置数据
remakeData() {
this.rightData = {
rightAnswer: "",
remark: "",
isShow: false,
};
(this.contentJsonArray = []), //选项
(this.checkIndex = "");
this.dataObj = this.$options.data().dataObj;
console.log("重置");
},
//单独计时器
hanleTime() {
this.answerUseTime = 0;
console.log('开始计时...'+this.answerUseTime)
this.timer = null
this.timer = setInterval(() => {
this.answerUseTime++;
}, 1000);
this.$once("hook:beforeDestroy", () => {
clearInterval(this.timer); //清理
});
},
//重置计时器
reserveTime() {
this.answerUseTime = 0
clearInterval(this.timer); //清理
}
},
mounted() {
this.categoryId = this.$route.query.categoryId;
this.toBank();
},
};
</script>
<style lang="scss" scoped>
.bck {
width: 100vw;
height: 100vh;
background-color: #f0f2f5;
padding: 5vw;
box-sizing: border-box;
.title {
display: flex;
align-items: center;
justify-content: space-between;
font-size: 4.5vw;
color: #ff7f24;
letter-spacing: 2px;
font-weight: 500;
span {
color: #999999;
}
}
.ans {
color: #333;
font-size: 4.4vw;
line-height: 50px;
font-weight: 600;
margin: 60px 0 50px;
}
.ans_card {
.ans_item {
margin: 60px 0;
font-size: 4.2vw;
letter-spacing: 3px;
}
.grey {
color: #999999;
}
.yellow {
color: #ff7f24;
}
}
.whiteLine {
margin: 150px 0 10px;
height: 2px;
width: 100%;
background-color: #fff;
}
.reply {
.reply_title {
color: #333333;
font-size: 4.3vw;
margin: 30px 0;
}
.reply_text {
font-size: 4.3vw;
color: #999999;
letter-spacing: 2px;
line-height: 50px;
}
}
.btn {
position: fixed;
left: 15vw;
bottom: 5vw;
width: 70vw;
height: 100px;
background-color: #ff3636;
font-size: 4.4vw;
margin: 30vw 0 10vw;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
border-radius: 10vw;
letter-spacing: 10px;
}
.blue {
background-color: #409eff;
}
}
</style>