算了,就一点,直接写了

This commit is contained in:
Qubot 2023-07-04 23:42:12 +08:00
parent b934f2cefb
commit 29509e6bc0

View File

@ -178,9 +178,6 @@
if (valueType === "choose") {
errors.push("请选择电阻类型");
}
if (!isNumeric(inputValue) || (inputValue.length > 4 && /[a-zA-Z]/.test(inputValue))) {
errors.push("阻值错误");
}
if (valueType === "choose") {
errors.push("请选择封装类型");
@ -203,15 +200,15 @@
let convertedValue;
if (valueType === "general-re") {
convertedValue = "1110" + formatInputValue(inputValue) + printValue + serialValue;
convertedValue = "1110" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "metal-re") {
convertedValue = "1111" + formatInputValue(inputValue) + printValue + serialValue;
convertedValue = "1111" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "temp-re") {
convertedValue = "1112" + formatInputValue(inputValue) + printValue + serialValue;
convertedValue = "1112" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "lignt-re") {
convertedValue = "1113" + formatInputValue(inputValue) + printValue + serialValue;
convertedValue = "1113" + res_namer(inputValue) + printValue + serialValue;
} else if (valueType === "other-re") {
convertedValue = "1119" + formatInputValue(inputValue) + printValue + serialValue;
convertedValue = "1119" + res_namer(inputValue) + printValue + serialValue;
}
@ -222,16 +219,32 @@
}
}
function formatInputValue(inputValue) {
if (inputValue.length > 4) {
inputValue = inputValue.substring(0, 4);
} else {
while (inputValue.length < 4) {
inputValue = "0" + inputValue;
}
}
return inputValue;
}
function res_namer(value_str) {
value_str = value_str.toLowerCase();
if (value_str.includes('k')) {
base = 1000;
} else if (value_str.includes('m')) {
base = 1000000;
} else if (value_str.includes('g')) {
base = 1000000000;
} else if (value_str.includes('r')) {
base = 1;
} else {
throw '错误的值';
}
value_flt = parseFloat(value_str);
inner_flt = value_flt * base;
if (inner_flt < 1 && inner_flt > 0) {
inner_flt=inner_flt*10
code = "0"+"R"+inner_flt.toString().replace('.', '');
}
else if (inner_flt < 10 && inner_flt > 1) {
code = inner_flt.toString().replace('.', '');
} else {
code = inner_flt.toString().slice(0, 3) + (inner_flt.toString().length - 1);
}
return code;
}
function isNumeric(value) {
return /^\d+$/.test(value);