You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
WebCAD/src/Common/CheckoutVaildValue.ts

115 lines
3.3 KiB

import { operationExpReg } from "./Utils";
export enum CheckObjectType
{
BR = "board",
DR = "drill",
}
export namespace CheckoutValid
{
export function HasInvailValue(obj: Object, objType: CheckObjectType)
{
switch (objType)
{
case CheckObjectType.BR:
return !Object.keys(obj).every(k =>
CheckoutBoardOption(k, obj[k]) === ""
)
}
}
export function CheckOption(type: CheckObjectType, k: string, v: string)
{
switch (type)
{
case CheckObjectType.BR:
return CheckoutBoardOption(k, v);
case CheckObjectType.DR:
return CheckoutDrillOption(k, v);
}
}
export function CheckoutBoardOption(k: string, v: string): string
{
switch (k)
{
case "calcHeight":
case "calcWidth":
if (!operationExpReg.test(v.replace(/["H"|"L"|]/, "1")))
return "表达式错误";
return "";
case "name":
case "boardPosition":
case "boardRelative":
case "type":
case "roomName":
case "cabinetName":
case "boardName":
case "material":
case "color":
case "striptype":
case "spliteHeight":
case "spliteWidth":
case "spliteThickness":
return "";
case "height":
case "width":
case "count":
case "thickness":
case "footThickness":
case "sealedUp":
case "sealedDown":
case "sealedLeft":
case "sealedRight":
if (!isNaN(parseFloat(v)) && parseFloat(v) <= 0) return "数值必须大于0";
default:
if (v === "" || isNaN(Number(v)))
{
return "数值不能为空且必须为数字"
}
}
return "";
}
export function CheckoutDrillOption(k: string, v: string): string
{
switch (k)
{
case "ljgPos":
case "woodPinPos":
if (!operationExpReg.test(v.replace(/["H"|"L"|]/, "1")))
return "表达式错误";
return "";
case "name":
case "spacing":
return "";
case "pxlOffset":
case "collsionDist":
case "tHoleOffset":
if (v === "")
return "不能为空";
return "";
case "pxlRad":
case "pxlDepth":
case "ljgRad":
case "ljgLength":
case "ymjRad":
case "ymjDepth":
case "wbHoleRad":
case "wbHoleDepth":
case "wsHoleLength":
case "wdepth":
case "originDist":
case "retDist":
if (!isNaN(parseFloat(v)) && parseFloat(v) === 0)
return "数值必须大于0";
default:
if (v === "" || isNaN(Number(v)))
{
return "数值不能为空且必须为数字";
}
if (!isNaN(parseFloat(v)) && parseFloat(v) < 0)
return "数值必须大于0";
}
return "";
}
}