同步小程序与管理端更新,完善抽烟记录和解绑冷静期

This commit is contained in:
2026-10-09 22:15:51 +08:00
parent a68a4ef411
commit b10fc3c4ac
149 changed files with 3794 additions and 589 deletions
+22 -19
View File
@@ -1,36 +1,34 @@
const { withDataCache } = require('../../utils/page-cache');
const { getLayout } = require('../../utils/layout');
// pages/discover/discover.js
const { api } = require('../../utils/request');
const { diaryEntry, albumEntry, memoryEntry } = require('../../utils/journal');
const { saveScrollPosition, getScrollPosition } = require('../../utils/scroll-pos');
const { saveScrollPosition, resetScrollOnTabShow } = require('../../utils/scroll-pos');
Page({
Page(withDataCache({
onResize: function() { this.setData(getLayout()); },
data: {
stats: null, loading: true, loadError: false, refreshing: false, publishOpen: false,
activeFilter: 'diary', filters: [{value:'diary',label:'日记'}, {value:'album',label:'相册'}, {value:'memory',label:'记忆日'}],
activeFilter: 'diary', filters: [{value:'diary',label:'日记',icon:'stat-book'}, {value:'album',label:'相册',icon:'stat-album'}, {value:'memory',label:'记忆日',icon:'stat-timeline'}],
entries: [], albums: [], memories: [],
scrollTop: 0
},
onLoad: function() {
this.setData(getLayout());
this.setData({ scrollTop: getScrollPosition('discover') });
this.setData({ scrollTop: 0 });
},
onShow: function() {
// 延迟设置 scrollTop,确保 scroll-view 在页面显示后重新应用滚动位置
// 解决从子页面 navigateBack 返回后滚动位置丢失的问题
var self = this;
var savedTop = getScrollPosition('discover');
this.setData({ scrollTop: savedTop });
setTimeout(function() {
self.setData({ scrollTop: savedTop });
}, 100);
resetScrollOnTabShow(this, 'discover');
const tabBar = this.getTabBar && this.getTabBar();
if (tabBar) tabBar.syncActive();
this._syncPublishTabBar();
this.loadStats();
},
// 保存滚动位置
onScroll: function(e) {
this._scrollTop = e.detail.scrollTop;
saveScrollPosition('discover', e.detail.scrollTop);
},
@@ -42,7 +40,7 @@ Page({
loadStats: async function() {
if (this._loading) return;
this._loading = true;
this.setData({loading:true, loadError:false});
this.setData({loading: !this._hasCachedData, loadError:false});
try {
const [timeline, album, diary] = await Promise.all([
@@ -68,8 +66,13 @@ Page({
onRefresh: async function() { this.setData({refreshing:true}); try { await this.loadStats(); } finally { this.setData({refreshing:false}); } },
selectFilter: function(e) { this.setData({activeFilter:e.currentTarget.dataset.filter}); },
showPublish: function() { this.setData({publishOpen:true}); },
hidePublish: function() { this.setData({publishOpen:false}); },
_syncPublishTabBar: function() {
const tabBar = this.getTabBar && this.getTabBar();
if (tabBar && tabBar.setHidden) tabBar.setHidden(this.data.publishOpen);
},
showPublish: function() { this.setData({publishOpen:true}); this._syncPublishTabBar(); },
hidePublish: function() { this.setData({publishOpen:false}); this._syncPublishTabBar(); },
onHide: function() { this.hidePublish(); },
noop: function() {}, preventMove: function() {},
_publish: function(type) { this.hidePublish(); this._savePosBeforeLeave(); wx.navigateTo({url:'/pages/publish/publish?type=' + type}); },
writeDiary: function() { this._publish('diary'); },
@@ -80,13 +83,13 @@ Page({
openAlbum: function(e) { this._savePosBeforeLeave(); wx.navigateTo({url:'/pages/album/album?album_id=' + e.currentTarget.dataset.id}); },
// 跳转前保存当前滚动位置
_savePosBeforeLeave: function() {
saveScrollPosition('discover', this.data.scrollTop);
saveScrollPosition('discover', this._scrollTop == null ? this.data.scrollTop : this._scrollTop);
},
// Tab 导航(替换,不留栈)
goHome: function() { this._savePosBeforeLeave(); wx.redirectTo({ url: '/pages/index/index' }); },
goHome: function() { this._savePosBeforeLeave(); wx.switchTab({ url: '/pages/index/index' }); },
goToDiaryFromDiscover: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/diary/diary?from=discover' }); },
goToProfile: function() { this._savePosBeforeLeave(); wx.redirectTo({ url: '/pages/profile/profile' }); },
goToProfile: function() { this._savePosBeforeLeave(); wx.switchTab({ url: '/pages/profile/profile' }); },
// 功能入口(推入栈,支持左滑返回)
goToTimeline: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/timeline/timeline' }); },
@@ -99,4 +102,4 @@ Page({
this._savePosBeforeLeave();
wx.navigateTo({ url: '/pages/period/period' });
}
});
}, {"loadStats": ["timelineList", "albumList", "diaryList"]}));