From 3223d43ffb430cc265319f5ace5881db8f84e339 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Sun, 18 Oct 2020 00:36:04 +0800 Subject: [PATCH] refactor: result to ts --- components/result/{index.jsx => index.tsx} | 21 +-- .../result/{noFound.jsx => noFound.tsx} | 104 +++++++-------- .../{serverError.jsx => serverError.tsx} | 124 +++++++++--------- .../result/style/{index.js => index.ts} | 0 .../{unauthorized.jsx => unauthorized.tsx} | 110 ++++++++-------- 5 files changed, 182 insertions(+), 177 deletions(-) rename components/result/{index.jsx => index.tsx} (84%) rename components/result/{noFound.jsx => noFound.tsx} (89%) rename components/result/{serverError.jsx => serverError.tsx} (89%) rename components/result/style/{index.js => index.ts} (100%) rename components/result/{unauthorized.jsx => unauthorized.tsx} (87%) diff --git a/components/result/index.jsx b/components/result/index.tsx similarity index 84% rename from components/result/index.jsx rename to components/result/index.tsx index a0e5c91df..0c48df53b 100644 --- a/components/result/index.jsx +++ b/components/result/index.tsx @@ -1,5 +1,6 @@ -import { inject } from 'vue'; +import { App, defineComponent, inject, VNodeTypes } from 'vue'; import PropTypes from '../_util/vue-types'; +import { tuple } from '../_util/type'; import { getComponent } from '../_util/props-util'; import { defaultConfigProvider } from '../config-provider'; import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled'; @@ -29,13 +30,15 @@ const ExceptionStatus = Object.keys(ExceptionMap); export const ResultProps = { prefixCls: PropTypes.string, icon: PropTypes.any, - status: PropTypes.oneOf(['success', 'error', 'info', 'warning', '404', '403', '500']).def('info'), + status: PropTypes.oneOf(tuple('success', 'error', 'info', 'warning', '404', '403', '500')).def( + 'info', + ), title: PropTypes.any, subTitle: PropTypes.any, extra: PropTypes.any, }; -const renderIcon = (prefixCls, { status, icon }) => { +const renderIcon = (prefixCls: string, { status, icon }) => { if (ExceptionStatus.includes(`${status}`)) { const SVGComponent = ExceptionMap[status]; return ( @@ -49,9 +52,10 @@ const renderIcon = (prefixCls, { status, icon }) => { return
{iconNode}
; }; -const renderExtra = (prefixCls, extra) => extra &&
{extra}
; +const renderExtra = (prefixCls: string, extra: VNodeTypes) => + extra &&
{extra}
; -const Result = { +const Result = defineComponent({ name: 'AResult', props: ResultProps, setup() { @@ -59,7 +63,7 @@ const Result = { configProvider: inject('configProvider', defaultConfigProvider), }; }, - render(h) { + render() { const { prefixCls: customizePrefixCls, status } = this; const getPrefixCls = this.configProvider.getPrefixCls; const prefixCls = getPrefixCls('result', customizePrefixCls); @@ -79,7 +83,7 @@ const Result = { ); }, -}; +}); /* add resource */ Result.PRESENTED_IMAGE_403 = ExceptionMap[403]; @@ -87,8 +91,9 @@ Result.PRESENTED_IMAGE_404 = ExceptionMap[404]; Result.PRESENTED_IMAGE_500 = ExceptionMap[500]; /* istanbul ignore next */ -Result.install = function(app) { +Result.install = function(app: App) { app.component(Result.name, Result); return app; }; + export default Result; diff --git a/components/result/noFound.jsx b/components/result/noFound.tsx similarity index 89% rename from components/result/noFound.jsx rename to components/result/noFound.tsx index 7c8e15967..dddcfe108 100644 --- a/components/result/noFound.jsx +++ b/components/result/noFound.tsx @@ -4,7 +4,7 @@ const NoFound = () => { - + { { { { { { /> { { diff --git a/components/result/serverError.jsx b/components/result/serverError.tsx similarity index 89% rename from components/result/serverError.jsx rename to components/result/serverError.tsx index 505e6c2b3..986da2b41 100644 --- a/components/result/serverError.jsx +++ b/components/result/serverError.tsx @@ -5,7 +5,7 @@ const ServerError = () => { - + { { /> { { { { { { { { return ( - + { { { { { /> { { { { {