import { IStepInfo } from '@/store' ; import { jsonParser } from '@/utils/tool/common' ; import { TOOL_NAME } from '@/constant/store' ; import i18n from '@/i18n' ; export function findAllDependStep ( step , stepList ) { const dependStep = [ ] ; for ( let i = 0 ; i < stepList . length ; i ++ ) { if ( step === stepList [ i ] . dataSourceStep ) { dependStep . push ( stepList [ i ] . step ) ; } } if ( dependStep . length > 0 ) { dependStep . slice ( ) . forEach ( ( v ) => { dependStep . push ( ... findAllDependStep ( v , stepList ) ) ; } ) ; return dependStep ; } return [ ] ; } export function reSortStepList ( deleteList , stepList ) { const currentList = JSON . parse ( JSON . stringify ( stepList ) ) ; for ( let i = 0 ; i < deleteList . length ; i ++ ) { for ( let j = deleteList [ i ] - 1 ; j < currentList . length ; j ++ ) { currentList [ j ] . step = currentList [ j ] . step - 1 ; if ( currentList [ j ] . dataSourceStep > deleteList [ i ] ) { currentList [ j ] . dataSourceStep -- ; } if ( currentList [ j ] . type === 2 ) { currentList [ j ] . name = `质检 - 步骤${ currentList [ j ] . dataSourceStep }` ; } } currentList . splice ( deleteList [ i ] - 1 , 1 ) ; } return currentList ; } export param { number } step param { IStepConfig [ ] } stepList export function reloadStepListReferenceStep ( step , stepList ) { return stepList . map ( ( v ) => { const config = jsonParser ( v ?. config ) ; if ( typeof config ?. referenceStep === 'number' ) { if ( config ?. referenceStep >= step ) { return { ... v , config : JSON . stringify ( { ... config , referenceStep : 0 , referenceFilterData : { } } ) , } ; } } return v ; } ) ; } export param { number } step param { IStepConfig [ ] } stepList returns export function deleteStep ( step , stepList ) { const deleteList = findAllDependStep ( step , stepList ) ; deleteList . unshift ( step ) ; const deleteStepList = stepList . filter ( ( item ) => deleteList . some ( ( i ) => i === item . step ) ) . map ( ( item ) => `${ i18n . t ( 'NStep' , { step : item . step } ) }
    ：${ i18n . t ( TOOL_NAME [ item . tool ] ) }` ) ; const newStepList = reSortStepList ( deleteList . sort ( ( a , b ) => b - a ) , reloadStepListReferenceStep ( step , stepList ) ) ; return { newStepList , deleteStepList } ; }