225 lines
8.2 KiB
JavaScript
225 lines
8.2 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const utils_request = require("../../utils/request.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
notices: [],
|
|
banners: [],
|
|
activities: []
|
|
};
|
|
},
|
|
computed: {
|
|
displayNotices() {
|
|
if (Array.isArray(this.notices) && this.notices.length)
|
|
return this.notices;
|
|
return [
|
|
{ id: "n1", text: "欢迎光临" },
|
|
{ id: "n2", text: "最新活动敬请期待" }
|
|
];
|
|
},
|
|
displayBanners() {
|
|
if (Array.isArray(this.banners) && this.banners.length)
|
|
return this.banners;
|
|
return [
|
|
{ id: "ph-1", title: "精彩内容即将上线", image: "" },
|
|
{ id: "ph-2", title: "敬请期待", image: "" },
|
|
{ id: "ph-3", title: "更多活动请关注", image: "" }
|
|
];
|
|
}
|
|
},
|
|
onShow() {
|
|
const token = common_vendor.index.getStorageSync("token");
|
|
const phoneBound = !!common_vendor.index.getStorageSync("phone_bound");
|
|
if (!token || !phoneBound) {
|
|
common_vendor.index.showModal({
|
|
title: "提示",
|
|
content: "请先登录并绑定手机号",
|
|
confirmText: "去登录",
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
common_vendor.index.navigateTo({ url: "/pages/login/index" });
|
|
}
|
|
}
|
|
});
|
|
}
|
|
try {
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:81", "home onShow", { token: !!token, phoneBound });
|
|
} catch (_) {
|
|
}
|
|
this.loadHomeData();
|
|
},
|
|
methods: {
|
|
toArray(x) {
|
|
return Array.isArray(x) ? x : [];
|
|
},
|
|
unwrap(list) {
|
|
if (Array.isArray(list))
|
|
return list;
|
|
const obj = list || {};
|
|
const arr = obj.list || obj.items || obj.data || [];
|
|
return Array.isArray(arr) ? arr : [];
|
|
},
|
|
cleanUrl(u) {
|
|
const s = String(u || "").trim();
|
|
const m = s.match(/https?:\/\/[^\s'"`]+/);
|
|
if (m && m[0])
|
|
return m[0];
|
|
return s.replace(/[`'\"]/g, "").trim();
|
|
},
|
|
apiGet(url) {
|
|
const token = common_vendor.index.getStorageSync("token");
|
|
const fn = token ? utils_request.authRequest : utils_request.request;
|
|
return fn({ url });
|
|
},
|
|
normalizeNotices(list) {
|
|
const arr = this.unwrap(list);
|
|
return arr.map((i, idx) => ({
|
|
id: i.id ?? String(idx),
|
|
text: i.content ?? i.text ?? i.title ?? ""
|
|
})).filter((i) => i.text);
|
|
},
|
|
normalizeBanners(list) {
|
|
const arr = this.unwrap(list);
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:112", "normalizeBanners input", list, "unwrapped", arr);
|
|
const mapped = arr.map((i, idx) => ({
|
|
id: i.id ?? String(idx),
|
|
title: i.title ?? "",
|
|
image: this.cleanUrl(i.imageUrl ?? i.image_url ?? i.image ?? i.img ?? i.pic ?? ""),
|
|
link: this.cleanUrl(i.linkUrl ?? i.link_url ?? i.link ?? i.url ?? ""),
|
|
sort: typeof i.sort === "number" ? i.sort : 0
|
|
})).filter((i) => i.image);
|
|
mapped.sort((a, b) => a.sort - b.sort);
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:121", "normalizeBanners mapped", mapped);
|
|
return mapped;
|
|
},
|
|
normalizeActivities(list) {
|
|
const arr = this.unwrap(list);
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:126", "normalizeActivities input", list, "unwrapped", arr);
|
|
const mapped = arr.map((i, idx) => ({
|
|
id: i.id ?? String(idx),
|
|
image: this.cleanUrl(i.banner ?? i.coverUrl ?? i.cover_url ?? i.image ?? i.img ?? i.pic ?? ""),
|
|
title: i.title ?? i.name ?? "",
|
|
subtitle: this.buildActivitySubtitle(i),
|
|
link: this.cleanUrl(i.linkUrl ?? i.link_url ?? i.link ?? i.url ?? ""),
|
|
category_name: (i.category_name ?? i.categoryName ?? "").trim(),
|
|
category_id: i.activity_category_id ?? i.category_id ?? i.categoryId ?? null
|
|
})).filter((i) => i.image || i.title);
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:136", "normalizeActivities mapped", mapped);
|
|
return mapped;
|
|
},
|
|
buildActivitySubtitle(i) {
|
|
const base = i.subTitle ?? i.sub_title ?? i.subtitle ?? i.desc ?? i.description ?? "";
|
|
if (base)
|
|
return base;
|
|
const cat = i.category_name ?? i.categoryName ?? "";
|
|
const price = i.price_draw !== void 0 && i.price_draw !== null ? `¥${i.price_draw}` : "";
|
|
const parts = [cat, price].filter(Boolean);
|
|
return parts.join(" · ");
|
|
},
|
|
async loadHomeData() {
|
|
const results = await Promise.allSettled([
|
|
this.apiGet("/api/app/notices"),
|
|
this.apiGet("/api/app/banners"),
|
|
this.apiGet("/api/app/activities")
|
|
]);
|
|
const [nRes, bRes, acRes] = results;
|
|
if (nRes.status === "fulfilled") {
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:155", "notices ok", nRes.value);
|
|
this.notices = this.normalizeNotices(nRes.value);
|
|
} else {
|
|
common_vendor.index.__f__("error", "at pages/index/index.vue:158", "notices error", nRes.reason);
|
|
this.notices = [];
|
|
}
|
|
if (bRes.status === "fulfilled") {
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:162", "banners ok", bRes.value);
|
|
this.banners = this.normalizeBanners(bRes.value);
|
|
} else {
|
|
common_vendor.index.__f__("error", "at pages/index/index.vue:165", "banners error", bRes.reason);
|
|
this.banners = [];
|
|
}
|
|
if (acRes.status === "fulfilled") {
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:169", "activities ok", acRes.value);
|
|
this.activities = this.normalizeActivities(acRes.value);
|
|
} else {
|
|
common_vendor.index.__f__("error", "at pages/index/index.vue:172", "activities error", acRes.reason);
|
|
this.activities = [];
|
|
}
|
|
common_vendor.index.__f__("log", "at pages/index/index.vue:175", "home normalized", { notices: this.notices, banners: this.banners, activities: this.activities });
|
|
},
|
|
onBannerTap(b) {
|
|
const imgs = (Array.isArray(this.banners) ? this.banners : []).map((x) => x.image).filter(Boolean);
|
|
const current = b && b.image;
|
|
if (current) {
|
|
common_vendor.index.previewImage({ urls: imgs.length ? imgs : [current], current });
|
|
return;
|
|
}
|
|
if (b.link && /^\/.+/.test(b.link)) {
|
|
common_vendor.index.navigateTo({ url: b.link });
|
|
}
|
|
},
|
|
onActivityTap(a) {
|
|
const name = (a.category_name || a.categoryName || "").trim();
|
|
const id = a.id;
|
|
let path = "";
|
|
if (name === "一番赏")
|
|
path = "/pages/activity/yifanshang/index";
|
|
else if (name === "无限赏")
|
|
path = "/pages/activity/wuxianshang/index";
|
|
else if (name === "对对碰")
|
|
path = "/pages/activity/duiduipeng/index";
|
|
if (path && id) {
|
|
common_vendor.index.navigateTo({ url: `${path}?id=${id}` });
|
|
return;
|
|
}
|
|
if (a.link && /^\/.+/.test(a.link)) {
|
|
common_vendor.index.navigateTo({ url: a.link });
|
|
}
|
|
}
|
|
}
|
|
};
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return common_vendor.e({
|
|
a: common_vendor.f($options.displayNotices, (n, k0, i0) => {
|
|
return {
|
|
a: common_vendor.t(n.text),
|
|
b: n.id
|
|
};
|
|
}),
|
|
b: common_vendor.f($options.displayBanners, (b, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: b.image
|
|
}, b.image ? {
|
|
b: b.image,
|
|
c: common_vendor.o(($event) => $options.onBannerTap(b), b.id)
|
|
} : {
|
|
d: common_vendor.t(b.title || "敬请期待")
|
|
}, {
|
|
e: b.id
|
|
});
|
|
}),
|
|
c: $data.activities.length
|
|
}, $data.activities.length ? {
|
|
d: common_vendor.f($data.activities, (a, k0, i0) => {
|
|
return common_vendor.e({
|
|
a: a.image
|
|
}, a.image ? {
|
|
b: a.image
|
|
} : {
|
|
c: common_vendor.t(a.title || "活动敬请期待")
|
|
}, {
|
|
d: common_vendor.t(a.title),
|
|
e: a.subtitle
|
|
}, a.subtitle ? {
|
|
f: common_vendor.t(a.subtitle)
|
|
} : {}, {
|
|
g: a.id,
|
|
h: common_vendor.o(($event) => $options.onActivityTap(a), a.id)
|
|
});
|
|
})
|
|
} : {});
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/index.js.map
|