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

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
+30 -23
View File
@@ -1,10 +1,13 @@
let lastLocationReport = 0;
let locationReportUser = null;
const { withDataCache } = require('../../utils/page-cache');
const { getLayout } = require('../../utils/layout');
// pages/index/index.js
const { api, getImageUrl } = require('../../utils/request');
const { diaryEntry } = 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: {
userId: null,
@@ -42,26 +45,22 @@ Page({
this.setData({
userId: wx.getStorageSync('userId'),
coupleId: wx.getStorageSync('coupleId'),
scrollTop: getScrollPosition('index')
scrollTop: 0
});
this.loadBg();
this.loadData();
},
onShow: function() {
var self = this;
var savedTop = getScrollPosition('index');
resetScrollOnTabShow(this, 'index');
const tabBar = this.getTabBar && this.getTabBar();
if (tabBar) tabBar.syncActive();
var prevCoupleId = this.data.coupleId;
var curCoupleId = wx.getStorageSync('coupleId');
this.setData({
userId: wx.getStorageSync('userId'),
coupleId: curCoupleId,
scrollTop: savedTop
coupleId: curCoupleId
});
// 延迟重新设置 scrollTop,解决从子页面 navigateBack 返回后滚动位置丢失的问题
setTimeout(function() {
self.setData({ scrollTop: savedTop });
}, 100);
// 检查是否已被解绑(之前有 coupleId 但被清除了)
if (prevCoupleId && !curCoupleId) {
wx.reLaunch({ url: '/pages/index/index' });
@@ -74,6 +73,7 @@ Page({
// 保存滚动位置
onScroll: function(e) {
this._scrollTop = e.detail.scrollTop;
saveScrollPosition('index', e.detail.scrollTop);
},
@@ -166,7 +166,8 @@ Page({
if (nb < t) nb.setFullYear(nb.getFullYear()+1);
var c = Math.ceil((nb - t) / 86400000);
if (c === 0) return '今天!';
if (c === 1) return '明天';
if (c === 1) return '1天';
if (!Number.isFinite(c)) return '';
return c + '天';
}
@@ -182,6 +183,7 @@ Page({
}
var dn = {
coupleId: info.id,
daysCount: daysCount,
daysLabel: '我们在一起',
datePrefix: '始于',
@@ -203,7 +205,7 @@ Page({
await this.loadStats();
} catch (e) {
this.setData({ homeError: true, relationshipKnown: false, statsLoading: false, statsError: true, recentDiary: [], recentAlbums: [], upcomingMemory: null });
this.setData({ homeError: true, relationshipKnown: !!this._hasCachedData, statsLoading: false, statsError: true });
console.error(e);
} finally {
@@ -212,11 +214,12 @@ Page({
},
loadStats: async function() {
this.setData({ statsLoading: true, statsError: false });
this.setData({ statsLoading: !this._hasCachedData, statsError: false });
try {
const [timeline, album, diary, songs, checkin, pet] = await Promise.all([
api.timelineList(), api.albumList(), api.diaryList(),
api.songsList(), api.checkinList(), api.petInfo()
api.songsList(), api.checkinList(),
this.data.coupleId ? api.petInfo() : Promise.resolve({ has_pet: false })
]);
var photoCount = 0;
if (Array.isArray(album)) {
@@ -245,11 +248,15 @@ Page({
pet: petLevel
}
});
} catch (e) { console.error(e); this.setData({ statsError: true, recentDiary: [], recentAlbums: [], upcomingMemory: null }); } finally { this.setData({ statsLoading: false }); }
} catch (e) { console.error(e); this.setData({ statsError: true }); } finally { this.setData({ statsLoading: false }); }
},
// 获取本机经纬度并上报后端解析地址(后端按距离判断是否重新解析,超过5km才更新),并刷新首页双方地址显示
fetchIpLocation: function() {
const locationUser = wx.getStorageSync('userId');
if (locationReportUser === locationUser && Date.now() - lastLocationReport < 300000) return;
locationReportUser = locationUser;
lastLocationReport = Date.now();
var self = this;
var report = function(lat, lng) {
var data = {};
@@ -258,7 +265,7 @@ Page({
if (resp && resp.location) {
self.loadData();
}
}).catch(function() {});
}).catch(function() { lastLocationReport = 0; });
};
// 优先用模糊定位获取经纬度(getFuzzyLocation 与 getLocation 互斥,统一用模糊定位)
if (wx.getFuzzyLocation) {
@@ -279,32 +286,32 @@ Page({
// 背景图以接口返回为准
loadBg: function() {
var self = this;
api.getBgConfig().then(function(cfg) {
return api.getBgConfig().then(function(cfg) {
self.setData({ bgImage: cfg && cfg.image ? getImageUrl(cfg.image) : '' });
}).catch(function(e){ console.warn('loadBg error:', e && (e.error || e._statusCode || e)); });
},
// 跳转前保存当前滚动位置
_savePosBeforeLeave: function() {
saveScrollPosition('index', this.data.scrollTop);
saveScrollPosition('index', this._scrollTop == null ? this.data.scrollTop : this._scrollTop);
},
// 页面跳转
goToDiary: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/diary/diary' }); },
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' }); },
goToAlbum: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/albums/albums' }); },
goToSongs: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/lovewords/lovewords' }); },
goToCheckin: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/punch/punch' }); },
goToPet: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/pet/pet' }); },
goToPeriod: function() { this._savePosBeforeLeave(); wx.navigateTo({ url: '/pages/period/period' }); },
bindPartner: function() { wx.reLaunch({ url: '/pages/profile/profile?bind=1' }); },
bindPartner: function() { getApp().globalData.openProfileBind = true; wx.switchTab({ url: '/pages/profile/profile' }); },
openJournalEntry: function(e) { wx.navigateTo({ url: '/pages/diary_detail/diary_detail?id=' + e.currentTarget.dataset.id }); },
writeDiary: function() { wx.navigateTo({ url: '/pages/publish/publish?type=diary' }); },
openAlbumPreview: function(e) { wx.navigateTo({ url: '/pages/album/album?album_id=' + e.currentTarget.dataset.id }); },
openRecentDiary: function(e) { wx.navigateTo({ url: '/pages/diary_detail/diary_detail?id=' + e.currentTarget.dataset.id }); },
showMore: function() {
wx.reLaunch({ url: '/pages/discover/discover' });
wx.switchTab({ url: '/pages/discover/discover' });
},
onPullDownRefresh: async function() {
await this.loadData();
@@ -339,4 +346,4 @@ Page({
imageUrl: '/images/share.png'
};
}
});
}, {"loadData": ["coupleInfo", "timelineList", "albumList", "diaryList", "songsList", "checkinList", "petInfo", "getBgConfig"]}));