/* https://work.fineres.com/browse/REPORT-91724 用于参数统一校验 */ import { ILLEGAL_STRINGS } from "./constant"; export type CheckResult = { legal: boolean, errorMsg: string, } export const CHECK_CORRECT: CheckResult = { legal: true, errorMsg: "", }; /** * 检测非法字符,返回错误提示 * @param value 要校验的字符串 */ export function checkIllegalStrings(value: string): CheckResult { // 后端传入的校验开关,如果没传,那也默认开启 const enabled = Dec.system.enableParameterVerify ?? true; if (enabled) { const illegalStringIndex = ILLEGAL_STRINGS.findIndex(s => value.includes(s)); if (illegalStringIndex === -1) { return CHECK_CORRECT; } return { legal: false, errorMsg: `${BI.i18nText("Dec-Basic_Check_Illegal_Strings")}${ILLEGAL_STRINGS[illegalStringIndex]}`, }; } return CHECK_CORRECT; } export function checkIllegalStringsInWidgetAndShowError(widget: any) { const value = widget.getValue(); const result = checkIllegalStrings(value); if (!result.legal) { widget.showError(result.errorMsg); } return result.legal; }