index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import PropTypes from '../_util/vue-types';
  2. import { getComponentFromProp } from '../_util/props-util';
  3. import { ConfigConsumerProps } from '../config-provider/configConsumerProps';
  4. import Icon from '../icon';
  5. import Base from '../base';
  6. import noFound from './noFound';
  7. import serverError from './serverError';
  8. import unauthorized from './unauthorized';
  9. export var IconMap = {
  10. success: 'check-circle',
  11. error: 'close-circle',
  12. info: 'exclamation-circle',
  13. warning: 'warning'
  14. };
  15. export var ExceptionMap = {
  16. '404': noFound,
  17. '500': serverError,
  18. '403': unauthorized
  19. };
  20. // ExceptionImageMap keys
  21. var ExceptionStatus = Object.keys(ExceptionMap);
  22. export var ResultProps = {
  23. prefixCls: PropTypes.string,
  24. icon: PropTypes.any,
  25. status: PropTypes.oneOf(['success', 'error', 'info', 'warning', '404', '403', '500']).def('info'),
  26. title: PropTypes.any,
  27. subTitle: PropTypes.any,
  28. extra: PropTypes.any
  29. };
  30. var renderIcon = function renderIcon(h, prefixCls, _ref) {
  31. var status = _ref.status,
  32. icon = _ref.icon;
  33. if (ExceptionStatus.includes('' + status)) {
  34. var SVGComponent = ExceptionMap[status];
  35. return h(
  36. 'div',
  37. { 'class': prefixCls + '-icon ' + prefixCls + '-image' },
  38. [h(SVGComponent)]
  39. );
  40. }
  41. // prop `icon` require slot or VNode
  42. var iconString = IconMap[status];
  43. var iconNode = icon || h(Icon, {
  44. attrs: { type: iconString, theme: 'filled' }
  45. });
  46. return h(
  47. 'div',
  48. { 'class': prefixCls + '-icon' },
  49. [iconNode]
  50. );
  51. };
  52. var renderExtra = function renderExtra(h, prefixCls, extra) {
  53. return extra && h(
  54. 'div',
  55. { 'class': prefixCls + '-extra' },
  56. [extra]
  57. );
  58. };
  59. var Result = {
  60. name: 'AResult',
  61. props: ResultProps,
  62. inject: {
  63. configProvider: { 'default': function _default() {
  64. return ConfigConsumerProps;
  65. } }
  66. },
  67. render: function render(h) {
  68. var customizePrefixCls = this.prefixCls,
  69. status = this.status;
  70. var getPrefixCls = this.configProvider.getPrefixCls;
  71. var prefixCls = getPrefixCls('result', customizePrefixCls);
  72. var title = getComponentFromProp(this, 'title');
  73. var subTitle = getComponentFromProp(this, 'subTitle');
  74. var icon = getComponentFromProp(this, 'icon');
  75. var extra = getComponentFromProp(this, 'extra');
  76. return h(
  77. 'div',
  78. { 'class': prefixCls + ' ' + prefixCls + '-' + status },
  79. [renderIcon(h, prefixCls, { status: status, icon: icon }), h(
  80. 'div',
  81. { 'class': prefixCls + '-title' },
  82. [title]
  83. ), subTitle && h(
  84. 'div',
  85. { 'class': prefixCls + '-subtitle' },
  86. [subTitle]
  87. ), this.$slots['default'] && h(
  88. 'div',
  89. { 'class': prefixCls + '-content' },
  90. [this.$slots['default']]
  91. ), renderExtra(h, prefixCls, extra)]
  92. );
  93. }
  94. };
  95. /* add resource */
  96. Result.PRESENTED_IMAGE_403 = ExceptionMap[403];
  97. Result.PRESENTED_IMAGE_404 = ExceptionMap[404];
  98. Result.PRESENTED_IMAGE_500 = ExceptionMap[500];
  99. /* istanbul ignore next */
  100. Result.install = function (Vue) {
  101. Vue.use(Base);
  102. Vue.component(Result.name, Result);
  103. };
  104. export default Result;