• 小程序上传图片


    wxml:

    <form class="page__bd" bindsubmit="formSubmit" bindreset="formReset">
    <view class="tupian">
    <view class='loadpic' >
    <block wx:for="{{imgArr}}" wx:key="id">
    <image src="{{item}}" mode="widthFix" data-id="{{index}}" bindtap="deleteImv"/>
    </block>
    </view>
    <view class='loadpic' bindtap="chooseImage" >
    <image src="../../image/xj.png" mode="widthFix"></image>
    </view>
    <view class="zhu">请将学生证置于取景框内拍摄,确保照片清晰、不反光</view>
    <view class='dl'>
    <image src='../../image/d1.png' mode='widthFix' class='fl '></image>
    <input placeholder='请输入您的身份证号码' name="card" placeholder-class='ziti' class='fr'></input>
    </view>
    <input type="hidden" style="display:none" name="img" value="{{img}}"> </input>
    <button class='dlu' form-type='submit'>确认提交</button>
    </view>
    </form>

    js:

    chooseImage: function () {
    var that = this;

    let token= wx.getStorageSync('token');
    let wxapp_id= 10001;
    /* wx.showToast({
    title: '正在上传...',
    icon: 'loading',
    mask: true,
    duration: 10000
    });*/
    wx.chooseImage({
    count: 8,
    sizeType: ['original', 'compressed'],
    sourceType: ['album', 'camera'],
    success: function (res) {
    if (res.tempFilePaths.count == 0) {
    return;
    }
    //上传图片
    var imgArrNow = that.data.imgArr;
    var upurl=App.api_root +'index/upload'
    imgArrNow = imgArrNow.concat(res.tempFilePaths);

    that.setData({
    imgArr: imgArrNow
    })
    for (var i = 0; i <imgArrNow.length;i++){
    wx.uploadFile({
    url: upurl,
    filePath: imgArrNow[i],
    name: 'file',
    formData: {token:token,wxapp_id:wxapp_id},
    header: {
    "content-type":'application/x-www-form-urlencoded'
    },
    success: function (res) {
    //console.log(JSON.parse(res.data).url);return false;
    var img = that.data.img;
    img = img.concat(JSON.parse(res.data).data);
    that.setData({
    img: img
    })
    },
    })
    }

    that.chooseViewShow();
    }
    })
    },

    deleteImv: function (e) {
    var imgArr = this.data.imgArr;
    var img = this.data.img;
    var itemIndex = e.currentTarget.dataset.id;
    imgArr.splice(itemIndex, 1);
    img.splice(itemIndex, 1);
    this.setData({
    imgArr: imgArr,
    img:img
    })
    //判断是否隐藏选择图片
    this.chooseViewShow();
    },
    chooseViewShow: function () {
    if (this.data.imgArr.length >= 9) {
    this.setData({
    chooseViewShow: false
    })
    } else {
    this.setData({
    chooseViewShow: true
    })
    }
    },

    如果 生命是场 寂寞的涡旋 不管 千回百转 方向不会偏
  • 相关阅读:
    Java知识体系之基础知识
    002-JavaNIO
    001-四种常见的IO模型
    c/c++面试题(6)运算符重载详解
    c/c++面试题(5)(c++重要的概念详解)
    c/c++面试题(4)字符串翻转/打印任意进制格式/类型转换
    c/c++面试题(3)strcat/strcmp/strlen/strcpy的实现
    c/c++面试题(2)
    c/c++面试题(1)
    cocos2dx 3.0 之 lua 创建类 (二)
  • 原文地址:https://www.cnblogs.com/dwq521/p/14669862.html
Copyright © 2020-2023  润新知