diff --git a/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue b/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue index c5f5a83..007b9fe 100644 --- a/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue +++ b/src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue @@ -275,6 +275,13 @@ export default { return null; }, }, + userId: { + // uid + type: [String, Number], + default() { + return null; + }, + }, }, data() { return { @@ -303,26 +310,32 @@ export default { visible(val) { if (val) { // 上面数据测试 - this.testData = JSON.parse(localStorage.getItem("testData")) || []; - this.groups = JSON.parse(localStorage.getItem("question")) || []; + this.testData = + JSON.parse(localStorage.getItem(this.userId + "testData")) || []; + this.groups = + JSON.parse(localStorage.getItem(this.userId + "question")) || []; // 如果都没有直接return 执行初始化 if (this.groups.length == 0) { this.init(); - localStorage.setItem("testData", JSON.stringify(this.list)); + localStorage.setItem( + this.userId + "testData", + JSON.stringify(this.list) + ); return; } // 如果一致 就直接赋值 if ( this.arraysHaveSameIds(this.testData, this.list) && - JSON.parse(localStorage.getItem("question")) + JSON.parse(localStorage.getItem(this.userId + "question")) ) { - console.log("一致"); return; } else { - console.log("不一致", this.testData, this.list); let data = this.findMissingIds(this.testData, this.list); this.testData = this.list; - localStorage.setItem("testData", JSON.stringify(this.testData)); + localStorage.setItem( + this.userId + "testData", + JSON.stringify(this.testData) + ); this.testAddDel(this.groups, data.addArr, data.delArr); } } else { @@ -349,7 +362,10 @@ export default { this.groups.reduce((accumulator, current) => { return accumulator.concat(current.subQuestionIds); }, []) || []; - localStorage.setItem("testData", JSON.stringify(this.testData)); + localStorage.setItem( + this.userId + "testData", + JSON.stringify(this.testData) + ); }, /** 按钮 - 取消 */ handleClose() { @@ -373,7 +389,10 @@ export default { allItems.forEach((item, index) => { item.globalIndex = index + 1; }); - localStorage.setItem("question", JSON.stringify(this.groups)); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); }, classifyByType(arr) { const result = {}; @@ -424,7 +443,10 @@ export default { // 保存修改后的内容,回车或失去焦点时触发 save() { this.isEditing = false; - localStorage.setItem("question", JSON.stringify(this.groups)); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); }, // 单题title修改 @@ -441,7 +463,10 @@ export default { // 单体title保存 groupSave(index) { this.$set(this.groups[index], "input", false); - localStorage.setItem("question", JSON.stringify(this.groups)); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); }, // 高亮 selectItem(id, type) { @@ -459,10 +484,16 @@ export default { let _index = this.groups.findIndex((item) => item.questionType == id); if (_index != -1) { this.groups.splice(_index, 1); - localStorage.setItem("question", JSON.stringify(this.groups)); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); this.updateGlobalIndexes(); this.testDataFun(); - localStorage.setItem("testlist", JSON.stringify(this.testData)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.testData) + ); this.$emit("setQuestions"); } } else { @@ -473,10 +504,16 @@ export default { ); } }); - localStorage.setItem("question", JSON.stringify(this.groups)); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); this.updateGlobalIndexes(); this.testDataFun(); - localStorage.setItem("testlist", JSON.stringify(this.testData)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.testData) + ); this.$emit("setQuestions"); } }, @@ -620,8 +657,6 @@ export default { let matchedArray1Item = arr1.find((item1) => item1.subQuestionIds.filter((item) => item.id == item3.id) ); - console.log(matchedArray1Item, "matchedArray1Item"); - if (matchedArray1Item) { // 如果找到了匹配的 type,遍历 matchedArray1Item 的 items let _index = matchedArray1Item.subQuestionIds.findIndex( @@ -682,8 +717,14 @@ export default { if (res.status == 0) { this.groups = []; this.testData = []; - localStorage.setItem("testlist", JSON.stringify(this.testData)); - localStorage.setItem("question", JSON.stringify(this.groups)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.testData) + ); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); this.$emit("setQuestions"); this.handleClose(); if (type == "print") { @@ -714,8 +755,15 @@ export default { .then(() => { this.groups = []; this.testDataFun(); - localStorage.setItem("question", JSON.stringify(this.groups)); - localStorage.setItem("testlist", JSON.stringify(this.testData)); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.testData) + ); + this.$emit("setQuestions"); }) .catch(() => { @@ -736,7 +784,10 @@ export default { // 当分数发生变化的时候 handleInput() { - localStorage.setItem("question", JSON.stringify(this.groups)); + localStorage.setItem( + this.userId + "question", + JSON.stringify(this.groups) + ); }, }, }; diff --git a/src/views/basic/askTestQuestion/wrongQuestion.vue b/src/views/basic/askTestQuestion/wrongQuestion.vue index 4d5fdbb..873c922 100644 --- a/src/views/basic/askTestQuestion/wrongQuestion.vue +++ b/src/views/basic/askTestQuestion/wrongQuestion.vue @@ -247,6 +247,7 @@ :sectionId="formData.sectionId" :gradeId="formData.grade" @setQuestions="setQuestions" + :userId="userId" /> obj.id === item.id)) return; - this.questions = JSON.parse(localStorage.getItem("testlist")) || []; + this.questions = + JSON.parse(localStorage.getItem(this.userId + "testlist")) || []; this.questions.push(item); - localStorage.setItem("testlist", JSON.stringify(this.questions)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.questions) + ); }, // 移除试卷 handleDel(item) { let _index = this.questions.findIndex((obj) => obj.id === item.id); if (_index !== -1) { this.questions.splice(_index, 1); // 从索引位置删除一个元素 - localStorage.setItem("testlist", JSON.stringify(this.questions)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.questions) + ); } }, // 全部选中 handleAllTest() { // 获取原来的localStorage - let list = JSON.parse(localStorage.getItem("testlist")) || []; + let list = + JSON.parse(localStorage.getItem(this.userId + "testlist")) || []; let ids = this.topicList.map((item) => { return item; }); - console.log(list, "-=-11-="); - this.questions = this.removeDuplicates([...ids, ...list]); - localStorage.setItem("testlist", JSON.stringify(this.questions)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.questions) + ); }, // 全部删除 handleDelTest() { let list = this.removeMatchingValues(this.topicList, this.questions); this.questions = list; - console.log("移除本业", this.questions); - - localStorage.setItem("testlist", JSON.stringify(this.questions)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.questions) + ); }, // 重置 去除locastorage 以及 questions handleRest() { this.questions = []; - localStorage.setItem("testlist", JSON.stringify(this.questions)); + localStorage.setItem( + this.userId + "testlist", + JSON.stringify(this.questions) + ); }, // 去重 removeDuplicates(arr) { @@ -532,27 +553,17 @@ export default { // 获取科目列表 async getSubject(params) { - console.log(params, "params"); - let data = await this.$request.getSubjectList(params); - console.log(data, "--------"); - this.subjectList = data.data.subjectNames; - console.log(this.subjectList, "我被打印了"); - this.formData.subjectName = this.subjectList[0]; this.getClassList(); }, // 获取年级列表 async getGradeList() { let data = await this.$request.getClassList(); - console.log(data, "----------data"); - this.gradeList = Array.from( new Map(data.data.list.map((item) => [item.grade, item])).values() ); - console.log(this.gradeList, "gradeList"); - this.formData.grade = this.gradeList[0].grade; this.formData.sectionId = this.gradeList[0].section; this.formData.gradeName = this.gradeList.find( @@ -562,8 +573,6 @@ export default { }, // 获取班级信息 async getClassList() { - console.log(this.formData, "this.formDate"); - let data = await this.$request.getGradeList({ grade: this.formData.grade, subjectName: this.formData.subjectName, @@ -632,7 +641,8 @@ export default { // 子集删除后 父级需要更新 setQuestions() { - this.questions = JSON.parse(localStorage.getItem("testlist")) || []; + this.questions = + JSON.parse(localStorage.getItem(this.userId + "testlist")) || []; }, // 查看解析