wallpaper.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 store from '../../../utils/store';
  7. // import EventManager from '../../utils/event_bus'
  8. // applicationType: "[0]"
  9. // createTime: "2025-01-10T09:36:04.000+00:00"
  10. // createTimeStr: null
  11. // id: "1877650605435129856"
  12. // name: null
  13. // note: ""
  14. // pic: "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20250110173600839933880.png"
  15. // sort: 1
  16. // status: 0
  17. // updateTime: "2025-01-10T09:36:04.000+00:00"
  18. Page({
  19. /**
  20. * 页面的初始数据
  21. */
  22. data: {
  23. topImg:
  24. {
  25. // pic: "",
  26. // id: "",
  27. },
  28. imageList: [
  29. ],
  30. selectIndex: 0,
  31. navbarData: {
  32. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  33. title: '壁纸设置', //导航栏 中间的标题
  34. },
  35. showCropImg: false,
  36. },
  37. closePage() {
  38. },
  39. footerTap() {
  40. route_util.jumpParam("../cropper/cropper", JSON.stringify(this.data.topImg ?? {}))
  41. },
  42. imageTopTap() {
  43. this.setData({
  44. topImg: {}
  45. })
  46. },
  47. imageTap(e) {
  48. console.log(e)
  49. // wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
  50. let image = e.currentTarget.dataset.image;
  51. let _this = this;
  52. if (image.id == this.data.topImg.id) {
  53. _this.setData({
  54. topImg: {}
  55. })
  56. } else {
  57. _this.setData({
  58. topImg: image ?? {}
  59. })
  60. }
  61. }, wallpaperList() {
  62. let _this = this;
  63. deviceWallPaper().then(res => {
  64. console.log("壁纸列表", res);
  65. let data = res ?? []
  66. let localImg = store.getStore("_imgTopPic");
  67. if (localImg) {
  68. data.unshift({
  69. id: 0,
  70. name: "本地壁纸",
  71. pic: localImg
  72. })
  73. }
  74. _this.setData({
  75. imageList: data ?? [],
  76. // topImg: data[0] ?? {}
  77. })
  78. })
  79. }, updateTopImg(topUrl) {
  80. let _this = this;
  81. // let hasImg = _this.data.imageList.find(function (vForItem) {
  82. // return vForItem.pic == topUrl;
  83. // })
  84. // if (!hasImg) {
  85. let newImg = {
  86. "pic": topUrl, "id": "0"
  87. }
  88. _this.data.imageList.push(newImg)
  89. _this.setData({
  90. imageList: _this.data.imageList,
  91. topImg: newImg
  92. })
  93. store.setStore('_imgTopPic', topUrl)
  94. // }
  95. },
  96. hideCut(e) {
  97. const img = arguments[0].detail
  98. if (img && img.path) {
  99. console.log("裁剪图片:", img)
  100. }
  101. this.setData({
  102. showCropImg: true,
  103. topImg: { "pic": img.path }
  104. })
  105. },
  106. /**
  107. * 生命周期函数--监听页面加载
  108. */
  109. onLoad(options) {
  110. let param = JSON.parse(options.param)
  111. console.log(param)
  112. this.wallpaperList();
  113. },
  114. /**
  115. * 生命周期函数--监听页面初次渲染完成
  116. */
  117. onReady() {
  118. },
  119. /**
  120. * 生命周期函数--监听页面显示
  121. */
  122. onShow() {
  123. },
  124. /**
  125. * 生命周期函数--监听页面隐藏
  126. */
  127. onHide() {
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload() {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh() {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom() {
  143. },
  144. /**
  145. * 用户点击右上角分享
  146. */
  147. onShareAppMessage() {
  148. }
  149. })