index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode } from "vue";
  3. import { defineComponent, computed } from 'vue';
  4. import PropTypes from '../_util/vue-types';
  5. import CheckCircleFilled from "@ant-design/icons-vue/es/icons/CheckCircleFilled";
  6. import CloseCircleFilled from "@ant-design/icons-vue/es/icons/CloseCircleFilled";
  7. import ExclamationCircleFilled from "@ant-design/icons-vue/es/icons/ExclamationCircleFilled";
  8. import WarningFilled from "@ant-design/icons-vue/es/icons/WarningFilled";
  9. import noFound from './noFound';
  10. import serverError from './serverError';
  11. import unauthorized from './unauthorized';
  12. import useConfigInject from '../config-provider/hooks/useConfigInject';
  13. import classNames from '../_util/classNames';
  14. import useStyle from './style';
  15. export const IconMap = {
  16. success: CheckCircleFilled,
  17. error: CloseCircleFilled,
  18. info: ExclamationCircleFilled,
  19. warning: WarningFilled
  20. };
  21. export const ExceptionMap = {
  22. '404': noFound,
  23. '500': serverError,
  24. '403': unauthorized
  25. };
  26. // ExceptionImageMap keys
  27. const ExceptionStatus = Object.keys(ExceptionMap);
  28. export const resultProps = () => ({
  29. prefixCls: String,
  30. icon: PropTypes.any,
  31. status: {
  32. type: [Number, String],
  33. default: 'info'
  34. },
  35. title: PropTypes.any,
  36. subTitle: PropTypes.any,
  37. extra: PropTypes.any
  38. });
  39. const renderIcon = (prefixCls, _ref) => {
  40. let {
  41. status,
  42. icon
  43. } = _ref;
  44. if (ExceptionStatus.includes(`${status}`)) {
  45. const SVGComponent = ExceptionMap[status];
  46. return _createVNode("div", {
  47. "class": `${prefixCls}-icon ${prefixCls}-image`
  48. }, [_createVNode(SVGComponent, null, null)]);
  49. }
  50. const IconComponent = IconMap[status];
  51. const iconNode = icon || _createVNode(IconComponent, null, null);
  52. return _createVNode("div", {
  53. "class": `${prefixCls}-icon`
  54. }, [iconNode]);
  55. };
  56. const renderExtra = (prefixCls, extra) => extra && _createVNode("div", {
  57. "class": `${prefixCls}-extra`
  58. }, [extra]);
  59. const Result = defineComponent({
  60. compatConfig: {
  61. MODE: 3
  62. },
  63. name: 'AResult',
  64. inheritAttrs: false,
  65. props: resultProps(),
  66. slots: Object,
  67. setup(props, _ref2) {
  68. let {
  69. slots,
  70. attrs
  71. } = _ref2;
  72. const {
  73. prefixCls,
  74. direction
  75. } = useConfigInject('result', props);
  76. const [wrapSSR, hashId] = useStyle(prefixCls);
  77. const className = computed(() => classNames(prefixCls.value, hashId.value, `${prefixCls.value}-${props.status}`, {
  78. [`${prefixCls.value}-rtl`]: direction.value === 'rtl'
  79. }));
  80. return () => {
  81. var _a, _b, _c, _d, _e, _f, _g, _h;
  82. const title = (_a = props.title) !== null && _a !== void 0 ? _a : (_b = slots.title) === null || _b === void 0 ? void 0 : _b.call(slots);
  83. const subTitle = (_c = props.subTitle) !== null && _c !== void 0 ? _c : (_d = slots.subTitle) === null || _d === void 0 ? void 0 : _d.call(slots);
  84. const icon = (_e = props.icon) !== null && _e !== void 0 ? _e : (_f = slots.icon) === null || _f === void 0 ? void 0 : _f.call(slots);
  85. const extra = (_g = props.extra) !== null && _g !== void 0 ? _g : (_h = slots.extra) === null || _h === void 0 ? void 0 : _h.call(slots);
  86. const pre = prefixCls.value;
  87. return wrapSSR(_createVNode("div", _objectSpread(_objectSpread({}, attrs), {}, {
  88. "class": [className.value, attrs.class]
  89. }), [renderIcon(pre, {
  90. status: props.status,
  91. icon
  92. }), _createVNode("div", {
  93. "class": `${pre}-title`
  94. }, [title]), subTitle && _createVNode("div", {
  95. "class": `${pre}-subtitle`
  96. }, [subTitle]), renderExtra(pre, extra), slots.default && _createVNode("div", {
  97. "class": `${pre}-content`
  98. }, [slots.default()])]));
  99. };
  100. }
  101. });
  102. /* add resource */
  103. Result.PRESENTED_IMAGE_403 = ExceptionMap[403];
  104. Result.PRESENTED_IMAGE_404 = ExceptionMap[404];
  105. Result.PRESENTED_IMAGE_500 = ExceptionMap[500];
  106. /* istanbul ignore next */
  107. Result.install = function (app) {
  108. app.component(Result.name, Result);
  109. return app;
  110. };
  111. export default Result;