pan-mini/unpackage/dist/dev/mp-weixin/pages/home/home.js

125 lines
3.7 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_login = require("../../utils/login.js");
const _sfc_main = {
data() {
return {
current: 0,
tabs: [
{ label: "热门", name: "hot", badge: 0 },
{ label: "最新", name: "new", badge: 0 }
],
page: 1,
size: 6,
tag: "hot",
isEnd: false,
videoConfig: {
"columns": 2
},
list: []
};
},
onLoad() {
common_vendor.index.$on("LOGIN_SUCCESS", this.handleLoginSuccess);
if (utils_login.checkLoginStatus()) {
this.queryList();
}
},
onUnload() {
common_vendor.index.$off("LOGIN_SUCCESS", this.handleLoginSuccess);
},
methods: {
handleTabChange(idx) {
var _a;
this.current = idx;
this.tag = (_a = this.tabs[idx]) == null ? void 0 : _a.name;
this.isEnd = false;
this.list = [];
this.page = 1;
this.queryList();
},
handlerClick(item) {
console.log("video click", item);
common_vendor.index.navigateTo({
url: "/pages/detail/detail?id=" + item.id,
// 支持路径传参
success: () => console.log("跳转成功"),
fail: (err) => console.error("跳转失败", err)
});
},
handleLoginSuccess(event) {
console.log("检测到登录成功,刷新首页数据");
this.queryList();
},
queryList() {
if (this.isEnd) {
common_vendor.index.showToast({
title: "没有更多数据了哦!^v^",
icon: "none",
complete: () => {
console.log("no more data");
}
});
return;
}
let param = {
index: this.page,
size: this.size,
tag: this.tag
};
try {
common_vendor.index.$http.get("/resource/list", param).then((resp) => {
var _a;
console.log("resp data", resp.data);
(_a = resp.data) == null ? void 0 : _a.list.forEach((item, idx) => {
this.list.push({
id: item == null ? void 0 : item.id,
name: item == null ? void 0 : item.name,
src: item == null ? void 0 : item.thumb_src,
android_src: item == null ? void 0 : item.android_src
});
});
console.log("length:", this.list.length, resp.data.page.rows, resp.data.page);
if (this.list.length >= resp.data.page.rows) {
this.isEnd = true;
} else {
this.isEnd = false;
}
this.page++;
});
} catch (err) {
console.log("catch query list err:", err);
}
}
}
};
if (!Array) {
const _easycom_smart_tabs2 = common_vendor.resolveComponent("smart-tabs");
const _easycom_image_grid_simple2 = common_vendor.resolveComponent("image-grid-simple");
(_easycom_smart_tabs2 + _easycom_image_grid_simple2)();
}
const _easycom_smart_tabs = () => "../../components/smart-tabs/smart-tabs.js";
const _easycom_image_grid_simple = () => "../../components/image-grid-simple/image-grid-simple.js";
if (!Math) {
(_easycom_smart_tabs + _easycom_image_grid_simple)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return {
a: common_vendor.o($options.handleTabChange),
b: common_vendor.p({
tabs: $data.tabs,
["initial-index"]: $data.current,
activeColor: "#19c324"
}),
c: common_vendor.o($options.handlerClick),
d: common_vendor.o($options.queryList),
e: common_vendor.p({
imageList: $data.list,
columns: 2,
height: "80vh"
})
};
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);