0.1.7 • Published 10 months ago

@cainiaofe/cn-error-feedback v0.1.7

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
10 months ago

何时使用

错误信息反馈提示/解决方案引导说明

API

export interface IErrorConstructInfo {
  /**
   * 基础信息
   */
  errorBaseInfo?: {
    appName?: string;
    codeKey?: string;
    codeDesc?: string;
  };
  /**
   * 异常信息
   */
  errorContentInfo?: {
    /**
     * 异常类型
     */
    typeCode?: 'permissionError' | 'operationError' | 'bizError' | 'sysError';
    /**
     * 展示模式
     */
    displayMode?: 'dialog' | 'tips';
    /**
     * 弹框title
     */
    errorTitle?: string;
    /**
     * 异常等级
     */
    errorLevel?: 'error' | 'warning';
    /**
     * 确认按钮文案(例:申请权限、立即处理)
     */
    confirmTexts?: string;
    /**
     * 确认按钮跳转链接
     */
    confirmUrl?: string;
  };
  /**
   * 解决方案
   */
  errorSolution?: {
    enableSolution?: boolean;
    /**
     * 解决方案类型
     */
    solutionType?: 'hyperlink' | 'iframe' | 'text';
    /**
     * hyperlink/iframe 文案
     */
    text?: string;
    /**
     * text 异常原因(solutionType = text)
     */
    textReason?: string;
    /**
     * text 解决方案(solutionType = text)
     */
    textSolution?: string;
    /**
     * hyperlink/iframe 填写链接
     */
    manualUrl?: string;
  };
  errorMsg?: string;
  errorCode?: string | number;
}

export interface ICnErrorFeedback {
  show: (errorConstructInfo: IErrorConstructInfo) => void;
}

CnRequest 接入示例

import CnErrorFeedback from '@alife/cn-error-feedback';

const findConstruct = (item) => (!item || 'success' in item ? item : findConstruct(item.data));

(response) => {
  try {
    const data = findConstruct(response);
    const { success, errorMsg, cndbErrorMsg, errorConstructInfo = {}, errorCode } = data;
    const { errorContentInfo } = errorConstructInfo || {};
    if (!success) {
      if (errorContentInfo) {
        // 调用信息反馈组件
        CnErrorFeedback.show({
          ...errorConstructInfo,
          errorMsg: cndbErrorMsg || errorMsg,
          errorCode,
        });
        return Promise.reject(data);
      }
    }
  } catch (error) {}
};

参考文档

0.1.7

10 months ago

1.0.1

2 years ago

1.0.1-beta.1

2 years ago

1.0.1-beta.0

2 years ago

1.0.0

2 years ago