移动开发平台 mPaaS 异常页组件

By | 2021年4月23日

AUNetErrorView 为空页面异常视图显示控件,包括两种提示风格:

  • 简单版风格(默认),包含 5 种样式。
  • 插图版风格,包含 5 种样式。

两种风格的主要区别在于使用的提示图片不同,见效果图。

效果图

  • 简单版本(半屏)风格

    image

  • 插图版本(全屏)风格

image

接口说明

  
  1. typedef NS_ENUM(NSInteger, AUNetErrorType) {
  2. AUNetErrorTypeLimit, // 限流
  3. AUNetErrorTypeAlert, // 系统繁忙(系统错误)、警示
  4. AUNetErrorTypeNetworkError, // 网络不给力
  5. AUNetErrorTypeEmpty, // 内容为空
  6. AUNetErrorTypeNotFound, // 404 找不到(与 AUNetErrorTypeAlert 图片相同)
  7. AUNetErrorTypeUserLogout, // 用户已注销
  8. AUNetErrorTypeFailure __attribute__((deprecated)) = AUNetErrorTypeNetworkError,
  9. AUNetErrorTypeError __attribute__((deprecated)) = AUNetErrorTypeNetworkError, //网络错误,完全无法连接
  10. AUNetErrorTypeSystemBusy __attribute__((deprecated)) = AUNetErrorTypeAlert, //警示
  11. APExceptionEnumNetworkError __attribute__((deprecated)) = AUNetErrorTypeNetworkError, //网络错误,完全无法连接
  12. APExceptionEnumEmpty __attribute__((deprecated)) = AUNetErrorTypeEmpty, //内容为空
  13. APExceptionEnumAlert __attribute__((deprecated)) = AUNetErrorTypeAlert, //警示
  14. APExceptionEnumLimit __attribute__((deprecated)) = AUNetErrorTypeLimit, //限流,
  15. APExceptionEnumNetworkFailure __attribute__((deprecated)) = AUNetErrorTypeNetworkError, //网络不给力
  16. };
  17. typedef NS_ENUM(NSInteger, AUNetErrorStyle) {
  18. AUNetErrorStyleMinimalist, //简单版
  19. AUNetErrorStyleIlustration, //插图版
  20. APExceptionStyleIlustration __attribute__((deprecated)) = AUNetErrorStyleIlustration, //插图版
  21. APExceptionStyleMinimalist __attribute__((deprecated)) = AUNetErrorStyleMinimalist //简单版
  22. };
  
  1. /**
  2. 空页面异常视图显示控件
  3. 包括两种提示风格:
  4. 1、简单版风格(默认),包含3种类型样式
  5. 2、插图版风格,包含7种类型样式
  6. 两种风格和类型主要是图片不一样。
  7. */
  8. @interface AUNetErrorView : UIView
  9. @property(nonatomic, strong, readonly) UIButton *actionButton; // 默认文案是刷新
  10. @property(nonatomic, strong, readonly) UIImageView *iconImageView; // icon 视图
  11. @property(nonatomic, strong, readonly) UILabel *infoLabel; // 主提示文案 Label
  12. @property(nonatomic, strong, readonly) UILabel *detailLabel; // 详细提示文案 Label
  13. @property(nonatomic, strong) NSString *infoTitle; // 主文案说明
  14. @property(nonatomic, strong) NSString *detailTitle; // 辅助文案说明
  15. /**
  16. * 初始化异常view并设定异常风格和类型
  17. * (target和action为空时,刷新按钮不显示)
  18. *
  19. * @param frame view 的坐标,必选
  20. * @param style 异常的风格,插画版 or 极简版,必选
  21. * @param type 异常类型,必选
  22. * @param target 刷新事件处理对象
  23. * @param action 刷新事件处理方法
  24. *
  25. * @return APExceptionView
  26. */
  27. - (id)initWithFrame:(CGRect)frame
  28. style:(AUNetErrorStyle)style
  29. type:(AUNetErrorType)type
  30. target:(id)target
  31. action:(SEL)action;
  32. /**
  33. * 初始化异常视图并显示在指定的视图上
  34. * (target 和 action 为空时,刷新按钮不显示)
  35. *
  36. * @param parent view 的 superView,必选
  37. * @param style 异常的风格,插画版 or 极简版,必选
  38. * @param type 异常类型,必选
  39. * @param target 刷新事件处理对象
  40. * @param action 刷新事件处理方法
  41. *
  42. * @return APExceptionView
  43. */
  44. + (id)showInView:(UIView *)parent
  45. style:(AUNetErrorStyle)style
  46. type:(AUNetErrorType)type
  47. target:(id)target
  48. action:(SEL)action;
  49. /**
  50. * 取消异常视图的显示
  51. */
  52. - (void)dismiss;
  53. /**
  54. * 倒计时 仅限限流使用
  55. * 如果 completeBlock == nil 且 业务没有设置 actionButton 的点击响应事件 则倒计时功能不生效;
  56. * 如果 completeBlock != nil,倒计时结束直接执行 completeBlock,同时隐藏 actionButton
  57. * 如果使用 getActionButton 来添加button的响应事件,要确保在该方法之前添加 actionButton 的响应事件
  58. */
  59. - (void)setCountdownTimeInterval:(NSInteger)startTime // 倒计时起始时间
  60. completeBlock:(void (^)(void))completeBlock; // 倒计时结束后
  61. @end

代码示例

  
  1. netErrorView = [[AUNetErrorView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame) + 5, self.view.width, 300) style:AUNetErrorStyleIlustration type:AUNetErrorTypeError target:self action:@selector(pressedNetErrorView)];
  2. netErrorView.detailTitle = @"类型是AUNetErrorTypeError";
  3. [self.view addSubview:netErrorView];
  4. // 设置倒计时
  5. [netErrorView setCountdownTimeInterval:10 completeBlock:^{
  6. NSLog(@"倒计时结束");
  7. }];

请关注公众号获取更多资料

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注