Skip to content

Commit

Permalink
fix(steps): update some naming problem
Browse files Browse the repository at this point in the history
  • Loading branch information
anlyyao committed Apr 14, 2022
1 parent 0691da8 commit 230a0f4
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions src/steps/step-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,16 @@ export default class StepItem extends SuperComponent {
return Array.isArray(data[attr]) && data[attr].length;
};

/**
* 去除字符串最后一个`connectLine`符号及之后的字符,即1-1 变为1, 1-10-1变为1-10
*/
const RegReplace = (s) => {
const getStepLevel = (s) => {
const reg = new RegExp(`(.*)${connectLine}{1}.*`);
return s.replace(reg, '$1');
};

/**
* 判断当前步骤条与current指定的步骤是否同级
*/
const sameSteps = (stepsTag: String, current: String) => {
return stepsTag.length !== current.length && RegReplace(stepsTag) === RegReplace(current);
const isSameLevelStep = (stepsTag: String, current: String) => {
return stepsTag.length !== current.length && getStepLevel(stepsTag) === getStepLevel(current);
};

/**
Expand All @@ -100,55 +97,51 @@ export default class StepItem extends SuperComponent {
* @returns 状态
*/
const stepFinalStatus = (item, index, itemTag, current: String, currentStatus) => {
let _status = '';
// console.log(item.status);
if (item.status !== 'default' && item.status !== undefined) {
_status = item.status === '' ? 'default' : item.status;
} else if (item.status === 'default' || item.status === undefined) {
return item.status === '' ? 'default' : item.status;
}

if (item.status === 'default' || item.status === undefined) {
let tempStatus = '';
if (itemTag < current) {
_status = 'finish';
tempStatus = 'finish';
}

if (itemTag === current || sameSteps(itemTag, current)) {
// console.log(itemTag, item.sta);
_status = item.status === '' ? 'default' : currentStatus;
if (itemTag === current || isSameLevelStep(itemTag, current)) {
tempStatus = item.status === '' ? 'default' : currentStatus;
// 子步骤
if (judgeObjAttr(item, '_subStepItems')) {
// 1. 获取所有子步骤条的状态
const _statusList = [];
item._subStepItems.forEach((subItem, subIndex) => {
const tempStatusList = item._subStepItems.map((subItem, subIndex) => {
const subItemTag = `${itemTag}${connectLine}${subIndex}`;
const subStatus = stepFinalStatus(subItem, subIndex, subItemTag, current, currentStatus);
_statusList.push(subStatus);
return stepFinalStatus(subItem, subIndex, subItemTag, current, currentStatus);
});

// 2. 根据数组中子步骤条状态,判断当前步骤条状态。优先级:finish>error>process
// 2.1. 子步骤条中存在process或current指向子步骤且子步骤全为default,当前步骤process
// 2.2. 子步骤条中存在error,当前步骤error
// 2.3. 最后一个子步骤条为finish,当前步骤为finish
if (_statusList.includes('process') || _statusList.every((item) => item === 'default')) {
_status = 'process';
if (tempStatusList.includes('process') || tempStatusList.every((item) => item === 'default')) {
tempStatus = 'process';
}
if (_statusList.includes('error')) {
_status = 'error';
if (tempStatusList.includes('error')) {
tempStatus = 'error';
}
if (_statusList[_statusList.length - 1] === 'finish') {
_status = 'finish';
if (tempStatusList[tempStatusList.length - 1] === 'finish') {
tempStatus = 'finish';
}
}
}
if (itemTag > current) {
_status = 'default';
tempStatus = 'default';
}
return tempStatus;
}

return _status;
};

// 1. 拷贝一份 subStepItems
if (judgeObjAttr(this.data, 'subStepItems')) {
const _subStepItems = JSON.parse(JSON.stringify(this.data.subStepItems));
this.data._subStepItems = _subStepItems;
this.data._subStepItems = JSON.parse(JSON.stringify(this.data.subStepItems));
}

// 2. 判断status
Expand Down

0 comments on commit 230a0f4

Please sign in to comment.