// pages/camera/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { nvabarData: { showCapsule: 1, //是否显示左上角图标,消息中心 1表示显示 0表示不显示 showBack: 0, //返回 title: '摄像头', //导航栏 中间的标题 // 此页面 页面内容距最顶部的距离 height: app.globalData.height * 2 + 20, }, scanCodeMsg: "", tempFilePaths: '' }, // 扫码 scanCode: function () { var that = this; wx.scanCode({ //扫描API success(res) { //扫描成功 // console.log(res) //输出回调信息 that.setData({ scanCodeMsg: res.result }); wx.showToast({ title: '成功', duration: 1000 }) } }) }, // 拍照获取图片路径 chooseimage: function () { var _this = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // console.log(res.tempFilePaths); // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 _this.setData({ tempFilePaths: res.tempFilePaths }) } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })