import { DataDisplayDto } from './../../shared-model'; import { RhSafeAny } from 'rh-base/model'; import { Component, Input, OnInit, SimpleChanges } from '@angular/core'; @Component({ selector: 'rh-basic-steps', templateUrl: './basic-steps.component.html', styleUrls: ['./basic-steps.component.less'] }) export class RhBasicStepsComponent implements OnInit { /** 数据源 */ @Input() rhDataSource!: RhSafeAny[]; /** 显示数据的键值 */ // 节点键值(用于显示当前节点) @Input() rhStepKey = ''; @Input() rhStepKeyValue = ''; // 节点标题(名称) @Input() rhTitle!: DataDisplayDto[]; // 节点副标题 @Input() rhSubTitle!: DataDisplayDto[]; // 节点描述 @Input() rhDescription!: DataDisplayDto[]; // 节点状态(看数据源中有无可以指定状态的字段) @Input() rhStatus: 'wait' | 'process' | 'finish' | 'error' = 'process'; // 节点图标 @Input() rhIcon = 'tool'; /** 当前节点的图标,默认为loading */ @Input() rhLoadingIcon = 'loading'; // 是否开启节点CUT功能 @Input() rhIsUseStepsCut = false; // 当前节点 currentStep = 0; index!: number; // 筛选后的数据 dataset!: RhSafeAny[]; constructor() { // } ngOnInit() { // } ngOnChanges(changes: SimpleChanges) { const { rhDataSource } = changes; if (rhDataSource && rhDataSource.currentValue) { if (this.rhStepKey && this.rhStepKeyValue) { if (this.rhIsUseStepsCut) { this.cutData(this.rhDataSource); } else { this.dataset = this.rhDataSource; this.currentStep = this.rhDataSource.findIndex((ele) => ele[this.rhStepKey] === this.rhStepKeyValue); } } else { this.currentStep = 0; this.dataset = this.rhDataSource; } } } // 判断数据量 cutData(dtos: RhSafeAny[]) { this.dataset = []; this.index = this.rhDataSource.findIndex((ele) => ele[this.rhStepKey] === this.rhStepKeyValue); // 当找不到当前正在生成的工序,表示已经都生产完成了。就隐藏工序step展示 if (this.index === -1) { return; } if (dtos.length > 5) { // 保留5个节点 if (2 <= this.index && this.index <= this.rhDataSource.length - 3) { // 保留当前节点及前后各两个节点 for (let i = this.index - 2; i <= this.index + 2; i++) { this.dataset.push(this.rhDataSource[i]); } } else if (this.index < 2) { // 保留前五个节点 for (let j = 0; j < 5; j++) { this.dataset.push(this.rhDataSource[j]); } } else if (this.index > this.rhDataSource.length - 3) { // 保留后五个节点 for (let k = this.rhDataSource.length - 1; k > this.rhDataSource.length - 6; k--) { this.dataset.unshift(this.rhDataSource[k]); } } this.currentStep = this.dataset.findIndex((ele) => ele[this.rhStepKey] === this.rhStepKeyValue); } else { this.dataset = dtos; this.currentStep = this.index; } this.dataset = [...this.dataset]; } }