npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-image-crop-upload

v1.2.6

Published

A beautiful react component for imgage crop and upload. (react头像剪裁上传组件).

Downloads

12

Readme

react-image-crop-upload

A beautiful react component for imgage crop and upload. (react图片剪裁上传组件).

Notice: This component is designed for pc, not recommended for use on the mobile side.(该组件适用于pc端,不推荐手机端使用)

借鉴

vue-image-crop-upload

更新日志

@1.2.3

  • 改为箭头函数,函数调用不需要再bind(this)

@1.2.1

  • react-image-crop调用upload方法增加file参数

@1.2.0

  • 修复package.json main指向不正确,导致引入错误

@1.1.0

  • 使用ajax上传图片

@1.0.0

  • 可以读取本地图片并进行剪辑,上传方法由外部提供

示例

点我.

截图

WX20190228-103838@2x.png

配置环境

react

安装

npm

$ npm install react-image-crop-upload

使用

Props

| 名称 | 类型 | 默认 | 说明 | | ----------------| ---------------- | ---------------| ------------------------------------------| | url | String | '' | 上传接口地址,如果为空,图片不会上传 | | method | String | 'POST' | 上传方法 | | field | String | 'upload' | 向服务器上传的文件名 | | value | Boolean | twoWay | 是否显示控件,双向绑定 | | params | Object | null | 上传附带其他数据,格式"{k:v}" | | headers | Object | null | 上传header设置,格式"{k:v}" | | width | Number | 200 | 最终得到的图片宽度 | | height | Number | 200 | 最终得到的图片高度 | | imgFormat | string | 'png' | jpg/png, 最终得到的图片格式 | | imgBgc | string | '#fff' | 导出图片背景色,当imgFormat属性为jpg时生效 | | noCircle | Boolean | false | 关闭 圆形图像预览 | | noSquare | Boolean | false | 关闭 方形图像预览 | | noRotate | Boolean | true | 关闭 旋转图像功能 | | withCredentials | Boolean | false | 支持跨域 | | ki | Number | 0 | 原名key,类似于id,触发事件会带上(如果一个页面多个图片上传控件,可以做区分 |

Methods

| 名称 | 说明 | | ----------------| ------------------------------------------| | handleCropUploadSuccess | 上传成功, 参数( jsonData, field, ki ) | | handleCropUploadFail | 上传失败, 参数( status, field, ki ) |

使用示例

import React, { Component } from "react";
import logo from "./logo.svg";
import "./App.scss";
import "react-image-crop-upload/index.css";
import ReactImageCropUpload from "react-image-crop-upload";

class App extends Component {
  state = {
    visible: false
  };

  handleClick() {
    this.setState({ visible: true });
  }

  off() {
    this.setState({ visible: false });
  }

  handleCropUploadSuccess(resData, field, ki) {
    console.log('resData, field, ki===>>>>', resData, field, ki);
    this.off()
  }

  handleCropUploadFail(sts, field, ki) {
    console.log('sts, field, ki===>>>>', sts, field, ki);
  }

  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <button className="set-upload-btn" onClick={this.handleClick.bind(this)}>设置上传</button>
          {this.state.visible && (
            <ReactImageCropUpload
              url="blog.masongzhi.cn/api/v1/public/testUpload"
              withCredentials={true}
              off={this.off.bind(this)}
              handleCropUploadSuccess={this.handleCropUploadSuccess.bind(this)}
              handleCropUploadFail={this.handleCropUploadFail.bind(this)}
            />
          )}
        </header>
      </div>
    );
  }
}

export default App;