2.0.6 • Published 2 years ago

w-upload v2.0.6

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

@weier/upload

  • Upload上传组件
// 安装
npm i @weier/w-upload

// 代码引入
import wUpload from 'w-upload'

注意事项

  1. 可以用v-model绑定value, 传入格式为 Array < Object > 类型
  2. 回显字段为localUrl/remoteUrl, 分别为本地路径和服务端路径
  3. value中的每一项有fileId,为文件id字段
  4. 必须在登录状态下使用,否则会报403

需要对接的后端注册相应的business字段进行业务标识,联系伊塔(后端)

基础用法

:::

<template>
<div style="margin: 12px;">普通上传</div>

<w-upload
  v-model="fileList"
  unique-name="upload1"
  envType="mock"
  ></w-upload>

</template>
<script>
export default {
  data(){
    return {
      fileList: []
    }}}
</script>

:::

其他用法

:::demo

<template>
<div style="margin: 12px;">不显示文件列表</div>
<w-upload
  v-model="fileList"
  unique-name="upload2"
  :envType="envType"
  :showFileList="false"
  :on-change="changeUpload"
  :on-success="successUpload"
  >
</w-upload>

<div style="margin: 12px;">自定义上传组件</div>
<w-upload v-model="fileList" :envType="envType" ref="customUpload">
<div class="custom-upload-area">自定义点击上传</div>
</w-upload>

<div style="margin: 12px;">普通图片上传</div>
<w-upload v-model="fileList2" uploadType="picture" accept='image/*' :envType="envType" ref="customUpload2" :limit="1">
</w-upload>

<div style="margin: 12px;">
<el-button @click="clearFiles">清除上传</el-button>
<el-button @click="uploadSelect">外部按钮触发</el-button>
<el-button @click="getAllUrls">获取所有链接</el-button>
</div>
</template>
<script>
export default {
  data(){
    return {
      fileList: [{name: '回显第一个文件', localUrl: ''}],
      fileList2: [],
      envType: 'mock'
    }
  },
  watch: {
    fileList (val, oldVal) {
      // console.log(val, oldVal)
    }
  },
  methods: {
    clearFiles(){
      this.$refs['customUpload'].clearFiles()
    },
    uploadSelect(){
      this.$refs['customUpload2'].execUpload()
    },
    getAllUrls() {
      const urlsPromise = this.$refs['customUpload2'].getAllUploadUrls()
      urlsPromise.then(res =>{
        // console.log(res)
      })
    },
    changeUpload(){
      console.log('change')
    },
    successUpload(){
      console.log('success')
    }
  },
  mounted(){
  }
}
</script>
<style>
.custom-upload-area {
  display: inline-block;
  margin-top: 20px;
  padding: 10px;
  border: 1px solid #efefef;
  cursor: pointer;
}
</style>

:::

Attributes

参数说明类型可选值默认值备注
business用于业务标识string——business——
headers用于自定义上传头object——{}自定义头部,默认可以不传
httpRequest自定义上传方法object——{}——
data用于自定义上传参数object——{}——
disabled是否禁用boolean——false
accept可接受的文件类型string————图片写死为'image/jpeg',具体可传参数,请参照唯一文件类型说明符
limit上传个数限制number——————
uploadType上传类型stringfile, picturefile——
uniqueName唯一标识string——unique多个upload出现的话,绑定的key值
isAutoFillUrl上传完成后是否自动填补urlboolean——true——
envType开发环境string'mock', 'dev', 'qa','pre','prod'dev——
showFileList是否显示文件列表boolean——true——

prop类型的钩子

用法: 1. template v-bind:beforeUpload="handleBeforeUpload" 2. jsx <Parent ...{props: {'before-upload': handleBeforeUpload}} />

属性名说明参数可选值默认值备注
beforeUpload文件上传前触发rawFile————返回false或者Promise并且reject, Promise.reject, 则不会继续上传,并且触发onError

emit风格的钩子, 参数与prop钩子一致

用法: 1. template写法:@change="handleChange" 2. jsx写法:onChange={handleChange} 原理为emit('动作', 参数列表) 父接收参数为args[]

事件名说明参数可选值默认值备注
change任何文件改变都会触发target, uploadList——————
success上传文件成功之后触发res, target, uploadList——————
progress文件上传过程中触发ev(progress对象,percentage为百分比), target, uploadList——————
error文件上传失败触发error, target, uploadList——————
exceed超过文件上传数量大小调用target, uploadList——————
remove移除文件触发index(移除文件在列表里的位置)——————

Methods

方法名说明参数
abort终止文件上传,参数为空则停止全部上传file
execUpload外部事件可以触发上传(必须要用户事件,定时器之类的非用户行为无效)——
getAllUploadUrls一次性获取已经上传完成的文件的url,返回promise,resolve参数为res——
getUrlsByIds通过外部传入ids,获取urls,返回promise,resolve参数为res——

其他备注

2.0.3

2 years ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.0-clone.0

3 years ago

2.0.6

2 years ago

2.0.0

2 years ago

1.0.2

3 years ago

1.0.1

3 years ago