wallpaper.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // pages/piano/wallpaper/wallpaper.js
  2. const { deviceWallPaper } = require('../../../request/deviceListRequest')
  3. // const sharp = require('sharp');
  4. // const fs = require('fs');
  5. import route_util from '../../../utils/route_util';
  6. // import EventManager from '../../utils/event_bus'
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. topImg:
  13. {
  14. // pic: "",
  15. // id: "",
  16. // name: ""
  17. },
  18. imageList: [
  19. ],
  20. selectIndex: 0,
  21. navbarData: {
  22. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  23. title: '壁纸设置', //导航栏 中间的标题
  24. },
  25. showCropImg: false,
  26. },
  27. closePage() {
  28. },
  29. footerTap() {
  30. route_util.jump("../cropper/cropper")
  31. return;
  32. const that = this;
  33. wx.chooseMedia({
  34. count: 1,
  35. mediaType: ['image'],
  36. sourceType: ['album'],
  37. // camera: 'back',
  38. success(res) {
  39. // console.log(res.tempFiles[0].tempFilePath)
  40. // console.log(res.tempFiles[0].size)
  41. //重置图片角度、缩放、位置
  42. // wx.getImageInfo({
  43. // src: res.tempFiles[0].tempFilePath,
  44. // success(res) {
  45. // console.log(res)
  46. // wx.cropImage({
  47. // src: res.path,// 图片路径
  48. // cropScale: '1:1', // 裁剪比例
  49. // success(res) {
  50. // console.log("裁剪后的图片", res)
  51. // that.setData({
  52. // showCropImg: true,
  53. // topImg: { "pic": res.tempFilePath }
  54. // })
  55. // that.convertImageToRGB565(res.tempFilePath)
  56. // },
  57. // })
  58. // }
  59. // })
  60. }
  61. })
  62. },
  63. imageTap(e) {
  64. // console.log(e)
  65. // wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
  66. let image = e.currentTarget.dataset.image;
  67. _this.setData({
  68. topImg: image ?? {}
  69. })
  70. }, wallpaperList() {
  71. let _this = this;
  72. deviceWallPaper().then(res => {
  73. console.log("壁纸列表", res);
  74. let data = res.data ?? []
  75. if (data.length == 0) {
  76. _this.setData({
  77. imageList: [],
  78. topImg: {},
  79. })
  80. return;
  81. }
  82. topImg = data[0];
  83. _this.setData({
  84. imageList: data ?? [],
  85. topImg: data[0] ?? {}
  86. })
  87. })
  88. },
  89. hideCut(e) {
  90. const img = arguments[0].detail
  91. if (img && img.path) {
  92. console.log("裁剪图片:", img)
  93. }
  94. this.setData({
  95. showCropImg: true,
  96. topImg: { "pic": img.path }
  97. })
  98. },
  99. /**
  100. * 生命周期函数--监听页面加载
  101. */
  102. onLoad(options) {
  103. let param = JSON.parse(options.param)
  104. console.log(param)
  105. this.wallpaperList();
  106. },
  107. /**
  108. * 生命周期函数--监听页面初次渲染完成
  109. */
  110. onReady() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面显示
  114. */
  115. onShow() {
  116. },
  117. /**
  118. * 生命周期函数--监听页面隐藏
  119. */
  120. onHide() {
  121. },
  122. /**
  123. * 生命周期函数--监听页面卸载
  124. */
  125. onUnload() {
  126. },
  127. /**
  128. * 页面相关事件处理函数--监听用户下拉动作
  129. */
  130. onPullDownRefresh() {
  131. },
  132. /**
  133. * 页面上拉触底事件的处理函数
  134. */
  135. onReachBottom() {
  136. },
  137. /**
  138. * 用户点击右上角分享
  139. */
  140. onShareAppMessage() {
  141. }
  142. })