Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
zan-upload
Advanced tools
这是一个文件上传组件
获取 token 接口由原来的 /dock/token.json 替换成以下几种获取 token 的方式:
具体采用哪个接口可以根据各业务的需求,更多信息可以参考 http://doc.qima-inc.com/pages/viewpage.action?pageId=15168143
后端需要自己封装token接口
:::demo 基础用法
import Upload from 'zan-upload';
class Simple extends React.Component {
uploadSuccess(data) {
console.log(data); // eslint-disable-line
}
uploadError(data) {
console.log(data);
}
renderTrigger() {
return <span></span>;
}
render() {
return <Upload
maxSize={8 * 1000 * 1000}
tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。"
onSuccess={this.uploadSuccess} onError={this.uploadError} />;
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
:::demo 仅上传本地图片
import Upload from 'zan-upload';
class Simple extends React.Component {
uploadSuccess(data) {
console.log(data); // eslint-disable-line
}
renderTrigger() {
return <span></span>;
}
render() {
return <Upload
tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。"
trigger={() => <span>xxx</span>}
onSuccess={this.uploadSuccess} localOnly />;
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
:::demo 素材银行
import Upload from 'zan-upload';
class Simple extends React.Component {
state = {
selectedItems: []
};
uploadSuccess = (data) => {
this.setState({
selectedItems: data
});
}
renderTrigger() {
return <span></span>;
}
render() {
const { selectedItems } = this.state;
return (
<div>
{selectedItems.map((item, index) => (
<img
key={index}
src={item.attachment_full_url}
width="80"
height="80"
style={{
display: 'inline-block',
marginRight: 10
}}
/>
))}
<Upload
tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。"
materials
triggerInline
imgcdn="https://img.yzcdn.cn"
mediaListUrl="mock/upload-mediaList.json"
categoryListUrl="mock/upload-categoryList.json"
onSuccess={this.uploadSuccess} />
</div>
);
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
:::demo 上传音频
import Upload from 'zan-upload';
class Simple extends React.Component {
uploadSuccess(data) {
console.log(data); // eslint-disable-line
}
renderTrigger() {
return <span></span>;
}
render() {
return <Upload
tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。"
materials
type="voice"
tokenUrl="https://materials.youzan.com/shop/pubAudioUploadToken.json"
imgcdn="https://img.yzcdn.cn"
mediaListUrl="mock/upload-mediaList.json"
onSuccess={this.uploadSuccess} />;
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
:::demo 不需要额外传参数,通过tokenUrl修改token
import Upload from 'zan-upload';
class Simple extends React.Component {
uploadSuccess(data) {
console.log(data); // eslint-disable-line
}
renderTrigger() {
return <span></span>;
}
render() {
return <Upload
maxAmount={5}
tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。"
materials
imgcdn="https://img.yzcdn.cn"
mediaListUrl="mock/upload-mediaList.json"
onSuccess={this.uploadSuccess}
tokenUrl="https://materials.youzan.com/shop/pubImgUploadToken.json" />;
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
:::demo 额外传递业务参数,通过onGetToken回调函数修改token
import Upload from 'zan-upload';
class Simple extends React.Component {
uploadSuccess(data) {
console.log(data); // eslint-disable-line
}
renderTrigger() {
return <span></span>;
}
getTokenHandler() {
return new Promise(resolve => {
setTimeout(() => {
resolve('xxxx');
}, 100);
});
}
render() {
return <Upload
maxAmount={1}
tips="建议尺寸:640 x 640 像素;您可以拖拽图片调整图片顺序。"
materials
imgcdn="https://img.yzcdn.cn"
mediaListUrl="mock/upload-mediaList.json"
onSuccess={this.uploadSuccess}
onGetToken={this.getTokenHandler} />;
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
:::demo 裁剪功能上传Logo
import Upload from 'zan-upload';
class Simple extends React.Component {
uploadSuccess(data) {
console.log(data); // eslint-disable-line
}
uploadError(data) {
console.log(data);
}
render() {
return <Upload
clipping
clippingUrl="https://img.yzcdn.cn/upload_files/2016/09/28/FskX-jOAV47z3QSPEJcwmgic5j8t.jpg"
tips="建议尺寸:640 x 640 像素。"
onSuccess={this.uploadSuccess}
onError={this.uploadError}
tokenUrl="https://materials.youzan.com/shop/pubImgUploadToken.json" />
}
}
ReactDOM.render(
<Simple />
, mountNode
);
:::
参数 | 说明 | 类型 | 默认值 | 是否必填 |
---|---|---|---|---|
type | 上传类型,默认为image,音频上传为voice | string | 'image' | 否 |
kdtId | 店铺id | number | 0 | 否 |
prefix | 前缀命名空间 | string | 'rc' | 否 |
className | 扩展类名 | string | '' | 否 |
inline | 是否行内属性 | boolean | false | 否 |
maxSize | 图片大小限制,单位为b | number | 1024 * 1024 | 否 |
maxAmount | 图片数量限制,0为不限制,1为只支持单文件 | number | 0 | 否 |
silent | 是否开启静默模式,不会提示成功/失败 | boolean | false | 否 |
tips | 提示文案 | string | '' | 否 |
localOnly | 是否只支持本地图片 | boolean | false | 否 |
materials | 是否支持素材银行 | boolean | false | 否 |
imgcdn | 自定义素材银行图片cdn域名,默认为_global.url.imgqn_ | string | '' | 否 |
categoryId | 固定categoryId,不显示分组列表 | any | null | 否 |
onSuccess | 上传成功回调,返回的是一个数组 | function | noop | 否 |
onError | 上传失败回调 | function | noop | 否 |
onProgress | 上传进度 | function | noop | 否 |
onGetToken | 自定义获取token回调,需要返回一个promise,如 resolve(token) | function | 内置getToken | 否 |
filterFiles | 过滤文件,支持同步和promise的方式 | function | noop | 否 |
accept | 支持文件类型 | string | 'image/gif, image/jpeg, image/png' | 否 |
scope | 图片空间名 | string | 'kdt_img' | 否 |
auto | 是否自动弹出 | boolean | false | 否 |
timeout | 上传超时毫秒数 | number | 60 * 1000 | 否 |
mediaListUrl | 自定义素材银行列表url [GET] | string | '//materials.youzan.com/media/mediaList.json' | 否 |
categoryListUrl | 自定义素材银行分组列表url [GET] | string | '//materials.youzan.com/category/categoryList.json' | 否 |
fetchUrl | 自定义提取网络图片url [POST] | string | '' | 否 |
onFetchUrl | 自定义提取图片的处理函数,需要返回一个promise | func | undefined | 否 |
tokenUrl | 自定义上传图片token的url [POST] | string | '' | 否 |
uploadUrl | 自定义上传图片url [POST] | string | '//upload.qbox.me' | 否 |
triggerClassName | 重写trigger样式 | string | 'rc-upload-trigger' | 否 |
clipping | 是否支持裁剪功能 | boolean | false | 否 |
clippingUrl | 裁剪功能默认展示预览图片 | string | '' | 否 |
clippingTitle | 裁剪Dialog标题 | string | '' | 否 |
showIconTab | 是否展示图标Tab页(在materials为true 时) | boolean | false | 否 |
iconListUrl | 自定义提取icon的url [GET] | string | '//materials.youzan.com/icon/list.json' | 否 |
FAQs
这是一个React Upload 组件
The npm package zan-upload receives a total of 1 weekly downloads. As such, zan-upload popularity was classified as not popular.
We found that zan-upload demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.