试题格式化样式优化
This commit is contained in:
parent
0f425d9277
commit
ef75fb7570
|
@ -16,8 +16,9 @@ export const isJson = (str) => {
|
|||
/**
|
||||
* @description processList 格式化试题
|
||||
* @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 += `<div style='width:80%;display:flex;'>`
|
||||
for(; j<workDescArr.length; j++){
|
||||
const char = String.fromCharCode(65+j);
|
||||
if (aloneOption) {
|
||||
tmp += `<div style='width:100%;display:flex;padding: 2px 0'>${char}.${workDescArr[j]}</div>`;
|
||||
}
|
||||
else {
|
||||
if(j%2 == 0){
|
||||
tmp += `<div style='width:100%;display:flex;'>`;
|
||||
}
|
||||
|
||||
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>';
|
||||
}
|
||||
const char = String.fromCharCode(65 + j)
|
||||
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 == 1) {
|
||||
tmp += '</div>'
|
||||
}
|
||||
}
|
||||
// j此刻已自增1, 故当选项为单数时, 需要补充结束标签
|
||||
if (j % 2 == 1) {
|
||||
tmp += '</div>'
|
||||
if(!aloneOption && j%2 == 1){
|
||||
tmp += '</div>';
|
||||
}
|
||||
|
||||
// workDescArr为 [''] 表示为 判断题或者填空题,这里不需要选项
|
||||
|
@ -136,31 +143,36 @@ export const processList = (row) => {
|
|||
* ]
|
||||
*/
|
||||
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) => {
|
||||
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 j = 0
|
||||
let optionsArr = item.options
|
||||
for (; j < optionsArr.length; j++) {
|
||||
if (j % 2 == 0) {
|
||||
tmp += `<div style='width:80%;display:flex;'>`
|
||||
for(; j<optionsArr.length; j++){
|
||||
const char = String.fromCharCode(65+j);
|
||||
if (aloneOption) {
|
||||
tmp += `<div style='width:100%;display:flex;padding: 2px 0'>${char}.${optionsArr[j]}</div>`;
|
||||
}
|
||||
else {
|
||||
if(j%2 == 0){
|
||||
tmp += `<div style='width:100%;display:flex;'>`;
|
||||
}
|
||||
|
||||
tmp += `<div style='padding-left: 10px; width: 50%'>${char}.${optionsArr[j]}</div>`;
|
||||
if(j%2 == 1){
|
||||
tmp += '</div>';
|
||||
}
|
||||
const char = String.fromCharCode(65 + j)
|
||||
tmp += `<div style='display:flex;margin-left: 2%; width: 36%'>${char}.${optionsArr[j]}</div>`
|
||||
if (j % 2 == 1) {
|
||||
tmp += '</div>'
|
||||
}
|
||||
}
|
||||
// j此刻已自增1, 故当选项为单数时, 需要补充结束标签
|
||||
if (j % 2 == 1) {
|
||||
tmp += '</div>'
|
||||
if(!aloneOption && j%2 == 1){
|
||||
tmp += '</div>';
|
||||
}
|
||||
|
||||
workDescHtml += tmp
|
||||
} 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>'
|
||||
|
@ -265,18 +277,24 @@ export const processList = (row) => {
|
|||
// 处理[选项显示] - 拼接ABCD首序号
|
||||
let tmp = ''
|
||||
let j = 0
|
||||
for (; j < workDescArr.length; j++) {
|
||||
if (j % 2 == 0) {
|
||||
tmp += `<div style='width:80%;display:flex;'>`
|
||||
for(; j<workDescArr.length; j++){
|
||||
const char = String.fromCharCode(65+j);
|
||||
if (aloneOption) {
|
||||
tmp += `<div style='width:100%;display:flex;padding: 2px 0'>${char}.${workDescArr[j]}</div>`;
|
||||
}
|
||||
const char = String.fromCharCode(65 + j)
|
||||
tmp += `<div style='display:flex;margin-left: 2%; width: 36%'>${char}.${workDescArr[j]}</div>`
|
||||
if (j % 2 == 1) {
|
||||
tmp += '</div>'
|
||||
else {
|
||||
if(j%2 == 0){
|
||||
tmp += `<div style='width:100%;display:flex;'>`;
|
||||
}
|
||||
|
||||
tmp += `<div style='padding-left: 10px; width: 50%'>${char}.${workDescArr[j]}</div>`;
|
||||
if(j%2 == 1){
|
||||
tmp += '</div>';
|
||||
}
|
||||
}
|
||||
if (j % 2 == 0) {
|
||||
tmp += '</div>'
|
||||
}
|
||||
if(!aloneOption && j%2== 0){
|
||||
tmp += '</div>';
|
||||
}
|
||||
row[i].workdescFormat = tmp
|
||||
|
||||
|
|
Loading…
Reference in New Issue