SOURCE

// mock数据
const applicationInfo = [
    {
        field: 'undertakeFlag',
        value: '承销+受托',
        display: '1',
        source: [
            {
                field: 'groupFlag',
                value: 'internal_review_debt',
                // or:true,
            },
            // {
            //     field: 'proTypeCode',
            //     value: 'ABS',
            //     not: true,
            // },
            // {
            //     field: 'proTypeCode',
            //     value: 'ABN',
            //     not: true,
            // },
            // {
            //     field: 'proTypeCode',
            //     value: 'CLO',
            //     not: true,
            // }
        ],
    },
    {
        field: 'proTypeCode',
        value: '公司债',
        display: '1',
    },
    {
        field: 'groupFlag',
        value: 'internal_review_debt',
        display: '0',
    },
];

// 对条件值取[非]
const judgeByNot = (not, condResult) => not ? !condResult : condResult;
// 对两个条件值取[与]或者[或]
const judgeByOr = (or, condResult1, condResult2) => or ? (condResult1 || condResult2) : (condResult1 && condResult2);

let tempInfo = applicationInfo.filter((item) => {
    const {
        field: itemField,   // 字段名
        value: itemValue,   // 字段值
        display,            // 字段是否显示,默认从FLOW_FORM_Q0001来?
        source,             // 字段的显示判断条件,从appLayout中来
    } = item;
    const isAuth = display === '1';    // 用户是否有查看权限
    if(Array.isArray(source) && source.length > 0) {
        const conditions = [...source];

        // 计算第一个条件的条件值
        const firstCondition = conditions.shift();
        const firstTargetItem = applicationInfo.find(item2 => item2.field === firstCondition.field);
        const showOnFirstCondition = judgeByNot(
            firstCondition.not,
            firstCondition.value === firstTargetItem.value
        );

        // 迭代校验剩余判断条件,使用第一个条件值作为初始值
        const showWithAllConditions = conditions.reduce((showTillLastCondition, curCondition) => {
            // showTillLastCondition: 截止前一个判断条件时得出的结果
            // curCondition: 当前判断条件对象
            const {
                field: condField,   // 条件判断的目标字段名
                value: condValue,   // 条件判断的目标字段值
                or,                 // 与前一结果是否进行或运算,否则进行与运算
                not,                // 是否对当前值判断结果进行非运算
            } = curCondition;
            // 查找判断条件的判断目标字段
            const targetItem = applicationInfo.find(item2 => item2.field === condField);
            if(targetItem) {
                // 先计算当前条件结果,判断当前条件设定值是否与目标字段值相等后,进行judgeByNot运算
                const showOnCurCondition = judgeByNot(not, condValue === targetItem.value);
                // 与截止前一个判断条件时得出的结果一同进行judgeByOr运算
                const showTillCurCondition = judgeByOr(or, showTillLastCondition, showOnCurCondition);
                // 返回截止当前判断条件时得出的结果
                return showTillCurCondition;
            } else {
                // 没有找到目标字段,即截止当前条件判断时,总判断结果为不通过
                return false;
            }
        }, showOnFirstCondition);
        // 最终判断结果为用户有权限查看,且所有条件的总值为true
        return isAuth && showWithAllConditions;
    } else {
        // 如果不存在判断条件,则以用户是否有权限查看为筛选结果
        return isAuth;
    }
});

console.log(tempInfo.map(item => `${item.field}: ${item.value}`).join('|'));
console 命令行工具 X clear

                    
>
console