wallpaper.js 5.0 KB

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