wallpaper.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 myImgList = store.getStore(_this.data._localImgPicKey)
  98. myImgList = myImgList ?? []
  99. let myIndex = myImgList.findIndex(img => img.pic === findImg.pic);
  100. if (myIndex < 0) {
  101. myImgList.unshift(newImg)
  102. }
  103. let imgList = _this.data._locImageList
  104. console.log("updateTopImg1", imgList)
  105. let findImg = imgList.find(function (img) { return img.pic === topUrl })
  106. console.log("updateTopImg3", findImg)
  107. if (findImg) {
  108. let index = imgList.findIndex(img => img.pic === findImg.pic);
  109. imgList.splice(index, 1);
  110. imgList.unshift(findImg);
  111. } else {
  112. imgList.unshift(newImg)
  113. }
  114. console.log("updateTopImg2", imgList, findImg)
  115. if (imgList.length > 10) {
  116. imgList.pop()
  117. }
  118. _this.data._locImageList = imgList
  119. _this.setData({
  120. imageList: _this.data._locImageList,
  121. image4List: _this.data._locImageList.slice(0, 4),
  122. topImg: newImg
  123. })
  124. store.setStore(_this.data._localImgPicKey, myImgList)
  125. // }
  126. },
  127. hideCut(e) {
  128. const img = arguments[0].detail
  129. if (img && img.path) {
  130. console.log("裁剪图片:", img)
  131. }
  132. this.setData({
  133. showCropImg: true,
  134. topImg: { "pic": img.path }
  135. })
  136. },
  137. /**
  138. * 生命周期函数--监听页面加载
  139. */
  140. onLoad(options) {
  141. let param = JSON.parse(options.param)
  142. console.log(param)
  143. this.data._localImgPicKey = this.data._localImgPicKey + param.deviceId;
  144. this.wallpaperList();
  145. },
  146. /**
  147. * 生命周期函数--监听页面初次渲染完成
  148. */
  149. onReady() {
  150. },
  151. /**
  152. * 生命周期函数--监听页面显示
  153. */
  154. onShow() {
  155. },
  156. /**
  157. * 生命周期函数--监听页面隐藏
  158. */
  159. onHide() {
  160. },
  161. /**
  162. * 生命周期函数--监听页面卸载
  163. */
  164. onUnload() {
  165. },
  166. /**
  167. * 页面相关事件处理函数--监听用户下拉动作
  168. */
  169. onPullDownRefresh() {
  170. },
  171. /**
  172. * 页面上拉触底事件的处理函数
  173. */
  174. onReachBottom() {
  175. },
  176. /**
  177. * 用户点击右上角分享
  178. */
  179. onShareAppMessage() {
  180. }
  181. })