| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_api = require("../../utils/api.js");
- const _sfc_main = {
- data() {
- return {
- historyList: [],
- userInfo: null,
- isLoading: false
- };
- },
- onLoad() {
- try {
- const userInfo = common_vendor.index.getStorageSync("userInfo");
- if (userInfo && userInfo.id) {
- this.userInfo = userInfo;
- this.loadBrowsingHistory();
- } else {
- common_vendor.index.showToast({
- title: "请先登录",
- icon: "none"
- });
- setTimeout(() => {
- common_vendor.index.navigateBack();
- }, 1500);
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/browsing-history/browsing-history.vue:67", "获取用户信息失败", e);
- }
- },
- methods: {
- goBack() {
- common_vendor.index.navigateBack();
- },
- async loadBrowsingHistory() {
- if (!this.userInfo || !this.userInfo.id) {
- return;
- }
- try {
- this.isLoading = true;
- const res = await utils_api.getBrowsingHistory(this.userInfo.id);
- if (res && res.code === 200 && res.data) {
- this.historyList = res.data.map((item) => ({
- id: item.bookId,
- title: item.title || "未知书籍",
- image: item.image || "https://via.placeholder.com/200x300?text=No+Image",
- time: item.time || ""
- }));
- } else {
- this.historyList = [];
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/browsing-history/browsing-history.vue:94", "加载浏览记录失败", e);
- this.historyList = [];
- } finally {
- this.isLoading = false;
- }
- },
- handleClear() {
- if (!this.userInfo || !this.userInfo.id) {
- return;
- }
- common_vendor.index.showModal({
- title: "提示",
- content: "确定要清空所有浏览记录吗?",
- success: async (res) => {
- if (res.confirm) {
- try {
- common_vendor.index.showLoading({
- title: "清空中...",
- mask: true
- });
- const result = await utils_api.clearBrowsingHistory(this.userInfo.id);
- common_vendor.index.hideLoading();
- if (result && result.code === 200) {
- this.historyList = [];
- common_vendor.index.showToast({
- title: "已清空",
- icon: "success"
- });
- } else {
- common_vendor.index.showToast({
- title: result.message || "清空失败",
- icon: "none"
- });
- }
- } catch (e) {
- common_vendor.index.hideLoading();
- common_vendor.index.__f__("error", "at pages/browsing-history/browsing-history.vue:133", "清空浏览记录失败", e);
- common_vendor.index.showToast({
- title: "清空失败,请重试",
- icon: "none"
- });
- }
- }
- }
- });
- },
- goToBookDetail(item) {
- if (!item || !item.id) {
- common_vendor.index.showToast({
- title: "书籍信息不完整",
- icon: "none"
- });
- return;
- }
- common_vendor.index.navigateTo({
- url: `/pages/book-detail/book-detail?bookId=${item.id}`
- });
- }
- }
- };
- 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.o((...args) => $options.handleClear && $options.handleClear(...args)),
- c: common_vendor.f($data.historyList, (item, index, i0) => {
- return {
- a: item.image,
- b: common_vendor.t(item.title),
- c: common_vendor.t(item.time),
- d: index,
- e: common_vendor.o(($event) => $options.goToBookDetail(item), index)
- };
- }),
- d: $data.historyList.length === 0
- }, $data.historyList.length === 0 ? {} : {});
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-3dbaa36d"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/browsing-history/browsing-history.js.map
|