index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. data() {
  5. return {
  6. searchText: "",
  7. activeTab: 0,
  8. categories: [],
  9. courses: [],
  10. loading: false,
  11. error: null,
  12. defaultCover: "/static/default-course.png"
  13. };
  14. },
  15. computed: {
  16. filteredCourses() {
  17. let list = this.courses;
  18. if (this.activeTab !== 0) {
  19. list = list.filter((c) => c.category === this.categories[this.activeTab]);
  20. }
  21. if (this.searchText) {
  22. list = list.filter(
  23. (c) => c.title.toLowerCase().includes(this.searchText.toLowerCase()) || c.description.toLowerCase().includes(this.searchText.toLowerCase())
  24. );
  25. }
  26. common_vendor.index.__f__("log", "at pages/discover/index.vue:70", list);
  27. return list;
  28. }
  29. },
  30. onLoad() {
  31. this.findAll();
  32. this.findCategory();
  33. },
  34. methods: {
  35. onSearch() {
  36. },
  37. async findCategory() {
  38. this.loading = true;
  39. this.error = null;
  40. try {
  41. const res = await common_vendor.index.request({
  42. url: "http://localhost:9527/product/findCategory",
  43. method: "GET"
  44. });
  45. common_vendor.index.__f__("log", "at pages/discover/index.vue:90", res.data);
  46. if (res.statusCode === 200) {
  47. this.categories = res.data.data;
  48. } else {
  49. throw new Error(res.data.message || "获取数据失败");
  50. }
  51. } catch (err) {
  52. this.error = err.message || "网络错误,请稍后重试";
  53. common_vendor.index.__f__("error", "at pages/discover/index.vue:98", "获取课程列表失败:", err);
  54. } finally {
  55. this.loading = false;
  56. }
  57. },
  58. async findAll() {
  59. this.loading = true;
  60. this.error = null;
  61. try {
  62. const res = await common_vendor.index.request({
  63. url: "http://localhost:9527/product/findAll",
  64. method: "GET"
  65. });
  66. if (res.statusCode === 200) {
  67. common_vendor.index.__f__("log", "at pages/discover/index.vue:113", res.data.data);
  68. this.courses = res.data.data;
  69. } else {
  70. throw new Error(res.data.message || "获取数据失败");
  71. }
  72. } catch (err) {
  73. this.error = err.message || "网络错误,请稍后重试";
  74. common_vendor.index.__f__("error", "at pages/discover/index.vue:120", "获取课程列表失败:", err);
  75. } finally {
  76. this.loading = false;
  77. }
  78. },
  79. navigateToDetail(id) {
  80. common_vendor.index.__f__("log", "at pages/discover/index.vue:126", id);
  81. common_vendor.index.navigateTo({
  82. url: `/pages/course/detail?id=${id}`
  83. });
  84. }
  85. }
  86. };
  87. if (!Array) {
  88. const _component_uni_load_more = common_vendor.resolveComponent("uni-load-more");
  89. _component_uni_load_more();
  90. }
  91. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  92. return common_vendor.e({
  93. a: common_vendor.o((...args) => $options.onSearch && $options.onSearch(...args)),
  94. b: $data.searchText,
  95. c: common_vendor.o(($event) => $data.searchText = $event.detail.value),
  96. d: common_vendor.f($data.categories, (tab, idx, i0) => {
  97. return {
  98. a: common_vendor.t(tab.name),
  99. b: tab.id,
  100. c: common_vendor.n(idx === $data.activeTab ? "active" : ""),
  101. d: common_vendor.o(($event) => $data.activeTab = idx, tab.id)
  102. };
  103. }),
  104. e: $data.loading
  105. }, $data.loading ? {
  106. f: common_vendor.p({
  107. status: "loading"
  108. })
  109. } : {
  110. g: common_vendor.f($data.courses, (cour, k0, i0) => {
  111. var _a;
  112. return {
  113. a: cour.mainImage,
  114. b: common_vendor.t(cour.name),
  115. c: common_vendor.t(cour.description),
  116. d: common_vendor.t(((_a = cour.price) == null ? void 0 : _a.toFixed(2)) || "0.00"),
  117. e: common_vendor.t(cour.sales || 0),
  118. f: cour.id,
  119. g: common_vendor.o(($event) => $options.navigateToDetail(cour.id), cour.id)
  120. };
  121. })
  122. });
  123. }
  124. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  125. wx.createPage(MiniProgramPage);
  126. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/discover/index.js.map