lx před 5 roky
rodič
revize
8626d323f9
3 změnil soubory, kde provedl 99 přidání a 21 odebrání
  1. 94 18
      pages/index/index.js
  2. 3 1
      pages/index/index.json
  3. 2 2
      project.config.json

+ 94 - 18
pages/index/index.js

@@ -56,7 +56,7 @@ function initChart(canvas, width, height, dpr, data) {
           color: ['#2B2B2B']
         }
       },
-      boundaryGap: false,//1.true 数据点在2个刻度直接  2.fals 数据点在分割线上,即刻度值上
+      boundaryGap: false,//1.true 数据点在2个刻度直接  2.false 数据点在分割线上,即刻度值上
       data: data.timeData,
       axisLine: {onZero: true},
       axisLabel: {
@@ -81,6 +81,7 @@ function initChart(canvas, width, height, dpr, data) {
       //   fontStyle:'normal'
       // },
       splitNumber: 5,//坐标轴的分割段数
+      scale:true,
       splitLine: {//坐标轴在 grid 区域中的分隔线。
         show: true,
         lineStyle: {
@@ -161,6 +162,10 @@ Page({
     userInfo: {},
     hasUserInfo: false,
     canIUse: wx.canIUse('button.open-type.getUserInfo'),
+    currPage:1,//当前页
+    pages:0,//每页条数
+    total:0,//总条数
+    aa:[],//列表
 
     imagewidth: 0,//缩放后的宽 
     imageheight: 0,//缩放后的高 
@@ -173,11 +178,11 @@ Page({
     //   ]
     // },
       chartDatas:{
-        actual:[572,556,3555,4744,552,576,3555],
-        prediction:[352,246,385,2424,542,546,255],
-        timeData : [
-          '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
-        ]
+        // actual:[572,556,3555,4744,552,576,3555],
+        // prediction:[352,246,385,2424,542,546,255],
+        // timeData : [
+        //   '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7'
+        // ]
       },
       ec: {
         onInit: initChart,
@@ -302,16 +307,7 @@ Page({
       // },
     ],
   },
-  //获取新闻列表
-  getNewsList:function(){
-    apiServer.getNewsList().then((res)=>{
-      if(res.statusCode == 200){
-        this.setData({
-          aa:res.data.data
-        })    
-      }
-    })
-  },
+ 
   //事件处理函数
   bindViewTap: function() {
     wx.navigateTo({
@@ -349,8 +345,8 @@ Page({
     //    console.log(res.top);
     // }).exec();
  },
-  onLoad: function () {
-    this.getNewsList();
+  onLoad: function (options) {
+    getNewsList(this);
     this.getHushen();
     let sysinfo = wx.getSystemInfoSync(),
     windowHeight = sysinfo.windowHeight,
@@ -402,6 +398,19 @@ Page({
     //     }
     //   })
     // }
+  },
+   /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+      //下拉刷新,重新初始化,isMerge = false
+      getNewsList(this);
+  },
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+      setPage(this);
   },
   computeScrollViewHeight() {
     var that = this
@@ -641,3 +650,70 @@ Page({
   }
 
 })
+  /**
+ * method:分页加载控制函数
+ * 
+ */
+function setPage(that) {
+  const {
+    currPage,
+      pages,
+      total
+  } = that.data;
+  const totalPages = getTotalPages(total,pages);
+
+  if (currPage >= totalPages || that.isLoading) {
+      //控制触底是否加载需要两个条件,满足一下两个条件,都不能调用请求函数
+      // 1.当前页是最后一页,
+      // 2. 正在加载中
+      return
+  }
+  //分页加载需要传递isMerge=true参数,表示需要合并到原来的数组上
+  getList(that,true)
+}
+/**
+ * method:得到总页数
+ * @param {Number,String} total 列表总数
+ * @param {Number,String} pages 每一页的条数
+ * @return {Number} totalPages 总页数 
+ */
+function getTotalPages(total,pages){
+  //总数除以每一页条数 如果余数!=0,结果需要+1
+  const remainder = Number(total) % Number(pages);
+  const value = Math.floor(total / pages);
+  const totalPages = remainder == 0 ? value : Number(value) + 1;
+  return totalPages
+}
+ //获取新闻列表
+ function getNewsList(that,isMerge){
+   that.isLoading = true
+   wx.showLoading({
+    title: '加载中',
+})
+const data = {};
+data.currPage = Number(that.data.currPage) + 1;
+if(!isMerge){
+    //不合并,页码需要重新设置为1
+    data.currPage = 1;
+}
+  apiServer.getNewsList(data).then((res)=>{
+    if(res.statusCode == 200){
+      let aa = that.data.aa;
+      if(!isMerge){
+          aa = [];
+      }
+      aa = aa.concat(res.data.data.incInfos)
+      that.setData({
+        aa,
+        currPage:res.data.data.current,
+        pages: res.data.data.pages,
+        total: res.data.data.total
+      })    
+    }
+    that.isLoading = false
+    wx.stopPullDownRefresh();
+    setTimeout(function(){
+        wx.hideLoading()
+    },500)
+  })
+}

+ 3 - 1
pages/index/index.json

@@ -3,5 +3,7 @@
   "usingComponents": {
     "navBar": "/components/navBar/navBar",
     "ec-canvas": "../../ec-canvas/ec-canvas"
-  }
+  },
+  "onReachBottomDistance":50,
+  "enablePullDownRefresh": true
 }

+ 2 - 2
project.config.json

@@ -25,9 +25,9 @@
 			"disablePlugins": [],
 			"outputPath": ""
 		},
-		"useIsolateContext": true,
 		"useCompilerModule": true,
-		"userConfirmedUseCompilerModuleSwitch": false
+		"userConfirmedUseCompilerModuleSwitch": false,
+		"useIsolateContext": true
 	},
 	"compileType": "miniprogram",
 	"libVersion": "2.11.1",