Files
2023-03-25 16:48:46 +08:00

50 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** 格式化显示数据定义 */
export const formatSpecsDisplay = (json) => {
let specs = JSON.parse(json);
if (!specs) {
return;
}
if (specs.type === "integer" || specs.type === "decimal") {
return (
"<span style='width:50%;display:inline-block;'>最大值:<span style=\"color:#F56C6C\">" +
specs.max +
'</span></span>最小值:<span style="color:#F56C6C">' +
specs.min +
"</span><br /><span style='width:50%;display:inline-block;'>步长:<span style=\"color:#F56C6C\">" +
specs.step +
'</span></span>单位:<span style="color:#F56C6C">' +
specs.unit
);
} else if (specs.type === "string") {
return (
'最大长度:<span style="color:#F56C6C">' + specs.maxLength + "</span>"
);
} else if (specs.type === "array") {
return (
'数组类型:<span style="color:#F56C6C">' + specs.arrayType + "</span>"
);
} else if (specs.type === "enum") {
let items = "";
for (let i = 0; i < specs.enumList.length; i++) {
items =
items +
"<span style='width:50%;display:inline-block;'>" +
specs.enumList[i].value +
"<span style='color:#F56C6C'>" +
specs.enumList[i].text +
"</span></span>";
if (i > 0 && i % 2 !== 0) {
items = items + "<br />";
}
}
return items;
} else if (specs.type === "bool") {
return (
"<span style='width:50%;display:inline-block;'>0<span style=\"color:#F56C6C\">" +
specs.falseText +
'</span></span>1<span style="color:#F56C6C">' +
specs.trueText
);
}
};