upload 上传组件

多文件选择上传,图片显示预览

upload 文件图片压缩上传

>{}

<template>
  <div>
  <p><Upload v-model="the.file"  @onEvent="onUploadEvent">上传图片</Upload></p>
   <p><Upload :mark="the.mark" @onEvent="onUploadEvent">上传图片,水印模式imgMin 函数会导致图片变大Bug,慎用</Upload></p>
    <Upload :multiple="true"
                named="file"
                type="execl"
                @onEvent="onUploadEvent">上传文件</Upload>
  </div>
</template>

<script>
export default {
  setup (props, { emit }) {

    const $plus = window.$plus;
    const frame  = $plus.frame;
    const reactive = $plus.vue.reactive;

   const the = reactive({
     // 图片水印
     mark: { text: 'Quick', font: 'bold 10rem Arial', y: 100 },
     // 支持单张图片双向绑定 base64
     file:''
   });

    /**
     * 上传事件 
     * 
    */
    const onUploadEvent = (res) => {
      console.log('onUploadEvent:' + res.data.length, res);
      switch (res.cmd) {
        case 'delete':
          console.log('onUploadEvent.', res.cmd);
          break;
        case 'imageZoom':
          // 预览图点击放大
          frame.open('<img width="100%" src="' + res.data.src + '" />');
          break;
        case 'execl': // type 参数事件

          // 结果输出,触发上传事件
          break;
        case 'base64':
           console.log('onUpload.base64',the.file);
        // 图片转码结果输出,触发上传事件,返回本地文件内容
        // res.data=[{
        // // 没超过max,可以上传
        // isUpload: true,
        // // 文件名
        // name: file.name,
        // lastModified: file.lastModified,
        // // 尺寸大小
        // size: file.size,
        // // 文件类型
        // type: file.type,
        // // 文件数据
        // data: null,
        // // 图片转换base64
        // src: null,
        // // 文件描述
        // title: ''
        // }]
          break;
      }
    };

    return {the, onUploadEvent}
  }
}
</script>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

upload props

属性说明类型参数默认值
named组件命名Stringupload
type上传文件类型,返回监听组件事件名cmdString'base64', 'execl'base64
multiple是否开启多文件上传Booleanfalse
accept指定上传文件类型Stringtype=base64,默认为image/*null
max最大上传尺寸单位为KB,默认3MNumber3 * 1024
ratio图片压缩质量等级Number0.6
scale图片压缩缩放尺寸比例Number0.7
mark图片加水印jsonnull

upload onEvent

  • 组件事件触发
参数名说明类型
cmd命令:imageZoom,delete,base64String
named组件命名,建议字段名String
type 0.4.2组件初始传入值类型,String,ObjectString
data事件数据Array
index点击或删除序号Number

Last Updated: