take-photo.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. var sysT = require('../../../tool/sys-tool.js')
  2. var businessT = require('../../../tool/business-tool.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. adapter: {
  9. suffix: '',
  10. cameraHeight: 0,
  11. viewHeight: 0,
  12. viewWidth: 0
  13. },
  14. },
  15. toAlbum: businessT.action(function (sender) {
  16. wx.chooseImage({
  17. count: 1,
  18. sizeType: ['compressed'],
  19. sourceType: ['album'],
  20. success: function(res) {
  21. businessT.debugLog(res)
  22. var pages = getCurrentPages()
  23. pages[pages.length - 2].finishTakePhoto(res.tempFilePaths[0])
  24. wx.navigateBack({
  25. })
  26. },
  27. })
  28. }),
  29. takePhoto: businessT.action(function (sender) {
  30. this.ctx.takePhoto({
  31. quality: 'normal',
  32. success: (res) => {
  33. businessT.debugLog(res)
  34. businessT.debugLog(this.data.adapter)
  35. wx.navigateTo({
  36. url: '../change-photo/change-photo?path=' + res.tempImagePath + '&height=' + res.height,
  37. })
  38. }
  39. })
  40. }),
  41. back: businessT.action(function (sender) {
  42. wx.navigateBack({
  43. })
  44. }),
  45. error: function (e) {
  46. wx.navigateBack({
  47. })
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function (options) {
  53. this.ctx = wx.createCameraContext()
  54. sysT.adaptor()
  55. var cameraHeight = sysT.usableHeight(316)//相机可是高度rpx
  56. var widthBorder = 40 * sysT.rpxToPx()//取景框横边距
  57. var borderWidth = sysT.sysInfo().windowWidth - widthBorder * 2//取景框宽
  58. var borderHeight = borderWidth / 1.58//取景框高
  59. var heightBorder = (cameraHeight * sysT.rpxToPx() - borderHeight) / 2//取景框竖边距
  60. var border = 'width:' + borderWidth + 'px;height:' + borderHeight + 'px;top:' + heightBorder + 'px;left:' + widthBorder + 'px;'
  61. this.data.adapter = {
  62. suffix: sysT.suffixOfClass(),
  63. cameraHeight: cameraHeight,
  64. border: border
  65. }
  66. this.setData({
  67. adapter: this.data.adapter
  68. })
  69. },
  70. /**
  71. * 生命周期函数--监听页面初次渲染完成
  72. */
  73. onReady: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面显示
  77. */
  78. onShow: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面隐藏
  82. */
  83. onHide: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面卸载
  87. */
  88. onUnload: function () {
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function () {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function () {
  99. },
  100. /**
  101. * 用户点击右上角分享
  102. */
  103. // onShareAppMessage: function () {
  104. // }
  105. })