JewelryMall/miniprogram/unpackage/dist/dev/mp-weixin/pages/index/index.js
2026-02-25 01:21:16 +08:00

128 lines
4.2 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const api_product = require("../../api/product.js");
const utils_request = require("../../utils/request.js");
if (!Math) {
(ProductCard + CustomerServiceBtn)();
}
const ProductCard = () => "../../components/ProductCard.js";
const CustomerServiceBtn = () => "../../components/CustomerServiceBtn.js";
const pageSize = 20;
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "index",
setup(__props) {
const products = common_vendor.ref([]);
const categories = common_vendor.ref([]);
const activeCategoryId = common_vendor.ref(void 0);
const loading = common_vendor.ref(false);
const showQrcode = common_vendor.ref(false);
const page = common_vendor.ref(1);
const keyword = common_vendor.ref("");
const statusBarHeight = common_vendor.ref(20);
const navBarHeight = common_vendor.ref(44);
try {
const sysInfo = common_vendor.index.getSystemInfoSync();
statusBarHeight.value = sysInfo.statusBarHeight || 20;
const menuBtn = common_vendor.index.getMenuButtonBoundingClientRect();
navBarHeight.value = (menuBtn.top - (sysInfo.statusBarHeight || 20)) * 2 + menuBtn.height;
} catch {
}
function fullUrl(path) {
if (!path)
return "";
if (path.startsWith("http"))
return path;
return utils_request.BASE_URL + path;
}
async function loadCategories() {
try {
const data = await api_product.getCategories();
categories.value = data;
} catch {
}
}
async function loadProducts(reset = false) {
if (reset) {
page.value = 1;
products.value = [];
}
loading.value = true;
try {
const params = { page: page.value, pageSize };
if (activeCategoryId.value)
params.categoryId = activeCategoryId.value;
if (keyword.value)
params.keyword = keyword.value;
const data = await api_product.getProducts(params);
if (reset) {
products.value = data.list;
} else {
products.value.push(...data.list);
}
} catch {
} finally {
loading.value = false;
}
}
function selectCategory(id) {
activeCategoryId.value = activeCategoryId.value === id ? void 0 : id;
loadProducts(true);
}
function goSearch() {
}
function goCalculator() {
common_vendor.index.navigateTo({ url: "/pages/calculator/index" });
}
common_vendor.onMounted(() => {
loadCategories();
loadProducts(true);
});
return (_ctx, _cache) => {
return common_vendor.e({
a: navBarHeight.value + "px",
b: statusBarHeight.value + "px",
c: common_assets._imports_0,
d: common_vendor.o(goSearch),
e: common_vendor.o(goSearch),
f: common_vendor.f(categories.value, (cat, k0, i0) => {
return common_vendor.e({
a: cat.icon
}, cat.icon ? {
b: fullUrl(cat.icon)
} : {}, {
c: common_vendor.t(cat.name),
d: cat.id,
e: activeCategoryId.value === cat.id ? 1 : "",
f: common_vendor.o(($event) => selectCategory(cat.id), cat.id)
});
}),
g: common_vendor.o(goCalculator),
h: common_vendor.o(($event) => showQrcode.value = true),
i: common_vendor.f(products.value, (product, k0, i0) => {
return {
a: "1cf27b2a-0-" + i0,
b: common_vendor.p({
product
}),
c: product.id
};
}),
j: !loading.value && products.value.length === 0
}, !loading.value && products.value.length === 0 ? {} : {}, {
k: loading.value
}, loading.value ? {} : {}, {
l: showQrcode.value
}, showQrcode.value ? {
m: common_vendor.o(($event) => showQrcode.value = false),
n: common_vendor.p({
mode: "qrcode"
})
} : {});
};
}
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map