| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const utils_api = require("../../utils/api.js");
- const _sfc_main = {
- data() {
- return {
- bannerList: [],
- categories: [
- { name: "全部分类", icon: "📄", color: "#81C784" },
- { name: "排行榜", icon: "👑", color: "#FFD54F" },
- { name: "热门书籍", icon: "🔥", color: "#E57373" },
- { name: "新书榜", icon: "📖", color: "#81C784" },
- { name: "VIP书籍", icon: "📚", color: "#4FC3F7" }
- ],
- todayRecommend: [],
- bestsellers: [],
- featuredList: [],
- moreRecommend: [],
- isLoading: false,
- featuredLoading: false,
- moreLoading: false
- };
- },
- onLoad() {
- this.loadBanners();
- this.loadTodayRecommend();
- this.loadBestsellers();
- this.loadFeaturedList();
- this.loadMoreRecommend();
- },
- onShow() {
- this.loadTodayRecommend();
- this.loadBestsellers();
- this.loadFeaturedList();
- this.loadMoreRecommend();
- },
- methods: {
- async loadBanners() {
- try {
- const res = await utils_api.getBannersByCode("home_banner");
- if (res && res.code === 200 && Array.isArray(res.data)) {
- this.bannerList = res.data.map((b) => ({
- image: b.image,
- title: b.title || "",
- targetType: b.targetType,
- targetId: b.targetId,
- link: b.link
- }));
- }
- } catch (e) {
- common_vendor.index.__f__("error", "at pages/index/index.vue:209", "加载轮播失败", e);
- }
- },
- // 加载今日推荐
- loadTodayRecommend() {
- common_vendor.index.__f__("log", "at pages/index/index.vue:214", "开始加载今日推荐...");
- this.isLoading = true;
- utils_api.getTodayRecommend(8).then((res) => {
- common_vendor.index.__f__("log", "at pages/index/index.vue:218", "今日推荐API响应:", res);
- this.isLoading = false;
- if (res && res.code === 200) {
- if (res.data && Array.isArray(res.data) && res.data.length > 0) {
- this.todayRecommend = res.data.map((book) => {
- return {
- id: book.id,
- title: book.title || "未知书名",
- image: book.image || book.cover || "https://picsum.photos/seed/default/200/300",
- author: book.author || ""
- };
- });
- common_vendor.index.__f__("log", "at pages/index/index.vue:234", "今日推荐数据加载成功,共", this.todayRecommend.length, "本");
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:236", "今日推荐数据为空或格式不正确:", res.data);
- this.todayRecommend = [];
- }
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:240", "今日推荐API返回错误:", res);
- this.todayRecommend = [];
- common_vendor.index.showToast({
- title: res.message || "获取推荐失败",
- icon: "none",
- duration: 2e3
- });
- }
- }).catch((err) => {
- this.isLoading = false;
- common_vendor.index.__f__("error", "at pages/index/index.vue:252", "获取今日推荐失败:", err);
- this.todayRecommend = [];
- common_vendor.index.showToast({
- title: err.message || "网络请求失败,请检查后端服务",
- icon: "none",
- duration: 3e3
- });
- });
- },
- // 加载畅销书籍
- loadBestsellers() {
- common_vendor.index.__f__("log", "at pages/index/index.vue:264", "开始加载畅销书籍...");
- this.isLoading = true;
- utils_api.getBestsellers(10).then((res) => {
- common_vendor.index.__f__("log", "at pages/index/index.vue:268", "畅销书籍API响应:", res);
- this.isLoading = false;
- if (res && res.code === 200) {
- if (res.data && Array.isArray(res.data) && res.data.length > 0) {
- this.bestsellers = res.data.map((book) => {
- return {
- id: book.id,
- title: book.title || "未知书名",
- desc: book.desc || book.brief || book.introduction || "",
- author: book.author || "",
- image: book.image || book.cover || "https://picsum.photos/seed/default/200/300"
- };
- });
- common_vendor.index.__f__("log", "at pages/index/index.vue:285", "畅销书籍数据加载成功,共", this.bestsellers.length, "本");
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:287", "畅销书籍数据为空或格式不正确:", res.data);
- this.bestsellers = [];
- }
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:291", "畅销书籍API返回错误:", res);
- this.bestsellers = [];
- common_vendor.index.showToast({
- title: res.message || "获取畅销书籍失败",
- icon: "none",
- duration: 2e3
- });
- }
- }).catch((err) => {
- this.isLoading = false;
- common_vendor.index.__f__("error", "at pages/index/index.vue:303", "获取畅销书籍失败:", err);
- this.bestsellers = [];
- common_vendor.index.showToast({
- title: err.message || "网络请求失败,请检查后端服务",
- icon: "none",
- duration: 3e3
- });
- });
- },
- // 加载精品书单
- loadFeaturedList() {
- common_vendor.index.__f__("log", "at pages/index/index.vue:315", "开始加载精品书单...");
- this.featuredLoading = true;
- utils_api.getFeaturedList(4).then((res) => {
- common_vendor.index.__f__("log", "at pages/index/index.vue:319", "精品书单API响应:", res);
- this.featuredLoading = false;
- if (res && res.code === 200) {
- if (res.data && Array.isArray(res.data) && res.data.length > 0) {
- this.featuredList = res.data.map((book) => {
- return {
- id: book.id,
- title: book.title || "未知书名",
- image: book.image || book.cover || "https://picsum.photos/seed/featured/200/300"
- };
- });
- common_vendor.index.__f__("log", "at pages/index/index.vue:330", "精品书单加载成功,共", this.featuredList.length, "本");
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:332", "精品书单数据为空或格式不正确:", res.data);
- this.featuredList = [];
- }
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:336", "精品书单API返回错误:", res);
- this.featuredList = [];
- common_vendor.index.showToast({
- title: res.message || "获取精品书单失败",
- icon: "none",
- duration: 2e3
- });
- }
- }).catch((err) => {
- this.featuredLoading = false;
- common_vendor.index.__f__("error", "at pages/index/index.vue:347", "获取精品书单失败:", err);
- this.featuredList = [];
- common_vendor.index.showToast({
- title: err.message || "网络请求失败,请检查后端服务",
- icon: "none",
- duration: 3e3
- });
- });
- },
- // 加载更多推荐书籍
- loadMoreRecommend() {
- common_vendor.index.__f__("log", "at pages/index/index.vue:358", "开始加载更多推荐书籍...");
- this.moreLoading = true;
- utils_api.getMoreRecommend(6).then((res) => {
- common_vendor.index.__f__("log", "at pages/index/index.vue:362", "更多推荐API响应:", res);
- this.moreLoading = false;
- if (res && res.code === 200) {
- if (res.data && Array.isArray(res.data) && res.data.length > 0) {
- this.moreRecommend = res.data.map((book) => {
- return {
- id: book.id,
- title: book.title || "未知书名",
- author: book.author || "",
- image: book.image || book.cover || "https://picsum.photos/seed/more/200/300"
- };
- });
- common_vendor.index.__f__("log", "at pages/index/index.vue:374", "更多推荐加载成功,共", this.moreRecommend.length, "本");
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:376", "更多推荐数据为空或格式不正确:", res.data);
- this.moreRecommend = [];
- }
- } else {
- common_vendor.index.__f__("warn", "at pages/index/index.vue:380", "更多推荐API返回错误:", res);
- this.moreRecommend = [];
- common_vendor.index.showToast({
- title: res.message || "获取更多推荐失败",
- icon: "none",
- duration: 2e3
- });
- }
- }).catch((err) => {
- this.moreLoading = false;
- common_vendor.index.__f__("error", "at pages/index/index.vue:391", "获取更多推荐失败:", err);
- this.moreRecommend = [];
- common_vendor.index.showToast({
- title: err.message || "网络请求失败,请检查后端服务",
- icon: "none",
- duration: 3e3
- });
- });
- },
- handleCategoryClick(item, index) {
- if (index === 0) {
- common_vendor.index.navigateTo({
- url: "/pages/category/category"
- });
- } else if (index === 1) {
- common_vendor.index.navigateTo({
- url: "/pages/ranking/ranking"
- });
- } else if (index === 2) {
- common_vendor.index.navigateTo({
- url: "/pages/hot-books/hot-books"
- });
- } else if (index === 3) {
- common_vendor.index.navigateTo({
- url: "/pages/new-books/new-books"
- });
- } else if (index === 4) {
- common_vendor.index.navigateTo({
- url: "/pages/vip-books/vip-books"
- });
- }
- },
- goToBookDetail(book) {
- if (!book || !book.id) {
- common_vendor.index.showToast({
- title: "书籍信息不完整",
- icon: "none"
- });
- return;
- }
- common_vendor.index.navigateTo({
- url: `/pages/book-detail/book-detail?bookId=${book.id}`
- });
- },
- goToMoreBooks(type) {
- common_vendor.index.navigateTo({
- url: `/pages/more-books/more-books?type=${type}`
- });
- },
- goToSearch() {
- common_vendor.index.navigateTo({
- url: "/pages/search/search"
- });
- },
- handleBannerClick(item) {
- if (!item)
- return;
- common_vendor.index.__f__("log", "at pages/index/index.vue:447", "轮播图点击:", item);
- if (item.targetType === "book" && item.targetId) {
- this.goToBookDetail({ id: item.targetId });
- return;
- }
- if (item.targetType === "audiobook" && item.targetId) {
- common_vendor.index.navigateTo({ url: `/pages/listen-detail/listen-detail?audiobookId=${item.targetId}` });
- return;
- }
- if (item.targetType === "url" && item.link) {
- common_vendor.index.showModal({
- title: "提示",
- content: "此链接需要复制后在浏览器打开",
- confirmText: "复制链接",
- success: (res) => {
- if (res.confirm) {
- common_vendor.index.setClipboardData({
- data: item.link,
- success: () => {
- common_vendor.index.showToast({
- title: "链接已复制",
- icon: "success"
- });
- }
- });
- }
- }
- });
- return;
- }
- if (item.link && !item.targetType)
- ;
- },
- handleImageError(index) {
- const fallbackImages = [
- "https://picsum.photos/seed/library1/1080/600",
- "https://picsum.photos/seed/library2/1080/600",
- "https://picsum.photos/seed/library3/1080/600",
- "https://picsum.photos/seed/library4/1080/600",
- "https://picsum.photos/seed/library5/1080/600"
- ];
- if (this.bannerList[index]) {
- this.bannerList[index].image = fallbackImages[index] || fallbackImages[0];
- }
- },
- handleBookImageError(book, listType) {
- book.image = "https://picsum.photos/seed/default/200/300";
- }
- }
- };
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.o((...args) => $options.goToSearch && $options.goToSearch(...args)),
- b: common_vendor.f($data.bannerList, (item, index, i0) => {
- return {
- a: item.image,
- b: common_vendor.o(($event) => $options.handleImageError(index), index),
- c: common_vendor.t(item.title),
- d: index,
- e: common_vendor.o(($event) => $options.handleBannerClick(item), index)
- };
- }),
- c: common_vendor.f($data.categories, (item, index, i0) => {
- return {
- a: common_vendor.t(item.icon),
- b: item.color,
- c: common_vendor.t(item.name),
- d: index,
- e: common_vendor.o(($event) => $options.handleCategoryClick(item, index), index)
- };
- }),
- d: common_vendor.o(($event) => $options.goToMoreBooks("today")),
- e: $data.isLoading && $data.todayRecommend.length === 0
- }, $data.isLoading && $data.todayRecommend.length === 0 ? {} : $data.todayRecommend.length > 0 ? {
- g: common_vendor.f($data.todayRecommend, (book, index, i0) => {
- return {
- a: book.image,
- b: common_vendor.o(($event) => $options.handleBookImageError(book, "todayRecommend"), book.id || index),
- c: common_vendor.t(book.title),
- d: book.id || index,
- e: common_vendor.o(($event) => $options.goToBookDetail(book), book.id || index)
- };
- })
- } : {}, {
- f: $data.todayRecommend.length > 0,
- h: common_vendor.o(($event) => $options.goToMoreBooks("bestseller")),
- i: $data.isLoading && $data.bestsellers.length === 0
- }, $data.isLoading && $data.bestsellers.length === 0 ? {} : $data.bestsellers.length > 0 ? {
- k: common_vendor.f($data.bestsellers, (book, index, i0) => {
- return {
- a: book.image,
- b: common_vendor.o(($event) => $options.handleBookImageError(book, "bestsellers"), book.id || index),
- c: common_vendor.t(book.title),
- d: common_vendor.t(book.desc),
- e: common_vendor.t(book.author),
- f: book.id || index,
- g: common_vendor.o(($event) => $options.goToBookDetail(book), book.id || index)
- };
- })
- } : {}, {
- j: $data.bestsellers.length > 0,
- l: common_vendor.o(($event) => $options.goToMoreBooks("featured")),
- m: $data.featuredLoading
- }, $data.featuredLoading ? {} : $data.featuredList.length > 0 ? {
- o: common_vendor.f($data.featuredList, (book, index, i0) => {
- return {
- a: book.image,
- b: common_vendor.o(($event) => $options.handleBookImageError(book, "featuredList"), book.id || index),
- c: common_vendor.t(book.title),
- d: book.id || index,
- e: common_vendor.o(($event) => $options.goToBookDetail(book), book.id || index)
- };
- })
- } : {}, {
- n: $data.featuredList.length > 0,
- p: $data.moreLoading
- }, $data.moreLoading ? {} : $data.moreRecommend.length > 0 ? {
- r: common_vendor.f($data.moreRecommend, (book, index, i0) => {
- return {
- a: book.image,
- b: common_vendor.o(($event) => $options.handleBookImageError(book, "moreRecommend"), book.id || index),
- c: common_vendor.t(book.title),
- d: common_vendor.t(book.author),
- e: book.id || index,
- f: common_vendor.o(($event) => $options.goToBookDetail(book), book.id || index)
- };
- })
- } : {}, {
- q: $data.moreRecommend.length > 0
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-1cf27b2a"]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map
|