123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- // pages/piano/wallpaper/wallpaper.js
- const { deviceWallPaper } = require('../../../request/deviceListRequest')
- // const sharp = require('sharp');
- // const fs = require('fs');
- import route_util from '../../../utils/route_util';
- import store from '../../../utils/store';
- // import EventManager from '../../utils/event_bus'
- // applicationType: "[0]"
- // createTime: "2025-01-10T09:36:04.000+00:00"
- // createTimeStr: null
- // id: "1877650605435129856"
- // name: null
- // note: ""
- // pic: "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20250110173600839933880.png"
- // sort: 1
- // status: 0
- // updateTime: "2025-01-10T09:36:04.000+00:00"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- topImg:
- {
- // pic: "",
- // id: "",
- },
- imageList: [],
- image4List: [],
- _locImageList: [],
- selectIndex: 0,
- _localImgPicKey: "_localImgPicListKey",
- navbarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '壁纸设置', //导航栏 中间的标题
- },
- showAllImages: false,
- useSystemNavBar: true // 设置为 true 以使用系统导航栏
- },
- closePage() {
- },
- footerTap() {
- route_util.jumpParam("../cropper/cropper", JSON.stringify(this.data.topImg ?? {}))
- },
- imageTopTap() {
- this.setData({
- topImg: {}
- })
- },
- toggleShowAll: function () {
- this.setData({
- showAllImages: !this.data.showAllImages
- });
- },
- imageTap(e) {
- console.log(e)
- // wxfile://tmp_d3e57489ead39c698676ff860df9cb8a37f66ee1a4777dbb.jpg
- let image = e.currentTarget.dataset.image;
- let _this = this;
- if (image.id == this.data.topImg.id) {
- _this.setData({
- topImg: {}
- })
- } else {
- _this.setData({
- topImg: image ?? {}
- })
- }
- },
- async wallpaperList() {
- let _this = this;
- deviceWallPaper().then(res => {
- let data = res ?? []
- let localImgList = store.getStore(_this.data._localImgPicKey);
- console.log("壁纸列表", data.length, localImgList, "空");
- if (localImgList) {
- console.log("壁纸列表2", res.length, localImgList, "空");
- data = localImgList.concat(data)
- }
- _this.data._locImageList = data;
- _this.setData({
- imageList: _this.data._locImageList,
- image4List: _this.data._locImageList.slice(0, 4),
- // topImg: data[0] ?? {}
- })
- })
- },
- async updateTopImg(topUrl) {
- let _this = this;
- // let hasImg = _this.data.imageList.find(function (vForItem) {
- // return vForItem.pic == topUrl;
- // })
- // if (!hasImg) {
- let newImg = {
- "pic": topUrl, "id": "0"
- }
- let imgList = _this.data._locImageList
- console.log("updateTopImg1", imgList)
- let findImg = imgList.find(function (img) { return img.pic === topUrl })
- console.log("updateTopImg3", findImg)
- if (findImg) {
- let index = imgList.findIndex(img => img.pic === findImg.pic);
- imgList.splice(index, 1);
- imgList.unshift(findImg);
- } else {
- imgList.unshift(newImg)
- }
- console.log("updateTopImg2", imgList, findImg)
- if (imgList.length > 10) {
- imgList.pop()
- }
- _this.data._locImageList = imgList
- _this.setData({
- imageList: _this.data._locImageList,
- image4List: _this.data._locImageList.slice(0, 4),
- topImg: newImg
- })
- store.setStore(_this.data._localImgPicKey, imgList)
- // }
- },
- hideCut(e) {
- const img = arguments[0].detail
- if (img && img.path) {
- console.log("裁剪图片:", img)
- }
- this.setData({
- showCropImg: true,
- topImg: { "pic": img.path }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- let param = JSON.parse(options.param)
- console.log(param)
- this.data._localImgPicKey = this.data._localImgPicKey + param.deviceId;
- this.wallpaperList();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|