const { tryLoginRenewal } = require('../../utils/subscribe'); const { getLayout } = require('../../utils/layout'); // pages/history/history.js const { api } = require('../../utils/request'); // 操作类型对应的图标和颜色 var ACTION_CONFIG = { login: { icon: '🔓', color: '#82B1FF', label: '登录' }, timeline_create: { icon: '📅', color: '#FF8A65', label: '记忆日' }, timeline_update: { icon: '✏️', color: '#FF8A65', label: '记忆日' }, album_create: { icon: '📷', color: '#66BB6A', label: '相册' }, photo_upload: { icon: '🖼️', color: '#66BB6A', label: '照片' }, diary_create: { icon: '📝', color: '#FF6B9D', label: '日记' }, diary_update: { icon: '✏️', color: '#FF6B9D', label: '日记' }, song_add: { icon: '🎵', color: '#AB47BC', label: '歌曲' }, checkin_do: { icon: '✅', color: '#42A5F5', label: '打卡' }, profile_edit: { icon: '👤', color: '#FFA726', label: '资料' }, partner_edit: { icon: '💑', color: '#FFA726', label: '资料' }, couple_edit: { icon: '💕', color: '#EC407A', label: '纪念日' }, unbind_request: { icon: '💔', color: '#EF5350', label: '解绑' }, unbind_agreed: { icon: '💔', color: '#EF5350', label: '解绑' }, unbind_rejected: { icon: '💖', color: '#EF5350', label: '解绑' }, unbind_cancelled: { icon: '↩️', color: '#EF5350', label: '解绑' }, }; Page({ onLoginSubscribeTap: function() { return tryLoginRenewal(); }, onResize: function() { this.setData(getLayout()); }, data: { loadError: false, list: [], page: 1, totalPages: 0, pages: [], loading: true }, onLoad: function() { this.setData(getLayout()); this.loadLogs(); }, onPullDownRefresh: async function() { this.setData({ page: 1, list: [] }); await this.loadLogs(); wx.stopPullDownRefresh(); }, loadLogs: async function() { if (this._pageLoading) return; this._pageLoading = true; this.setData({loading:true, loadError:false}); var cp = this.data.page; this.setData({ loading: true }); try { const res = await api.activityLogList({ page: cp, page_size: 20 }); var items = (res.items || []).map(function(item) { item.created_at = item.created_at ? item.created_at.substring(0, 16).replace('T', ' ') : ''; var cfg = ACTION_CONFIG[item.action_type] || { icon: '📌', color: '#999', label: '' }; item.action_icon = cfg.icon; item.action_color = cfg.color; item.action_label = cfg.label; return item; }); var tp = res.total_pages || 1; var pages = []; if (tp <= 7) { for (var i = 1; i <= tp; i++) { pages.push({ num: i, dot: false }); } } else { pages.push({ num: 1, dot: false }); pages.push({ num: 2, dot: false }); pages.push({ num: 3, dot: false }); if (cp > 4) pages.push({ num: 0, dot: true }); pages.push({ num: tp - 2, dot: false }); pages.push({ num: tp - 1, dot: false }); pages.push({ num: tp, dot: false }); } var pageData = { list: items, page: cp, totalPages: tp, pages: pages, loading: false }; this.setData(pageData); } catch (e) { this.setData({loadError:true}); this.setData({ loading: false }); wx.showToast({ title: '加载失败', icon: 'none' }); } finally { this._pageLoading = false; this.setData({loading:false}); } }, goPage: function(e) { var p = parseInt(e.currentTarget.dataset.page); if (p === this.data.page) return; this.setData({ page: p }); this.loadLogs(); }, goPrev: function() { if (this.data.page <= 1) return; this.setData({ page: this.data.page - 1 }); this.loadLogs(); }, goNext: function() { if (this.data.page >= this.data.totalPages) return; this.setData({ page: this.data.page + 1 }); this.loadLogs(); }, goToSettings: function() { wx.navigateTo({ url: '/pages/settings/settings' }); }, goHome: function() { wx.switchTab({ url: '/pages/index/index' }); }, goToProfile: function() { wx.switchTab({ url: '/pages/profile/profile' }); } });