From e1d5caf1922884d55dc17b197c6d14a8f18584bf Mon Sep 17 00:00:00 2001 From: sdaduanbilei Date: Fri, 21 Nov 2025 11:56:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE=E6=89=80=E5=B1=9E=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/community/add.js | 96 ++++++++++++++++++++++++++- pages/community/add.wxml | 6 +- pages/community/index.js | 37 ++++++++--- pages/community/index.wxml | 12 ++-- pages/garden/index.js | 9 +-- pages/garden/index.wxml | 74 ++++++--------------- pages/garden/info.wxml | 132 ++++++++++++++++++++++--------------- pages/garden/info.wxss | 2 +- pages/index/index.js | 30 ++++----- pages/index/index.wxml | 92 ++++++++++++++++++-------- pages/index/index.wxss | 26 +++++++- 11 files changed, 334 insertions(+), 182 deletions(-) diff --git a/pages/community/add.js b/pages/community/add.js index 5c2388e..ca01706 100644 --- a/pages/community/add.js +++ b/pages/community/add.js @@ -1,11 +1,15 @@ // pages/community/add.js +const config = require("../../config/config") +const { api } = require("../../utils/api") Page({ /** * 页面的初始数据 */ data: { - + content: '', + ossIds: [], + fileList: [] }, /** @@ -15,6 +19,96 @@ Page({ }, + upload(e) { + const { + files + } = e.detail; + console.log(files); + this.setData({ + fileList: files + }) + }, + remove(e) { + const { + index + } = e.detail; + const { + fileList + } = this.data + fileList.splice(index, 1); + this.setData({ + fileList + }); + }, + input(e) { + const value = e.detail.value + this.setData({ + content: value + }) + }, + submit() { + if (this.data.content.length === 0) { + wx.showModal({ + content: '请输入这一刻的想法', + }) + return + } + wx.showLoading({ + title: '请稍后', + }) + // 上传图片 + const uploadTasks = this.data.fileList.map(file => this.uploadSingle(file)); + Promise.all(uploadTasks) + .then(ossIds => { + console.log("全部上传成功", ossIds); + // ossIds 是一个 [id1, id2, id3...] + this.save(ossIds); + }) + .catch(err => { + console.error("有上传失败", err); + wx.showToast({ + title: '上传失败', + icon: 'none' + }); + }); + + }, + + save(ids){ + const data = {content:this.data.content,ossIds: ids,title:this.data.content} + api('/post/add','POST',data,'json').then(res => { + if (res.code === 200){ + wx.navigateBack() + } else{ + wx.showModal({ + content: res.msg + }) + } + }) + }, + + uploadSingle(file) { + console.log(file); + return new Promise((resolve, reject) => { + wx.uploadFile({ + filePath: file.url, + name: 'file', + header: { + 'Authorization': 'Bearer ' + wx.getStorageSync('token'), + }, + url: config.baseUrl + '/oss/upload', + success: res => { + const data = JSON.parse(res.data); + if (data.code === 200) { + resolve(data.data.file.id); // 返回 ossId + } else { + reject(data); + } + }, + fail: reject + }); + }) + }, /** * 生命周期函数--监听页面初次渲染完成 */ diff --git a/pages/community/add.wxml b/pages/community/add.wxml index 0ebd922..71e6742 100644 --- a/pages/community/add.wxml +++ b/pages/community/add.wxml @@ -4,10 +4,10 @@ - + - + @@ -37,7 +37,7 @@ - 发布 + 发布 \ No newline at end of file diff --git a/pages/community/index.js b/pages/community/index.js index 39d67af..bff3ae9 100644 --- a/pages/community/index.js +++ b/pages/community/index.js @@ -1,3 +1,5 @@ +const { api } = require("../../utils/api") + // pages/community/index.js Page({ @@ -5,16 +7,11 @@ Page({ * 页面的初始数据 */ data: { - list:[ - { - content:'植物园的枫叶🍁', - imgList:["https://pic1.zhimg.com/v2-e58efabf7a05544e04b6004b9b63e645_720w.jpg?source=172ae18b"] - }, - { - content:"下周就要冷了! 是不是今天就是今年最后一个适合看花看景的秋日了....", - imgList:["https://res.catter.cn/pub/2025/11/18/20251118170136790.png","https://res.catter.cn/pub/2025/11/18/20251118170155441.png"] - } - ] + page:{ + current:0, + pageSize:10 + }, + list:[] }, /** @@ -41,7 +38,27 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { + this.fetchList() + }, + fetchList(){ + const data = {...this.data.page} + api('/post/page','POST',data,'json').then(res => { + if (res.code === 200){ + console.log(res.data); + const tmps = res.data.list + this.setData({list:tmps}) + } + }) + }, + + like(e){ + const {id,hasLiked} = e.currentTarget.dataset.item + api( hasLiked === 1 ? '/post/cancelLike':'/post/like','GET',{id}).then(res => { + if (res.code === 200){ + this.fetchList() + } + }) }, /** diff --git a/pages/community/index.wxml b/pages/community/index.wxml index 0415a52..3e6658c 100644 --- a/pages/community/index.wxml +++ b/pages/community/index.wxml @@ -21,25 +21,25 @@ - + - + - - - 10 + + + {{item.likeCount}} - 4 + {{item.commentCount}} diff --git a/pages/garden/index.js b/pages/garden/index.js index cbf1d3c..7125e77 100644 --- a/pages/garden/index.js +++ b/pages/garden/index.js @@ -26,13 +26,8 @@ Page({ this.setData({list:[]}) return } - const tmps = res.data.map(e => { - if (e.imgList.length >0){ - e.pic = e.imgList[0].url - } - return e - }) - this.setData({list:tmps}) + + this.setData({list:res.data}) } }) }, diff --git a/pages/garden/index.wxml b/pages/garden/index.wxml index 4a53195..6f79173 100644 --- a/pages/garden/index.wxml +++ b/pages/garden/index.wxml @@ -28,69 +28,35 @@ - 必做任务 (2) - - - - - - - {{item.name}} - 立即完成 - - - 需要养护: - - + + {{item.name}} + + + + + + + + {{item.plant.name}} + 立即完成 + 已完成 + 跳过 + 已逾期{{item.todayCare.expireDays}}天 + + + + + - - - - 已逾期 (2) - - - - - - - {{item.name}} - 立即完成 - - - - 需要养护: - - - - - - - 今日已完成 (2) - - - - - - - {{item.name}} - - - 需要养护: - - - - - - - + \ No newline at end of file diff --git a/pages/garden/info.wxml b/pages/garden/info.wxml index eaf43c7..d3a1ac9 100644 --- a/pages/garden/info.wxml +++ b/pages/garden/info.wxml @@ -16,76 +16,104 @@ - + - + {{info.name}} - 种植于 {{info.plantTimeStr}} 已种植 {{info.plantDays}} 天 + 陪伴你第 {{info.plantDays}} 天 · 种植于 {{info.plantTimeStr}} - - - - - 养护事项 - - - {{info.growthHabit}} - + + + + + + 🌡 温度适宜:16–23°C - - - - - - - - - {{item.name}} - 每{{item.period}}天一次 - - 已完成 - - - 已逾期{{item.expireDays}}天 - 今天 - - - - - + + 🌞 今日光照:良好 + + + 💧 湿度 适宜 - - - 养护记录 - - - - - - - - - - - - - {{item.name}} - {{item.careTimeStr}} - 今天 - {{item.remark}} + + 记录此刻 + + + + + + 养护事项 + + + {{info.growthHabit}} + + + + + + + + + + + {{item.name}} + 每{{item.period}}天一次 + + 已完成 + + + 已逾期{{item.expireDays}}天 + 今天 + + + + 养护记录 + + + + + + + + + + + + + + {{item.name}} + {{item.careTimeStr}} + + 今天 + {{item.remark}} + + + + + + + + + + 植物知识卡 + + + + 成就徽章 + diff --git a/pages/garden/info.wxss b/pages/garden/info.wxss index 8cf5fe9..5605baa 100644 --- a/pages/garden/info.wxss +++ b/pages/garden/info.wxss @@ -5,7 +5,7 @@ page { .grid { display: grid; - grid-template-columns: 50% 50%; + grid-template-columns: 47% 47%; grid-row-gap: 16px; grid-column-gap: 16px; } diff --git a/pages/index/index.js b/pages/index/index.js index 7e3136f..43bae7a 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -36,7 +36,6 @@ Page({ * 生命周期函数--监听页面显示 */ onShow() { - this.setData({leftList:[],rightList:[]}) this.fetchList() }, fetchList() { @@ -49,50 +48,47 @@ Page({ if (res.data === null) { return } + this.setData({leftList:[],rightList:[]}) const tmps = res.data.list.map(e => { e.pic = e.imgList[0].url + e.cover = e.imgList[0] return e }) this.addItems(tmps) - // this.setData({ - // list: tmps - // }) + this.setData({ + list: tmps + }) } }) }, addItems(newItems) { - newItems.forEach(item => { + let h1 = 0; + let h2 = 0; + newItems.forEach((item,index) => { // 动态获取图片尺寸 - wx.getImageInfo({ - src: item.pic, - success: res => { - const scale = res.width / res.height; - const imgHeight = 345 / scale; // 假设宽度是 345rpx - if (this.data.leftHeight <= this.data.rightHeight) { + if (index % 2 === 0) { this.data.leftList.push(item); - this.data.leftHeight += imgHeight; + h1 += item.cover.height / item.cover.width; } else { this.data.rightList.push(item); - this.data.rightHeight += imgHeight; + h2 += item.cover.height / item.cover.width; } - this.setData({ leftList: this.data.leftList, rightList: this.data.rightList, }); - } - }); }); }, goInfo(e){ + console.log(e); const id = e.currentTarget.dataset.id wx.navigateTo({ - url: '../index/info?id=' + id, + url: '../garden/info?id=' + id, }) }, diff --git a/pages/index/index.wxml b/pages/index/index.wxml index 3c59de5..35a202d 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -10,37 +10,73 @@ 20 ℃ - 花园健康度 83 分, 今日需养护 2 株植物 + 今日需养护 2 株植物 龟背竹长期未更新照片 - + - - - - - {{item.name}} - 今日无需养护 - 上次养护:2 天前 - 健康指数:83% + + + + + + {{item.name}} + + + 陪伴 · {{item.plantDays}} 天 + + + + + + + + 今日需养护 + + + + + + 今日无需养护 + + + 上次养护:{{item.lastPeriod ? itme.lastPeriod:'-' }} 天前 - - - - - {{item.name}} - 今日无需养护 - 上次养护:2 天前 - 健康指数:83% + + + + + + {{item.name}} + + + 陪伴 · {{item.plantDays}} 天 + + + + + + + + 今日需养护 + + + + + + 今日无需养护 + + + 上次养护:{{item.lastPeriod ? itme.lastPeriod:'-' }} 天前 @@ -52,7 +88,7 @@ - 欢迎来到你的秘密花园 🌿~ + 欢迎来到你的秘密花园 🌿~ 从添加第一盆植物开始你的养花之旅吧 @@ -61,20 +97,20 @@ 您还可以从以下热门植物中,免费领取 - - - - - 绿萝 - 超好养 + + + + + 绿萝 + 超好养 + + 日照充足、超级好养 - 日照充足、超级好养 - - + \ No newline at end of file diff --git a/pages/index/index.wxss b/pages/index/index.wxss index ea34169..2da790f 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -15,18 +15,17 @@ .waterfall { display: flex; justify-content: space-between; - padding: 32rpx; + padding:16rpx; } .column { - width: 48%; + width: 49%; } .card { box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.06); background-color: white; border-radius: 12rpx; - } .img { @@ -55,4 +54,25 @@ grid-row-gap: 16px; grid-column-gap: 12px; border-radius: 12rpx; +} + +.img-wrapper { position: relative; } +.overlay { + position: absolute; + bottom: 0; + left: 0; + right: 0; + padding: 6rpx 16rpx; + background: rgba(0,0,0,0.5); + color: #fff; +} +.small { + font-size: 22rpx; + opacity: 0.9; +} + +.info { + padding-top: 0rpx; + padding-left: 16rpx; + padding-bottom: 16rpx; } \ No newline at end of file