You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.1 KiB
100 lines
3.1 KiB
4 years ago
|
import { App, defineComponent, inject, VNodeTypes } from 'vue';
|
||
5 years ago
|
import PropTypes from '../_util/vue-types';
|
||
4 years ago
|
import { tuple } from '../_util/type';
|
||
5 years ago
|
import { getComponent } from '../_util/props-util';
|
||
4 years ago
|
import { defaultConfigProvider } from '../config-provider';
|
||
5 years ago
|
import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
|
||
|
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
|
||
|
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled';
|
||
|
import WarningFilled from '@ant-design/icons-vue/WarningFilled';
|
||
5 years ago
|
import noFound from './noFound';
|
||
|
import serverError from './serverError';
|
||
|
import unauthorized from './unauthorized';
|
||
|
|
||
|
export const IconMap = {
|
||
5 years ago
|
success: CheckCircleFilled,
|
||
|
error: CloseCircleFilled,
|
||
|
info: ExclamationCircleFilled,
|
||
|
warning: WarningFilled,
|
||
5 years ago
|
};
|
||
|
|
||
|
export const ExceptionMap = {
|
||
|
'404': noFound,
|
||
|
'500': serverError,
|
||
|
'403': unauthorized,
|
||
|
};
|
||
|
|
||
|
// ExceptionImageMap keys
|
||
|
const ExceptionStatus = Object.keys(ExceptionMap);
|
||
|
|
||
|
export const ResultProps = {
|
||
|
prefixCls: PropTypes.string,
|
||
|
icon: PropTypes.any,
|
||
4 years ago
|
status: PropTypes.oneOf(tuple('success', 'error', 'info', 'warning', '404', '403', '500')).def(
|
||
|
'info',
|
||
|
),
|
||
5 years ago
|
title: PropTypes.any,
|
||
|
subTitle: PropTypes.any,
|
||
|
extra: PropTypes.any,
|
||
|
};
|
||
|
|
||
4 years ago
|
const renderIcon = (prefixCls: string, { status, icon }) => {
|
||
5 years ago
|
if (ExceptionStatus.includes(`${status}`)) {
|
||
5 years ago
|
const SVGComponent = ExceptionMap[status];
|
||
|
return (
|
||
|
<div class={`${prefixCls}-icon ${prefixCls}-image`}>
|
||
|
<SVGComponent />
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
5 years ago
|
const IconComponent = IconMap[status];
|
||
|
const iconNode = icon || <IconComponent />;
|
||
5 years ago
|
return <div class={`${prefixCls}-icon`}>{iconNode}</div>;
|
||
|
};
|
||
|
|
||
4 years ago
|
const renderExtra = (prefixCls: string, extra: VNodeTypes) =>
|
||
|
extra && <div class={`${prefixCls}-extra`}>{extra}</div>;
|
||
5 years ago
|
|
||
4 years ago
|
const Result = defineComponent({
|
||
5 years ago
|
name: 'AResult',
|
||
|
props: ResultProps,
|
||
5 years ago
|
setup() {
|
||
|
return {
|
||
4 years ago
|
configProvider: inject('configProvider', defaultConfigProvider),
|
||
5 years ago
|
};
|
||
5 years ago
|
},
|
||
4 years ago
|
render() {
|
||
5 years ago
|
const { prefixCls: customizePrefixCls, status } = this;
|
||
5 years ago
|
const getPrefixCls = this.configProvider.getPrefixCls;
|
||
|
const prefixCls = getPrefixCls('result', customizePrefixCls);
|
||
|
|
||
5 years ago
|
const title = getComponent(this, 'title');
|
||
|
const subTitle = getComponent(this, 'subTitle');
|
||
|
const icon = getComponent(this, 'icon');
|
||
|
const extra = getComponent(this, 'extra');
|
||
5 years ago
|
|
||
|
return (
|
||
|
<div class={`${prefixCls} ${prefixCls}-${status}`}>
|
||
5 years ago
|
{renderIcon(prefixCls, { status, icon })}
|
||
5 years ago
|
<div class={`${prefixCls}-title`}>{title}</div>
|
||
|
{subTitle && <div class={`${prefixCls}-subtitle`}>{subTitle}</div>}
|
||
5 years ago
|
{this.$slots.default && <div class={`${prefixCls}-content`}>{this.$slots.default()}</div>}
|
||
5 years ago
|
{renderExtra(prefixCls, extra)}
|
||
5 years ago
|
</div>
|
||
|
);
|
||
|
},
|
||
4 years ago
|
});
|
||
5 years ago
|
|
||
|
/* add resource */
|
||
|
Result.PRESENTED_IMAGE_403 = ExceptionMap[403];
|
||
|
Result.PRESENTED_IMAGE_404 = ExceptionMap[404];
|
||
|
Result.PRESENTED_IMAGE_500 = ExceptionMap[500];
|
||
|
|
||
|
/* istanbul ignore next */
|
||
4 years ago
|
Result.install = function(app: App) {
|
||
5 years ago
|
app.component(Result.name, Result);
|
||
4 years ago
|
return app;
|
||
5 years ago
|
};
|
||
4 years ago
|
|
||
5 years ago
|
export default Result;
|