diff --git a/src/renderer/src/hooks/useProcessList.js b/src/renderer/src/hooks/useProcessList.js index 1a1ca4f..e7329eb 100644 --- a/src/renderer/src/hooks/useProcessList.js +++ b/src/renderer/src/hooks/useProcessList.js @@ -15,9 +15,10 @@ export const isJson = (str) => { /** * @description processList 格式化试题 - * @param {*} row + * @param {*} row + * @param {*} aloneOption 选择题中选项是否为每行一个 */ -export const processList = (row) => { +export const processList = (row, aloneOption=false) => { for (var i = 0; i < row.length; i++) { if (isJson(row[i].workanalysis)) { //1、先默认格式化 格式化各项内容(待优化, 后续界面显示的为format的值) @@ -55,19 +56,25 @@ export const processList = (row) => { const workDescArr = element.split('#&') let tmp = '' let j = 0 - for (; j < workDescArr.length; j++) { - if (j % 2 == 0) { - tmp += `
` + for(; j${char}.${workDescArr[j]}
`; } - const char = String.fromCharCode(65 + j) - tmp += `
${char}.${workDescArr[j]}
` - if (j % 2 == 1) { - tmp += '' + else { + if(j%2 == 0){ + tmp += `
`; + } + + tmp += `
${char}.${workDescArr[j]}
`; + if(j%2 == 1){ + tmp += '
'; + } } } // j此刻已自增1, 故当选项为单数时, 需要补充结束标签 - if (j % 2 == 1) { - tmp += '' + if(!aloneOption && j%2 == 1){ + tmp += ''; } // workDescArr为 [''] 表示为 判断题或者填空题,这里不需要选项 @@ -136,31 +143,36 @@ export const processList = (row) => { * ] */ let workDescArr = JSON.parse(row[i].workdesc) - let workDescHtml = `
` workDescArr.map((item, index) => { if (item.type == '单选题' || item.type == '多选题') { - workDescHtml += `
${index + 1}. ${item.title}
` + workDescHtml += `
${index + 1}. ${item.title}
` let tmp = '' let j = 0 let optionsArr = item.options - for (; j < optionsArr.length; j++) { - if (j % 2 == 0) { - tmp += `
` + for(; j${char}.${optionsArr[j]}
`; } - const char = String.fromCharCode(65 + j) - tmp += `
${char}.${optionsArr[j]}
` - if (j % 2 == 1) { - tmp += '
' + else { + if(j%2 == 0){ + tmp += `
`; + } + + tmp += `
${char}.${optionsArr[j]}
`; + if(j%2 == 1){ + tmp += '
'; + } } } // j此刻已自增1, 故当选项为单数时, 需要补充结束标签 - if (j % 2 == 1) { - tmp += '' + if(!aloneOption && j%2 == 1){ + tmp += ''; } - workDescHtml += tmp } else if (item.type == '填空题' || item.type == '判断题' || item.type == '主观题') { - workDescHtml += `
${index + 1}. ${item.title}
` + workDescHtml += `
${index + 1}. ${item.title}
` } }) workDescHtml += '' @@ -265,18 +277,24 @@ export const processList = (row) => { // 处理[选项显示] - 拼接ABCD首序号 let tmp = '' let j = 0 - for (; j < workDescArr.length; j++) { - if (j % 2 == 0) { - tmp += `
` + for(; j${char}.${workDescArr[j]}
`; } - const char = String.fromCharCode(65 + j) - tmp += `
${char}.${workDescArr[j]}
` - if (j % 2 == 1) { - tmp += '' + else { + if(j%2 == 0){ + tmp += `
`; + } + + tmp += `
${char}.${workDescArr[j]}
`; + if(j%2 == 1){ + tmp += '
'; + } } } - if (j % 2 == 0) { - tmp += '' + if(!aloneOption && j%2== 0){ + tmp += ''; } row[i].workdescFormat = tmp