change-photo.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. var businessT = require('../../../tool/business-tool.js')
  2. var sysT = require('../../../tool/sys-tool.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. adapter: {
  9. viewHeight: 0,
  10. viewWidth: 0
  11. },
  12. },
  13. cancelAction: businessT.action(function (sender) {
  14. wx.navigateBack({
  15. })
  16. }),
  17. finishAction: businessT.action(function (sender) {
  18. wx.canvasToTempFilePath({
  19. x: 0,
  20. y: 0,
  21. width: sysT.sysInfo().windowWidth,
  22. height: sysT.sysInfo().windowWidth / 1.58,
  23. canvasId: 'canvas',
  24. success: function (res) {
  25. var pages = getCurrentPages()
  26. pages[pages.length - 3].finishTakePhoto(res.tempFilePath)
  27. wx.navigateBack({
  28. delta: 2
  29. })
  30. }
  31. })
  32. }),
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */
  36. onLoad: function (options) {
  37. sysT.adaptor()
  38. var viewWidth = sysT.sysInfo().windowWidth
  39. var viewHeight = sysT.sysInfo().windowWidth / 1.58
  40. var cameraHeight = sysT.usableHeight(316)//相机可是高度rpx
  41. if (sysT.suffixOfClass() == '-X') {
  42. var cameraHeight = sysT.usableHeight(500)//相机可是高度rpx
  43. }
  44. var widthBorder = 40 * sysT.rpxToPx()//取景框横边距
  45. var borderWidth = sysT.sysInfo().windowWidth - widthBorder * 2//取景框宽
  46. var borderHeight = borderWidth / 1.58//取景框高
  47. var heightBorder = (cameraHeight * sysT.rpxToPx() - borderHeight) / 2//取景框竖边距
  48. var proportion = viewWidth / borderWidth //放大比例
  49. var bigWidthBorder = widthBorder * proportion//放大后图片的横边距
  50. var bigHeightBorder = heightBorder * proportion//放大后图片的竖边距
  51. var bigImageWidth = sysT.sysInfo().windowWidth * proportion//放大后图片宽
  52. var bigImageHeight = cameraHeight * sysT.rpxToPx() * proportion//放大后图片高
  53. this.data.adapter = {
  54. viewWidth: viewWidth,
  55. viewHeight: viewHeight
  56. }
  57. this.setData({
  58. adapter: this.data.adapter
  59. })
  60. businessT.debugLog(options)
  61. var ctx = wx.createCanvasContext('canvas')
  62. ctx.drawImage(options.path, -bigWidthBorder, -bigHeightBorder, bigImageWidth, bigImageHeight)
  63. ctx.draw()
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide: function () {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload: function () {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh: function () {
  89. },
  90. /**
  91. * 页面上拉触底事件的处理函数
  92. */
  93. onReachBottom: function () {
  94. },
  95. /**
  96. * 用户点击右上角分享
  97. */
  98. // onShareAppMessage: function () {
  99. // }
  100. })