更新记录

1.0.0(2024-05-10)

初始化组件


平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.1.0 app-vue × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × ×

tf-img-upload

  1. 组件作用
    • 图片上传组件(基于uview上传组件二次封装)
  2. 组件引用例子
<template>
    <view class="content">
        <ImgUpload
            name="files"
            :action="action" 
            :header="header" 
            :form-data="formData"
            :file-list="fileList"
            :show-progress="true"
            :notUpload="isDisabled"
            @on-success="uploadImgSuccess"
            @on-remove="removeImg"
        />
    </view>
</template>

<script>
    import ImgUpload from '../../uni_modules/tf-img-upload/components/tf-img-upload/tf-img-upload.vue'
    export default {
        components: {
            ImgUpload
        },
        data() {
            return {
                formData: { //具体参数根据情况而定
                    bizId: null,
                    bizType: 'SETTLEMENT_BILL_FILES',
                    fileAcl: 'PUBLIC_READ_WRITE'
                },
                action: 'http://192.168.0.xxx:xxxx/xxx/xxx',//上传文件接口地址
                header: { //具体参数根据情况而定
                    Authorization: 'xxx',//登录令牌
                    token: "xxx",//token
                },
                fileList:[],
                isDisabled:false
            }
        },
        methods:{
            /**
             * 上传成功事件
             */
            uploadImgSuccess(data, index, lists, name) {
                if (data.code === 0) {
                    this.fileList[index] = data.data[0]
                    uni.showToast({
                        title: '图片上传成功',
                        icon: 'none'
                    })
                    console.log('上传图片',this.fileList)
                } else {
                    uni.showToast({
                        title: '图片上传失败',
                        icon: 'none'
                    })
                }
            },
            /**
             * 删除图片事件
             */
            removeImg(index) {
                this.fileList.splice(index,1)
                console.log('移除图片',this.fileList)
            }
        }
    }
</script>

<style scoped>
</style>
  1. 组件属性说明
属性名 类型 默认值 说明
showUploadList Boolean true 是否显示组件自带的图片预览功能
action String '' 文件上传后端地址
maxCount String 9 最大上传数量
showProgress Boolean true 是否显示进度条
disabled Boolean false 是否启用
imageMode String 'aspectFill' 预览上传的图片时的裁剪模式,和image组件mode属性一致
header Object {} 请求头
formData Object {} 额外携带的参数
name String 'file' 上传文件名
sizeType Array ['original', 'compressed'] 所选的图片的尺寸, 可选值为original compressed
sourceType Array ['album', 'camera'] 选择图片的来源,album-从相册选图,camera-使用相机,默认二者都有
previewFullImage Boolean true 是否在点击预览图后展示全屏图片预览
multiple Boolean true 是否开启图片多选,部分安卓机型不支持
deletable Boolean true 是否展示删除按钮
maxSize String/Number Number.MAX_VALUE 文件大小限制,单位为byte
fileList Array [] 显示已上传的文件列表
uploadText String '添加照片' 上传区域的提示文字
autoUpload Boolean true 是否自动上传
showTips Boolean true 是否显示toast消息提示
customBtn Boolean false 是否通过slot自定义传入选择图标的按钮
width String/Number 200 内部预览图片区域和选择图片按钮的区域宽度
height String/Number 200 内部预览图片区域和选择图片按钮的区域高度
delBgColor String '#fa3534' 右上角关闭按钮的背景颜色
delColor String '#ffffff' 右上角关闭按钮的叉号图标的颜色
delIcon String 'close' 右上角删除图标名称,只能为uView内置图标
toJson Boolean true 如果上传后的返回值为json字符串,是否自动转json
beforeUpload Function null 上传前的钩子,每个文件上传前都会执行
beforeRemove Function null 移除文件前的钩子
limitType Array ['png', 'jpg', 'jpeg', 'webp', 'gif', 'image'] 允许上传的图片后缀
index String/Number '' 在各个回调事件中的最后一个参数返回,用于区别是哪一个组件的事件
notUpload Boolean false 不需要继续上传
  1. 组件方法说明(具体参照uview官网上传组件事件)
事件名 说明 回调参数
on-success 图片上传成功时触发 (data, index, lists, name),data为服务器返回的数据,name为通过props传递的index参数
on-remove 移除图片时触发 (index, lists, name),name为通过props传递的index参数

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问