Code Monkey home page Code Monkey logo

vux-uploader-component's Introduction

vux-uploader-component

a mobile vue component implementation for weui uploader

Install

npm install -S vux-uploader-component

Mobile demo

https://ejayyoung.github.io/vux-uploader-component/index.html

scan the qrcode and have a test in your device

Usage

Basic

<template>
  <uploader
    v-model="fileList"
    :url="remoteUrl"
    @on-change="onChange"
    @on-cancel="onCancel"
    @on-success="onSuccess"
    @on-error="onError"
    @on-delete="onDelete"
  ></uploader>
</template>
<script>
  import Uploader from "vux-uploader-component";

  export default {
    components: {
      Uploader
    },
    data() {
      return {
        fileList: []
      };
    }
  };
</script>

Custom name

<uploader
  v-model="fileList"
  :url="remoteUrl"
  name="upload"
></uploader>

Extra Params

<uploader
  v-model="fileList"
  :url="remoteUrl"
  :params="{
    token: '13579',
    linkid: '2323',
    modelname: 'modelname'
  }"
></uploader>

Manual Upload

<template>
  <uploader v-model="fileList" :autoUpload="false"></uploader>
</template>
<script>
  import Uploader from "vux-uploader-component";

  export default {
    components: {
      Uploader
    },
    data() {
      return {
        fileList: []
      };
    },
    methods: {
      submit() {
        const formData = new FormData();
        formData.append("file", fileList[0].blob);
        fetch
          .post(url, formData)
          .then(() => {})
          .catch(() => {});
      }
    }
  };
</script>

Props

property type default description
title String '图片上传' 组件标题
files Array [] 初始化数据源,通过on-fileList-change事件绑定 v-model
limit Number | String 5 限制上传图片个数
limitPrompt Function (limit) => `不能上传超过${limit}张图片` 限制上传alert的提示语
capture Number | String false 是否只选择调用相机
enableCompress Boolean true 是否压缩
maxWidth String | Number 1024 图片压缩最大宽度
quality String | Number 0.92 图片压缩率
url String - 上传服务器 url
headers Object {} 上传文件时自定义请求头
withCredentials Boolean - 设置为true的话,支持标准CORS设置cookie值
params Object - 上传文件时自定义参数
name String 'file' 上传文件时 FormData 的 Key,默认为 file
autoUpload Boolean true 是否自动开启上传
multiple String | Boolean "" 是否支持多选, false为不支持
readonly Boolean false 只读模式(隐藏添加和删除按钮)

Events

event param description
on-change (FileItem, FileList) 选完照片,删除照片时,FileList 变化时触发,返回当前改变的 FileItem,以及当前的 FileList
on-cancel () 选择照片后取消的回调,用于错误提示
on-success (result, fileItem) 上传请求成功后的回调,返回远程请求的返回结果,及当前添加文件的 FileItem
on-error (xhr) 上传请求失败后的回调,返回xhr
on-delete (cb) 删除照片时的回调,返回隐藏 Previewer,删除图片的回调,没监听onDelete事件的时候,直接执行删除回调

v-model

通过 v-model 可以在组件外部获取更新的组件的FileList

返回的 FileItem 格式

目前将 File 对象的属性复制组成 FileItem, FileItem 组成 FileList,便于用户获取 File 对象的信息

{
  "blob": Blob,
  "fetchStatus": "success",
  "lastModified": 1552382376925,
  "lastModifiedDate": "Tue Mar 12 2019 17:19:36 GMT+0800 (**标准时间)",
  "name": "YourImage.jpeg",
  "progress": 100,
  "size": 68905,
  "type": "image/jpeg",
  "url": "blob:http://0.0.0.0:8080/e3a87d67-a1dc-4909-b5fa-7bb3a7baad11"
}

Todo

  • 调用手机相机
  • 获取图片并渲染到浏览器
  • 解决图片 EXIF 旋转
  • 预览图片
  • 删除图片
  • 支持上传图片配置
  • 显示上传进度
  • 支持多选
  • 支持 v-model 获取 FileList
  • 接入Photoswipe,增强预览功能
  • xhr支持自定义头部和withCredentials
  • 自定义限制alert的提示语内容
  • 改为vue-cli 3.0 打包

Development

# install dependencies
npm install

# serve with hot reload at http://0.0.0.0:8080/
npm run dev

# build for production with minification
npm run build:prod

# publish package
npm version patch
npm publish

For detailed explanation on how things work, consult the docs for vue-loader.

Relevant

License

The MIT License

vux-uploader-component's People

Contributors

ejayyoung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vux-uploader-component's Issues

Wrong Content-Type and empty blob.type

Greetings!

Last version (v1.0.22) replaced canvas.toBlob second parameter to file.type

Before that fix posted data was something like this (see wrong Content-Type):
------WebKitFormBoundaryBcBUpvEfzANNrA8m
Content-Disposition: form-data; name="image"; filename="twitter.svg"
Content-Type: image/jpeg

But now I see application/octet-stream content type instead of image/svg+xml (or any other matching type of image)
------WebKitFormBoundaryBcBUpvEfzANNrA8m
Content-Disposition: form-data; name="image"; filename="twitter.svg"
Content-Type: application/octet-stream

Blob receives empty type parameter.

Can you fix that?

How to show uploaded image

I have successfully uploaded the image. Now in my edit form, I want to display the uploaded image. How can I do so?

canvas图片处理bug

直接访问demo地址
问题:
1.图片被纵向拉伸,测试的图片分辨率89*93
2.png图片透明处变黑
image

PNG Images turn alpha channel to black background

Hi, i really like this component but when i try to upload png images with a transparent background they change the alpha channel to black, is there a way to keep the transparency? Im using "vux-uploader-component": "^1.0.21"

在图片预览界面滑动后的删除bug

现象: 上传两张图片, 点第一张图片的预览, 滑动到第二张, 点删除. 删掉的是第一张图片.
期待结果: 删掉的是当前预览页的图片, 也就是上面的第二张, 而不是第一张图片.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.