fengxiang
2017-12-27 e8c0a91458bf36db6b20bf2abd9a035d8ca466f9
设备信息
11 files added
8 files modified
8531 ■■■■■ changed files
.gitignore 2 ●●●●● patch | view | raw | blame | history
src/app/core/entity/grid.ts 98 ●●●●● patch | view | raw | blame | history
src/app/core/enum/types.enum.ts 3 ●●●●● patch | view | raw | blame | history
src/app/core/pipe/pipe.module.ts 14 ●●●●● patch | view | raw | blame | history
src/app/core/pipe/tyep-handle.pipe.ts 33 ●●●●● patch | view | raw | blame | history
src/app/core/services/example.service.ts 46 ●●●●● patch | view | raw | blame | history
src/app/core/services/tools.service.ts 6 ●●●●● patch | view | raw | blame | history
src/app/routes/devices/devices.module.ts 21 ●●●●● patch | view | raw | blame | history
src/app/routes/devices/version/add-or-edit/add-or-edit.component.html 3 ●●●●● patch | view | raw | blame | history
src/app/routes/devices/version/add-or-edit/add-or-edit.component.ts 15 ●●●●● patch | view | raw | blame | history
src/app/routes/devices/version/version.component.html 60 ●●●●● patch | view | raw | blame | history
src/app/routes/devices/version/version.component.ts 124 ●●●●● patch | view | raw | blame | history
src/app/routes/devices/version/version.service.ts 33 ●●●●● patch | view | raw | blame | history
src/app/routes/routes.module.ts 8 ●●●● patch | view | raw | blame | history
src/app/rxjs-operators.ts 15 ●●●●● patch | view | raw | blame | history
src/app/shared/shared.module.ts 2 ●●●●● patch | view | raw | blame | history
src/environments/environment.prod.ts 2 ●●● patch | view | raw | blame | history
tsconfig.json 2 ●●●●● patch | view | raw | blame | history
yarn.lock 8044 ●●●●● patch | view | raw | blame | history
.gitignore
@@ -37,3 +37,5 @@
.DS_Store
Thumbs.db
.angulardoc.json
yarn.lock
src/app/core/entity/grid.ts
New file
@@ -0,0 +1,98 @@
import { Type } from '@angular/core';
import { Types } from '@core/enum/types.enum';
export interface Column {
   text?: string;
   name?: string;
   value?: any;
   width?: string;
   sort?: boolean;
   type?: DataType;
}
export interface DataType {
    name: Types;
    format?: any;
}
// 作为http来回传递参数
export interface PageBean {
    pageIndex?: number ; // 页码
    pageSize?: number ; // 一页多少条
    total?: number;
    data?: any[];
    queryParams?: string;
}
export class Grid implements PageBean {
    title = '';
    pageIndex = 0; // 页码
    pageSize = 10; // 每页几行数据
    data: any[] = [];
    total = 0;
    queryParams = '';
    pages = 0; // 总页数
    queryMap?: any = {};
    size  = 0;  // 当前页数据条数
    sorts?: any[] = [];
    indeterminate = false;
    allChecked = false;
    selectedIndexs?: number[] = []; // 被选中序列号
    columns?: Column[] = [];
    checkAll(value: boolean) {
        this.data.forEach(
            row => {row.checked = value;}
        )
        this.refreshStatus();
    }
    getData():any[]{
        return this.data;
    }
    initData(pageData: {data?: any[], total?: number}) {
        if ( pageData != null && pageData.data != null) {
            let index = 0;
            this.data = pageData.data.map(row => {
                row['index'] = index++;
                return row;
            });
            this.total = pageData.total;
        }
    }
    refreshStatus() {
        const data = this.data;
        const allChecked =   data.every(value => value.checked);
        const allUnChecked = data.every(value => !value.checked);
        this.allChecked = allChecked;
        this.indeterminate = (!allChecked) && (!allUnChecked);
        this.selectedIndexs = data.filter(value => value.checked).map(
            row => {
               return row['index'] != null ? row['index'] : 0;
            }
        );
        this.selectedIndexs = this.selectedIndexs == null ? [] : this.selectedIndexs;
      }
    constructor(config: object) {
        if (config != null) {
            const keys = Object.getOwnPropertyNames(config);
            for (const index in keys) {
                const key = keys[index];
                if (this[key] != null) {
                    this[key] = config[key];
                }
            }
        }
    }
    public setColumns(obj: Object) {
        this.columns = this.objectToArray(obj);
    }
    private objectToArray(obj: Object): any[] {
        const arr = [];
        const keys = Object.getOwnPropertyNames(obj);
        for (const index in keys) {
            const key = keys[index];
            const item = obj[key];
            if ( item['name'] == null) {
              item['name'] = key;
            }
            arr.push(item);
        }
        return arr;
    }
}
src/app/core/enum/types.enum.ts
New file
@@ -0,0 +1,3 @@
export enum Types {
    Date,json
}
src/app/core/pipe/pipe.module.ts
New file
@@ -0,0 +1,14 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TyepHandlePipe } from './tyep-handle.pipe';
import { DateService } from '@core/services/date.service';
@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [TyepHandlePipe],
  exports: [TyepHandlePipe],
  providers: [DateService]
})
export class PipeModule { }
src/app/core/pipe/tyep-handle.pipe.ts
New file
@@ -0,0 +1,33 @@
import { DatePipe } from '@angular/common/src/pipes/date_pipe';
import { Types } from './../enum/types.enum';
import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { NzDatePipe } from 'ng-zorro-antd/src/util/nz-date.pipe';
import { DateService } from '@core/services/date.service';
import { Column } from '@core/entity/grid';
@Pipe({
  name: 'tyepHandle'
})
export class TyepHandlePipe implements PipeTransform {
  constructor(private dateService: DateService) {
  }
  transform(value: any, col?: Column): any {
       const t = Types.Date;
       const type  = col.type;
       if(type!=null&&type.name!=null){
         value = this.transformHandle(value,type.name,type.format);
       }
       return value;
  }
  private transformHandle(value:any,type: Types,format:any):any{
        switch(type){
           case Types.Date:
           return this.dateService.date_format(value,format);
        }
  }
}
src/app/core/services/example.service.ts
New file
@@ -0,0 +1,46 @@
import { Injectable } from '@angular/core';
import { Column } from '@core/entity/grid';
export class  Criteria{
    private static CONDITION_SPLIT = "||";
     private conditions: string[] = [];
     public getConditions(): string[]{
       return this.conditions;
     }
     public addCondition(condition: string,colName:string,...values: any[]){
        const split = Criteria.CONDITION_SPLIT;//'||'
        this.conditions.push(condition+split+colName+split+ values.join(split));
     }
     public andLike(col:Column): Criteria{
         this.addCondition('andLike',col.name,col.value);
         return this;
     }
     public andEqualTo(col:Column): Criteria{
        this.addCondition('andEqualTo',col.name,col.value);
        return this;
     }
}
@Injectable()
export class ExampleService {
  private static OR_SPLIT = "or|";
  private static  CRITERIA_SPLIT = "|||";
  private criterion: Criteria[]=[];
  public getSqlParam():string{
      let whereSql = '';
     for(let cri of this.criterion){
            const conditions = cri.getConditions();
            whereSql += ExampleService.OR_SPLIT+conditions.join(ExampleService.CRITERIA_SPLIT);
     }
     return encodeURI(whereSql);
  }
  constructor() { }
    public or(){
        const cri = new Criteria();
        this.criterion.push(cri);
        return cri;
    }
}
src/app/core/services/tools.service.ts
New file
@@ -0,0 +1,6 @@
import { Injectable } from '@angular/core';
@Injectable()
export class ToolsService {
}
src/app/routes/devices/devices.module.ts
@@ -1,9 +1,19 @@
import { ToolsService } from './../../core/services/tools.service';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BasicInfoComponent } from './basic-info/basic-info.component';
import { VersionComponent } from './version/version.component';
import { MonitorPointComponent } from './monitor-point/monitor-point.component';
import {RouterModule, Routes} from '@angular/router';
import { SharedModule } from '@shared/shared.module';
import { VersionService } from 'app/routes/devices/version/version.service';
import { Version } from '@angular/compiler/src/util';
import { _HttpClient } from '@delon/theme/services/http/http.client';
import { AddOrEditComponent } from './version/add-or-edit/add-or-edit.component';
import { PipeModule } from '@core/pipe/pipe.module';
const COMPONENTS_NOROUNT = [ AddOrEditComponent ];
const routes: Routes = [
  {
@@ -18,13 +28,20 @@
@NgModule({
  imports: [
    //管道模块必须当前模块导入
    PipeModule,
    CommonModule,
    SharedModule,
    RouterModule.forChild(routes)
  ],
  declarations: [
    BasicInfoComponent,
    VersionComponent,
    MonitorPointComponent
  ]
    MonitorPointComponent,
    ...COMPONENTS_NOROUNT,
    AddOrEditComponent
  ],
  providers: [ToolsService, VersionService, _HttpClient],
  entryComponents: COMPONENTS_NOROUNT
})
export class DevicesModule { }
src/app/routes/devices/version/add-or-edit/add-or-edit.component.html
New file
@@ -0,0 +1,3 @@
<p>
  add-or-edit works!
</p>
src/app/routes/devices/version/add-or-edit/add-or-edit.component.ts
New file
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
  selector: 'app-add-or-edit',
  templateUrl: './add-or-edit.component.html',
  styles: []
})
export class AddOrEditComponent implements OnInit {
  constructor() { }
  ngOnInit() {
  }
}
src/app/routes/devices/version/version.component.html
@@ -1,3 +1,57 @@
<p>
  version works1!
</p>
<pro-header [title]="grid.title"></pro-header>
<nz-card [nzBordered]="false">
        <div class="mb-md">
                <button nz-button (click)="add()" [nzType]="'primary'" [nzSize]="'large'">
                    <i class="anticon anticon-plus"></i><span>新建</span>
                </button>
                <ng-container *ngIf="grid.selectedIndexs.length > 0"> &nbsp;
                <button nz-button [nzSize]="'large'" (click)="remove()">批量删除</button>
                </ng-container>
                <nz-input [ngStyle]="{'width': '280px','float':'right'}" [(ngModel)]="queryMap.value" name=""  [nzPlaceHolder]="queryMap.text"
                (change)="queryTextChanged($event)" ></nz-input>
        </div>
        <div class="mb-md">
                <nz-alert *ngIf="grid.selectedIndexs.length > 0" [nzType]="'info'" [nzShowIcon]="true">
                    <span alert-body>
                         已选择<strong class="text-primary">{{grid.selectedIndexs.length}}</strong>项
                    </span>
                </nz-alert>
    </div>
    <nz-table #nzTable
              [nzAjaxData]="grid.data"
              [nzTotal]="grid.total"
              [(nzPageIndex)]="grid.pageIndex"
              [(nzPageSize)]="grid.pageSize"
              [nzLoading]="http.loading"
              [nzShowTotal]="true"
              (nzPageIndexChange)="load()"
              (nzDataChange)="dataChange($event)">
              <thead nz-thead>
                  <tr>
                    <th nz-th [nzCheckbox]="true">
                        <label nz-checkbox [(ngModel)]="grid.allChecked" [nzIndeterminate]="grid.indeterminate" (ngModelChange)="grid.checkAll($event)"></label>
                    </th>
                    <th nz-th *ngFor="let col of grid.columns"
                     [ngStyle]="{'width':col.width,'text-align':col['align'] === undefined?'left':col.align}" >
                           <span>{{ col.text }}</span>
                    </th>
                  </tr>
              </thead>
              <tbody nz-tbody>
                <tr nz-tbody-tr *ngFor="let row of nzTable.data">
                    <td nz-td [nzCheckbox]="true">
                       <label nz-checkbox [(ngModel)]="row.checked" (ngModelChange)="grid.refreshStatus($event)"></label>
                    </td>
                    <td nz-td *ngFor="let col of grid.columns"
                    [ngStyle]="{'width':col.width,'text-align':col['align'] === undefined?'left':col.align}">
                        <span [ngSwitch]="col.type">
                             <!-- 要使用管道,无法自动生成 -->
                            <span *ngSwitchDefault> {{ row[col.name]|tyepHandle:col }} </span>
                             <!-- 要使用管道,无法自动生成 -->
                        </span>
                    </td>
                </tr>
              </tbody>
              </nz-table>
  </nz-card>
src/app/routes/devices/version/version.component.ts
@@ -1,5 +1,23 @@
import { Subject } from 'rxjs/Subject';
import '../../../rxjs-operators';
import { ToolsService } from '@core/services/tools.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 { environment } from '../../../../environments/environment';
import { DateService } from '@core/services/date.service';
import { VersionService } from 'app/routes/devices/version/version.service';
import { Types } from '@core/enum/types.enum';
import { Column, Grid, PageBean } from '@core/entity/grid';
interface DeviceVersion {
  createTime: Column;
  description: Column;
  id?: Column;
  name: Column;
  version: Column;
}
@Component({
  selector: 'app-version',
  templateUrl: './version.component.html',
@@ -7,9 +25,113 @@
})
export class VersionComponent implements OnInit {
  constructor() { }
  grid: Grid = new Grid(null);
  queryMap = { text: '请输入名称或型号', value: ''};
  queryTextStream: Subject<string> = new Subject<string>();
    private initPage() {
    const columns: DeviceVersion = {
       name: {
        text: '名称',
        width: '22%'
       },
       version: {
        text: '型号',
        width: '22%'
      },
      createTime: {
          text: '创建时间',
          width: '22%',
          type: {
            name: Types.Date,
            format: 'YYYY-MM-DD HH:mm:ss'
          }
      },
      description: {
          text: '备注',
          width: '22%'
      }
    };
    this.grid.title = '设备型号';
    this.grid.setColumns(columns);
    this.grid.pageSize = 10;
  }
  constructor(
    public http: HttpClient,
    private versionService: VersionService,
    public dateSrv: DateService,
    public msgSrv: NzMessageService,
    private modalHelper: ModalHelper,
    private toolsService: ToolsService) {}
  ngOnInit() {
    this.initPage();
    this.queryTextStream
    .debounceTime(1000)
    .distinctUntilChanged()
    .subscribe(queryText => {
        this.load();
    });
  }
  queryTextChanged($event) {
      // tslint:disable-next-line:no-debugger
      debugger;
      this.queryTextStream.next(this.queryText);
  }
  load(reload: boolean = false) {
    if (reload) {
      this.grid.pageIndex = 1 ;
    }
    this.versionService.getPagingList(this.grid, this.queryText).subscribe(
       (res: PageBean) => {
            if (res.total > 0 && res.data != null) {
              this.grid.initData(res);
              this.grid.refreshStatus();
            }
       }
    );
  }
  edit() {
    // this.modalHelper.static(VersionEditComponent, { user }).subscribe(() => {
    //   this.load(true);
    //   this.msgSrv.success('安装用户修改成功!');
    // });
  }
  add() {
    // const user = {};
    // this.modalHelper.static(VersionEditComponent, { user }).subscribe(() => {
    //   this.load(true);
    //   this.msgSrv.success('安装用户保存成功!');
    // });
  }
  delete(user) {
    this.http.delete(environment.SERVER_BASH_URL + '/user/operate_user/' + user.id).subscribe((res: any) => {
      this.msgSrv.success('安装用户删除成功!');
      this.load(true);
    });
  }
  remove() {
  }
  dataChange(res: any) {
  }
  sort(field: string, value: any) {
    // this.sortMap = {};
    // this.sortMap[field] = value;
    // this.q.sorter = value ? `${field}_${value}` : '';
    // this.load(true);
  }
  reset(ls: any[]) {
    for (const item of ls) item.value = false;
    this.load(true);
  }
}
src/app/routes/devices/version/version.service.ts
New file
@@ -0,0 +1,33 @@
import { DeviceVersion } from './version.service';
import { ExampleService } from './../../../core/services/example.service';
import { _HttpClient } from '@delon/theme';
import { environment } from './../../../../environments/environment.prod';
import { RouteConfigLoadStart } from '@angular/router';
import { Injectable } from '@angular/core';
import { equal } from 'assert';
import { Observable } from 'rxjs/Observable';
import {  PageBean } from '@core/entity/grid';
export interface DeviceVersion {
  createTime?: any;
  description?: string;
  id?: number;
  name?: string;
  version?: number;
}
@Injectable()
export class VersionService {
  private urls = {
      edit: environment.SERVER_BASH_URL + '/device-version/page-list'
  };
  constructor(private http: _HttpClient) { }
   public getPagingList(page: PageBean, queryText: string): Observable<PageBean> {
    const example = new ExampleService();
    example.or().andLike({name: 'name', value: '%' + queryText + '%'});
    example.or().andEqualTo({name: 'version', value: queryText});
    const param: PageBean = {pageSize: page.pageSize, pageIndex: page.pageIndex, queryParams: example.getSqlParam()};
    return this.http.get(this.urls.edit, param);
  }
}
src/app/routes/routes.module.ts
@@ -1,3 +1,5 @@
import { DevicesModule } from './devices/devices.module';
import { _HttpClient } from '@delon/theme';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { SharedModule } from '@shared/shared.module';
@@ -8,6 +10,7 @@
import { DashboardAnalysisComponent } from './dashboard/analysis/analysis.component';
import { DashboardMonitorComponent } from './dashboard/monitor/monitor.component';
import { DashboardWorkplaceComponent } from './dashboard/workplace/workplace.component';
import { CoreModule } from '@core/core.module';
@NgModule({
    imports: [
@@ -18,10 +21,13 @@
        DashboardV1Component,
        DashboardAnalysisComponent,
        DashboardMonitorComponent,
        DashboardWorkplaceComponent,
        DashboardWorkplaceComponent
    ],
    exports: [
        RouterModule
    ],
    providers: [
        _HttpClient
    ]
})
src/app/rxjs-operators.ts
New file
@@ -0,0 +1,15 @@
// import 'rxjs/Rx'; // adds ALL RxJS statics & operators to Observable
// See node_module/rxjs/Rxjs.js
// Import just the rxjs statics and operators we need for THIS app.
// Statics
import 'rxjs/add/observable/throw';
// Operators
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/toPromise';
src/app/shared/shared.module.ts
@@ -142,6 +142,8 @@
    AdImageModule,
    AdUtilsModule
} from '@delon/abc';
import { _HttpClient } from '@delon/theme/services/http/http.client';
import { CoreModule } from '@core/core.module';
const ABCMODULES = [
    AdAvatarListModule,
    AdChartsModule,
src/environments/environment.prod.ts
@@ -3,5 +3,5 @@
    production: true,
    hmr: false,
    useHash: true,
    SERVER_BASH_URL: 'http://47.96.171.62:8080/screen_api_v2'
    SERVER_BASH_URL: 'http://localhost:8001'
};
tsconfig.json
@@ -7,6 +7,8 @@
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
yarn.lock
New file
Diff too large