/** * @file Santd result component file * @author mayihui@baidu.com */ import './style/index.less'; import * as I from './interface'; import Base from 'santd/base'; import Icon from '../icon'; import {classCreator} from '../core/util'; import {BaseElement} from '../core/util/dom'; import noFound from './NoFound'; import serverError from './ServerError'; import unauthorized from './Unauthorized'; const prefixCls = classCreator('result')(); export const IconMap = { success: 'check-circle', error: 'close-circle', info: 'exclamation-circle', warning: 'warning' }; export const ExceptionMap = { 404: noFound as BaseElement, 500: serverError as BaseElement, 403: unauthorized as BaseElement, }; class Result extends Base { initData(): I.State { return { status: 'info', exceptionMap: ExceptionMap, iconMap: IconMap }; } static components = { 's-icon': Icon, 's-nofound': noFound, 's-servererror': serverError, 's-unauthorized': unauthorized } inited(): void { this.data.set('hasIcon', !!this.sourceSlots.named.icon); this.data.set('hasExtra', !!this.sourceSlots.named.extra); // 由于named slot会留下换行,所以用是否含有children来判断是不是有noname slot; let noName = this.sourceSlots.noname || []; this.data.set('hasContent', !!noName.filter(item => !!item.children).length); } static template = /* html */ `
{{title}}
{{subTitle}}
`; }; Object.keys(ExceptionMap).forEach(key => { const privateKey = `PRESENTED_IMAGE_${key}`; (Result as any)[privateKey] = (ExceptionMap as any)[key]; }); export default Result;