wallpaper.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. image4List: [],
  30. _locImageList: [],
  31. selectIndex: 0,
  32. _localImgPicKey: "_localImgPicListKey",
  33. navbarData: {
  34. showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
  35. title: '壁纸设置', //导航栏 中间的标题
  36. },
  37. showAllImages: false,
  38. useSystemNavBar: true // 设置为 true 以使用系统导航栏
  39. },
  40. closePage() {
  41. },
  42. footerTap() {
  43. route_util.jumpParam("../cropper/cropper", JSON.stringify(this.data.topImg ?? {}))
  44. },
  45. imageTopTap() {
  46. this.setData({
  47. topImg: {}
  48. })
  49. },
  50. toggleShowAll: function () {
  51. this.setData({
  52. showAllImages: !this.data.showAllImages
  53. });
  54. },
  55. imageTap(e) {
  56. console.log(e)
  57. // wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
  58. let image = e.currentTarget.dataset.image;
  59. let _this = this;
  60. if (image.id == this.data.topImg.id) {
  61. _this.setData({
  62. topImg: {}
  63. })
  64. } else {
  65. _this.setData({
  66. topImg: image ?? {}
  67. })
  68. }
  69. },
  70. async wallpaperList() {
  71. let _this = this;
  72. deviceWallPaper().then(res => {
  73. let data = res ?? []
  74. let localImgList = store.getStore(_this.data._localImgPicKey);
  75. console.log("壁纸列表", data.length, localImgList, "空");
  76. if (localImgList) {
  77. console.log("壁纸列表2", res.length, localImgList, "空");
  78. data = localImgList.concat(data)
  79. }
  80. _this.data._locImageList = data;
  81. _this.setData({
  82. imageList: _this.data._locImageList,
  83. image4List: _this.data._locImageList.slice(0, 4),
  84. // topImg: data[0] ?? {}
  85. })
  86. })
  87. },
  88. async updateTopImg(topUrl) {
  89. let _this = this;
  90. // let hasImg = _this.data.imageList.find(function (vForItem) {
  91. // return vForItem.pic == topUrl;
  92. // })
  93. // if (!hasImg) {
  94. let newImg = {
  95. "pic": topUrl, "id": "0"
  96. }
  97. let imgList = _this.data._locImageList
  98. console.log("updateTopImg1", imgList)
  99. let findImg = imgList.find(function (img) { return img.pic === topUrl })
  100. console.log("updateTopImg3", findImg)
  101. if (findImg) {
  102. let index = imgList.findIndex(img => img.pic === findImg.pic);
  103. imgList.splice(index, 1);
  104. imgList.unshift(findImg);
  105. } else {
  106. imgList.unshift(newImg)
  107. }
  108. console.log("updateTopImg2", imgList, findImg)
  109. if (imgList.length > 10) {
  110. imgList.pop()
  111. }
  112. _this.data._locImageList = imgList
  113. _this.setData({
  114. imageList: _this.data._locImageList,
  115. image4List: _this.data._locImageList.slice(0, 4),
  116. topImg: newImg
  117. })
  118. store.setStore(_this.data._localImgPicKey, imgList)
  119. // }
  120. },
  121. hideCut(e) {
  122. const img = arguments[0].detail
  123. if (img && img.path) {
  124. console.log("裁剪图片:", img)
  125. }
  126. this.setData({
  127. showCropImg: true,
  128. topImg: { "pic": img.path }
  129. })
  130. },
  131. /**
  132. * 生命周期函数--监听页面加载
  133. */
  134. onLoad(options) {
  135. let param = JSON.parse(options.param)
  136. console.log(param)
  137. this.data._localImgPicKey = this.data._localImgPicKey + param.deviceId;
  138. this.wallpaperList();
  139. },
  140. /**
  141. * 生命周期函数--监听页面初次渲染完成
  142. */
  143. onReady() {
  144. },
  145. /**
  146. * 生命周期函数--监听页面显示
  147. */
  148. onShow() {
  149. },
  150. /**
  151. * 生命周期函数--监听页面隐藏
  152. */
  153. onHide() {
  154. },
  155. /**
  156. * 生命周期函数--监听页面卸载
  157. */
  158. onUnload() {
  159. },
  160. /**
  161. * 页面相关事件处理函数--监听用户下拉动作
  162. */
  163. onPullDownRefresh() {
  164. },
  165. /**
  166. * 页面上拉触底事件的处理函数
  167. */
  168. onReachBottom() {
  169. },
  170. /**
  171. * 用户点击右上角分享
  172. */
  173. onShareAppMessage() {
  174. }
  175. })