wallpaper.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. callback() {
  25. if (this._imageBuffer) {
  26. wx.showModal({
  27. title: '保存图片中,确定要中断退出吗?',
  28. content: '',
  29. complete: (res) => {
  30. if (res.cancel) {
  31. }
  32. if (res.confirm) {
  33. this.endImage(2)
  34. }
  35. }
  36. })
  37. } else {
  38. wx.navigateBack({
  39. delta: 1,
  40. })
  41. }
  42. }
  43. },
  44. showCropImg: false,
  45. },
  46. closePage() {
  47. },
  48. footerTap() {
  49. route_util.jump("../cropper/cropper")
  50. return;
  51. const that = this;
  52. wx.chooseMedia({
  53. count: 1,
  54. mediaType: ['image'],
  55. sourceType: ['album'],
  56. // camera: 'back',
  57. success(res) {
  58. // console.log(res.tempFiles[0].tempFilePath)
  59. // console.log(res.tempFiles[0].size)
  60. //重置图片角度、缩放、位置
  61. // wx.getImageInfo({
  62. // src: res.tempFiles[0].tempFilePath,
  63. // success(res) {
  64. // console.log(res)
  65. // wx.cropImage({
  66. // src: res.path,// 图片路径
  67. // cropScale: '1:1', // 裁剪比例
  68. // success(res) {
  69. // console.log("裁剪后的图片", res)
  70. // that.setData({
  71. // showCropImg: true,
  72. // topImg: { "pic": res.tempFilePath }
  73. // })
  74. // that.convertImageToRGB565(res.tempFilePath)
  75. // },
  76. // })
  77. // }
  78. // })
  79. }
  80. })
  81. },
  82. imageTap(e) {
  83. // console.log(e)
  84. // wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
  85. let image = e.currentTarget.dataset.image;
  86. _this.setData({
  87. topImg: image ?? {}
  88. })
  89. }, wallpaperList() {
  90. let _this = this;
  91. deviceWallPaper().then(res => {
  92. console.log("壁纸列表", res);
  93. let data = res.data ?? []
  94. if (data.length == 0) {
  95. _this.setData({
  96. imageList: [],
  97. topImg: {},
  98. })
  99. return;
  100. }
  101. topImg = data[0];
  102. _this.setData({
  103. imageList: data ?? [],
  104. topImg: data[0] ?? {}
  105. })
  106. })
  107. },
  108. hideCut(e) {
  109. const img = arguments[0].detail
  110. if (img && img.path) {
  111. console.log("裁剪图片:", img)
  112. }
  113. this.setData({
  114. showCropImg: true,
  115. topImg: { "pic": img.path }
  116. })
  117. },
  118. /**
  119. * 生命周期函数--监听页面加载
  120. */
  121. onLoad(options) {
  122. let param = JSON.parse(options.param)
  123. console.log(param)
  124. this.wallpaperList();
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow() {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide() {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload() {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh() {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom() {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage() {
  160. }
  161. })