配餐项目前端文件
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.

47 lines
1.3 KiB

2 years ago
import { AbstractControl, FormControl, FormGroup } from "@angular/forms";
export class Utils {
static validateFormGroup(formGroup: FormGroup) {
if (!formGroup.valid) {
Object.keys(formGroup.controls).forEach((field) => {
const control = formGroup.get(field);
if (control instanceof FormControl) {
control.markAsDirty();
control.markAsTouched({ onlySelf: true });
control.updateValueAndValidity({ onlySelf: true });
} else if (control instanceof FormGroup) {
Utils.validateFormGroup(control);
}
});
}
return formGroup.valid;
}
static validateFormControl(control: AbstractControl) {
control.markAsDirty();
control.markAsTouched({ onlySelf: true });
control.updateValueAndValidity({ onlySelf: true });
return control.valid;
}
static queryify(query: {}): string {
const o = Object.create(null);
Object.entries(query).forEach(([k, v]) => {
if (v !== void 0 && v !== null) {
o[k] = v;
}
});
return new URLSearchParams(o).toString();
}
static getHostByEnvironment(prod?: boolean) {
const protocol = window.location.protocol;
const host = prod ? window.location.host : `localhost:${window.location.port}`;
return `${protocol}//${host}`;
}
// static detectionImagePath(jobId: string, imgName: string) {
// return `/record/${jobId}/detect/${imgName}`;
// }
}