|
|
@@ -55,24 +55,24 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
computed:{
|
|
|
- ...mapState('target', ['subjectCode'])
|
|
|
+ ...mapState('target', ['subjectCode', 'levelCode'])
|
|
|
},
|
|
|
inject: ['openAiRobot'],//注入Ai机器人组件调用方法
|
|
|
watch:{
|
|
|
- // 监听顶部的subjectCode变化
|
|
|
- subjectCode(newVal, oldVal){
|
|
|
- console.log('科目编码改变了', newVal, oldVal)
|
|
|
- // ========= 业务逻辑写这里 =========
|
|
|
- // 例如:切换科目,重置步骤、重新请求知识点图谱数据
|
|
|
- if (newVal) {
|
|
|
- this.FetchWaitExerciseNum();
|
|
|
- }
|
|
|
+ subjectCode(newVal){
|
|
|
+ if (newVal) this.scheduleFetchWaitExerciseNum();
|
|
|
+ },
|
|
|
+ levelCode(newVal){
|
|
|
+ if (newVal) this.scheduleFetchWaitExerciseNum();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
mounted()
|
|
|
{
|
|
|
- this.FetchWaitExerciseNum();
|
|
|
+ this.scheduleFetchWaitExerciseNum();
|
|
|
+ },
|
|
|
+ beforeDestroy() {
|
|
|
+ clearTimeout(this._waitNumTimer);
|
|
|
},
|
|
|
methods: {
|
|
|
|
|
|
@@ -94,11 +94,24 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 科目、学段同一时刻先后就绪时,合并成一次请求
|
|
|
+ */
|
|
|
+ scheduleFetchWaitExerciseNum()
|
|
|
+ {
|
|
|
+ clearTimeout(this._waitNumTimer);
|
|
|
+ this._waitNumTimer = setTimeout(() => {
|
|
|
+ this.FetchWaitExerciseNum();
|
|
|
+ }, 0);
|
|
|
+ },
|
|
|
+
|
|
|
// 获取知识点练习作答待练习数量
|
|
|
FetchWaitExerciseNum()
|
|
|
{
|
|
|
- const levelCode = localStorage.getItem('student_level_code') || '';
|
|
|
+ const levelCode = this.levelCode || localStorage.getItem('student_level_code') || '';
|
|
|
const subjectCode = this.subjectCode || '';
|
|
|
+ // 登录后头部数据未回来前不请求,避免空参导致 500
|
|
|
+ if (!levelCode || !subjectCode) return;
|
|
|
this.$api.target.waitExerciseNum({
|
|
|
levelCode,
|
|
|
subjectCode
|