最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序-拍照或選擇圖片并上傳文件

 更新時(shí)間:2017年01月06日 15:31:51   投稿:lqh  
這篇文章主要介紹了微信小程序-拍照或選擇圖片并上傳文件的相關(guān)資料,需要的朋友可以參考下

微信小程序-拍照或選擇圖片并上傳文件

調(diào)用拍照API:https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-picture.html?t=20161222#wxchooseimageobject

上傳文件API:https://mp.weixin.qq.com/debug/wxadoc/dev/api/network-file.html

主要js代碼:

choice: function () { 
  var that = this 
  wx.chooseImage({ 
   count: 1, // 默認(rèn)9 
   sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,默認(rèn)二者都有 
   sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機(jī),默認(rèn)二者都有 
   success: function (res) { 
    // 返回選定照片的本地文件路徑列表,tempFilePath可以作為img標(biāo)簽的src屬性顯示圖片 
    var tempFilePaths = res.tempFilePaths 
    that.setData({ 
     textHidden: true, 
     image_photo: tempFilePaths, 
     photoHidden: false 
    }) 
   } 
  }) 
 }, 
 uploadPhoto: function () { 
  var that = this 
  let param = util.json2Form({ 
   tel: '18600346580', 
   orderSn: that.data.orderSn, 
   parkingPhoto: that.data.image_photo, 
  }); 
  wx.uploadFile({ 
   url: 'https://testapi.****.com/v4.0.0/uploadParkingPhoto', //僅為示例 
   filePath: that.data.image_photo[0], 
   name: 'parkingPhoto', 
   formData: { 
    'tel': '***********', 
    'orderSn': that.data.orderSn, 
   }, 
   success: function (res) { 
    var obj = JSON.parse(res.data);; 
    console.log(obj.result) 
    console.log(obj.msg) 
    var resule = obj.result; 
    var msg = obj.msg; 
    if (resule == 'false') { 
     wx.showToast({ 
      title: msg, 
      icon: 'success', 
      duration: 2000 
     }) 
    } else { 
     wx.navigateBack({ 
      delta: 1, 
      success: function (res) { 
       wx.showToast({ 
        title: msg, 
        icon: 'success', 
        duration: 2000 
       }) 
      }, 
 
     }) 
    } 
   } 
  }) 
 
 } 

Tip:

1.調(diào)用wx.chooseImage() 自動(dòng)彈出選擇窗口,不用調(diào)用操作菜單wx.showActionSheet(),否則重復(fù)

如圖

2. 上傳文件的時(shí)候filePath必須是數(shù)組,當(dāng)你單張的時(shí)候需要使用數(shù)組,若只有一張要用[0]

3. 最需要注意的是,success返回?cái)?shù)據(jù)是String類型,我們需要將String類型轉(zhuǎn)換成Object

js字符串轉(zhuǎn)換成obj

用js 是有三種方法的

  1. js自帶的eval函數(shù),其中需要添加小括號(hào)eval('('+str+')');
  2. JSON.parse(str)
  3. $.parseJSON( jsonstr )

但是在微信小程序中,我們只能用JSON.parse(str),其他的都不可以

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論

桦南县| SHOW| 榆树市| 洪洞县| 永善县| 城口县| 恩平市| 洪江市| 阿拉善右旗| 桐梓县| 咸阳市| 宁都县| 福州市| 涞水县| 新泰市| 曲水县| 南漳县| 稷山县| 名山县| 浦县| 丹阳市| 白玉县| 武威市| 闽侯县| 株洲市| 抚顺市| 寻乌县| 海丰县| 乌鲁木齐县| 朝阳区| 嘉义市| 富阳市| 许昌县| 北宁市| 酒泉市| 桂阳县| 红安县| 承德县| 古蔺县| 青浦区| 兴文县|