From 0e184df30a1d07a30d412e2d5fd91bc37711455d Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Wed, 10 Jan 2018 10:04:33 +0800 Subject: [PATCH] 安装用户 管理 --- src/app/routes/users/installer/edit/edit.component.ts | 60 ++++++----- src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.html | 2 src/app/routes/users/installer/installer.component.html | 12 - src/app/routes/users/installer/edit/edit.component.html | 36 ++---- src/app/routes/users/installer/installer.component.ts | 52 +++------- src/app/routes/systems/account/account.component.ts | 4 src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.ts | 31 +++-- src/app/routes/systems/account/account-edit/account-edit.component.html | 8 src/app/routes/systems/account/account-edit/account-edit.component.ts | 37 ++++--- 9 files changed, 110 insertions(+), 132 deletions(-) diff --git a/src/app/routes/systems/account/account-edit/account-edit.component.html b/src/app/routes/systems/account/account-edit/account-edit.component.html index 3ab5a28..b9d3adc 100644 --- a/src/app/routes/systems/account/account-edit/account-edit.component.html +++ b/src/app/routes/systems/account/account-edit/account-edit.component.html @@ -13,10 +13,10 @@ <div nz-form-explain *ngIf="validateForm.controls.accountName.dirty && validateForm.controls.accountName.hasError('unique')">���������������������!</div> </div> <div nz-form-label nz-col [nzSpan]="4"> - <label nz-form-item-required>������</label> + <label>������</label> </div> <div nz-form-control nz-col [nzSpan]="8" nzHasFeedback> - <input nz-input maxlength="11" formControlName="mobile" required/> + <input nz-input maxlength="11" formControlName="mobile" /> </div> </div> <div nz-form-item nz-row class="mb-sm"> @@ -35,9 +35,9 @@ </div> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSpan]="4"> - <label>������</label> + <label nz-form-item-required>������</label> </div> - <div nz-form-control nz-col [nzSpan]="8" > + <div nz-form-control nz-col [nzSpan]="8" nzHasFeedback> <nz-select style="width: 290px;" nzAllowClear [nzPlaceHolder]="'input search text'" [nzFilter]="false" nzShowSearch formControlName="organizationId" (nzSearchChange)="searchChange($event)" [nzNotFoundContent]="'������������'" > <nz-option *ngFor="let option of searchOptions" [nzLabel]="option['name']" [nzValue]="option['id']"> </nz-option> diff --git a/src/app/routes/systems/account/account-edit/account-edit.component.ts b/src/app/routes/systems/account/account-edit/account-edit.component.ts index 4964b13..01a6157 100644 --- a/src/app/routes/systems/account/account-edit/account-edit.component.ts +++ b/src/app/routes/systems/account/account-edit/account-edit.component.ts @@ -24,30 +24,33 @@ } ngOnInit() { + const account = this.account; this.validateForm = this.formBuilder.group({ - accountName: [this.account.accountName], - mobile: [this.account.mobile], - email: [this.account.email], - weixin: [this.account.weixin], - organizationId: [this.account.organizationId], - expireTime: [this.account.expireTime], - id: [this.account.id] + accountName: [account.accountName], + mobile: [account.mobile], + email: [account.email], + weixin: [account.weixin], + organizationId: [account.organizationId], + expireTime: [account.expireTime], + id: [account.id] }); - this.searchOptions = this.account.organization ? [this.account.organization] : []; + this.searchOptions = account.organization ? [account.organization] : []; } save() { - if (this.validateForm.valid) { - for (const i in this.validateForm.controls) { - this.validateForm.controls[i].disable(); + const validateForm = this.validateForm; + const controls = validateForm.controls; + if (validateForm.valid) { + for (const i in controls) { + controls[i].disable(); } - this.http.post(environment.SERVER_BASH_URL + '/account/account', this.validateForm.value).subscribe(() => { + this.http.post(environment.SERVER_BASH_URL + '/account/account', validateForm.value).subscribe(() => { this.subject.next('true'); this.close(); }); } else { - for (const i in this.validateForm.controls) { - this.validateForm.controls[i].markAsDirty(); + for (const i in controls) { + controls[i].markAsDirty(); } } } @@ -57,14 +60,15 @@ } check(accountName) { + const controlsAccountName = this.validateForm.controls.accountName; if (accountName) { this.http.get(environment.SERVER_BASH_URL + '/account/' + accountName).subscribe((res: any) => { if (res.data > 0) { - this.validateForm.controls.accountName.setErrors({unique: true}); + controlsAccountName.setErrors({unique: true}); } }); } else { - this.validateForm.controls.accountName.setErrors({required: true}); + controlsAccountName.setErrors({required: true}); } } @@ -78,4 +82,5 @@ } } } + } diff --git a/src/app/routes/systems/account/account.component.ts b/src/app/routes/systems/account/account.component.ts index 053d41d..69ff1db 100644 --- a/src/app/routes/systems/account/account.component.ts +++ b/src/app/routes/systems/account/account.component.ts @@ -13,7 +13,7 @@ export class AccountComponent implements OnInit { - isDeleteOptions = [ + private isDeleteOptions = [ {value: '1', label: '���'}, {value: '0', label: '���'} ]; @@ -98,7 +98,7 @@ } }); } - + checkAll(value: boolean) { this.data.forEach(i => { if (i.isDelete == '1') { diff --git a/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.html b/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.html index 2f23f91..9b8d9f3 100644 --- a/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.html +++ b/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.html @@ -1,7 +1,7 @@ <div class="modal-header"> <div class="modal-title">{{alarmUser.id > 0 ? '������' : '������'}} - ������������</div> </div> -<form #f="ngForm" (ngSubmit)="save()" nz-form [nzType]="'horizontal'" [formGroup]="validateForm"> +<form (ngSubmit)="save()" nz-form [nzType]="'horizontal'" [formGroup]="validateForm"> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSpan]="4"> <label>���������</label> diff --git a/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.ts b/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.ts index 82e80f5..fa64f79 100644 --- a/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.ts +++ b/src/app/routes/users/alarm-user/alarm-user-edit/alarm-user-edit.component.ts @@ -22,30 +22,33 @@ ) {} ngOnInit() { + const alarmUser = this.alarmUser; this.validateForm = this.formBuilder.group({ - name: [this.alarmUser.name], - mobile: [this.alarmUser.mobile, [Validators.pattern("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$")]], - email: [this.alarmUser.email,[Validators.email]], - weixin: [this.alarmUser.weixin], - organizationId: [this.alarmUser.organizationId], - expireTime: [this.alarmUser.expireTime], - id: [this.alarmUser.id] + name: [alarmUser.name], + mobile: [alarmUser.mobile, [Validators.pattern("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$")]], + email: [alarmUser.email, [Validators.email]], + weixin: [alarmUser.weixin], + organizationId: [alarmUser.organizationId], + expireTime: [alarmUser.expireTime], + id: [alarmUser.id] }); - this.searchOptions = this.alarmUser.organization ? [this.alarmUser.organization] : []; + this.searchOptions = alarmUser.organization ? [alarmUser.organization] : []; } save() { - if (this.validateForm.valid) { - for (const i in this.validateForm.controls) { - this.validateForm.controls[i].disable(); + const validateForm = this.validateForm; + const controls = validateForm.controls; + if (validateForm.valid) { + for (const i in controls) { + controls[i].disable(); } - this.http.post(environment.SERVER_BASH_URL + '/alarmUser/alarmUser', this.validateForm.value).subscribe(() => { + this.http.post(environment.SERVER_BASH_URL + '/alarmUser/alarmUser', validateForm.value).subscribe(() => { this.subject.next('true'); this.close(); }); } else { - for (const i in this.validateForm.controls) { - this.validateForm.controls[i].markAsDirty(); + for (const i in controls) { + controls[i].markAsDirty(); } } } diff --git a/src/app/routes/users/installer/edit/edit.component.html b/src/app/routes/users/installer/edit/edit.component.html index 480658d..12a0a00 100644 --- a/src/app/routes/users/installer/edit/edit.component.html +++ b/src/app/routes/users/installer/edit/edit.component.html @@ -1,48 +1,36 @@ <div class="modal-header"> <div class="modal-title">{{user.id > 0 ? '������' : '������'}} - ������������</div> </div> -<form #f="ngForm" (ngSubmit)="save()" nz-form [nzType]="'horizontal'"> +<form (ngSubmit)="save()" nz-form [nzType]="'horizontal'" [formGroup]="validateForm"> <div nz-form-item nz-row class="mb-sm"> - <div nz-form-label nz-col [nzSpan]="4"><label>������</label></div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="user.name" name="name" maxlength="30" required /> + <div nz-form-label nz-col [nzSpan]="4"><label nz-form-item-required>������</label></div> + <div nz-form-control nz-col [nzSpan]="8" nzHasFeedback> + <input nz-input formControlName="name" maxlength="30" required /> </div> - <div nz-form-label nz-col [nzSpan]="4"><label>������</label></div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="user.mobile" name="mobile" maxlength="11" required /> + <div nz-form-label nz-col [nzSpan]="4"><label nz-form-item-required>������/������</label></div> + <div nz-form-control nz-col [nzSpan]="8" nzHasFeedback> + <input nz-input formControlName="mobile" maxlength="11" required /> </div> </div> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSpan]="4"><label>������������</label></div> <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="user.email" name="email" required /> + <input nz-input formControlName="email"/> </div> <div nz-form-label nz-col [nzSpan]="4"><label>���������</label></div> <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="user.weixin" name="weixin" /> + <input nz-input formControlName="weixin" /> </div> </div> <div nz-form-item nz-row class="mb-sm"> <div nz-form-label nz-col [nzSpan]="4"><label>������</label></div> <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="user.organizationId" name="organizationId" maxlength="20" placeholder="20���������" /> - </div> - <div nz-form-label nz-col [nzSpan]="4"><label>������</label></div> - <div nz-form-control nz-col [nzSpan]="8"> - <input nz-input [(ngModel)]="user.password" name="password" maxlength="30" placeholder="30���������" required /> - </div> - </div> - <div nz-form-item nz-row class="mb-sm"> - <div nz-form-label nz-col [nzSpan]="4"><label>������������</label></div> - <div nz-form-control nz-col [nzSpan]="8"> - <div nz-form-control [nzValidateStatus]="createTime"> - <nz-datepicker [(ngModel)]="user.createTime" name="createTime"></nz-datepicker> - </div> + <input nz-input formControlName="organizationId" maxlength="20" placeholder="20���������" /> </div> <div nz-form-label nz-col [nzSpan]="4"><label>������������</label></div> <div nz-form-control nz-col [nzSpan]="8"> - <div nz-form-control [nzValidateStatus]="expireTime"> - <nz-datepicker [(ngModel)]="user.expireTime" name="expireTime"></nz-datepicker> + <div nz-form-control > + <nz-datepicker style="width: 290px;" formControlName="expireTime"></nz-datepicker> </div> </div> </div> diff --git a/src/app/routes/users/installer/edit/edit.component.ts b/src/app/routes/users/installer/edit/edit.component.ts index fa8d5ff..6509fe4 100644 --- a/src/app/routes/users/installer/edit/edit.component.ts +++ b/src/app/routes/users/installer/edit/edit.component.ts @@ -1,9 +1,10 @@ -import { NzModalSubject, NzMessageService } from 'ng-zorro-antd'; -import { Component, OnInit } from '@angular/core'; -import { ModalHelper } from '@delon/theme'; -import { HttpClient } from '@angular/common/http'; -import { environment } from '../../../../../environments/environment'; -import { DateService } from '../../../../core/services/date.service'; +import {NzModalSubject, NzMessageService} from 'ng-zorro-antd'; +import {Component, OnInit} from '@angular/core'; +import {ModalHelper} from '@delon/theme'; +import {HttpClient} from '@angular/common/http'; +import {environment} from '../../../../../environments/environment'; +import {DateService} from '../../../../core/services/date.service'; +import {FormGroup, FormBuilder, FormControl, Validators} from '@angular/forms'; @Component({ selector: 'app-edit', @@ -13,42 +14,47 @@ export class UserInstallerEditComponent implements OnInit { user: any; + private validateForm: FormGroup; constructor( private modalHelper: ModalHelper, private subject: NzModalSubject, public dateSrv: DateService, public msgSrv: NzMessageService, - public http: HttpClient) { } + public http: HttpClient, + private formBuilder: FormBuilder + ) {} ngOnInit() { -// if (this.user.id > 0) { -// this.http.get(environment.SERVER_BASH_URL + '/user/operate_user/' + this.user.id).subscribe((res: any) => { -// this.user = res; -// this.user.createTime = this.dateSrv.date_format(this.user.createTime, 'YYYY-MM-DD'); -// this.user.expireTime = this.dateSrv.date_format(this.user.expireTime, 'YYYY-MM-DD'); -// }); -// } else { -// this.user.createTime = this.dateSrv.today('YYYY-MM-DD'); -// this.user.expireTime = this.dateSrv.today('YYYY-MM-DD'); -// } + const user = this.user; + this.validateForm = this.formBuilder.group({ + name: [user.name], + mobile: [user.mobile, [Validators.pattern("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$")]], + email: [user.email], + weixin: [user.weixin], + organizationId: [user.organizationId], + expireTime: [user.expireTime], + id: [user.id] + }); } save() { - if (this.user.name == null || this.user.name === '') { - this.msgSrv.error('���������������'); - } else if (this.user.mobile == null || this.user.mobile === '') { - this.msgSrv.error('���������������'); - } else if (this.user.email == null || this.user.email === '') { - this.msgSrv.error('���������������������'); - } else if (this.user.password == null || this.user.password === '') { - this.msgSrv.error('���������������'); - } else { - this.http.post(environment.SERVER_BASH_URL + '/operateUser/operateUser', this.user).subscribe(() => { + const validateForm = this.validateForm; + const controls = validateForm.controls; + if (validateForm.valid) { + for (const i in controls) { + controls[i].disable(); + } + this.http.post(environment.SERVER_BASH_URL + '/operateUser/operateUser', validateForm.value).subscribe(() => { this.subject.next('true'); this.close(); }); + } else { + for (const i in controls) { + controls[i].markAsDirty(); + } } + } close() { diff --git a/src/app/routes/users/installer/installer.component.html b/src/app/routes/users/installer/installer.component.html index 849b08c..9f6c4ab 100644 --- a/src/app/routes/users/installer/installer.component.html +++ b/src/app/routes/users/installer/installer.component.html @@ -12,7 +12,7 @@ </div> <div nz-col [nzSpan]="8" class="mb-md"> <div nz-form-item class="d-flex"> - <div nz-form-label><label for="u_mobile">������</label></div> + <div nz-form-label><label for="u_mobile">������/������</label></div> <div nz-form-control class="flex-1"> <nz-input [(ngModel)]="q.u_mobile" name="u_mobile" [nzSize]="'large'" [nzPlaceHolder]="'���������������'" nzId="u_mobile"></nz-input> </div> @@ -20,7 +20,7 @@ </div> <div nz-col [nzSpan]="8" class="mb-md"> <button nz-button type="submit" [nzType]="'primary'" [nzLoading]="loading" [nzSize]="'large'">������</button> - <button nz-button type="reset" (click)="load(true)" [nzSize]="'large'" class="mx-sm">������</button> + <button nz-button type="reset" [nzSize]="'large'" class="mx-sm">������</button> </div> </div> </form> @@ -41,7 +41,7 @@ </div> <nz-table #nzTable [nzAjaxData]="data" - [nzLoading]="http.loading" + [nzLoading]="loading" [nzTotal]="total" [(nzPageIndex)]="q.pi" [nzPageSize]="q.ps" @@ -53,10 +53,9 @@ <label nz-checkbox [(ngModel)]="allChecked" [nzIndeterminate]="indeterminate" (ngModelChange)="checkAll($event)"></label> </th> <th nz-th><span>������</span></th> - <th nz-th><span>������</span></th> + <th nz-th><span>������/������</span></th> <th nz-th><span>������������</span></th> <th nz-th><span>���������</span></th> - <th nz-th><span>������</span></th> <th nz-th><span>������</span></th> <th nz-th><span>������������</span></th> <th nz-th> @@ -76,18 +75,15 @@ <td nz-td>{{i.mobile}}</td> <td nz-td>{{i.email}}</td> <td nz-td>{{i.weixin}}</td> - <td nz-td>{{i.password}}</td> <td nz-td>{{i.organizationId}}</td> <td nz-td>{{format_date(i.createTime)}}</td> <td nz-td>{{format_date(i.expireTime)}}</td> <td nz-td> <a (click)="edit(i)">������</a> - <ng-container *ngIf="i.isDelete == '0'"> <span nz-table-divider></span> <nz-popconfirm [nzTitle]="'���������������������������?'" [nzOkText]="'Yes'" [nzCancelText]="'No'" (nzOnConfirm)="delete(i)" > <a nz-popconfirm>������</a> </nz-popconfirm> - </ng-container> </td> </tr> </tbody> diff --git a/src/app/routes/users/installer/installer.component.ts b/src/app/routes/users/installer/installer.component.ts index d1cacb7..f59a364 100644 --- a/src/app/routes/users/installer/installer.component.ts +++ b/src/app/routes/users/installer/installer.component.ts @@ -1,10 +1,10 @@ -import { Component, OnInit } from '@angular/core'; -import { NzMessageService } from 'ng-zorro-antd'; -import { ModalHelper } from '@delon/theme'; -import { HttpClient } from '@angular/common/http'; -import { UserInstallerEditComponent } from './edit/edit.component'; -import { environment } from '../../../../environments/environment'; -import { DateService } from '../../../core/services/date.service'; +import {Component, OnInit} from '@angular/core'; +import {NzMessageService} from 'ng-zorro-antd'; +import {ModalHelper} from '@delon/theme'; +import {HttpClient} from '@angular/common/http'; +import {UserInstallerEditComponent} from './edit/edit.component'; +import {environment} from '../../../../environments/environment'; +import {DateService} from '../../../core/services/date.service'; @Component({ selector: 'app-installer', @@ -28,6 +28,7 @@ allChecked = false; indeterminate = false; sortMap: any = {}; + loading: boolean = true; constructor( public http: HttpClient, @@ -44,39 +45,15 @@ this.q.pi = 1; } this.http.get(environment.SERVER_BASH_URL + '/operateUser/list', {params: this.q}).subscribe((res: any) => { - // let data = res.data; - // const total = res.total; - // - // if (this.q.sorter !== '') { - // const s = this.q.sorter.split('_'); - // data.sort((prev, next) => { - // if (s[1] === 'descend') { - // return moment(next[s[0]]).unix() - moment(prev[s[0]]).unix(); - // } - // return moment(prev[s[0]]).unix() - moment(next[s[0]]).unix(); - // }); - // } - // - // if (this.q.u_name) { - // data = data.filter(d => d.name.indexOf(this.q.u_name) > -1); - // } - // if (this.q.u_mobile) { - // data = data.filter(d => d.mobile.toString().indexOf(this.q.u_mobile) > -1); - // } - // - // const start = (this.q.pi - 1) * this.q.ps; - // this.data = data.slice(start, start + this.q.ps); - // this.total = total; - this.data = res.data.data; this.total = res.data.total; this.dataChange(this.data); - + this.loading = false; }); } edit(user) { - this.modalHelper.static(UserInstallerEditComponent, { user }).subscribe(() => { + this.modalHelper.static(UserInstallerEditComponent, {user}).subscribe(() => { this.load(true); this.msgSrv.success('���������������������������'); }); @@ -84,14 +61,14 @@ add() { const user = {}; - this.modalHelper.static(UserInstallerEditComponent, { user }).subscribe(() => { + this.modalHelper.static(UserInstallerEditComponent, {user}).subscribe(() => { this.load(true); this.msgSrv.success('���������������������������'); }); } delete(user) { - this.http.post(environment.SERVER_BASH_URL + '/operateUser/operateUser/id',user).subscribe((res: any) => { + this.http.post(environment.SERVER_BASH_URL + '/operateUser/operateUser/id', user).subscribe((res: any) => { this.msgSrv.success('���������������������������'); this.load(true); }); @@ -103,6 +80,7 @@ ids.push(i.id); }); this.http.post(environment.SERVER_BASH_URL + '/operateUser/operateUsers/ids', ids).subscribe((res: any) => { + this.msgSrv.success('���������������������������'); this.load(true); }); } @@ -144,6 +122,8 @@ } format_date(date) { - return this.dateSrv.date_format(date, 'YYYY-MM-DD'); + if (date) { + return this.dateSrv.date_format(date, 'YYYY-MM-DD'); + } } } -- Gitblit v1.8.0