//压力单位
|
var enum_unitH_M = 0; //米m(默认)
|
var enum_unitH_MPa = 1; //MPa
|
var enum_unitH_KPa = 2; //KPa
|
var enum_unitH_Bar = 3; //bar
|
var enum_unitH_Ft = 4; //ft
|
var enum_unitH_Psi = 5; //psi
|
|
//流量单位
|
var enum_unitQ_LS = 0; // L/s
|
var enum_unitQ_M3H = 1; // m3/h (默认)
|
var enum_unitQ_M3Min = 2; // m3/min
|
var enum_unitQ_ImpGalMin = 3; // Imp.GalMin
|
var enum_unitQ_USGalMin = 4; // us.gal/min
|
var enum_unitQ_Ft3H = 5; // ft3/h
|
var enum_unitQ_Ft3Min = 6; // ft3/min
|
var enum_unitQ_M3S = 7; // m3/s
|
var enum_unitQ_LMIN = 8; // L/min
|
|
//功率
|
var enum_unitP_W = 0; // W
|
var enum_unitP_KW = 1; //kW 默认
|
var enum_unitP_HP = 2; //hp
|
|
//汽蚀
|
var enum_unitNPSH_M = 0; //m 默认
|
var enum_unitNPSH_FT = 4; //ft
|
|
//长度(叶轮外径)
|
var enum_unitLength_mm = 0; //工制 mm
|
var enum_unitLenght_inch = 1; //英制
|
|
//风机--静压
|
var enum_unitStaticPressure_pa = 0; //Pa
|
var enum_unitStaticPressure_inH20 = 1; //in.H20
|
|
//风机--风量
|
var enum_unitBlowingRate_M3H = 0; //m³/h
|
var enum_unitBlowingRate_CFM = 1; //CFM
|
|
// 粘度
|
var enum_unitNianDu_cSt = 0; //cSt
|
var enum_unitNianDu_St = 1; //St
|
var enum_unitNianDu_CP = 5; //CP
|
|
// 密度
|
var enum_unitMiDu_kgM3 = 0; //kg/m³
|
var enum_unitMiDu_gCM3 = 1; //g/cm³
|
var enum_unitMiDu_bizhong = 2; //比重
|
var enum_unitMiDu_kgL = 3; //kg/L
|
|
var Unit = {
|
//标准单位
|
Default: { Q: enum_unitQ_M3H, H: enum_unitH_M, P: enum_unitP_KW },
|
|
//扬程
|
H: {
|
m: enum_unitH_M, //标准单位
|
MPa: enum_unitH_MPa,
|
KPa: enum_unitH_KPa,
|
bar: enum_unitH_Bar,
|
ft: enum_unitH_Ft,
|
psi: enum_unitH_Psi,
|
},
|
|
//流量
|
Q: {
|
Ls: enum_unitQ_LS,
|
m3h: enum_unitQ_M3H, //标准单位
|
m3min: enum_unitQ_M3Min,
|
ImpGalMin: enum_unitQ_ImpGalMin,
|
usGalMin: enum_unitQ_USGalMin,
|
ft3h: enum_unitQ_Ft3H,
|
ft3min: enum_unitQ_Ft3Min,
|
m3s: enum_unitQ_M3S,
|
Lmin: enum_unitQ_LMIN,
|
},
|
|
//功率
|
P: {
|
W: enum_unitP_W,
|
KW: enum_unitP_KW,
|
hp: enum_unitP_HP,
|
},
|
//汽蚀
|
NPSH: {
|
m: enum_unitNPSH_M,
|
ft: enum_unitNPSH_FT,
|
},
|
//长度
|
Length: {
|
mm: enum_unitLength_mm,
|
inch: enum_unitLenght_inch,
|
},
|
//风机--静压
|
StaticPressure: {
|
Pa: enum_unitStaticPressure_pa,
|
inH20: enum_unitStaticPressure_inH20,
|
},
|
//风机--风量
|
BlowingRate: {
|
m3h: enum_unitBlowingRate_M3H,
|
CFM: enum_unitBlowingRate_CFM,
|
},
|
NianDu: {
|
cSt: enum_unitNianDu_cSt,
|
St: enum_unitNianDu_St,
|
CP: enum_unitNianDu_CP,
|
},
|
MiDu: {
|
kgM3: enum_unitMiDu_kgM3,
|
gCM3: enum_unitMiDu_gCM3,
|
bizhong: enum_unitMiDu_bizhong,
|
kgL: enum_unitMiDu_kgL,
|
},
|
//压力单位
|
H_Value_List: [
|
{ label: "m", value: enum_unitH_M }, //标准单位
|
{ label: "MPa", value: enum_unitH_MPa },
|
{ label: "KPa", value: enum_unitH_KPa },
|
{ label: "bar", value: enum_unitH_Bar },
|
{ label: "ft", value: enum_unitH_Ft },
|
{ label: "psi", value: enum_unitH_Psi },
|
],
|
|
//流量单位
|
Q_Value_List: [
|
{ label: "L/s", value: enum_unitQ_LS },
|
{ label: "m³/h", value: enum_unitQ_M3H }, //标注单位
|
{ label: "m³/min", value: enum_unitQ_M3Min },
|
{ label: "I.gpm", value: enum_unitQ_ImpGalMin },
|
{ label: "us.gpm", value: enum_unitQ_USGalMin },
|
{ label: "ft³/h", value: enum_unitQ_Ft3H },
|
{ label: "ft³/min", value: enum_unitQ_Ft3Min },
|
{ label: "m³/s", value: enum_unitQ_M3S },
|
{ label: "L/min", value: enum_unitQ_LMIN },
|
],
|
|
//功率
|
P_Value_List: [
|
{ label: "W", value: enum_unitP_W },
|
{ label: "kW", value: enum_unitP_KW }, //标准单位
|
{ label: "hp", value: enum_unitP_HP },
|
],
|
|
//汽蚀
|
NPSH_Value_List: [
|
{ label: "m", value: enum_unitNPSH_M },
|
{ label: "ft", value: enum_unitNPSH_FT },
|
],
|
|
//长度
|
Length_Value_List: [
|
{ label: "mm", value: enum_unitLength_mm },
|
{ label: "inch", value: enum_unitLenght_inch },
|
],
|
//静压
|
StaticPressure_Value_List: [
|
{ label: "Pa", value: enum_unitStaticPressure_pa },
|
{ label: "in.H20", value: enum_unitStaticPressure_inH20 },
|
],
|
//风量
|
BlowingRate_Value_List: [
|
{ label: "m³/h", value: enum_unitBlowingRate_M3H },
|
{ label: "CFM", value: enum_unitBlowingRate_CFM },
|
],
|
|
//粘度
|
NianDu_Value_List: [
|
{ label: "cSt", value: enum_unitNianDu_cSt },
|
{ label: "St", value: enum_unitNianDu_St },
|
{ label: "CP", value: enum_unitNianDu_CP },
|
],
|
|
//密度
|
MiDu_Value_List: [
|
{ label: "kg/m³", value: enum_unitMiDu_kgM3 },
|
{ label: "g/cm³", value: enum_unitMiDu_gCM3 },
|
{ label: "比重", value: enum_unitMiDu_bizhong },
|
{ label: "kg/L", value: enum_unitMiDu_kgL },
|
],
|
|
/**
|
* @description 保留小数位转换
|
*/
|
formatToFixed(n, l) {
|
if (n == 0) {
|
return n;
|
}
|
var a1 = Math.floor(Math.log(n) / Math.LN10);
|
l = l ? l : 1;
|
if (a1 < 0) {
|
a1 = Math.abs(a1 - l);
|
} else {
|
a1 = l;
|
}
|
var b = parseFloat(n.toFixed(a1));
|
return b;
|
},
|
|
/**
|
* @description 保留小数位 规整
|
*/
|
valueFormat(value) {
|
if (value == 0) return 0;
|
var value_float = parseFloat(value);
|
var value_str = value.toString();
|
var decimalIndex = value_str.indexOf(".");
|
if (decimalIndex < 0) {
|
return value_float;
|
}
|
var point_str = value_str.substring(decimalIndex + 1); //小数点部分
|
if (point_str.length < 3) {
|
return value_float;
|
}
|
if (point_str.startsWith("00")) {
|
return value_float.toFixed(0);
|
}
|
if (point_str.startsWith("99")) {
|
return value_float.toFixed(0);
|
}
|
return value_float.toFixed(1);
|
},
|
/**
|
* @description 通过int值获取流量单位名
|
*/
|
GetUnitNameQ(fromUnit) {
|
var lable = "";
|
Unit.Q_Value_List.forEach((item) => {
|
if (item.value == fromUnit) {
|
lable = item.label;
|
}
|
});
|
return lable;
|
},
|
|
/**
|
* @description 通过 流量单位名 获取值
|
*/
|
GetUnitValueQ(fromUnitName) {
|
var v = 0;
|
Unit.Q_Value_List.forEach((item) => {
|
if (item.label == fromUnitName) {
|
v = item.value;
|
}
|
});
|
return v;
|
},
|
|
/**
|
* @description 通过int值获取扬程单位名
|
*/
|
GetUnitNameH(fromUnit) {
|
var lable = "";
|
Unit.H_Value_List.forEach((item) => {
|
if (item.value == fromUnit) {
|
lable = item.label;
|
}
|
});
|
return lable;
|
},
|
|
/**
|
* @description 通过 扬程单位名 获取值
|
*/
|
GetUnitValueH(fromUnitName) {
|
var v = 0;
|
Unit.H_Value_List.forEach((item) => {
|
if (item.label == fromUnitName) {
|
v = item.value;
|
}
|
});
|
return v;
|
},
|
|
/**
|
* @description 通过int值获取功率单位名
|
*/
|
GetUnitNameP(fromUnit) {
|
var lable = "";
|
Unit.P_Value_List.forEach((item) => {
|
if (item.value == fromUnit) {
|
lable = item.label;
|
}
|
});
|
if (lable == "") return "kW";
|
return lable;
|
},
|
|
/**
|
* @description 通过 功率单位名 获取值
|
*/
|
GetUnitValueP(fromUnitName) {
|
var v = 0;
|
Unit.P_Value_List.forEach((item) => {
|
if (item.label == fromUnitName) {
|
v = item.value;
|
}
|
});
|
return v;
|
},
|
/**
|
* @description 通过int值获取功率单位名
|
*/
|
GetUnitNameNPSH(fromUnit) {
|
if (fromUnit == 4) return "ft";
|
if (fromUnit == 0) return "m";
|
return "m";
|
},
|
/**
|
* @description 通过int值获取功率单位名
|
*/
|
GetUnitNameLength(fromUnit) {
|
if (fromUnit == 0) return "mm";
|
if (fromUnit == 0) return "inch";
|
return "mm";
|
},
|
/**
|
* @description 通过int值获取密度单位名
|
*/
|
GetUnitNameMiDu(fromUnit) {
|
var v = 0;
|
Unit.MiDu_Value_List.forEach((item) => {
|
if (item.label == fromUnit) {
|
v = item.value;
|
}
|
});
|
return v;
|
},
|
/**
|
* @description 通过int值获取粘度单位名
|
*/
|
GetUnitNameNianDu(fromUnit) {
|
var v = 0;
|
Unit.NianDu_Value_List.forEach((item) => {
|
if (item.label == fromUnit) {
|
v = item.value;
|
}
|
});
|
return v;
|
},
|
/**
|
* @description 流量单位转换
|
*/
|
ConvertQ(fromUnit, toUnit, fromValue) {
|
if (fromUnit == toUnit) return fromValue;
|
var m3h = Unit.ConvertQ_toM3H(fromUnit, fromValue);
|
return Unit.ConvertQ_fromM3H(toUnit, m3h);
|
},
|
|
/**
|
* @description 扬程单位转换
|
*/
|
ConvertH(fromUnit, toUnit, fromValue) {
|
if (fromValue == 0) {
|
return 0;
|
}
|
if (fromUnit == toUnit) return fromValue;
|
var m = Unit.ConvertH_toM(fromUnit, fromValue);
|
return Unit.ConvertH_fromM(toUnit, m);
|
},
|
|
/**
|
* @description 功率单位转换
|
*/
|
ConvertP(fromUnit, toUnit, fromValue) {
|
if (fromUnit == toUnit) return fromValue;
|
var kw = Unit.ConvertP_toKW(fromUnit, fromValue);
|
return Unit.ConvertP_fromKW(toUnit, kw);
|
},
|
|
/**
|
* @description 流量单位转换
|
*/
|
ConvertQ_toM3H: function (fromUnit, fromValue) {
|
if (fromUnit == enum_unitQ_M3H) return fromValue;
|
|
if (fromUnit == enum_unitQ_LS) {
|
return fromValue * 3.6;
|
} else if (fromUnit == enum_unitQ_M3Min) {
|
return fromValue * 60;
|
} else if (fromUnit == enum_unitQ_ImpGalMin) {
|
return fromValue * 0.27279;
|
} else if (fromUnit == enum_unitQ_USGalMin) {
|
return fromValue * 0.2271;
|
} else if (fromUnit == enum_unitQ_Ft3H) {
|
return fromValue * 0.02832;
|
} else if (fromUnit == enum_unitQ_Ft3Min) {
|
return fromValue * 1.6992;
|
} else if (fromUnit == enum_unitQ_M3S) {
|
return fromValue * 3600;
|
} else if (fromUnit == enum_unitQ_LMIN) {
|
return fromValue * 0.06;
|
}
|
return fromValue;
|
},
|
ConvertQ_fromM3H(toUnit, fromValue) {
|
if (fromValue < 0.00001) return 0;
|
if (toUnit == enum_unitQ_M3H) return fromValue;
|
|
if (toUnit == enum_unitQ_LS) {
|
return parseFloat((fromValue / 3.6).toFixed(2));
|
} else if (toUnit == enum_unitQ_M3Min) {
|
return fromValue / 60;
|
} else if (toUnit == enum_unitQ_ImpGalMin) {
|
return fromValue / 0.27279;
|
} else if (toUnit == enum_unitQ_USGalMin) {
|
return fromValue / 0.2271;
|
} else if (toUnit == enum_unitQ_Ft3H) {
|
return fromValue / 0.02832;
|
} else if (toUnit == enum_unitQ_Ft3Min) {
|
return fromValue / 1.6992;
|
} else if (toUnit == enum_unitQ_M3S) {
|
return fromValue / 3600;
|
} else if (toUnit == enum_unitQ_LMIN) {
|
return fromValue / 0.06;
|
}
|
return fromValue;
|
},
|
/**
|
* @description 扬程单位转换
|
*/
|
ConvertH_toM(fromUnit, fromValue) {
|
if (fromUnit == enum_unitH_M) {
|
return fromValue;
|
}
|
|
if (fromUnit == enum_unitH_MPa) {
|
var M2mpaCoeff = window.pageConfig.UnitSetting?.M2mpaCoeff || 0.00981;
|
return fromValue / M2mpaCoeff; //fromValue * 100;
|
} else if (fromUnit == enum_unitH_KPa) {
|
var M2mpaCoeff = window.pageConfig.UnitSetting?.M2mpaCoeff || 0.00981;
|
return fromValue / (M2mpaCoeff * 1000); //fromValue * 0.1;
|
} else if (fromUnit == enum_unitH_Bar) {
|
var M2mpaCoeff = window.pageConfig.UnitSetting?.M2mpaCoeff || 0.00981;
|
return (fromValue * 0.1) / M2mpaCoeff;
|
} else if (fromUnit == enum_unitH_Ft) {
|
return fromValue / 3.2808399;
|
} else if (fromUnit == enum_unitH_Psi) {
|
return (fromValue * 102.0) / 145.0;
|
}
|
return fromValue;
|
},
|
|
ConvertH_fromM(toUnit, fromValue) {
|
if (toUnit == enum_unitH_M) {
|
return fromValue;
|
}
|
|
if (toUnit == enum_unitH_MPa) {
|
var M2mpaCoeff = window.pageConfig.UnitSetting?.M2mpaCoeff || 0.00981;
|
return fromValue * M2mpaCoeff; //fromValue / 100;
|
} else if (toUnit == enum_unitH_KPa) {
|
var M2mpaCoeff = window.pageConfig.UnitSetting?.M2mpaCoeff || 0.00981;
|
return fromValue * M2mpaCoeff * 1000; //fromValue * 10;
|
} else if (toUnit == enum_unitH_Bar) {
|
var M2mpaCoeff = window.pageConfig.UnitSetting?.M2mpaCoeff || 0.00981;
|
return fromValue * 10.0 * M2mpaCoeff; //fromValue / 10.0;
|
} else if (toUnit == enum_unitH_Ft) {
|
return fromValue * 3.2808399;
|
} else if (toUnit == enum_unitH_Psi) {
|
return (fromValue * 145.0) / 102.0;
|
}
|
return fromValue;
|
},
|
|
/**
|
* @description 功率单位转换
|
*/
|
ConvertP_toKW(fromUnit, fromValue) {
|
if (fromUnit == enum_unitP_KW) {
|
return fromValue;
|
}
|
if (fromUnit == enum_unitP_W) {
|
return fromValue / 1000;
|
}
|
if (fromUnit == enum_unitP_HP) {
|
return fromValue * 0.7457;
|
}
|
return fromValue;
|
},
|
ConvertP_fromKW(fromUnit, fromValue) {
|
if (fromUnit == enum_unitP_KW) {
|
return fromValue;
|
}
|
if (fromUnit == enum_unitP_W) {
|
return fromValue * 1000;
|
}
|
if (fromUnit == enum_unitP_HP) {
|
return fromValue / 0.7457;
|
}
|
return fromValue;
|
},
|
/**
|
* @description 汽蚀单位转换
|
*/
|
ConvertNPSH_toM(fromUnit, fromValue) {
|
if (fromUnit == 0) {
|
return fromValue;
|
}
|
if (fromUnit == null) {
|
return fromValue;
|
}
|
if (fromUnit == 4) {
|
return (fromValue / 3.2808399).toFixed(2);
|
}
|
|
return fromValue;
|
},
|
ConvertNPSH_fromM(fromUnit, fromValue) {
|
if (fromUnit == 0) {
|
return fromValue;
|
}
|
if (fromUnit == null) {
|
return fromValue;
|
}
|
// console.log(fromUnit,fromValue);
|
if (fromUnit == 4) {
|
var toValue = fromValue * 3.2808399;
|
return this.formatToFixed(toValue, 2);
|
}
|
|
return fromValue;
|
},
|
ConverLength_FromM(fromUnit, fromValue) {
|
if (fromUnit == enum_unitLength_mm) {
|
return fromValue;
|
}
|
if (fromUnit == enum_unitLenght_inch) {
|
return fromValue * 25.4;
|
}
|
return fromValue;
|
},
|
|
ConverLength_FromMM(fromUnit, fromValue) {
|
if (fromUnit == enum_unitLength_mm) {
|
return fromValue;
|
}
|
if (fromUnit == enum_unitLenght_inch) {
|
return fromValue * 25.4;
|
}
|
return fromValue;
|
},
|
/**
|
* @description 功率单位转换
|
*/
|
getDispValueLength(mm, d2IsMeter, isHaveUnit) {
|
if (d2IsMeter) return mm;
|
|
var inchD = mm / 25.4;
|
var inchInt = parseInt(inchD);
|
var space = inchD - inchInt;
|
if (space < 0.1) return inchInt.toFixed(2) + '"';
|
else if (space < 0.3) return (inchInt + 0.25).toFixed(2) + '"';
|
else if (space < 0.6) return (inchInt + 0.5).toFixed(2) + '"';
|
else if (space < 0.8) return (inchInt + 0.75).toFixed(2) + '"';
|
else return (inchInt + 1).toFixed(2) + '"';
|
},
|
|
ConvertMeter(fromUnit, fromValue) {
|
if (fromUnit == enum_unitLength_mm) return fromValue;
|
|
return fromValue / 25.4;
|
},
|
ConvertInch(fromUnit, fromValue) {
|
if (fromUnit == enum_unitLenght_inch) return fromValue;
|
|
return fromValue * 25.4;
|
},
|
/**
|
* @description 长度单位转换
|
*/
|
getDispValueQ(v) {
|
if (v == null || v == "") {
|
return 0;
|
}
|
if (v < 0.1) {
|
return v.toFixed(3);
|
} else if (v < 3) {
|
return v.toFixed(2);
|
} else if (v < 10) {
|
return v.toFixed(2);
|
} else if (v < 20) {
|
return v.toFixed(1);
|
} else if (v < 200) {
|
return v.toFixed(1);
|
} else {
|
return v.toFixed(0);
|
}
|
},
|
|
getDispValueH(v) {
|
if (v == null || v == "") {
|
return 0;
|
}
|
|
if (v == 0) {
|
return 0;
|
}
|
if (v < 0.1) {
|
return v.toFixed(3);
|
} else if (v < 3) {
|
return v.toFixed(2);
|
} else if (v < 10) {
|
return v.toFixed(2);
|
} else if (v < 20) {
|
return v.toFixed(1);
|
} else {
|
return v.toFixed(1);
|
}
|
},
|
getDispValueP(v) {
|
if (v == null || v == "") {
|
return 0;
|
}
|
if (v == 0) return 0;
|
if (v < 0.1) {
|
return v.toFixed(3);
|
} else if (v < 1) {
|
return v.toFixed(2);
|
} else if (v < 10) {
|
return v.toFixed(2);
|
} else if (v < 20) {
|
return v.toFixed(1);
|
} else {
|
return v.toFixed(0);
|
}
|
},
|
getDispValueE(v) {
|
if (v == null || v == "") {
|
return 0;
|
}
|
if (v == 0) return 0;
|
var num = new Number(v);
|
return num.toFixed(1);
|
},
|
|
getDispValueNPSH(v) {
|
if (v == null || v == "") {
|
return 0;
|
}
|
if (v == 0) return 0;
|
var num = new Number(v);
|
return num.toFixed(1);
|
},
|
|
/**
|
* @description 获取当前的流量单位枚举值在流量单位列表中的索引
|
* @param {} value 流量单位枚举值
|
*/
|
getQunitValueInQArrIndex(value) {
|
let currentIndex = 0;
|
if (value == " " || value == null) return currentIndex;
|
Unit.Q_Value_List.forEach((item, index) => {
|
if (item.value != value) {
|
return currentIndex;
|
} else {
|
currentIndex = index;
|
}
|
});
|
return currentIndex;
|
},
|
|
/**
|
* @description 获取当前的扬程单位枚举值在扬程单位列表中的索引
|
* @param {} value 扬程单位枚举值
|
*/
|
getHunitValueInHArrIndex(value) {
|
let currentIndex = 0;
|
if (value == " " || value == null) return currentIndex;
|
Unit.H_Value_List.forEach((item, index) => {
|
if (item.value != value) {
|
currentIndex = 0;
|
} else {
|
currentIndex = index;
|
}
|
});
|
return currentIndex;
|
},
|
/**
|
* @description 切除.0这种数字,并变成字符
|
* @param {} value 数字
|
*/
|
toStringTrim(value) {
|
var str = value.toString();
|
if (str.endsWith(".00")) {
|
return str.replace(".00", "");
|
}
|
if (str.endsWith(".0")) {
|
return str.replace(".0", "");
|
}
|
return str;
|
},
|
};
|
|
export default Unit;
|