audio-novel.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const utils_api = require("../../utils/api.js");
  4. const _sfc_main = {
  5. data() {
  6. return {
  7. audioList: [],
  8. isLoading: false
  9. };
  10. },
  11. onLoad() {
  12. this.loadAudioList();
  13. },
  14. methods: {
  15. async loadAudioList() {
  16. this.isLoading = true;
  17. try {
  18. const res = await utils_api.getRecommendAudiobooks(50);
  19. if (res && res.code === 200 && Array.isArray(res.data)) {
  20. this.audioList = res.data.map((item) => ({
  21. id: item.id,
  22. title: item.title,
  23. author: item.author || "",
  24. desc: item.brief || item.desc || "",
  25. cover: item.image || item.cover || "https://picsum.photos/seed/audio-novel/200/300"
  26. }));
  27. } else {
  28. this.audioList = [];
  29. }
  30. } catch (error) {
  31. common_vendor.index.__f__("error", "at pages/audio-novel/audio-novel.vue:85", "加载有声小说失败:", error);
  32. this.audioList = [];
  33. common_vendor.index.showToast({
  34. title: "加载失败",
  35. icon: "none"
  36. });
  37. } finally {
  38. this.isLoading = false;
  39. }
  40. },
  41. goBack() {
  42. common_vendor.index.navigateBack({
  43. delta: 1
  44. });
  45. },
  46. goToSearch() {
  47. common_vendor.index.navigateTo({
  48. url: "/pages/search/search"
  49. });
  50. },
  51. goToAudioDetail(audio) {
  52. if (!audio || !audio.id) {
  53. common_vendor.index.showToast({
  54. title: "听书信息不完整",
  55. icon: "none"
  56. });
  57. return;
  58. }
  59. common_vendor.index.navigateTo({
  60. url: `/pages/listen-detail/listen-detail?audiobookId=${audio.id}`
  61. });
  62. },
  63. handlePlay(audio) {
  64. if (!audio || !audio.id) {
  65. common_vendor.index.showToast({
  66. title: "听书信息不完整",
  67. icon: "none"
  68. });
  69. return;
  70. }
  71. this.goToAudioDetail(audio);
  72. },
  73. handleImageError(index) {
  74. if (this.audioList[index]) {
  75. this.audioList[index].cover = `https://picsum.photos/seed/audio-novel-fallback${index}/200/300`;
  76. }
  77. }
  78. }
  79. };
  80. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  81. return common_vendor.e({
  82. a: common_vendor.o((...args) => $options.goBack && $options.goBack(...args)),
  83. b: common_vendor.o((...args) => $options.goToSearch && $options.goToSearch(...args)),
  84. c: $data.isLoading
  85. }, $data.isLoading ? {} : $data.audioList.length === 0 ? {} : {}, {
  86. d: $data.audioList.length === 0,
  87. e: common_vendor.f($data.audioList, (audio, index, i0) => {
  88. return {
  89. a: audio.cover,
  90. b: common_vendor.o(($event) => $options.handleImageError(index), audio.id || index),
  91. c: common_vendor.t(audio.title),
  92. d: common_vendor.t(audio.desc),
  93. e: common_vendor.t(audio.author),
  94. f: common_vendor.o(($event) => $options.handlePlay(audio), audio.id || index),
  95. g: audio.id || index,
  96. h: common_vendor.o(($event) => $options.goToAudioDetail(audio), audio.id || index)
  97. };
  98. })
  99. });
  100. }
  101. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-0c5530b9"]]);
  102. wx.createPage(MiniProgramPage);
  103. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/audio-novel/audio-novel.js.map