diff --git a/app.json b/app.json index 2f5a002..399dff5 100644 --- a/app.json +++ b/app.json @@ -15,7 +15,9 @@ "pages/profile/identify-history/index", "pages/profile/badges/index", "pages/profile/badges/level-detail/index", - "pages/profile/badges/badge-wall/index" + "pages/profile/badges/badge-wall/index", + "pages/profile/favorites/index", + "pages/profile/posts/index" ], "window": { "backgroundTextStyle": "light", diff --git a/assets/icons/arrow-left.png b/assets/icons/arrow-left.png deleted file mode 100644 index da2775d..0000000 Binary files a/assets/icons/arrow-left.png and /dev/null differ diff --git a/assets/icons/book-open.png b/assets/icons/book-open.png deleted file mode 100644 index 270d9fe..0000000 Binary files a/assets/icons/book-open.png and /dev/null differ diff --git a/assets/icons/calendar.png b/assets/icons/calendar.png deleted file mode 100644 index d9186e0..0000000 Binary files a/assets/icons/calendar.png and /dev/null differ diff --git a/assets/icons/camera.png b/assets/icons/camera.png deleted file mode 100644 index 2c80455..0000000 Binary files a/assets/icons/camera.png and /dev/null differ diff --git a/assets/icons/check.png b/assets/icons/check.png deleted file mode 100644 index 3e02c2d..0000000 Binary files a/assets/icons/check.png and /dev/null differ diff --git a/assets/icons/chevron-right.png b/assets/icons/chevron-right.png deleted file mode 100644 index 33c08a5..0000000 Binary files a/assets/icons/chevron-right.png and /dev/null differ diff --git a/assets/icons/crown.png b/assets/icons/crown.png deleted file mode 100644 index 7988520..0000000 Binary files a/assets/icons/crown.png and /dev/null differ diff --git a/assets/icons/droplets.png b/assets/icons/droplets.png deleted file mode 100644 index 338cf4e..0000000 Binary files a/assets/icons/droplets.png and /dev/null differ diff --git a/assets/icons/file-text.png b/assets/icons/file-text.png deleted file mode 100644 index f98d984..0000000 Binary files a/assets/icons/file-text.png and /dev/null differ diff --git a/assets/icons/heart.png b/assets/icons/heart.png deleted file mode 100644 index d8bdf3f..0000000 Binary files a/assets/icons/heart.png and /dev/null differ diff --git a/assets/icons/help-circle.png b/assets/icons/help-circle.png deleted file mode 100644 index 0be30cc..0000000 Binary files a/assets/icons/help-circle.png and /dev/null differ diff --git a/assets/icons/image.png b/assets/icons/image.png deleted file mode 100644 index 900f3e1..0000000 Binary files a/assets/icons/image.png and /dev/null differ diff --git a/assets/icons/lock.png b/assets/icons/lock.png deleted file mode 100644 index f86b5cc..0000000 Binary files a/assets/icons/lock.png and /dev/null differ diff --git a/assets/icons/medal.png b/assets/icons/medal.png deleted file mode 100644 index a78b9cc..0000000 Binary files a/assets/icons/medal.png and /dev/null differ diff --git a/assets/icons/scan-line.png b/assets/icons/scan-line.png deleted file mode 100644 index c527065..0000000 Binary files a/assets/icons/scan-line.png and /dev/null differ diff --git a/assets/icons/scissors.png b/assets/icons/scissors.png deleted file mode 100644 index e42f020..0000000 Binary files a/assets/icons/scissors.png and /dev/null differ diff --git a/assets/icons/search.png b/assets/icons/search.png deleted file mode 100644 index ea69e1b..0000000 Binary files a/assets/icons/search.png and /dev/null differ diff --git a/assets/icons/settings.png b/assets/icons/settings.png deleted file mode 100644 index 149c1cf..0000000 Binary files a/assets/icons/settings.png and /dev/null differ diff --git a/assets/icons/shield.png b/assets/icons/shield.png deleted file mode 100644 index adc5c59..0000000 Binary files a/assets/icons/shield.png and /dev/null differ diff --git a/assets/icons/shovel.png b/assets/icons/shovel.png deleted file mode 100644 index 6b2f2d8..0000000 Binary files a/assets/icons/shovel.png and /dev/null differ diff --git a/assets/icons/star.png b/assets/icons/star.png deleted file mode 100644 index c167221..0000000 Binary files a/assets/icons/star.png and /dev/null differ diff --git a/assets/icons/trophy.png b/assets/icons/trophy.png deleted file mode 100644 index 391da9b..0000000 Binary files a/assets/icons/trophy.png and /dev/null differ diff --git a/assets/icons/x.png b/assets/icons/x.png deleted file mode 100644 index 662dc7f..0000000 Binary files a/assets/icons/x.png and /dev/null differ diff --git a/assets/icons/zap.png b/assets/icons/zap.png deleted file mode 100644 index 1a8d85f..0000000 Binary files a/assets/icons/zap.png and /dev/null differ diff --git a/assets/react.svg b/assets/react.svg deleted file mode 100644 index 6c87de9..0000000 --- a/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/pages/community/index.js b/pages/community/index.js index 15881fd..bc10d59 100644 --- a/pages/community/index.js +++ b/pages/community/index.js @@ -13,7 +13,9 @@ Page({ current: 1, pageSize: 10, hasMore: true, - userInfo: null + userInfo: null, + scrollTop: 0, + isRefreshing: false }, onLoad() { @@ -33,9 +35,16 @@ Page({ } }, - // Called by create post page + // Called by create post page or Pull Down onRefresh() { - this.fetchPosts(true); + this.setData({ isRefreshing: true }); + this.fetchPosts(true).then(() => { + this.setData({ isRefreshing: false }); + }); + }, + + onTabItemTap() { + this.setData({ scrollTop: Math.random() * 0.01 }); }, onPullDownRefresh() { @@ -60,7 +69,7 @@ Page({ try { // Correct API Endpoint and Params - const res = await request.post('/post/page', { current, pageSize }); + const res = await request.post('/post/page', { current, pageSize, hasReviewed: 1 }); // Handle response structure: { code: 200, data: { list: [], ... } } // OR if request.js unwraps it: { list: [], ... } @@ -79,14 +88,16 @@ Page({ content: item.content, images: (item.imgList || []).map(img => img.url), time: item.createdAtStr || '刚刚', - likes: (item.likeList || []).map(l => l.liker ? (l.liker.nickName || l.liker.name) : '花友'), + likes: item.hasLiked === 1 ? ['我'] : [], comments: (item.commentList || []).map(c => ({ id: c.id, user: c.commentator ? (c.commentator.nickName || c.commentator.name) : '花友', content: c.content })), likedByMe: item.hasLiked === 1, + isFavorited: item.hasStar === 1, likeCount: item.likeCount || 0, + stars: (item.starList || []).map(s => s.starer ? (s.starer.nickName || s.starer.name) : '花友'), commentCount: item.commentCount || 0, isExpanded: false }; @@ -125,12 +136,7 @@ Page({ // Preview image in full screen previewImage(e) { const { url, urls } = e.currentTarget.dataset; - const resolvedUrls = urls.map(img => { - if (img.indexOf('http') === 0 || img.indexOf('wxfile') === 0) { - return img; - } - return `/assets/${img}`; - }); + const resolvedUrls = urls.map(img => img); wx.previewImage({ current: url, @@ -169,10 +175,15 @@ Page({ try { await request.get('/post/like', { id: postId, type }); - // Optimistic Update: Only toggle button state. Do NOT modify likes list text. + // Optimistic Update const updatedPosts = this.data.posts.map(p => { if (p.id === postId) { - return { ...p, likedByMe: !p.likedByMe }; + const liked = !p.likedByMe; + return { + ...p, + likedByMe: liked, + likes: liked ? ['我'] : [] + }; } return p; }); @@ -192,6 +203,42 @@ Page({ } }, + // Collect post + async collectPost(e) { + const postId = e.currentTarget.dataset.id; + const post = this.data.posts.find(p => p.id === postId); + if (!post) return; + + const type = post.isFavorited ? 2 : 1; // 1: Collect, 2: Cancel + + try { + await request.get('/post/star', { id: postId, type }); + + // Optimistic Update + const updatedPosts = this.data.posts.map(p => { + if (p.id === postId) { + return { ...p, isFavorited: !p.isFavorited }; + } + return p; + }); + + this.setData({ + posts: updatedPosts, + displayedPosts: updatedPosts, + activePostId: null + }); + + // Refresh list to sync detailed data (like IDs if needed) + this.fetchPosts(true); + + wx.showToast({ title: type === 1 ? '已收藏' : '已取消', icon: 'success' }); + + } catch (err) { + console.error('Collect failed', err); + wx.showToast({ title: '操作失败', icon: 'none' }); + } + }, + // Show comment input bar showCommentInput(e) { const postId = e.currentTarget.dataset.id; diff --git a/pages/community/index.json b/pages/community/index.json index 46387a6..489d5eb 100644 --- a/pages/community/index.json +++ b/pages/community/index.json @@ -1,5 +1,5 @@ { - "navigationBarTitleText": "植友动态", + "navigationBarTitleText": "花友动态", "usingComponents": { "t-avatar": "tdesign-miniprogram/avatar/avatar", "t-image": "tdesign-miniprogram/image/image", diff --git a/pages/community/index.wxml b/pages/community/index.wxml index 913e5c1..ed6c89d 100644 --- a/pages/community/index.wxml +++ b/pages/community/index.wxml @@ -15,6 +15,11 @@ enhanced="{{true}}" show-scrollbar="{{false}}" bindtap="hideActionPopup" + scroll-top="{{scrollTop}}" + bindscrolltolower="onReachBottom" + refresher-enabled="{{true}}" + bindrefresherrefresh="onRefresh" + refresher-triggered="{{isRefreshing}}" > @@ -49,10 +54,15 @@ + + + {{item.isFavorited ? '取消' : '收藏'}} + + 评论 @@ -68,17 +78,26 @@ - + + + + 删除植物 + diff --git a/pages/plant-detail/index.wxss b/pages/plant-detail/index.wxss index 6df68ec..3cdcdca 100644 --- a/pages/plant-detail/index.wxss +++ b/pages/plant-detail/index.wxss @@ -811,3 +811,21 @@ page { font-weight: 500; color: #90A4AE; } + +.delete-plant-box { + display: flex; + align-items: center; + justify-content: center; + gap: 12rpx; + padding: 24rpx; + margin-top: 40rpx; + background: #FFF; + border-radius: 24rpx; + box-shadow: 0 4rpx 12rpx rgba(239, 83, 80, 0.1); +} + +.delete-text { + font-size: 28rpx; + color: #EF5350; + font-weight: 500; +} diff --git a/pages/profile/favorites/index.js b/pages/profile/favorites/index.js new file mode 100644 index 0000000..bce09e8 --- /dev/null +++ b/pages/profile/favorites/index.js @@ -0,0 +1,34 @@ +import request from '../../../utils/request'; + +Page({ + data: { + favTab: 'all', + favorites: [], + filteredFavorites: [] + }, + + onLoad() { + this.loadFavorites(); + }, + + loadFavorites() { + // TODO: Call API + this.filterFavorites(); + }, + + onFavTabChange(e) { + const val = e.currentTarget.dataset.value; + this.setData({ favTab: val }, () => { + this.filterFavorites(); + }); + }, + + filterFavorites() { + const { favorites, favTab } = this.data; + const filtered = favorites.filter(item => { + if (favTab === 'all') return true; + return item.type === favTab; + }); + this.setData({ filteredFavorites: filtered }); + } +}); diff --git a/pages/profile/favorites/index.json b/pages/profile/favorites/index.json new file mode 100644 index 0000000..892735f --- /dev/null +++ b/pages/profile/favorites/index.json @@ -0,0 +1,7 @@ +{ + "navigationBarTitleText": "我的收藏", + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-image": "tdesign-miniprogram/image/image" + } +} \ No newline at end of file diff --git a/pages/profile/favorites/index.wxml b/pages/profile/favorites/index.wxml new file mode 100644 index 0000000..8d19ef4 --- /dev/null +++ b/pages/profile/favorites/index.wxml @@ -0,0 +1,27 @@ + + + 全部 + 植物 + 文章 + + + + + + + + {{item.name}} + + + {{item.meta}} + + + + + + + 暂无收藏内容 + + + + diff --git a/pages/profile/favorites/index.wxss b/pages/profile/favorites/index.wxss new file mode 100644 index 0000000..eba094b --- /dev/null +++ b/pages/profile/favorites/index.wxss @@ -0,0 +1,98 @@ +.favorites-page { + background: #F4F6F0; + height: 100vh; + padding: 24rpx; + box-sizing: border-box; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.category-filter { + display: flex; + gap: 16rpx; + margin-bottom: 24rpx; +} + +.filter-chip { + padding: 12rpx 32rpx; + background: #fff; + border: 2rpx solid transparent; + border-radius: 40rpx; + font-size: 26rpx; + color: #6B7280; + transition: all 0.2s; + font-weight: 500; +} + +.filter-chip.active { + background: #333; + color: #fff; + font-weight: 600; + box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.1); +} + +.fav-scroll { + flex: 1; + height: 0; + width: 100%; +} + +.fav-grid { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 20rpx; +} + +.fav-card { + background: white; + border-radius: 20rpx; + overflow: hidden; + box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.03); + display: flex; + flex-direction: column; +} + +.fav-img { + background: #f0f0f0; +} + +.fav-info { + padding: 16rpx 20rpx; +} + +.fav-name { + display: block; + font-size: 28rpx; + font-weight: 600; + color: #1F2937; + margin-bottom: 8rpx; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} + +.fav-meta-row { + display: flex; + align-items: center; + gap: 8rpx; +} + +.fav-type { + font-size: 22rpx; + color: #9CA3AF; +} + +.empty-state { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 120rpx 0; +} + +.empty-text { + font-size: 28rpx; + color: #9CA3AF; + margin-top: 16rpx; +} diff --git a/pages/profile/index.js b/pages/profile/index.js index 1dd2e9c..8ea62da 100644 --- a/pages/profile/index.js +++ b/pages/profile/index.js @@ -29,7 +29,9 @@ Page({ myDrafts: [], // App version - appVersion: '1.0.0' + // App version + appVersion: '1.0.0', + scrollTop: 0 }, onLoad() { @@ -44,6 +46,13 @@ Page({ this.loadUserInfo(); }, + onTabItemTap() { + this.setData({ + view: 'profile', + scrollTop: Math.random() * 0.01 + }); + }, + // ======== User Info ======== loadUserInfo() { request.get('/profile/detail').then(res => { @@ -57,6 +66,7 @@ Page({ this.setData({ userName: res.nickname || '植物爱好者', userAvatar: avatarUrl, + currentAvatarId: res.avatarId || (res.avatar ? res.avatar.id : ''), // Stats plantCount: res.plantCount || 0, @@ -88,127 +98,16 @@ Page({ // ======== Navigation ======== - setView(e) { - const view = e.currentTarget.dataset.view; - this.setData({ view }); - - if (view === 'favorites') { - this.loadFavorites(); - } else if (view === 'posts') { - this.loadMyPosts(); - this.loadDrafts(); - } - }, - goBack() { this.setData({ view: 'profile' }); }, - // ======== Favorites ======== - loadFavorites() { - // TODO: Call favorites API when available - // request.get('/user/favorites').then(...) - this.filterFavorites(); + goToFavorites() { + wx.navigateTo({ url: '/pages/profile/favorites/index' }); }, - onFavTabChange(e) { - this.setData({ favTab: e.detail.value }, () => { - this.filterFavorites(); - }); - }, - - filterFavorites() { - const { favorites, favTab } = this.data; - const filtered = favorites.filter(item => { - if (favTab === 'all') return true; - return item.type === favTab; - }); - this.setData({ filteredFavorites: filtered }); - }, - - // ======== Posts ======== - loadMyPosts() { - request.post('/post/page', { current: 1, pageSize: 50, onlyMine: true }).then(res => { - const records = res.records || res.list || []; - const posts = records.map(item => { - const publisher = item.publisher || {}; - const imgList = item.imgList || []; - return { - id: item.id, - content: item.content || '', - time: this._formatTime(item.createdAt || item.createTime), - images: imgList.map(img => img.url), - likes: item.likeList || [], - comments: item.commentList || [] - }; - }); - this.setData({ myPublishedPosts: posts }); - }).catch(() => { - this.setData({ myPublishedPosts: [] }); - }); - }, - - loadDrafts() { - try { - const draft = wx.getStorageSync('post_draft'); - if (draft && (draft.content || (draft.images && draft.images.length > 0))) { - this.setData({ - myDrafts: [{ - id: 'draft_1', - content: draft.content || '', - images: draft.images || [], - selectedTopics: draft.selectedTopics || [] - }] - }); - } else { - this.setData({ myDrafts: [] }); - } - } catch (e) { - this.setData({ myDrafts: [] }); - } - }, - - onPostsTabChange(e) { - this.setData({ postsTab: e.detail.value }); - }, - - deletePost(e) { - const postId = e.currentTarget.dataset.id; - wx.showModal({ - title: '删除动态', - content: '确定要删除这条动态吗?', - confirmColor: '#EF5350', - success: (res) => { - if (!res.confirm) return; - wx.showLoading({ title: '删除中...' }); - request.get('/post/delete', { id: postId }).then(() => { - wx.hideLoading(); - this.loadMyPosts(); - wx.showToast({ title: '已删除', icon: 'success' }); - }).catch(() => { - wx.hideLoading(); - wx.showToast({ title: '删除失败', icon: 'none' }); - }); - } - }); - }, - - editDraft() { - wx.navigateTo({ url: '/pages/community/create/index' }); - }, - - deleteDraft() { - wx.showModal({ - title: '删除草稿', - content: '确定要删除这份草稿吗?', - confirmColor: '#EF5350', - success: (res) => { - if (!res.confirm) return; - try { wx.removeStorageSync('post_draft'); } catch (e) { } - this.setData({ myDrafts: [] }); - wx.showToast({ title: '已删除', icon: 'success' }); - } - }); + goToPosts() { + wx.navigateTo({ url: '/pages/profile/posts/index' }); }, // ======== Menu Actions ======== @@ -284,10 +183,12 @@ Page({ }, async saveProfile() { - const { tempAvatar, tempNickname, userName, userAvatar } = this.data; + const { tempAvatar, tempNickname, userName, userAvatar, currentAvatarId } = this.data; - // Check if anything changed - const isNameChanged = tempNickname && tempNickname !== userName; + // Determine if there are changes + // tempNickname might be undefined if user didn't edit nickname input + const finalNickname = tempNickname !== undefined ? tempNickname : userName; + const isNameChanged = finalNickname !== userName; const isAvatarChanged = tempAvatar && tempAvatar !== userAvatar; if (!isNameChanged && !isAvatarChanged) { @@ -295,61 +196,65 @@ Page({ return; } + if (!finalNickname.trim()) { + wx.showToast({ title: '昵称不能为空', icon: 'none' }); + return; + } + wx.showLoading({ title: '保存中...', mask: true }); try { - const updatePayload = {}; + let finalAvatarId = currentAvatarId; - // 1. Upload avatar if changed + // Upload new avatar if changed if (isAvatarChanged) { const uploadRes = await request.upload(tempAvatar); - // Correctly extract ID from file object based on known API response - let fileId = ''; if (uploadRes && uploadRes.file && uploadRes.file.id) { - fileId = uploadRes.file.id; + finalAvatarId = uploadRes.file.id; } else if (uploadRes && uploadRes.id) { - fileId = uploadRes.id; - } - - if (fileId) { - updatePayload.avatarId = fileId; + finalAvatarId = uploadRes.id; + } else { + throw new Error('Avatar upload failed, no ID returned'); } } - // 2. Set nickname if changed - if (isNameChanged) { - updatePayload.nickname = tempNickname; - } + // Construct Full Payload + const updatePayload = { + nickname: finalNickname, + avatarId: finalAvatarId + }; - // 3. Call update API - if (Object.keys(updatePayload).length > 0) { - await request.post('/profile/update', updatePayload); - } + // Call API + await request.post('/profile/update', updatePayload); - wx.hideLoading(); - - // 4. Update local state + // Update UI State this.setData({ - userName: tempNickname || userName, - userAvatar: tempAvatar || userAvatar, // Use tempAvatar for immediate display + userName: finalNickname, + userAvatar: tempAvatar || userAvatar, + currentAvatarId: finalAvatarId, showProfileEditor: false }); wx.showToast({ title: '资料已更新', icon: 'success' }); - // 5. Update globalData + // Update Global Data const userInfo = app.globalData.userInfo || {}; - if (updatePayload.nickname) userInfo.name = updatePayload.nickname; - if (updatePayload.avatarId) userInfo.avatarId = updatePayload.avatarId; - // Also update URL if we have it locally? - // Better to re-fetch profile to get canonical URL, but optimistic update is fine. - userInfo.avatar = tempAvatar; + userInfo.nickname = finalNickname; + userInfo.name = finalNickname; + // Update avatar structure in global store too + if (isAvatarChanged) { + userInfo.avatar = { ...(userInfo.avatar || {}), url: tempAvatar, id: finalAvatarId }; + } + userInfo.avatarId = finalAvatarId; + app.globalData.userInfo = userInfo; + wx.setStorageSync('userInfo', userInfo); } catch (err) { - wx.hideLoading(); console.error('Save profile failed', err); wx.showToast({ title: '保存失败', icon: 'none' }); + } finally { + wx.hideLoading(); } }, diff --git a/pages/profile/index.wxml b/pages/profile/index.wxml index 032fe05..dd3a2c7 100644 --- a/pages/profile/index.wxml +++ b/pages/profile/index.wxml @@ -1,70 +1,7 @@ - - - - - 我的收藏 - - - - 全部 - 植物 - 文章 - - - - - - - - {{item.name}} - - - {{item.meta}} - - - - - - 暂无收藏内容 - - - - - - - - - 我的发布 - - - - - {{item.time}} - - {{item.content}} - - - - - - - - - - - - + 关于我们 @@ -134,12 +71,12 @@ - + 常用功能 - + @@ -149,7 +86,7 @@ - + diff --git a/pages/profile/posts/index.js b/pages/profile/posts/index.js new file mode 100644 index 0000000..b398fca --- /dev/null +++ b/pages/profile/posts/index.js @@ -0,0 +1,123 @@ +import request from '../../../utils/request'; + +Page({ + data: { + myPublishedPosts: [], + current: 1, + pageSize: 10, + hasMore: true, + isLoading: false, + isRefreshing: false + }, + + onLoad() { + this.loadMyPosts(true); + }, + + onPullDownRefresh() { + if (this.data.isLoading) return; + this.setData({ isRefreshing: true }); + this.loadMyPosts(true).then(() => { + this.setData({ isRefreshing: false }); + }); + }, + + onReachBottom() { + if (this.data.hasMore && !this.data.isLoading) { + this.loadMyPosts(false); + } + }, + + async loadMyPosts(reset = false) { + if (this.data.isLoading) return; + this.setData({ isLoading: true }); + + const current = reset ? 1 : this.data.current; + const { pageSize } = this.data; + + try { + const res = await request.post('/post/myPost', { + current, + pageSize + }); + + const data = res.data || res || {}; + const records = data.records || data.list || []; + + const posts = records.map(item => { + const imgList = item.imgList || []; + return { + id: item.id, + content: item.content || '', + time: this._formatTime(item.createdAt || item.createTime), + images: imgList.map(img => img.url), + likes: item.likeList || [], + comments: item.commentList || [], + hasReviewed: item.hasReviewed + }; + }); + + if (reset) { + this.setData({ + myPublishedPosts: posts, + current: current + 1, + hasMore: posts.length >= pageSize, + isLoading: false + }); + } else { + this.setData({ + myPublishedPosts: [...this.data.myPublishedPosts, ...posts], + current: current + 1, + hasMore: posts.length >= pageSize, + isLoading: false + }); + } + } catch (err) { + console.error('Load my posts failed', err); + this.setData({ isLoading: false }); + wx.showToast({ title: '加载失败', icon: 'none' }); + } + }, + + _formatTime(dateStr) { + if (!dateStr) return ''; + const d = new Date(dateStr); + const now = new Date(); + const diffMs = now - d; + const diffMin = Math.floor(diffMs / 60000); + if (diffMin < 1) return '刚刚'; + if (diffMin < 60) return diffMin + '分钟前'; + const diffHour = Math.floor(diffMin / 60); + if (diffHour < 24) return diffHour + '小时前'; + const diffDay = Math.floor(diffHour / 24); + if (diffDay < 7) return diffDay + '天前'; + const month = (d.getMonth() + 1).toString().padStart(2, '0'); + const day = d.getDate().toString().padStart(2, '0'); + return `${month}-${day}`; + }, + + deletePost(e) { + const postId = e.currentTarget.dataset.id; + wx.showModal({ + title: '删除动态', + content: '确定要删除这条动态吗?', + confirmColor: '#EF5350', + success: (res) => { + if (!res.confirm) return; + wx.showLoading({ title: '删除中...' }); + + // Use new API: POST /post/delete with ids array + request.post('/post/delete', { ids: [postId] }).then(() => { + wx.hideLoading(); + wx.showToast({ title: '已删除', icon: 'success' }); + // Remove from list locally + const newList = this.data.myPublishedPosts.filter(p => p.id !== postId); + this.setData({ myPublishedPosts: newList }); + }).catch(() => { + wx.hideLoading(); + wx.showToast({ title: '删除失败', icon: 'none' }); + }); + } + }); + } +}); diff --git a/pages/profile/posts/index.json b/pages/profile/posts/index.json new file mode 100644 index 0000000..348452e --- /dev/null +++ b/pages/profile/posts/index.json @@ -0,0 +1,8 @@ +{ + "navigationBarTitleText": "我的发布", + "disableScroll": true, + "usingComponents": { + "t-icon": "tdesign-miniprogram/icon/icon", + "t-image": "tdesign-miniprogram/image/image" + } +} \ No newline at end of file diff --git a/pages/profile/posts/index.wxml b/pages/profile/posts/index.wxml new file mode 100644 index 0000000..8449762 --- /dev/null +++ b/pages/profile/posts/index.wxml @@ -0,0 +1,42 @@ + + + + + {{item.time}} + + + 待审核 + 已发布 + + {{item.content}} + + + + + + + + + + 暂无发布内容 + + + + diff --git a/pages/profile/posts/index.wxss b/pages/profile/posts/index.wxss new file mode 100644 index 0000000..9e532a8 --- /dev/null +++ b/pages/profile/posts/index.wxss @@ -0,0 +1,170 @@ +.posts-page { + background: #F4F6F0; + height: 100vh; + padding: 32rpx 32rpx 0; + box-sizing: border-box; + display: flex; + flex-direction: column; + overflow: hidden; +} + +.sub-scroll { + flex: 1; + height: 0; /* Crucial for scrolling in flex layout */ + width: 100%; +} + +.posts-list { + position: relative; + padding-bottom: 60rpx; +} + +/* Timeline Line */ +.posts-list::before { + content: ''; + position: absolute; + top: 40rpx; + bottom: 40rpx; + left: 112rpx; /* Adjust based on time width */ + width: 2rpx; + background: #E0E0E0; + z-index: 0; +} + +.my-post-card { + display: flex; + gap: 32rpx; + margin-bottom: 48rpx; + position: relative; + z-index: 1; +} + +/* Time Column */ +.my-post-time { + width: 100rpx; + flex-shrink: 0; + font-size: 26rpx; + color: #90A4AE; + font-weight: 700; + text-align: right; + padding-top: 28rpx; + position: relative; +} + +/* Timeline Dot */ +.my-post-time::after { + content: ''; + position: absolute; + top: 40rpx; + right: -24rpx; /* Center on line */ + width: 16rpx; + height: 16rpx; + background: #fff; + border: 4rpx solid #CFD8DC; + border-radius: 50%; + z-index: 2; + box-shadow: 0 0 0 4rpx #F4F6F0; /* Outline mask */ +} + +/* Highlight dot for today/recent? Optional */ + +/* Content Card */ +.my-post-content-wrap { + flex: 1; + background: #fff; + border-radius: 28rpx; + box-shadow: 0 8rpx 24rpx rgba(0,0,0,0.03); + padding: 32rpx; + position: relative; + overflow: hidden; + transition: all 0.2s; +} + +.my-post-content-wrap:active { + transform: scale(0.98); +} + +/* Post Text */ +.post-text { + font-size: 30rpx; + color: #374151; + line-height: 1.6; + margin-bottom: 24rpx; + display: block; + min-height: 48rpx; + margin-top: 8rpx; +} + +/* Status Tags - Corner Style */ +.status-tag { + position: absolute; + top: 0; + right: 0; + padding: 8rpx 20rpx; + font-size: 22rpx; + font-weight: 700; + border-bottom-left-radius: 24rpx; + z-index: 10; + box-shadow: -4rpx 4rpx 12rpx rgba(0,0,0,0.05); +} + +.status-tag.pending { + background: #FFF8E1; + color: #F57C00; +} + +.status-tag.success { + background: #E8F5E9; + color: #388E3C; +} + +/* Images */ +.my-post-images { + display: flex; + flex-wrap: wrap; + gap: 12rpx; + margin-bottom: 24rpx; +} + +/* Footer */ +.my-post-footer { + display: flex; + align-items: center; + border-top: 2rpx solid #F9FAFB; + padding-top: 24rpx; + margin-top: 12rpx; +} + +.footer-item { + display: flex; + align-items: center; + gap: 8rpx; + font-size: 24rpx; + color: #9CA3AF; + margin-right: 32rpx; +} + +/* Empty State */ +.empty-state { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + padding: 160rpx 0; +} + +.empty-text { + font-size: 28rpx; + color: #B0BEC5; + margin-top: 24rpx; +} + + + +/* Hide Scrollbar Globally */ +::-webkit-scrollbar { + width: 0; + height: 0; + color: transparent; + display: none; +} diff --git a/pages/tasks/index.js b/pages/tasks/index.js index 814aa7b..8b7a406 100644 --- a/pages/tasks/index.js +++ b/pages/tasks/index.js @@ -7,11 +7,20 @@ Page({ groupedTasks: [], progress: 0, completingTask: null, - remark: '' + remark: '', + remarkPlaceholder: '', + scrollTop: 0, + + // Reward Modals + showLevelUpModal: false, + levelUpData: null, + showBadgeModal: false, + badgeData: null }, onLoad() { this.fetchTodayTasks(); + this._popupQueue = []; }, onShow() { @@ -23,6 +32,42 @@ Page({ this.fetchTodayTasks(); }, + // ... (fetchTodayTasks, processTaskData Omitted) ... + + // Reward Queue Processing + processPopupQueue() { + if (this._popupQueue.length === 0) return; + + const next = this._popupQueue[0]; + if (next.type === 'level') { + this.setData({ + levelUpData: next.data, + showLevelUpModal: true + }); + } else if (next.type === 'badge') { + this.setData({ + badgeData: next.data, + showBadgeModal: true + }); + } + }, + + closeLevelUpModal() { + this.setData({ showLevelUpModal: false }); + this._popupQueue.shift(); + setTimeout(() => { + this.processPopupQueue(); + }, 300); + }, + + closeBadgeModal() { + this.setData({ showBadgeModal: false }); + this._popupQueue.shift(); + setTimeout(() => { + this.processPopupQueue(); + }, 300); + }, + fetchTodayTasks() { request.get('/plant/todayTask').then(res => { // Check if res is array (list of PlantTaskVO) @@ -45,12 +90,7 @@ Page({ // Parse Image let imageUrl = ''; if (plant.imgList && plant.imgList.length > 0) { - let url = plant.imgList[0].url; - if (url && !url.startsWith('http') && !url.startsWith('/') && !url.startsWith('wxfile')) { - imageUrl = '/assets/' + url; - } else { - imageUrl = url; - } + imageUrl = plant.imgList[0].url || ''; } const plantGroup = { @@ -149,9 +189,36 @@ Page({ handleTaskClick(e) { const task = e.currentTarget.dataset.task; if (task.isCompleted) return; + + // Compute placeholder based on task type or name + let placeholder = '添加备注 (可选)...'; + // Get name from taskIcon first, then name. + // name from backend is usually the name (e.g. "浇水"). + const typeRaw = (task.taskIcon ? task.taskIcon.name : task.name) || ''; + const typeStr = typeRaw.toLowerCase(); + + if (typeStr.includes('浇水')) { + placeholder = '例如:浇了 200ml 水...'; + } else if (typeStr.includes('施肥')) { + placeholder = '例如:施了通用液肥...'; + } else if (typeStr.includes('修剪')) { + placeholder = '例如:修剪了枯叶和黄叶...'; + } else if (typeStr.includes('换盆')) { + placeholder = '例如:更换了陶盆,加了底肥...'; + } else if (typeStr.includes('换土')) { + placeholder = '例如:更换了新配方土...'; + } else if (typeStr.includes('喷雾')) { + placeholder = '例如:给叶面喷了水...'; + } else if (typeStr.includes('用药') || typeStr.includes('虫')) { + placeholder = '例如:喷洒了杀虫剂...'; + } else if (typeStr.includes('晒太阳') || typeStr.includes('日照')) { + placeholder = '例如:晒了 2 小时太阳...'; + } + this.setData({ completingTask: task, - remark: '' + remark: '', + remarkPlaceholder: placeholder }); }, @@ -172,16 +239,29 @@ Page({ const taskId = this.data.completingTask.id; const remark = this.data.remark || ''; - // Optimistic Update immediately for better feel? - // Or wait for server? Wait is safer. wx.showLoading({ title: '提交中...', mask: true }); request.post('/plant/completeTask', { taskId: taskId, remark: remark - }).then(() => { + }).then(res => { wx.hideLoading(); + // Handle Rewards + const queue = []; + // Check if res has level up or badge data + // Note: res is already data.data from request.js + if (res && res.isLevelUp && res.currentLevel) { + queue.push({ type: 'level', data: res.currentLevel }); + } + + // Check for Badge using IsGetBadge flag (allowing for casing variance) + if (res && (res.IsGetBadge === true || res.isGetBadge === true) && res.newBadge) { + queue.push({ type: 'badge', data: res.newBadge }); + } + + this._popupQueue = queue; + // Optimistic UI Update Logic const groups = this.data.groupedTasks; let updated = false; @@ -208,10 +288,14 @@ Page({ showSunshine: true }); - // Hide Animation after duration + // Hide Animation after duration and Start showing modals setTimeout(() => { this.setData({ showSunshine: false }); - }, 3000); + // Show rewards after sunshine animation + if (this._popupQueue.length > 0) { + this.processPopupQueue(); + } + }, 1000); // 1.0s delay usually covers animation // Sync with backend silently this.fetchTodayTasks(); @@ -227,5 +311,9 @@ Page({ wx.switchTab({ url: '/pages/garden/index' }); + }, + + onTabItemTap() { + this.setData({ scrollTop: Math.random() * 0.01 }); } }) diff --git a/pages/tasks/index.wxml b/pages/tasks/index.wxml index e24f822..464c19c 100644 --- a/pages/tasks/index.wxml +++ b/pages/tasks/index.wxml @@ -44,7 +44,7 @@ 去看看花园 - + @@ -85,7 +85,7 @@ - + 确认完成任务 @@ -110,7 +110,7 @@ 添加记录备注 (可选)