From 374b22a9e174c65c486014ad9e5a2a1d0fb8f23e Mon Sep 17 00:00:00 2001 From: wkj <278599135@.com> Date: Tue, 26 Dec 2023 12:55:28 +0800 Subject: [PATCH] upload native --- es/components/message/render.native.js | 1 - es/platforms/native/router/withRouter.js | 5 ++--- es/utils/upload.native.d.ts | 3 +++ es/utils/upload.native.js | 15 +++++++++++++ lib/utils/upload.native.d.ts | 3 +++ lib/utils/upload.native.js | 19 ++++++++++++++++ src/components/message/render.native.tsx | 1 - src/platforms/native/router/withRouter.tsx | 14 ++---------- src/utils/upload.native.ts | 25 ++++++++++++++++++++++ 9 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 es/utils/upload.native.d.ts create mode 100644 es/utils/upload.native.js create mode 100644 lib/utils/upload.native.d.ts create mode 100644 lib/utils/upload.native.js create mode 100644 src/utils/upload.native.ts diff --git a/es/components/message/render.native.js b/es/components/message/render.native.js index 50157fd4..fc6479fd 100644 --- a/es/components/message/render.native.js +++ b/es/components/message/render.native.js @@ -48,7 +48,6 @@ export default function Render(props) { type: type, placement: placement, duration: data.duration || 4000, - animationType: 'zoom-in', }); } }, [data]); diff --git a/es/platforms/native/router/withRouter.js b/es/platforms/native/router/withRouter.js index fcb8af01..c0335a5e 100644 --- a/es/platforms/native/router/withRouter.js +++ b/es/platforms/native/router/withRouter.js @@ -62,7 +62,6 @@ const withRouter = (Component, { path, properties }) => { const navigation = props.navigation; const route = props.route; const { params: routeParams } = route || {}; - const { forwardedRef, ...rest } = props; let params = {}; /** * 由path来判定是否为Page。这里有个隐患,未来实现了keepAlive后,可能会影响到之前压栈的Page @@ -71,8 +70,8 @@ const withRouter = (Component, { path, properties }) => { if (path) { params = Object.assign(params, getParams(routeParams, properties)); } - return (); + return ; }; - return React.forwardRef((props, ref) => ); + return ComponentWithRouterProp; }; export default withRouter; diff --git a/es/utils/upload.native.d.ts b/es/utils/upload.native.d.ts new file mode 100644 index 00000000..95dcee0d --- /dev/null +++ b/es/utils/upload.native.d.ts @@ -0,0 +1,3 @@ +export declare class Upload { + uploadFile(file: File | string, name: string, uploadUrl: string, formData: Record, autoInform?: boolean): Promise; +} diff --git a/es/utils/upload.native.js b/es/utils/upload.native.js new file mode 100644 index 00000000..b625d828 --- /dev/null +++ b/es/utils/upload.native.js @@ -0,0 +1,15 @@ +export class Upload { + async uploadFile(file, name, uploadUrl, formData, autoInform) { + const formData2 = new FormData(); + for (const key of Object.keys(formData)) { + formData2.append(key, formData[key]); + } + formData2.append(name || 'file', file); + const options = { + body: formData2, + method: 'POST', + }; + const result = await fetch(uploadUrl, options); + return result; + } +} diff --git a/lib/utils/upload.native.d.ts b/lib/utils/upload.native.d.ts new file mode 100644 index 00000000..95dcee0d --- /dev/null +++ b/lib/utils/upload.native.d.ts @@ -0,0 +1,3 @@ +export declare class Upload { + uploadFile(file: File | string, name: string, uploadUrl: string, formData: Record, autoInform?: boolean): Promise; +} diff --git a/lib/utils/upload.native.js b/lib/utils/upload.native.js new file mode 100644 index 00000000..43ca1c42 --- /dev/null +++ b/lib/utils/upload.native.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Upload = void 0; +class Upload { + async uploadFile(file, name, uploadUrl, formData, autoInform) { + const formData2 = new FormData(); + for (const key of Object.keys(formData)) { + formData2.append(key, formData[key]); + } + formData2.append(name || 'file', file); + const options = { + body: formData2, + method: 'POST', + }; + const result = await fetch(uploadUrl, options); + return result; + } +} +exports.Upload = Upload; diff --git a/src/components/message/render.native.tsx b/src/components/message/render.native.tsx index 1704c6dc..279a9b2b 100644 --- a/src/components/message/render.native.tsx +++ b/src/components/message/render.native.tsx @@ -54,7 +54,6 @@ export default function Render(props: { data: { data: MessageProps } }) { type: type, placement: placement, duration: data.duration || 4000, - animationType: 'zoom-in', }); } }, [data]); diff --git a/src/platforms/native/router/withRouter.tsx b/src/platforms/native/router/withRouter.tsx index 14e848ab..01465fd3 100644 --- a/src/platforms/native/router/withRouter.tsx +++ b/src/platforms/native/router/withRouter.tsx @@ -81,10 +81,7 @@ const withRouter = (Component: React.ComponentType, { path, properties }: { const route = props.route; const { params: routeParams } = route || {}; - const { forwardedRef, ...rest } = props; - let params = {}; - /** * 由path来判定是否为Page。这里有个隐患,未来实现了keepAlive后,可能会影响到之前压栈的Page * 待测试。by Xc 20231102 @@ -93,16 +90,9 @@ const withRouter = (Component: React.ComponentType, { path, properties }: { params = Object.assign(params, getParams(routeParams, properties)); } - return ( - - ); + return ; }; - return React.forwardRef((props, ref) => ); + return ComponentWithRouterProp; }; export default withRouter; diff --git a/src/utils/upload.native.ts b/src/utils/upload.native.ts new file mode 100644 index 00000000..f4e21d14 --- /dev/null +++ b/src/utils/upload.native.ts @@ -0,0 +1,25 @@ + + +export class Upload { + async uploadFile( + file: File | string, + name: string, + uploadUrl: string, + formData: Record, + autoInform?: boolean + ): Promise { + const formData2 = new FormData(); + for (const key of Object.keys(formData)) { + formData2.append(key, formData[key]); + } + formData2.append(name || 'file', file as File); + + const options = { + body: formData2, + method: 'POST', + }; + + const result = await fetch(uploadUrl, options); + return result; + } +}