Commit 0f9101e3 authored by van.chen's avatar van.chen

修改表单验证

parent 3faec8f5
......@@ -46,8 +46,8 @@
[data]="[{a: 'json', b: 0}, {a: 'bin', b: 1}]" optL="a" optV="b"></app-search-select>
<app-search-select *ngIf="!isUpdate" isMust="true" inModal="true" [label]="'probesModel' | translate" [(value)]="req.probesModelNo"
[data]="probesModels" optL="probesModelName" optV="probesModelNo"></app-search-select>
<app-search-item isMust="true" inModal="true" [label]="'dataInterval' | translate" [(value)]="req.dataInterval"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'frequency' | translate" [(value)]="req.frequency"></app-search-item>
<app-search-item inModal="true" [label]="'dataInterval' | translate" [(value)]="req.dataInterval"></app-search-item>
<!--<app-search-item isMust="true" inModal="true" [label]="'frequency' | translate" [(value)]="req.frequency"></app-search-item>-->
<app-search-item isMust="true" inModal="true" [label]="'interval' | translate" [(value)]="req.interval"></app-search-item>
</ng-template>
<ng-template #foot1>
......
......@@ -4,6 +4,7 @@ import {NzMessageService, NzModalService} from 'ng-zorro-antd';
import {TranslateService} from '@ngx-translate/core';
import {fadeIn} from '../../animation/fade-in';
import {ActivatedRoute, Router} from '@angular/router';
import {CheckService} from '../../service/check';
@Component({
selector: 'app-topic-module-detail',
......@@ -21,9 +22,11 @@ export class TopicModuleDetailComponent implements OnInit {
isV = false;
isUpdate = false;
probesModels = [];
try = {};
constructor(private api: ApiService, private message: NzMessageService, private ac: ActivatedRoute,
private translate: TranslateService, private router: Router, private modalService: NzModalService) {
private translate: TranslateService, private router: Router, private modalService: NzModalService,
private ck: CheckService) {
}
ngOnInit() {
......@@ -88,14 +91,20 @@ export class TopicModuleDetailComponent implements OnInit {
add() {
this.req = {};
this.req.frequency = 0;
this.isUpdate = false;
this.try = {field: ['topicName', 'topicType', 'dataType', 'interval'],
num: ['dataType', 'interval', 'dataInterval']};
this.isV = true;
}
update(one) {
this.isUpdate = true;
this.req = {...one};
this.req.frequency = 0;
this.req.oldTopicName = one.topicName;
this.try = {field: ['topicModelNo', 'topicName', 'topicType', 'dataType', 'interval'],
num: ['dataType', 'interval', 'dataInterval']};
this.isV = true;
}
......@@ -109,10 +118,18 @@ export class TopicModuleDetailComponent implements OnInit {
if (this.isUpdate) {
req = this.req;
req.topicModelNo = this.topicModelNo;
if (!this.ck.formCheck(req, this.try)) {
this.isLoading = false;
return false;
}
this.api.topicModelInfo.updateTopicModelInfo([req, this.next]);
} else {
req.topicModelNo = this.topicModelNo;
req.addTopicModelForInfoVos = [this.req];
if (!this.ck.formCheck(req.addTopicModelForInfoVos[0], this.try)) {
this.isLoading = false;
return false;
}
this.api.topicModelInfo.addTopicModelInfo([req, this.next]);
}
}
......
......@@ -51,12 +51,12 @@
[nzFooter]="foot1" [nzTitle]="isUpdate ? ('update' | translate) : ('add' | translate)" (nzOnCancel)="cancel()" nzMaskClosable="false">
<ng-template #con1>
<div class="half">
<app-search-item isMust="true" inModal="true" [label]="'wayName' | translate" [(value)]="req.name"></app-search-item>
<app-search-item inModal="true" [label]="'per' | translate" [(value)]="req.unit"></app-search-item>
<app-search-item nz-tooltip nzTitle="此处输入为英文" isMust="true" inModal="true" [label]="'wayName' | translate" [(value)]="req.name"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'per' | translate" [(value)]="req.unit"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'wayDescription' | translate" [(value)]="req.description"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'max' | translate" [(value)]="req.rangeMax"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'alarmMax' | translate" [(value)]="req.alarmUp"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'alarmMaxMax' | translate" [(value)]="req.upperAlarmLimit"></app-search-item>
<app-search-item inModal="true" [label]="'max' | translate" [(value)]="req.rangeMax"></app-search-item>
<app-search-item inModal="true" [label]="'alarmMax' | translate" [(value)]="req.alarmUp"></app-search-item>
<app-search-item inModal="true" [label]="'alarmMaxMax' | translate" [(value)]="req.upperAlarmLimit"></app-search-item>
<div class="searchItem inModal">
<div class="item-label"><span class="deleteFontColor">* </span>{{'isAlarm' | translate}}</div>
<div class="item-input">
......@@ -68,15 +68,15 @@
</div>
</div>
<div class="half">
<app-search-item inModal="true" [label]="'wayAlias' | translate" [(value)]="req.alias"></app-search-item>
<app-search-item nz-tooltip nzTitle="此处输入为英文" isMust="true" inModal="true" [label]="'wayAlias' | translate" [(value)]="req.alias"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'wayType' | translate" [(value)]="req.type"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'min' | translate" [(value)]="req.rangeMin"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'alarmMin' | translate" [(value)]="req.alarmDown"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'alarmMinMin' | translate" [(value)]="req.lowerAlarmLimit"></app-search-item>
<app-search-item isMust="true" inModal="true" [label]="'alarmInterval' | translate" [(value)]="req.alarmInterval"></app-search-item>
<app-search-item inModal="true" [label]="'min' | translate" [(value)]="req.rangeMin"></app-search-item>
<app-search-item inModal="true" [label]="'alarmMin' | translate" [(value)]="req.alarmDown"></app-search-item>
<app-search-item inModal="true" [label]="'alarmMinMin' | translate" [(value)]="req.lowerAlarmLimit"></app-search-item>
<app-search-item inModal="true" [label]="'alarmInterval' | translate" [(value)]="req.alarmInterval"></app-search-item>
</div>
<div class="searchItem inModal">
<div class="item-label" style="width: 149px;"><span class="deleteFontColor">* </span>{{'wayInfo' | translate}}</div>
<div class="item-label" style="width: 149px;">{{'wayInfo' | translate}}</div>
<div class="item-input" style="width: calc(100% - 158px);">
<textarea nz-input [(ngModel)]="req.boxedart"></textarea>
</div>
......
......@@ -4,6 +4,7 @@ import {NzMessageService, NzModalService} from 'ng-zorro-antd';
import {ActivatedRoute, Router} from '@angular/router';
import {TranslateService} from '@ngx-translate/core';
import {fadeIn} from '../../animation/fade-in';
import {CheckService} from '../../service/check';
@Component({
selector: 'app-topic-module-way',
......@@ -20,9 +21,11 @@ export class TopicModuleWayComponent implements OnInit {
topicName = '';
isV = false;
isUpdate = false;
try = {};
constructor(private api: ApiService, private message: NzMessageService, private ac: ActivatedRoute,
private translate: TranslateService, private router: Router, private modalService: NzModalService) {
private translate: TranslateService, private router: Router, private modalService: NzModalService,
private ck: CheckService) {
}
ngOnInit() {
......@@ -76,6 +79,10 @@ export class TopicModuleWayComponent implements OnInit {
this.req = {};
this.isUpdate = false;
this.isV = true;
this.try = {
field: ['topicModelNo', 'topicName', 'name', 'alias', 'description', 'type', 'unit', 'isAlarm'],
eng: ['name', 'alias']
};
}
update(one) {
......@@ -83,6 +90,10 @@ export class TopicModuleWayComponent implements OnInit {
this.req = {...one};
this.req.oldName = one.name;
this.isV = true;
this.try = {
field: ['topicModelNo', 'topicName', 'name', 'alias', 'description', 'type', 'unit', 'isAlarm'],
eng: ['name', 'alias']
};
}
cancel() {
......@@ -93,6 +104,10 @@ export class TopicModuleWayComponent implements OnInit {
this.isLoading = true;
this.req.topicModelNo = this.topicModelNo;
this.req.topicName = this.topicName;
if (!this.ck.formCheck(this.req, this.try)) {
this.isLoading = false;
return false;
}
if (this.isUpdate) {
this.api.topicConfigModel.updateTopicConfigModel([this.req, this.next]);
} else {
......
......@@ -58,7 +58,7 @@ export class CheckService {
}
private checkTime(fieldStr, data, time) {
if ((data[time] === '' || isUndefined(data[time]) || data[time] === null) && fieldStr.indexOf('-' + time + '-') > -1) {
if ((data[time] === '' || isUndefined(data[time]) || data[time] === null) && fieldStr.indexOf('-' + time + '-') <= -1) {
return true;
}
if (data[time] && new Date(data[time]).getTime() > 0 && new Date(data[time]).getTime().toString().length === 13) {
......@@ -69,7 +69,7 @@ export class CheckService {
}
private checkTel(fieldStr, data, tel) {
if ((data[tel] === '' || isUndefined(data[tel]) || data[tel] === null) && fieldStr.indexOf('-' + tel + '-') > -1) {
if ((data[tel] === '' || isUndefined(data[tel]) || data[tel] === null) && fieldStr.indexOf('-' + tel + '-') <= -1) {
return true;
}
const reg = new RegExp( '^1\\d{10}$');
......@@ -81,7 +81,7 @@ export class CheckService {
}
private checkMoney(fieldStr, data, money) {
if ((data[money] === '' || isUndefined(data[money]) || data[money] === null) && fieldStr.indexOf('-' + money + '-') > -1) {
if ((data[money] === '' || isUndefined(data[money]) || data[money] === null) && fieldStr.indexOf('-' + money + '-') <= -1) {
return true;
}
if (parseFloat(data[money]).toFixed(2) === data[money] && parseInt(data[money], 10).toString().length < 8) {
......@@ -92,7 +92,7 @@ export class CheckService {
}
private checkNum(fieldStr, data, num) {
if ((data[num] === '' || isUndefined(data[num]) || data[num] === null) && fieldStr.indexOf('-' + num + '-') > -1) {
if ((data[num] === '' || isUndefined(data[num]) || data[num] === null) && fieldStr.indexOf('-' + num + '-') <= -1) {
return true;
}
const reg = new RegExp( '^[0-9]*$');
......@@ -104,7 +104,7 @@ export class CheckService {
}
private checkFloat2(fieldStr, data, float2) {
if ((data[float2] === '' || isUndefined(data[float2]) || data[float2] === null) && fieldStr.indexOf('-' + float2 + '-') > -1) {
if ((data[float2] === '' || isUndefined(data[float2]) || data[float2] === null) && fieldStr.indexOf('-' + float2 + '-') <= -1) {
return true;
}
if ( parseFloat(data[float2]).toFixed(2).toString() === data[float2]) {
......@@ -115,7 +115,7 @@ export class CheckService {
}
private checkEng(fieldStr, data, eng) {
if ((data[eng] === '' || isUndefined(data[eng]) || data[eng] === null) && fieldStr.indexOf('-' + eng + '-') > -1) {
if ((data[eng] === '' || isUndefined(data[eng]) || data[eng] === null) && fieldStr.indexOf('-' + eng + '-') <= -1) {
return true;
}
const reg = new RegExp( '^[a-zA-Z]*$');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment