|
|
@@ -1,6 +1,4 @@
|
|
|
// pages/match/index.js
|
|
|
-const app = getApp();
|
|
|
-var util = require("../../utils/util.js");
|
|
|
|
|
|
Page({
|
|
|
|
|
|
@@ -8,186 +6,20 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- appAssetsUrl2: app.appAssetsUrl2,
|
|
|
- matchList: [],
|
|
|
- statusBarHeightTop: 0,
|
|
|
- statusBarHeight: 0,
|
|
|
- // 分页相关数据
|
|
|
- pageNum: 1,
|
|
|
- pageSize: 10,
|
|
|
- total: 0,
|
|
|
- hasMore: true,
|
|
|
- isLoading: false,
|
|
|
- imglist: [],
|
|
|
- current: 0,
|
|
|
- activeTitle: false,
|
|
|
- nodata: util.nodata(),
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 赛事项目点击事件
|
|
|
- */
|
|
|
- onMatchItemTap(e) {
|
|
|
- const index = e.currentTarget.dataset.index;
|
|
|
- const matchItem = this.data.matchList[index];
|
|
|
- console.log('点击赛事项目:', matchItem);
|
|
|
-
|
|
|
- // 跳转到详情页面
|
|
|
- wx.navigateTo({
|
|
|
- url: `/pages/match/details/index?id=${matchItem.id}`
|
|
|
- });
|
|
|
+ webViewUrl: '',
|
|
|
+ token: '',
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad(options) {
|
|
|
- this.height();
|
|
|
- this.loadImg();
|
|
|
- // 加载赛事数据
|
|
|
- this.loadMatchData();
|
|
|
- },
|
|
|
- changeSwiper(e) {
|
|
|
- let {
|
|
|
- current,
|
|
|
- source
|
|
|
- } = e.detail;
|
|
|
- if (source === "autoplay" || source === "touch") {
|
|
|
- this.setData({
|
|
|
- current: current,
|
|
|
- });
|
|
|
- }
|
|
|
- // this.setData({
|
|
|
- // current: e.detail.current
|
|
|
- // })
|
|
|
- },
|
|
|
- //banner跳转
|
|
|
- imgJump(v) {
|
|
|
- // console.log(v);
|
|
|
- // console.log(v.currentTarget.dataset.item.jumpAddressType);
|
|
|
- if (v.currentTarget.dataset.item.jumpAddressType == 0) {
|
|
|
- //内部跳转
|
|
|
- wx.navigateTo({
|
|
|
- url: v.currentTarget.dataset.item.linkUrl,
|
|
|
- });
|
|
|
- } else if (v.currentTarget.dataset.item.jumpAddressType == 1) {
|
|
|
- //公众号跳转 'https://www.kujiale.cn/design/3FO4EQWQJF0M/show'
|
|
|
- wx.setStorageSync("gzurl", v.currentTarget.dataset.item.linkUrl);
|
|
|
- wx.navigateTo({
|
|
|
- url: "./gz/gz",
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
- // 首页banner
|
|
|
- loadImg: function () {
|
|
|
- let _this = this;
|
|
|
- let params = {
|
|
|
- type: "03",
|
|
|
- area: "",
|
|
|
- };
|
|
|
- app._post_form("img/mylist", "application/json", params, function (res) {
|
|
|
- if (res.code == 0) {
|
|
|
- _this.setData({
|
|
|
- imglist: res.data,
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 加载赛事数据
|
|
|
- */
|
|
|
- loadMatchData() {
|
|
|
- // 如果正在加载或没有更多数据,则不执行
|
|
|
- if (this.data.isLoading || !this.data.hasMore) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- this.setData({
|
|
|
- isLoading: true
|
|
|
- });
|
|
|
-
|
|
|
- wx.showLoading({
|
|
|
- title: this.data.pageNum === 1 ? '加载中...' : '加载更多...'
|
|
|
- });
|
|
|
-
|
|
|
- // 调用API获取赛事数据
|
|
|
- const params = {
|
|
|
- page: this.data.pageNum,
|
|
|
- pageSize: this.data.pageSize
|
|
|
- };
|
|
|
-
|
|
|
- // 使用项目中已有的请求方法
|
|
|
- app._get('news/page', params, (res) => {
|
|
|
- wx.hideLoading();
|
|
|
- this.setData({
|
|
|
- isLoading: false
|
|
|
- });
|
|
|
-
|
|
|
- if (res.code === 0) {
|
|
|
- // 处理返回的数据
|
|
|
- const newList = res.page.list || [];
|
|
|
- const total = res.page.totalCount || 0;
|
|
|
-
|
|
|
- // 如果是第一页,直接设置数据;否则追加数据
|
|
|
- const matchList = this.data.pageNum === 1 ? newList : [...this.data.matchList, ...newList];
|
|
|
-
|
|
|
- this.setData({
|
|
|
- matchList: matchList,
|
|
|
- total: total,
|
|
|
- hasMore: matchList.length < total
|
|
|
- });
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: '数据加载失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- }
|
|
|
- }, (fail) => {
|
|
|
- wx.hideLoading();
|
|
|
+ let token = wx.getStorageSync('token');
|
|
|
+ if (!token) {
|
|
|
this.setData({
|
|
|
- isLoading: false
|
|
|
- });
|
|
|
- wx.showToast({
|
|
|
- title: '请求失败',
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
-
|
|
|
- /**
|
|
|
- * 重置并重新加载数据
|
|
|
- */
|
|
|
- reloadMatchData() {
|
|
|
- this.setData({
|
|
|
- pageNum: 1,
|
|
|
- matchList: [],
|
|
|
- hasMore: true
|
|
|
- });
|
|
|
- this.loadMatchData();
|
|
|
- },
|
|
|
-
|
|
|
- height() {
|
|
|
- const {
|
|
|
- platform,
|
|
|
- statusBarHeight
|
|
|
- } = wx.getSystemInfoSync();
|
|
|
- let statusBarHeightTop = statusBarHeight;
|
|
|
- let height = statusBarHeight + 4; //ios 24px
|
|
|
- let mH = statusBarHeight + 4;
|
|
|
- if (platform.toLowerCase() == "android") {
|
|
|
- height += 4; //android 28px
|
|
|
- mH += 4;
|
|
|
+ webViewUrl: 'http://192.168.0.193:5173/'
|
|
|
+ })
|
|
|
}
|
|
|
- height = height + 60;
|
|
|
- // height = height + 38 + 118;
|
|
|
- // 胶囊高度 32px 下边框6px height 状态栏高度
|
|
|
- this.setData({
|
|
|
- statusBarHeightTop: statusBarHeightTop + "px",
|
|
|
- statusBarHeight: height + "px",
|
|
|
- statusBarMH: mH + "px",
|
|
|
- });
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -201,7 +33,15 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
+ let token = wx.getStorageSync('token');
|
|
|
// 页面显示时刷新数据
|
|
|
+ if (this.data.token != token) {
|
|
|
+ this.setData({
|
|
|
+ token,
|
|
|
+ webViewUrl: `http://192.168.0.193:5173/?token=${token}`,
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -222,24 +62,14 @@ Page({
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
*/
|
|
|
onPullDownRefresh() {
|
|
|
- this.loadImg();
|
|
|
- // 下拉刷新
|
|
|
- this.reloadMatchData();
|
|
|
- wx.stopPullDownRefresh();
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
*/
|
|
|
onReachBottom() {
|
|
|
- // 上拉加载更多
|
|
|
- console.log('加载更多赛事数据');
|
|
|
- if (this.data.hasMore && !this.data.isLoading) {
|
|
|
- this.setData({
|
|
|
- pageNum: this.data.pageNum + 1
|
|
|
- });
|
|
|
- this.loadMatchData();
|
|
|
- }
|
|
|
+
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -248,22 +78,4 @@ Page({
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
},
|
|
|
- onPageScroll: function (e) {
|
|
|
- if (
|
|
|
- e.scrollTop >= 10 &&
|
|
|
- this.data.activeTitle == false
|
|
|
- ) {
|
|
|
- this.setData({
|
|
|
- activeTitle: true,
|
|
|
- });
|
|
|
- }
|
|
|
- if (
|
|
|
- e.scrollTop < 10 &&
|
|
|
- this.data.activeTitle == true
|
|
|
- ) {
|
|
|
- this.setData({
|
|
|
- activeTitle: false,
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
});
|