更新记录

2.0(2023-09-17)

增加组件使用注意事项 优化使用体验

1.0.1(2023-06-18)

更新了使用说明

1.0.0(2023-06-18)

组件初始化

查看更多

平台兼容性

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

cc-imgPreDelUpload

注意组件实现代码

<!-- 注意此处需要设置与服务端保持统一 -->   
// name:服务端文件接受key  filePath: 需与服务端文件接收字段保持一致(如服务端此处设置为imageUrl则为imageUrl字段)
                        let tmpdict = {
                            'name': 'image',
                            'filePath': res.tempFilePaths[j]
                        };                  

使用方法

<!-- count: 最大上传数量  imageList: 图片上传选择数组-->
<cc-imgPreDelUpload :count="6" :imageList="imgList"></cc-imgPreDelUpload>

<!-- 上传请求事件 -->
goUploadClick() {

                if (this.imgList.length < 1) {

                    uni.showModal({
                        title: '温馨提示',
                        content: '请上传图片'
                    })
                    return;
                }
                console.log('图片上传数组 = ' + JSON.stringify(this.imgList));

                // 服务器地址上传地址 仅为示例,非真实的接口地址
                let baseUrl = "http://gzcc.com/cc//appSc/up"

                uni.showLoading({
                    title: '上传中'
                })
                const uploadTask = uni.uploadFile({
                    url: baseUrl, //仅为示例,非真实的接口地址
                    files: this.imgList, //请求图片数组
                    formData: {}, //请求参数
                    success: (uploadFileRes) => {

                        uni.hideLoading();
                        console.log('上传成功 = ' + uploadFileRes.data);
                    }
                });
                uploadTask.Update((res) => {

                    if (typeof(res.progress) != String) {
                        res.progress = '0';
                    }
                    // 此处为了模拟上传进度
                    uni.showLoading({
                        title: '上传进度: ' + res.progress + '%'
                    })
                    console.log('上传进度' + res.progress);
                    console.log('已经上传的数据长度' + res.totalBytesSent);
                    console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);

                });
            }
        }   

HTML代码实现部分


<template>
    <view class="content">

        <!-- count: 最大上传数量  imageList: 图片上传选择数组-->
        <cc-imgPreDelUpload :count="6" :imageList="imgList"></cc-imgPreDelUpload>

        <button style="width: 120px;background-color: antiquewhite; margin-top: 60px;" @click="goUploadClick"> 上传
        </button>

    </view>
</template>

<script>
    export default {

        data() {
            return {
                imgList: []
            }
        },

        methods: {

            goUploadClick() {

                if (this.imgList.length < 1) {

                    uni.showModal({
                        title: '温馨提示',
                        content: '请上传图片'
                    })
                    return;
                }
                console.log('图片上传数组 = ' + JSON.stringify(this.imgList));

                // 服务器地址上传地址 仅为示例,非真实的接口地址
                let baseUrl = "http://gzcc.com/cc//appSc/up"

                uni.showLoading({
                    title: '上传中'
                })
                const uploadTask = uni.uploadFile({
                    url: baseUrl, //仅为示例,非真实的接口地址
                    files: this.imgList, //请求图片数组
                    formData: {}, //请求参数
                    success: (uploadFileRes) => {

                        uni.hideLoading();
                        console.log('上传成功 = ' + uploadFileRes.data);
                    }
                });
                uploadTask.Update((res) => {

                    if (typeof(res.progress) != String) {
                        res.progress = '0';
                    }
                    // 此处为了模拟上传进度
                    uni.showLoading({
                        title: '上传进度: ' + res.progress + '%'
                    })
                    console.log('上传进度' + res.progress);
                    console.log('已经上传的数据长度' + res.totalBytesSent);
                    console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);

                });
            }
        }
    }
</script>

<style>
    .content {
        display: flex;
        flex-direction: column;

    }
</style>

隐私、权限声明

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

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

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

许可协议

MIT协议

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