Commit c412d95df69de6c193f5e2f62467a72a0430a2a1
1 parent
adea2553
wip: 代码提交
Showing
2 changed files
with
111 additions
and
50 deletions
src/views/basic/askTestQuestion/components/wrongQuestionDialog.vue
| ... | ... | @@ -275,6 +275,13 @@ export default { | 
| 275 | 275 | return null; | 
| 276 | 276 | }, | 
| 277 | 277 | }, | 
| 278 | + userId: { | |
| 279 | + // uid | |
| 280 | + type: [String, Number], | |
| 281 | + default() { | |
| 282 | + return null; | |
| 283 | + }, | |
| 284 | + }, | |
| 278 | 285 | }, | 
| 279 | 286 | data() { | 
| 280 | 287 | return { | 
| ... | ... | @@ -303,26 +310,32 @@ export default { | 
| 303 | 310 | visible(val) { | 
| 304 | 311 | if (val) { | 
| 305 | 312 | // 上面数据测试 | 
| 306 | - this.testData = JSON.parse(localStorage.getItem("testData")) || []; | |
| 307 | - this.groups = JSON.parse(localStorage.getItem("question")) || []; | |
| 313 | + this.testData = | |
| 314 | + JSON.parse(localStorage.getItem(this.userId + "testData")) || []; | |
| 315 | + this.groups = | |
| 316 | + JSON.parse(localStorage.getItem(this.userId + "question")) || []; | |
| 308 | 317 | // 如果都没有直接return 执行初始化 | 
| 309 | 318 | if (this.groups.length == 0) { | 
| 310 | 319 | this.init(); | 
| 311 | - localStorage.setItem("testData", JSON.stringify(this.list)); | |
| 320 | + localStorage.setItem( | |
| 321 | + this.userId + "testData", | |
| 322 | + JSON.stringify(this.list) | |
| 323 | + ); | |
| 312 | 324 | return; | 
| 313 | 325 | } | 
| 314 | 326 | // 如果一致 就直接赋值 | 
| 315 | 327 | if ( | 
| 316 | 328 | this.arraysHaveSameIds(this.testData, this.list) && | 
| 317 | - JSON.parse(localStorage.getItem("question")) | |
| 329 | + JSON.parse(localStorage.getItem(this.userId + "question")) | |
| 318 | 330 | ) { | 
| 319 | - console.log("一致"); | |
| 320 | 331 | return; | 
| 321 | 332 | } else { | 
| 322 | - console.log("不一致", this.testData, this.list); | |
| 323 | 333 | let data = this.findMissingIds(this.testData, this.list); | 
| 324 | 334 | this.testData = this.list; | 
| 325 | - localStorage.setItem("testData", JSON.stringify(this.testData)); | |
| 335 | + localStorage.setItem( | |
| 336 | + this.userId + "testData", | |
| 337 | + JSON.stringify(this.testData) | |
| 338 | + ); | |
| 326 | 339 | this.testAddDel(this.groups, data.addArr, data.delArr); | 
| 327 | 340 | } | 
| 328 | 341 | } else { | 
| ... | ... | @@ -349,7 +362,10 @@ export default { | 
| 349 | 362 | this.groups.reduce((accumulator, current) => { | 
| 350 | 363 | return accumulator.concat(current.subQuestionIds); | 
| 351 | 364 | }, []) || []; | 
| 352 | - localStorage.setItem("testData", JSON.stringify(this.testData)); | |
| 365 | + localStorage.setItem( | |
| 366 | + this.userId + "testData", | |
| 367 | + JSON.stringify(this.testData) | |
| 368 | + ); | |
| 353 | 369 | }, | 
| 354 | 370 | /** 按钮 - 取消 */ | 
| 355 | 371 | handleClose() { | 
| ... | ... | @@ -373,7 +389,10 @@ export default { | 
| 373 | 389 | allItems.forEach((item, index) => { | 
| 374 | 390 | item.globalIndex = index + 1; | 
| 375 | 391 | }); | 
| 376 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 392 | + localStorage.setItem( | |
| 393 | + this.userId + "question", | |
| 394 | + JSON.stringify(this.groups) | |
| 395 | + ); | |
| 377 | 396 | }, | 
| 378 | 397 | classifyByType(arr) { | 
| 379 | 398 | const result = {}; | 
| ... | ... | @@ -424,7 +443,10 @@ export default { | 
| 424 | 443 | // 保存修改后的内容,回车或失去焦点时触发 | 
| 425 | 444 | save() { | 
| 426 | 445 | this.isEditing = false; | 
| 427 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 446 | + localStorage.setItem( | |
| 447 | + this.userId + "question", | |
| 448 | + JSON.stringify(this.groups) | |
| 449 | + ); | |
| 428 | 450 | }, | 
| 429 | 451 | |
| 430 | 452 | // 单题title修改 | 
| ... | ... | @@ -441,7 +463,10 @@ export default { | 
| 441 | 463 | // 单体title保存 | 
| 442 | 464 | groupSave(index) { | 
| 443 | 465 | this.$set(this.groups[index], "input", false); | 
| 444 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 466 | + localStorage.setItem( | |
| 467 | + this.userId + "question", | |
| 468 | + JSON.stringify(this.groups) | |
| 469 | + ); | |
| 445 | 470 | }, | 
| 446 | 471 | // 高亮 | 
| 447 | 472 | selectItem(id, type) { | 
| ... | ... | @@ -459,10 +484,16 @@ export default { | 
| 459 | 484 | let _index = this.groups.findIndex((item) => item.questionType == id); | 
| 460 | 485 | if (_index != -1) { | 
| 461 | 486 | this.groups.splice(_index, 1); | 
| 462 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 487 | + localStorage.setItem( | |
| 488 | + this.userId + "question", | |
| 489 | + JSON.stringify(this.groups) | |
| 490 | + ); | |
| 463 | 491 | this.updateGlobalIndexes(); | 
| 464 | 492 | this.testDataFun(); | 
| 465 | - localStorage.setItem("testlist", JSON.stringify(this.testData)); | |
| 493 | + localStorage.setItem( | |
| 494 | + this.userId + "testlist", | |
| 495 | + JSON.stringify(this.testData) | |
| 496 | + ); | |
| 466 | 497 | this.$emit("setQuestions"); | 
| 467 | 498 | } | 
| 468 | 499 | } else { | 
| ... | ... | @@ -473,10 +504,16 @@ export default { | 
| 473 | 504 | ); | 
| 474 | 505 | } | 
| 475 | 506 | }); | 
| 476 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 507 | + localStorage.setItem( | |
| 508 | + this.userId + "question", | |
| 509 | + JSON.stringify(this.groups) | |
| 510 | + ); | |
| 477 | 511 | this.updateGlobalIndexes(); | 
| 478 | 512 | this.testDataFun(); | 
| 479 | - localStorage.setItem("testlist", JSON.stringify(this.testData)); | |
| 513 | + localStorage.setItem( | |
| 514 | + this.userId + "testlist", | |
| 515 | + JSON.stringify(this.testData) | |
| 516 | + ); | |
| 480 | 517 | this.$emit("setQuestions"); | 
| 481 | 518 | } | 
| 482 | 519 | }, | 
| ... | ... | @@ -620,8 +657,6 @@ export default { | 
| 620 | 657 | let matchedArray1Item = arr1.find((item1) => | 
| 621 | 658 | item1.subQuestionIds.filter((item) => item.id == item3.id) | 
| 622 | 659 | ); | 
| 623 | - console.log(matchedArray1Item, "matchedArray1Item"); | |
| 624 | - | |
| 625 | 660 | if (matchedArray1Item) { | 
| 626 | 661 | // 如果找到了匹配的 type,遍历 matchedArray1Item 的 items | 
| 627 | 662 | let _index = matchedArray1Item.subQuestionIds.findIndex( | 
| ... | ... | @@ -682,8 +717,14 @@ export default { | 
| 682 | 717 | if (res.status == 0) { | 
| 683 | 718 | this.groups = []; | 
| 684 | 719 | this.testData = []; | 
| 685 | - localStorage.setItem("testlist", JSON.stringify(this.testData)); | |
| 686 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 720 | + localStorage.setItem( | |
| 721 | + this.userId + "testlist", | |
| 722 | + JSON.stringify(this.testData) | |
| 723 | + ); | |
| 724 | + localStorage.setItem( | |
| 725 | + this.userId + "question", | |
| 726 | + JSON.stringify(this.groups) | |
| 727 | + ); | |
| 687 | 728 | this.$emit("setQuestions"); | 
| 688 | 729 | this.handleClose(); | 
| 689 | 730 | if (type == "print") { | 
| ... | ... | @@ -714,8 +755,15 @@ export default { | 
| 714 | 755 | .then(() => { | 
| 715 | 756 | this.groups = []; | 
| 716 | 757 | this.testDataFun(); | 
| 717 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 718 | - localStorage.setItem("testlist", JSON.stringify(this.testData)); | |
| 758 | + localStorage.setItem( | |
| 759 | + this.userId + "question", | |
| 760 | + JSON.stringify(this.groups) | |
| 761 | + ); | |
| 762 | + localStorage.setItem( | |
| 763 | + this.userId + "testlist", | |
| 764 | + JSON.stringify(this.testData) | |
| 765 | + ); | |
| 766 | + | |
| 719 | 767 | this.$emit("setQuestions"); | 
| 720 | 768 | }) | 
| 721 | 769 | .catch(() => { | 
| ... | ... | @@ -736,7 +784,10 @@ export default { | 
| 736 | 784 | |
| 737 | 785 | // 当分数发生变化的时候 | 
| 738 | 786 | handleInput() { | 
| 739 | - localStorage.setItem("question", JSON.stringify(this.groups)); | |
| 787 | + localStorage.setItem( | |
| 788 | + this.userId + "question", | |
| 789 | + JSON.stringify(this.groups) | |
| 790 | + ); | |
| 740 | 791 | }, | 
| 741 | 792 | }, | 
| 742 | 793 | }; | ... | ... | 
src/views/basic/askTestQuestion/wrongQuestion.vue
| ... | ... | @@ -247,6 +247,7 @@ | 
| 247 | 247 | :sectionId="formData.sectionId" | 
| 248 | 248 | :gradeId="formData.grade" | 
| 249 | 249 | @setQuestions="setQuestions" | 
| 250 | + :userId="userId" | |
| 250 | 251 | /> | 
| 251 | 252 | <analysisDialog | 
| 252 | 253 | :visible.sync="analysisVisible" | 
| ... | ... | @@ -316,18 +317,25 @@ export default { | 
| 316 | 317 | grade: null, // 年级 | 
| 317 | 318 | gradeName: null, // 年级名称 | 
| 318 | 319 | }, | 
| 320 | + userId: "", | |
| 319 | 321 | questions: [], | 
| 320 | 322 | }; | 
| 321 | 323 | }, | 
| 322 | 324 | created() { | 
| 325 | + let user = JSON.parse(localStorage.getItem("info")); | |
| 326 | + this.userId = user.uid; | |
| 323 | 327 | this.handleDate(this.formData.type); | 
| 324 | 328 | this.queryLoading = true; | 
| 325 | 329 | this.getGradeList(); | 
| 326 | - if (!localStorage.getItem("testlist")) { | |
| 327 | - localStorage.setItem("testlist", JSON.stringify(this.questions)); | |
| 330 | + if (!localStorage.getItem(this.userId + "testlist")) { | |
| 331 | + localStorage.setItem( | |
| 332 | + this.userId + "testlist", | |
| 333 | + JSON.stringify(this.questions) | |
| 334 | + ); | |
| 328 | 335 | } else { | 
| 329 | - this.questions = JSON.parse(localStorage.getItem("testlist")); | |
| 330 | - console.log(this.questions, "==="); | |
| 336 | + this.questions = JSON.parse( | |
| 337 | + localStorage.getItem(this.userId + "testlist") | |
| 338 | + ); | |
| 331 | 339 | } | 
| 332 | 340 | }, | 
| 333 | 341 | methods: { | 
| ... | ... | @@ -458,43 +466,56 @@ export default { | 
| 458 | 466 | handleAddTest(item) { | 
| 459 | 467 | // if (this.questions.includes(item.id)) return; | 
| 460 | 468 | if (this.questions.some((obj) => obj.id === item.id)) return; | 
| 461 | - this.questions = JSON.parse(localStorage.getItem("testlist")) || []; | |
| 469 | + this.questions = | |
| 470 | + JSON.parse(localStorage.getItem(this.userId + "testlist")) || []; | |
| 462 | 471 | this.questions.push(item); | 
| 463 | - localStorage.setItem("testlist", JSON.stringify(this.questions)); | |
| 472 | + localStorage.setItem( | |
| 473 | + this.userId + "testlist", | |
| 474 | + JSON.stringify(this.questions) | |
| 475 | + ); | |
| 464 | 476 | }, | 
| 465 | 477 | // 移除试卷 | 
| 466 | 478 | handleDel(item) { | 
| 467 | 479 | let _index = this.questions.findIndex((obj) => obj.id === item.id); | 
| 468 | 480 | if (_index !== -1) { | 
| 469 | 481 | this.questions.splice(_index, 1); // 从索引位置删除一个元素 | 
| 470 | - localStorage.setItem("testlist", JSON.stringify(this.questions)); | |
| 482 | + localStorage.setItem( | |
| 483 | + this.userId + "testlist", | |
| 484 | + JSON.stringify(this.questions) | |
| 485 | + ); | |
| 471 | 486 | } | 
| 472 | 487 | }, | 
| 473 | 488 | // 全部选中 | 
| 474 | 489 | handleAllTest() { | 
| 475 | 490 | // 获取原来的localStorage | 
| 476 | - let list = JSON.parse(localStorage.getItem("testlist")) || []; | |
| 491 | + let list = | |
| 492 | + JSON.parse(localStorage.getItem(this.userId + "testlist")) || []; | |
| 477 | 493 | |
| 478 | 494 | let ids = this.topicList.map((item) => { | 
| 479 | 495 | return item; | 
| 480 | 496 | }); | 
| 481 | - console.log(list, "-=-11-="); | |
| 482 | - | |
| 483 | 497 | this.questions = this.removeDuplicates([...ids, ...list]); | 
| 484 | - localStorage.setItem("testlist", JSON.stringify(this.questions)); | |
| 498 | + localStorage.setItem( | |
| 499 | + this.userId + "testlist", | |
| 500 | + JSON.stringify(this.questions) | |
| 501 | + ); | |
| 485 | 502 | }, | 
| 486 | 503 | // 全部删除 | 
| 487 | 504 | handleDelTest() { | 
| 488 | 505 | let list = this.removeMatchingValues(this.topicList, this.questions); | 
| 489 | 506 | this.questions = list; | 
| 490 | - console.log("移除本业", this.questions); | |
| 491 | - | |
| 492 | - localStorage.setItem("testlist", JSON.stringify(this.questions)); | |
| 507 | + localStorage.setItem( | |
| 508 | + this.userId + "testlist", | |
| 509 | + JSON.stringify(this.questions) | |
| 510 | + ); | |
| 493 | 511 | }, | 
| 494 | 512 | // 重置 去除locastorage 以及 questions | 
| 495 | 513 | handleRest() { | 
| 496 | 514 | this.questions = []; | 
| 497 | - localStorage.setItem("testlist", JSON.stringify(this.questions)); | |
| 515 | + localStorage.setItem( | |
| 516 | + this.userId + "testlist", | |
| 517 | + JSON.stringify(this.questions) | |
| 518 | + ); | |
| 498 | 519 | }, | 
| 499 | 520 | // 去重 | 
| 500 | 521 | removeDuplicates(arr) { | 
| ... | ... | @@ -532,27 +553,17 @@ export default { | 
| 532 | 553 | |
| 533 | 554 | // 获取科目列表 | 
| 534 | 555 | async getSubject(params) { | 
| 535 | - console.log(params, "params"); | |
| 536 | - | |
| 537 | 556 | let data = await this.$request.getSubjectList(params); | 
| 538 | - console.log(data, "--------"); | |
| 539 | - | |
| 540 | 557 | this.subjectList = data.data.subjectNames; | 
| 541 | - console.log(this.subjectList, "我被打印了"); | |
| 542 | - | |
| 543 | 558 | this.formData.subjectName = this.subjectList[0]; | 
| 544 | 559 | this.getClassList(); | 
| 545 | 560 | }, | 
| 546 | 561 | // 获取年级列表 | 
| 547 | 562 | async getGradeList() { | 
| 548 | 563 | let data = await this.$request.getClassList(); | 
| 549 | - console.log(data, "----------data"); | |
| 550 | - | |
| 551 | 564 | this.gradeList = Array.from( | 
| 552 | 565 | new Map(data.data.list.map((item) => [item.grade, item])).values() | 
| 553 | 566 | ); | 
| 554 | - console.log(this.gradeList, "gradeList"); | |
| 555 | - | |
| 556 | 567 | this.formData.grade = this.gradeList[0].grade; | 
| 557 | 568 | this.formData.sectionId = this.gradeList[0].section; | 
| 558 | 569 | this.formData.gradeName = this.gradeList.find( | 
| ... | ... | @@ -562,8 +573,6 @@ export default { | 
| 562 | 573 | }, | 
| 563 | 574 | // 获取班级信息 | 
| 564 | 575 | async getClassList() { | 
| 565 | - console.log(this.formData, "this.formDate"); | |
| 566 | - | |
| 567 | 576 | let data = await this.$request.getGradeList({ | 
| 568 | 577 | grade: this.formData.grade, | 
| 569 | 578 | subjectName: this.formData.subjectName, | 
| ... | ... | @@ -632,7 +641,8 @@ export default { | 
| 632 | 641 | |
| 633 | 642 | // 子集删除后 父级需要更新 | 
| 634 | 643 | setQuestions() { | 
| 635 | - this.questions = JSON.parse(localStorage.getItem("testlist")) || []; | |
| 644 | + this.questions = | |
| 645 | + JSON.parse(localStorage.getItem(this.userId + "testlist")) || []; | |
| 636 | 646 | }, | 
| 637 | 647 | |
| 638 | 648 | // 查看解析 | ... | ... | 
