From 7ca521e4267b987270f6ccbb9a6c076aeb467d96 Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Wed, 04 Jul 2018 17:11:33 +0800
Subject: [PATCH] 设备,监控站 管理功能增强
---
src/app/business/services/util/tools.service.ts | 46 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 45 insertions(+), 1 deletions(-)
diff --git a/src/app/business/services/util/tools.service.ts b/src/app/business/services/util/tools.service.ts
index b2eb6f8..3841b8f 100644
--- a/src/app/business/services/util/tools.service.ts
+++ b/src/app/business/services/util/tools.service.ts
@@ -1,6 +1,50 @@
+import { FormGroup, FormArray, AbstractControl } from '@angular/forms';
import { Injectable } from '@angular/core';
@Injectable()
export class ToolsService {
-
+ public static markAsDirty(controlSet: FormGroup|FormArray) {
+ const controls = controlSet.controls;
+ Object.values(controls).forEach(
+ (control: AbstractControl) => {
+ if (control instanceof FormGroup || control instanceof FormArray) {
+ ToolsService.markAsDirty(control);
+ } else {
+ control.markAsDirty();
+ }
+ }
+ );
+ }
+ public static getValueFormControl(controlSet: FormGroup, name: string) {
+ return controlSet.controls[name].value;
+ }
+ public static setValueToControl(controlSet: FormGroup, name: string, value: any) {
+ controlSet.controls[name].setValue(value);
+ controlSet.controls[name].updateValueAndValidity();
+ }
+ public static removePrivate(obj: object) {
+ Object.keys(obj).forEach(
+ (key: string) => {
+ if (key.startsWith('_')) {
+ delete obj[key];
+ } else {
+ if (obj[key] instanceof Object) {
+ ToolsService.removePrivate(obj[key]);
+ }
+ }
+ }
+ );
+ }
+ public static toThousands(number: string): string {
+ let num = (number || 0).toString(), result = '';
+ while (num.length > 3) {
+ result = ',' + num.slice(-3) + result;
+ num = num.slice(0, num.length - 3);
+ }
+ if (num) { result = num + result; }
+ return result;
+ }
+ public static getObjById<T>(id: number, list: T[]): T {
+ return list.find(item => item['id'] === id);
+ }
}
--
Gitblit v1.8.0