export default()

in packages/data-render/src/models/isHidden.ts [101:143]


export default (key: any, data: any, addons: any) => {
  let newKey = key;

  // 说明是函数表达式
  if (
    newKey.substring(0, 2) === '{{' &&
    newKey.substring(newKey.length - 2, newKey.length) === '}}'
  ) {
    newKey = newKey.substring(2, newKey.length - 2);
  }

  // 相等,说明不是函数表达式
  if (newKey === key || operators.every((item) => !newKey.includes(item))) {
    return !getValueFromKey({ data, path: newKey, defaultValue: false, addons });
  }

  // 两种运算符都不存在
  if (!hasOr(newKey) && !hasAnd(newKey)) {
    return !calculate(newKey, data, addons);
  }

  // 只有 && 运算符
  if (!hasOr(newKey) && hasAnd(newKey)) {
    return !getList(newKey, '&&').every((item: string) => {
      const res = calculate(item, data, addons);
      return res;
    });
  }

  // 只有 || 运算符
  if (hasOr(newKey) && !hasAnd(newKey)) {
    return !getList(newKey, '||').some((item: string) => calculate(item, data, addons));
  }

  // 两种运算符都存在
  return !getList(newKey, '||').some((item: string) => {
    // 存在 && 运算符
    if (hasAnd(item)) {
      return getList(item, '&&').every((item: string) => calculate(item, data, addons));
    }
    return calculate(item, data, addons);
  });
};