var sysT = require('../../../tool/sys-tool.js') var businessT = require('../../../tool/business-tool.js') Page({ /** * 页面的初始数据 */ data: { adapter: { suffix: '', cameraHeight: 0, viewHeight: 0, viewWidth: 0 }, }, toAlbum: businessT.action(function (sender) { wx.chooseImage({ count: 1, sizeType: ['compressed'], sourceType: ['album'], success: function(res) { businessT.debugLog(res) var pages = getCurrentPages() pages[pages.length - 2].finishTakePhoto(res.tempFilePaths[0]) wx.navigateBack({ }) }, }) }), takePhoto: businessT.action(function (sender) { this.ctx.takePhoto({ quality: 'normal', success: (res) => { businessT.debugLog(res) businessT.debugLog(this.data.adapter) wx.navigateTo({ url: '../change-photo/change-photo?path=' + res.tempImagePath + '&height=' + res.height, }) } }) }), back: businessT.action(function (sender) { wx.navigateBack({ }) }), error: function (e) { wx.navigateBack({ }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.ctx = wx.createCameraContext() sysT.adaptor() var cameraHeight = sysT.usableHeight(316)//相机可是高度rpx var widthBorder = 40 * sysT.rpxToPx()//取景框横边距 var borderWidth = sysT.sysInfo().windowWidth - widthBorder * 2//取景框宽 var borderHeight = borderWidth / 1.58//取景框高 var heightBorder = (cameraHeight * sysT.rpxToPx() - borderHeight) / 2//取景框竖边距 var border = 'width:' + borderWidth + 'px;height:' + borderHeight + 'px;top:' + heightBorder + 'px;left:' + widthBorder + 'px;' this.data.adapter = { suffix: sysT.suffixOfClass(), cameraHeight: cameraHeight, border: border } this.setData({ adapter: this.data.adapter }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ // onShareAppMessage: function () { // } })