mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-18 15:26:45 +08:00
Compare commits
1 Commits
fix_1155
...
master-bug
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b517d92347 |
@@ -167,7 +167,7 @@
|
|||||||
import simplePaper from "@/components/Course/simpleTestPaper.vue";
|
import simplePaper from "@/components/Course/simpleTestPaper.vue";
|
||||||
import apiCourse from '../../api/modules/course.js';
|
import apiCourse from '../../api/modules/course.js';
|
||||||
import apiExamPaper from '../../api/modules/paper.js';
|
import apiExamPaper from '../../api/modules/paper.js';
|
||||||
import { deepClone } from "../../utils";
|
import { deepClone, safeJsonParse } from "../../utils";
|
||||||
export default{
|
export default{
|
||||||
components:{simplePaper},
|
components:{simplePaper},
|
||||||
props:{
|
props:{
|
||||||
@@ -253,7 +253,7 @@
|
|||||||
this.examInfo=res.result;
|
this.examInfo=res.result;
|
||||||
if(res.result.paperType==1){
|
if(res.result.paperType==1){
|
||||||
this.examInfo.paperContent=res.result.paperContent;
|
this.examInfo.paperContent=res.result.paperContent;
|
||||||
this.examPaper=JSON.parse(res.result.paperContent);
|
this.examPaper = safeJsonParse(res.result.paperContent, { items: [] });
|
||||||
}else{
|
}else{
|
||||||
apiExamPaper.detail(this.examInfo.paperId).then(rs=>{
|
apiExamPaper.detail(this.examInfo.paperId).then(rs=>{
|
||||||
if(rs.status==200){
|
if(rs.status==200){
|
||||||
|
|||||||
@@ -132,6 +132,7 @@ import apiCourse from '@/api/modules/course.js';
|
|||||||
import apiExamPaper from '@/api/modules/paper.js';
|
import apiExamPaper from '@/api/modules/paper.js';
|
||||||
import {formatDate,formatSeconds} from '@/utils/datetime.js';
|
import {formatDate,formatSeconds} from '@/utils/datetime.js';
|
||||||
import {testType,correctJudgment,numberToLetter} from '@/utils/tools.js';
|
import {testType,correctJudgment,numberToLetter} from '@/utils/tools.js';
|
||||||
|
import { safeJsonParse } from '@/utils/index.js';
|
||||||
export default {
|
export default {
|
||||||
props:{
|
props:{
|
||||||
studyId: {
|
studyId: {
|
||||||
@@ -217,7 +218,11 @@ export default {
|
|||||||
if(res.status==200){
|
if(res.status==200){
|
||||||
this.info=res.result;
|
this.info=res.result;
|
||||||
if(this.showTest) {
|
if(this.showTest) {
|
||||||
let paper= JSON.parse(this.info.paperContent);
|
let paper = safeJsonParse(this.info.paperContent, { items: [] });
|
||||||
|
if(!paper.items || paper.items.length === 0){
|
||||||
|
this.viewTest = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
paper.items.forEach(item=>{
|
paper.items.forEach(item=>{
|
||||||
//console.log(item);
|
//console.log(item);
|
||||||
if(item.type==101){
|
if(item.type==101){
|
||||||
|
|||||||
@@ -575,7 +575,7 @@
|
|||||||
import apiExamPaper from '../../api/modules/paper.js';
|
import apiExamPaper from '../../api/modules/paper.js';
|
||||||
import audioPlayer from '@/components/AudioPlayer/index.vue';
|
import audioPlayer from '@/components/AudioPlayer/index.vue';
|
||||||
import {getType} from '../../utils/tools.js';
|
import {getType} from '../../utils/tools.js';
|
||||||
import { deepClone } from "../../utils";
|
import { deepClone, safeJsonParse } from "../../utils";
|
||||||
export default{
|
export default{
|
||||||
components:{WxEditor,simplePaper,FileUpload,pdfPreview,audioPlayer,chooseCourseFile},
|
components:{WxEditor,simplePaper,FileUpload,pdfPreview,audioPlayer,chooseCourseFile},
|
||||||
props: {
|
props: {
|
||||||
@@ -921,7 +921,7 @@
|
|||||||
if(res.status==200){
|
if(res.status==200){
|
||||||
this.exam.info=res.result;
|
this.exam.info=res.result;
|
||||||
if(res.result.paperType==1){
|
if(res.result.paperType==1){
|
||||||
this.exam.paperJson=JSON.parse(res.result.paperContent);
|
this.exam.paperJson = safeJsonParse(res.result.paperContent, { items: [] });
|
||||||
}else{
|
}else{
|
||||||
apiExamPaper.detail(this.exam.info.paperId).then(rs=>{
|
apiExamPaper.detail(this.exam.info.paperId).then(rs=>{
|
||||||
if(rs.status==200){
|
if(rs.status==200){
|
||||||
|
|||||||
@@ -109,6 +109,7 @@
|
|||||||
import imgupload from '@/components/ImageUpload/single.vue';
|
import imgupload from '@/components/ImageUpload/single.vue';
|
||||||
import apiExamTask from '@/api/modules/examTask.js';
|
import apiExamTask from '@/api/modules/examTask.js';
|
||||||
import examQuestionApi from "@/api/modules/question";
|
import examQuestionApi from "@/api/modules/question";
|
||||||
|
import { safeJsonParse } from '../../utils';
|
||||||
import {numberToLetter, deepCopy} from '../../utils/tools.js';
|
import {numberToLetter, deepCopy} from '../../utils/tools.js';
|
||||||
export default {
|
export default {
|
||||||
name: 'comEditPaper',
|
name: 'comEditPaper',
|
||||||
@@ -163,7 +164,7 @@
|
|||||||
if(res.status === 200) {
|
if(res.status === 200) {
|
||||||
this.paper=res.result;
|
this.paper=res.result;
|
||||||
//转化试题
|
//转化试题
|
||||||
this.qitems=JSON.parse(res.result.paperContent);
|
this.qitems = safeJsonParse(res.result.paperContent, []);
|
||||||
//console.log(this.qitems,this.qitems)
|
//console.log(this.qitems,this.qitems)
|
||||||
this.tempItems=this.qitems;
|
this.tempItems=this.qitems;
|
||||||
this.paperCalculation();
|
this.paperCalculation();
|
||||||
|
|||||||
@@ -310,6 +310,42 @@ export function deepClone(source) {
|
|||||||
return targetObj
|
return targetObj
|
||||||
}
|
}
|
||||||
|
|
||||||
|
import { Message } from 'element-ui';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全解析 JSON 字符串,统一处理错误日志和 UI 提示
|
||||||
|
* @param {string|object} text 待解析的字符串(或对象)
|
||||||
|
* @param {*} fallback 解析失败或为空时的回退值,默认为空对象 {}
|
||||||
|
* @param {string} errorMessage UI 提示信息,默认为试卷格式错误提示
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
export function safeJsonParse(text, fallback = {}, errorMessage = '试卷内容格式有误,请联系管理员检查试卷数据') {
|
||||||
|
// 1. 如果已经是对象或数组,直接返回
|
||||||
|
if (typeof text === 'object' && text !== null) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 处理空值情况
|
||||||
|
if (text === null || text === undefined || text === '') {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 尝试解析
|
||||||
|
try {
|
||||||
|
return JSON.parse(text);
|
||||||
|
} catch (error) {
|
||||||
|
// 4. 统一日志和报错
|
||||||
|
console.error('JSON 解析失败:', {
|
||||||
|
input: text,
|
||||||
|
error: error.message
|
||||||
|
});
|
||||||
|
if (errorMessage) {
|
||||||
|
Message.error(errorMessage);
|
||||||
|
}
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array} arr
|
* @param {Array} arr
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
|
|||||||
@@ -296,7 +296,7 @@
|
|||||||
import apiPaper from '@/api/modules/paper.js';
|
import apiPaper from '@/api/modules/paper.js';
|
||||||
import apiExamTask from '@/api/modules/examTask.js';
|
import apiExamTask from '@/api/modules/examTask.js';
|
||||||
import examQuestionApi from "@/api/modules/question";
|
import examQuestionApi from "@/api/modules/question";
|
||||||
import { deepClone } from '../../utils';
|
import { deepClone, safeJsonParse } from '../../utils';
|
||||||
import {numberToLetter, deepCopy} from '../../utils/tools.js';
|
import {numberToLetter, deepCopy} from '../../utils/tools.js';
|
||||||
import { mapGetters,mapActions} from 'vuex';
|
import { mapGetters,mapActions} from 'vuex';
|
||||||
import editPaper from "@/components/Exam/EditPaper";
|
import editPaper from "@/components/Exam/EditPaper";
|
||||||
@@ -689,7 +689,7 @@ export default {
|
|||||||
this.viewVolumeShow=true;
|
this.viewVolumeShow=true;
|
||||||
apiPaper.detail(row.id).then(res=>{
|
apiPaper.detail(row.id).then(res=>{
|
||||||
if(res.status === 200) {
|
if(res.status === 200) {
|
||||||
this.viewShowData = JSON.parse(res.result.paperContent);
|
this.viewShowData = safeJsonParse(res.result.paperContent, { items: [] });
|
||||||
console.log(this.viewShowData,'lll')
|
console.log(this.viewShowData,'lll')
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(res.message);
|
this.$message.error(res.message);
|
||||||
@@ -720,8 +720,9 @@ export default {
|
|||||||
apiPaper.detail(row.id).then(res=>{
|
apiPaper.detail(row.id).then(res=>{
|
||||||
if(res.status === 200) {
|
if(res.status === 200) {
|
||||||
this.paper = res.result;
|
this.paper = res.result;
|
||||||
this.paper.data = JSON.parse(res.result.paperContent);
|
const parsedValue = safeJsonParse(res.result.paperContent, []);
|
||||||
this.paperData = JSON.parse(res.result.paperContent);
|
this.paper.data = parsedValue;
|
||||||
|
this.paperData = parsedValue;
|
||||||
this.paper.paperType = Number(res.result.paperType);
|
this.paper.paperType = Number(res.result.paperType);
|
||||||
if(res.result.resOwner3) {
|
if(res.result.resOwner3) {
|
||||||
this.resOwner = [res.result.resOwner1,res.result.resOwner2,res.result.resOwner3];
|
this.resOwner = [res.result.resOwner1,res.result.resOwner2,res.result.resOwner3];
|
||||||
|
|||||||
@@ -357,7 +357,7 @@ import apiCourse from "@/api/modules/course.js";
|
|||||||
import apiCourseFile from "@/api/modules/courseFile.js";
|
import apiCourseFile from "@/api/modules/courseFile.js";
|
||||||
import apiCoursePortal from "@/api/modules/coursePortal.js";
|
import apiCoursePortal from "@/api/modules/coursePortal.js";
|
||||||
import apiUser from '@/api/system/user.js';
|
import apiUser from '@/api/system/user.js';
|
||||||
import {
|
import {
|
||||||
formatDate,
|
formatDate,
|
||||||
resListMap,
|
resListMap,
|
||||||
toScore,
|
toScore,
|
||||||
@@ -365,8 +365,9 @@ import {
|
|||||||
getType,
|
getType,
|
||||||
numberToLetter,
|
numberToLetter,
|
||||||
correctJudgment
|
correctJudgment
|
||||||
} from "@/utils/tools.js";
|
} from "@/utils/tools.js";
|
||||||
import apicourseStudy from "@/api/modules/courseStudy.js";
|
import { safeJsonParse } from "@/utils";
|
||||||
|
import apicourseStudy from "@/api/modules/courseStudy.js";
|
||||||
import apiCourseGrade from "@/api/modules/courseGrade.js";
|
import apiCourseGrade from "@/api/modules/courseGrade.js";
|
||||||
import apiPraises from "@/api/modules/praises.js";
|
import apiPraises from "@/api/modules/praises.js";
|
||||||
import apiTrample from "@/api/modules/trample.js";
|
import apiTrample from "@/api/modules/trample.js";
|
||||||
@@ -716,7 +717,7 @@ export default {
|
|||||||
apiCourse.getExam(this.examInfo.content.id).then(res => {
|
apiCourse.getExam(this.examInfo.content.id).then(res => {
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
this.examInfo.info = res.result;
|
this.examInfo.info = res.result;
|
||||||
this.examInfo.paper = JSON.parse(res.result.paperContent);
|
this.examInfo.paper = safeJsonParse(res.result.paperContent, { items: [] });
|
||||||
} else if (res.status == 404) {
|
} else if (res.status == 404) {
|
||||||
//没有找到考试信息
|
//没有找到考试信息
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user