From 230a0f44018d86e87ddde1525dd23da8573e598e Mon Sep 17 00:00:00 2001 From: anlyyao Date: Thu, 14 Apr 2022 15:18:06 +0800 Subject: [PATCH] fix(steps): update some naming problem --- src/steps/step-item.ts | 51 ++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/src/steps/step-item.ts b/src/steps/step-item.ts index b8f11a2ab..01bfcf80a 100644 --- a/src/steps/step-item.ts +++ b/src/steps/step-item.ts @@ -76,10 +76,7 @@ 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'); }; @@ -87,8 +84,8 @@ export default class StepItem extends SuperComponent { /** * 判断当前步骤条与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); }; /** @@ -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