zoukankan      html  css  js  c++  java
  • 上传图片

    uploadFile(index){//选择图片
                    this.biuldPlanId = this.arr[index].id
                     let _this = this
                    // #ifdef H5
                    uni.chooseImage({
                        // count:  允许上传的照片数量
                        count: 1,
                        // sizeType:  original 原图,compressed 压缩图,默认二者都有
                        sizeType: "compressed",
                        success(res) {
                            // _this.iconFile = res.tempFiles[0]
                            _this.iconFile = res.tempFiles[0]
                            _this.uploadImg()
                        },
                        fail(res) {
                            console.log('失败', res);
                        }
                    });
                    // #endif
    
                    // #ifdef MP-WEIXIN
                    uni.getSetting({
                        success(res) {
                            if (res.authSetting['scope.camera']) {
                                uni.chooseImage({
                                    // count:  允许上传的照片数量
                                    count: 1,
                                    // sizeType:  original 原图,compressed 压缩图,默认二者都有
                                    sizeType: "compressed",
                                    success(res) {
                                        _this.iconFile = res.tempFilePaths[0]
                                        _this.uploadImg()
                                    },
                                    fail(res) {
                                        console.log('失败', res);
                                    }
                                });
                            } else {
                                _this.getLimit('scope.camera')
                            }
                        }
                    })
                    // #endif
                },
                uploadImg(){//上传图片
                    let _this = this
                    // #ifdef H5
                    uni.uploadFile({
                        url: _this.uploadUrl,
                        header: {
                            "Authorization": uni.getStorageSync('access_token'),
                        },
                        name: 'IconFiles',
                        file: _this.iconFile,
                        success(res) {
                            let obj = JSON.parse(res.data)
                            _this.confirmImg(obj.message);
                        },
                        fail(res) {
                            console.log('失败', res)
                        }
                    })
                    // #endif
                    // #ifdef MP-WEIXIN
                    uni.uploadFile({
                        url: _this.uploadUrl,
                        header: {
                            "Authorization": uni.getStorageSync('access_token'),
                        },
                        filePath: _this.iconFile,
                        name: 'IconFiles',
                        // files: aa,
                        success(res) {
                            let obj = JSON.parse(res.data)
                            // 得到 图片路径
                            _this.confirmImg(obj.message);
                        },
                        fail(res) {
                            console.log('失败', res)
                        }
                    })
                    // #endif
                },
  • 相关阅读:
    树的重心备忘
    Hdu 2196
    HDU 1520
    TOJ1068 商务旅行
    携程HDU第一场1001
    USACO 4.3.2 The Primes
    Html常用标签的应用
    Html
    开班心得
    for循环练习及字符串处理
  • 原文地址:https://www.cnblogs.com/peipeiyu/p/14715013.html
Copyright © 2011-2022 走看看