123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- "use strict";
- const common_vendor = require("../../common/vendor.js");
- const _sfc_main = {
- data() {
- return {
- searchText: "",
- activeTab: 0,
- categories: [],
- courses: [],
- loading: false,
- error: null,
- defaultCover: "/static/default-course.png"
- };
- },
- computed: {
- filteredCourses() {
- let list = this.courses;
- if (this.activeTab !== 0) {
- list = list.filter((c) => c.category === this.categories[this.activeTab]);
- }
- if (this.searchText) {
- list = list.filter(
- (c) => c.title.toLowerCase().includes(this.searchText.toLowerCase()) || c.description.toLowerCase().includes(this.searchText.toLowerCase())
- );
- }
- common_vendor.index.__f__("log", "at pages/discover/index.vue:70", list);
- return list;
- }
- },
- onLoad() {
- this.findAll();
- this.findCategory();
- },
- methods: {
- onSearch() {
- },
- async findCategory() {
- this.loading = true;
- this.error = null;
- try {
- const res = await common_vendor.index.request({
- url: "http://localhost:9527/product/findCategory",
- method: "GET"
- });
- common_vendor.index.__f__("log", "at pages/discover/index.vue:90", res.data);
- if (res.statusCode === 200) {
- this.categories = res.data.data;
- } else {
- throw new Error(res.data.message || "获取数据失败");
- }
- } catch (err) {
- this.error = err.message || "网络错误,请稍后重试";
- common_vendor.index.__f__("error", "at pages/discover/index.vue:98", "获取课程列表失败:", err);
- } finally {
- this.loading = false;
- }
- },
- async findAll() {
- this.loading = true;
- this.error = null;
- try {
- const res = await common_vendor.index.request({
- url: "http://localhost:9527/product/findAll",
- method: "GET"
- });
- if (res.statusCode === 200) {
- common_vendor.index.__f__("log", "at pages/discover/index.vue:113", res.data.data);
- this.courses = res.data.data;
- } else {
- throw new Error(res.data.message || "获取数据失败");
- }
- } catch (err) {
- this.error = err.message || "网络错误,请稍后重试";
- common_vendor.index.__f__("error", "at pages/discover/index.vue:120", "获取课程列表失败:", err);
- } finally {
- this.loading = false;
- }
- },
- navigateToDetail(id) {
- common_vendor.index.__f__("log", "at pages/discover/index.vue:126", id);
- common_vendor.index.navigateTo({
- url: `/pages/course/detail?id=${id}`
- });
- }
- }
- };
- if (!Array) {
- const _component_uni_load_more = common_vendor.resolveComponent("uni-load-more");
- _component_uni_load_more();
- }
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: common_vendor.o((...args) => $options.onSearch && $options.onSearch(...args)),
- b: $data.searchText,
- c: common_vendor.o(($event) => $data.searchText = $event.detail.value),
- d: common_vendor.f($data.categories, (tab, idx, i0) => {
- return {
- a: common_vendor.t(tab.name),
- b: tab.id,
- c: common_vendor.n(idx === $data.activeTab ? "active" : ""),
- d: common_vendor.o(($event) => $data.activeTab = idx, tab.id)
- };
- }),
- e: $data.loading
- }, $data.loading ? {
- f: common_vendor.p({
- status: "loading"
- })
- } : {
- g: common_vendor.f($data.courses, (cour, k0, i0) => {
- var _a;
- return {
- a: cour.mainImage,
- b: common_vendor.t(cour.name),
- c: common_vendor.t(cour.description),
- d: common_vendor.t(((_a = cour.price) == null ? void 0 : _a.toFixed(2)) || "0.00"),
- e: common_vendor.t(cour.sales || 0),
- f: cour.id,
- g: common_vendor.o(($event) => $options.navigateToDetail(cour.id), cour.id)
- };
- })
- });
- }
- const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
- wx.createPage(MiniProgramPage);
- //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/discover/index.js.map
|