upload native

This commit is contained in:
wkj 2023-12-26 12:55:28 +08:00
parent 1eb423e0c0
commit 374b22a9e1
9 changed files with 69 additions and 17 deletions

View File

@ -48,7 +48,6 @@ export default function Render(props) {
type: type,
placement: placement,
duration: data.duration || 4000,
animationType: 'zoom-in',
});
}
}, [data]);

View File

@ -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 (<Component {...rest} {...params} width="xs" ref={forwardedRef}/>);
return <Component {...props} {...params} width="xs" />;
};
return React.forwardRef((props, ref) => <ComponentWithRouterProp {...props} forwardedRef={ref}/>);
return ComponentWithRouterProp;
};
export default withRouter;

3
es/utils/upload.native.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export declare class Upload {
uploadFile(file: File | string, name: string, uploadUrl: string, formData: Record<string, any>, autoInform?: boolean): Promise<any>;
}

15
es/utils/upload.native.js Normal file
View File

@ -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;
}
}

3
lib/utils/upload.native.d.ts vendored Normal file
View File

@ -0,0 +1,3 @@
export declare class Upload {
uploadFile(file: File | string, name: string, uploadUrl: string, formData: Record<string, any>, autoInform?: boolean): Promise<any>;
}

View File

@ -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;

View File

@ -54,7 +54,6 @@ export default function Render(props: { data: { data: MessageProps } }) {
type: type,
placement: placement,
duration: data.duration || 4000,
animationType: 'zoom-in',
});
}
}, [data]);

View File

@ -81,10 +81,7 @@ const withRouter = (Component: React.ComponentType<any>, { path, properties }: {
const route = props.route;
const { params: routeParams } = route || {};
const { forwardedRef, ...rest } = props;
let params = {};
/**
* path来判定是否为PagekeepAlive后Page
* by Xc 20231102
@ -93,16 +90,9 @@ const withRouter = (Component: React.ComponentType<any>, { path, properties }: {
params = Object.assign(params, getParams(routeParams, properties));
}
return (
<Component
{...rest}
{...params}
width="xs"
ref={forwardedRef}
/>
);
return <Component {...props} {...params} width="xs" />;
};
return React.forwardRef((props, ref) => <ComponentWithRouterProp {...props} forwardedRef={ref} />);
return ComponentWithRouterProp;
};
export default withRouter;

View File

@ -0,0 +1,25 @@
export class Upload {
async uploadFile(
file: File | string,
name: string,
uploadUrl: string,
formData: Record<string, any>,
autoInform?: boolean
): Promise<any> {
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;
}
}