You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
clothesProject/pages/navigation/index/add/camera/camera.js

138 lines
3.1 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

// pages/navigation/index/add/camera/camera.js
Page({
  /**
   * 页面的初始数据
   */
  
  data: {
    src:null
  },
  takePhoto() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
           src: res.tempImagePath
         
        
        })
        console.log(this.data.src)
        var app = getApp();
        app.globalData.url = this.data.src;
      }
    })
    
  },error(e) {
   console.log(e.detail)
  },
  see:function(e){
    var current = e.currentTarget.dataset.src;
    console.log(current);
    
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: [this.data.src],
      
    })
   },
   // 获取图片上传后的url路径
  // addImagePath(fileId) {
  //   console.log("diaoyongla")
  //   console.log(fileId)
  //   wx.cloud.getTempFileURL({
  //     fileList: [fileId],
  //     success: res => {
  //       app.globalData.url = res.fileList[0].tempFileURL
  //     },
  //     fail: console.error
  //   })
 //},
   upload:function(e){
    wx.cloud.uploadFile({
      cloudPath: 'photo/one.jpg', // 上传至云端的路径
      
      filePath: this.data.src, // 小程序临时文件路径
      success: res => {
        // 返回文件 ID
        console.log(res.fileID)
        wx.showToast({
          title: '上传成功',
          icon:'success',
         
        })
        //获取图片的http路径
        //that.addImagePath(res.fileID)
      },
      fail: console.error
    })
   },
   gotoPage: function (options) {
    wx.navigateTo({
          //url: '../add/add',//要跳转到的页面路径
          url:'../add',
 })  
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
  }
})