zouyf_dev #353

Merged
zouyf merged 5 commits from zouyf_dev into main 2024-10-22 16:54:42 +08:00
1 changed files with 51 additions and 33 deletions
Showing only changes of commit ef75fb7570 - Show all commits

View File

@ -15,9 +15,10 @@ export const isJson = (str) => {
/** /**
* @description processList 格式化试题 * @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++) { for (var i = 0; i < row.length; i++) {
if (isJson(row[i].workanalysis)) { if (isJson(row[i].workanalysis)) {
//1、先默认格式化 格式化各项内容(待优化, 后续界面显示的为format的值) //1、先默认格式化 格式化各项内容(待优化, 后续界面显示的为format的值)
@ -55,19 +56,25 @@ export const processList = (row) => {
const workDescArr = element.split('#&') const workDescArr = element.split('#&')
let tmp = '' let tmp = ''
let j = 0 let j = 0
for (; j < workDescArr.length; j++) { for(; j<workDescArr.length; j++){
if (j % 2 == 0) { const char = String.fromCharCode(65+j);
tmp += `<div style='width:80%;display:flex;'>` if (aloneOption) {
tmp += `<div style='width:100%;display:flex;padding: 2px 0'>${char}.${workDescArr[j]}</div>`;
} }
const char = String.fromCharCode(65 + j) else {
tmp += `<div style='display:flex;margin-left:2%;width:35%;overflow:hidden;text-overflow:ellipsis;font-size:0.9em;'>${char}.${workDescArr[j]}</div>` if(j%2 == 0){
if (j % 2 == 1) { tmp += `<div style='width:100%;display:flex;'>`;
tmp += '</div>' }
tmp += `<div style='padding-left:10px;width:50%;overflow:hidden;text-overflow:ellipsis;font-size:0.9em;'>${char}.${workDescArr[j]}</div>`;
if(j%2 == 1){
tmp += '</div>';
}
} }
} }
// j此刻已自增1, 故当选项为单数时, 需要补充结束标签 // j此刻已自增1, 故当选项为单数时, 需要补充结束标签
if (j % 2 == 1) { if(!aloneOption && j%2 == 1){
tmp += '</div>' tmp += '</div>';
} }
// workDescArr为 [''] 表示为 判断题或者填空题,这里不需要选项 // workDescArr为 [''] 表示为 判断题或者填空题,这里不需要选项
@ -136,31 +143,36 @@ export const processList = (row) => {
* ] * ]
*/ */
let workDescArr = JSON.parse(row[i].workdesc) let workDescArr = JSON.parse(row[i].workdesc)
let workDescHtml = `<div style='width:80%;display:flex;>` let workDescHtml = `<div style='width:100%;display:flex;>`
workDescArr.map((item, index) => { workDescArr.map((item, index) => {
if (item.type == '单选题' || item.type == '多选题') { if (item.type == '单选题' || item.type == '多选题') {
workDescHtml += `<div style='width:80%;display:flex;'>${index + 1}. ${item.title}</div>` workDescHtml += `<div style='width:100%;display:flex;'>${index + 1}. ${item.title}</div>`
let tmp = '' let tmp = ''
let j = 0 let j = 0
let optionsArr = item.options let optionsArr = item.options
for (; j < optionsArr.length; j++) { for(; j<optionsArr.length; j++){
if (j % 2 == 0) { const char = String.fromCharCode(65+j);
tmp += `<div style='width:80%;display:flex;'>` if (aloneOption) {
tmp += `<div style='width:100%;display:flex;padding: 2px 0'>${char}.${optionsArr[j]}</div>`;
} }
const char = String.fromCharCode(65 + j) else {
tmp += `<div style='display:flex;margin-left: 2%; width: 36%'>${char}.${optionsArr[j]}</div>` if(j%2 == 0){
if (j % 2 == 1) { tmp += `<div style='width:100%;display:flex;'>`;
tmp += '</div>' }
tmp += `<div style='padding-left: 10px; width: 50%'>${char}.${optionsArr[j]}</div>`;
if(j%2 == 1){
tmp += '</div>';
}
} }
} }
// j此刻已自增1, 故当选项为单数时, 需要补充结束标签 // j此刻已自增1, 故当选项为单数时, 需要补充结束标签
if (j % 2 == 1) { if(!aloneOption && j%2 == 1){
tmp += '</div>' tmp += '</div>';
} }
workDescHtml += tmp workDescHtml += tmp
} else if (item.type == '填空题' || item.type == '判断题' || item.type == '主观题') { } else if (item.type == '填空题' || item.type == '判断题' || item.type == '主观题') {
workDescHtml += `<div style='width:80%;display:flex;'>${index + 1}. ${item.title}</div>` workDescHtml += `<div style='width:100%;display:flex;'>${index + 1}. ${item.title}</div>`
} }
}) })
workDescHtml += '</div>' workDescHtml += '</div>'
@ -265,18 +277,24 @@ export const processList = (row) => {
// 处理[选项显示] - 拼接ABCD首序号 // 处理[选项显示] - 拼接ABCD首序号
let tmp = '' let tmp = ''
let j = 0 let j = 0
for (; j < workDescArr.length; j++) { for(; j<workDescArr.length; j++){
if (j % 2 == 0) { const char = String.fromCharCode(65+j);
tmp += `<div style='width:80%;display:flex;'>` if (aloneOption) {
tmp += `<div style='width:100%;display:flex;padding: 2px 0'>${char}.${workDescArr[j]}</div>`;
} }
const char = String.fromCharCode(65 + j) else {
tmp += `<div style='display:flex;margin-left: 2%; width: 36%'>${char}.${workDescArr[j]}</div>` if(j%2 == 0){
if (j % 2 == 1) { tmp += `<div style='width:100%;display:flex;'>`;
tmp += '</div>' }
tmp += `<div style='padding-left: 10px; width: 50%'>${char}.${workDescArr[j]}</div>`;
if(j%2 == 1){
tmp += '</div>';
}
} }
} }
if (j % 2 == 0) { if(!aloneOption && j%2== 0){
tmp += '</div>' tmp += '</div>';
} }
row[i].workdescFormat = tmp row[i].workdescFormat = tmp