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

    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
    })
    }
    },

    如果 生命是场 寂寞的涡旋 不管 千回百转 方向不会偏
  • 相关阅读:
    逻辑智力题【更新中】
    每天进步一点点_抽奖程序
    GDC2016【For Honor-荣耀战魂】的次世代动画技术
    GDC2016【彩虹六号:围攻 】使丰富的“突破”成为可能的破坏系统
    GDC2016 【巫师3 狂猎】的游戏事件工作流
    GDC 2016 神秘海域4中使用Substance制作Texture
    GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告
    【FFXV】中物理模拟的结构以及游戏业界的乐趣
    龙珠 超宇宙 [Dragon Ball Xenoverse]
    如龙0
  • 原文地址:https://www.cnblogs.com/dwq521/p/14669862.html
Copyright © 2011-2022 走看看