"use strict"; const common_vendor = require("../../common/vendor.js"); const utils_api = require("../../utils/api.js"); const _sfc_main = { data() { return { messageList: [], loading: false, page: 1, size: 20, hasMore: true }; }, onLoad() { this.loadMessages(); }, onPullDownRefresh() { this.page = 1; this.messageList = []; this.hasMore = true; this.loadMessages().finally(() => { common_vendor.index.stopPullDownRefresh(); }); }, onReachBottom() { if (this.hasMore && !this.loading) { this.page++; this.loadMessages(); } }, methods: { async loadMessages() { const userInfo = common_vendor.index.getStorageSync("userInfo"); if (!userInfo || !userInfo.id) { common_vendor.index.showToast({ title: "请先登录", icon: "none" }); setTimeout(() => { common_vendor.index.navigateTo({ url: "/pages/login/login" }); }, 1500); return; } if (this.loading) return; this.loading = true; try { const res = await utils_api.getMessages(userInfo.id, null, null, this.page, this.size); if (res && res.code === 200 && res.data) { const newMessages = res.data.list || []; if (this.page === 1) { this.messageList = newMessages; } else { this.messageList = this.messageList.concat(newMessages); } this.hasMore = newMessages.length >= this.size; this.messageList.forEach((msg) => { if (!msg.avatar) { msg.avatar = "https://picsum.photos/seed/default/200/200"; } }); } else { if (this.page === 1) { this.messageList = []; } this.hasMore = false; } } catch (error) { common_vendor.index.__f__("error", "at pages/messages/messages.vue:121", "加载消息失败:", error); if (this.page === 1) { this.messageList = []; } if (this.page > 1) { this.page--; } } finally { this.loading = false; } }, goBack() { common_vendor.index.navigateBack(); }, async handleMessageClick(message) { if (message.isRead === 0) { try { await utils_api.markMessageAsRead(message.id); message.isRead = 1; } catch (error) { common_vendor.index.__f__("error", "at pages/messages/messages.vue:142", "标记消息已读失败:", error); } } if (message.type === "like" || message.type === "reply") { common_vendor.index.showToast({ title: "查看评论详情", icon: "none" }); } else if (message.type === "comment") { common_vendor.index.showToast({ title: "查看书籍详情", icon: "none" }); } } } }; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return common_vendor.e({ a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)), b: common_vendor.f($data.messageList, (message, index, i0) => { return common_vendor.e({ a: message.avatar, b: common_vendor.t(message.sender), c: common_vendor.t(message.time), d: common_vendor.t(message.actionIcon), e: common_vendor.t(message.actionText), f: message.comment }, message.comment ? { g: common_vendor.t(message.comment) } : {}, { h: index, i: common_vendor.o(($event) => $options.handleMessageClick(message), index) }); }), c: $data.messageList.length === 0 }, $data.messageList.length === 0 ? {} : {}); } const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ecc172b4"]]); wx.createPage(MiniProgramPage); //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/messages/messages.js.map