Browse Source

下拉刷新

zjh 5 years ago
parent
commit
f36c6a521f
8 changed files with 151 additions and 52 deletions
  1. 10 3
      api/request.js
  2. 2 1
      api/urls.js
  3. 7 8
      pages/attention/attention.js
  4. 120 30
      pages/index/index.js
  5. 3 1
      pages/index/index.json
  6. 5 5
      pages/index/index.wxml
  7. 2 2
      pages/index/index.wxss
  8. 2 2
      project.config.json

+ 10 - 3
api/request.js

@@ -40,12 +40,19 @@ const service = {
   }
 }
 module.exports = {
-  //沪深
-  getHushen:(data) =>{
+  //上证
+  getHz:(data) =>{
     return new Promise((resolve,reject)=> {
-      resolve(service.get(urls.hushen,data))
+      resolve(service.get(urls.hz,data))
     })
   },
+ //深证
+ getSz:(data) =>{
+  return new Promise((resolve,reject)=> {
+    resolve(service.get(urls.sz,data))
+  })
+},
+
   // 获取新闻列表
   getNewsList: (data) => {
     return new Promise((resolve,reject)=> {

+ 2 - 1
api/urls.js

@@ -1,7 +1,8 @@
 const host = 'http://192.168.1.73:28002';
 
 const urls ={
-    hushen:host + '/api/his/hushen',
+    hz:host + '/api/his/hz',
+    sz:host+ '/api/his/sz',
     newsList:host + '/api/news/list',
     detail:host +'/api/news/details',
     search: host + '/api/news/search',

+ 7 - 8
pages/attention/attention.js

@@ -60,22 +60,21 @@ Page({
       onInit: initChart
     },
     array:[],
+    currentPage:1
 
   },
   onLoad: function() {
     var that = this;
     // 获取关注的信息
+    console.log(this.data.currentPage)
     var userId={
-      userId:wx.getStorageSync('openid')
-      // userId:'ocVI541TGfnTChi5DlIa7beac2YM'
-    }
-    // console.log(userId);
+      userId:wx.getStorageSync('openid'),
+      currPage:this.data.currentPage
+    };
     var that = this;
-    // this.getFollow(userId);
     wx.showLoading({title: '加载中…'})
-    wxRequest.followList(userId).then((res)=>{
-      
-      // console.log(res);
+    wxRequest.followList(userId).then((res)=>{     
+      console.log(res);
       // console.log(res.data.data); 
       wx.hideLoading()    
       if(res.statusCode==200){

+ 120 - 30
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,23 +162,27 @@ Page({
     userInfo: {},
     hasUserInfo: false,
     canIUse: wx.canIUse('button.open-type.getUserInfo'),
+    currPage:1,//当前页
+    pages:0,//每页条数
+    total:0,//总条数
+    aa:[],//列表
 
     imagewidth: 0,//缩放后的宽 
     imageheight: 0,//缩放后的高 
-    // chartData:{
-    //   actual:[552,586,3555,4454,552,556,4455],
-    //   prediction:[552,546,3585,4424,542,546,35,44,524,56,355,444,2224,421],
-    //   timeData : [
-    //     '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7', '2020/6/8', '2020/6/9', '2020/6/10','2020/6/11',
-    //     '2020/6/12','2020/6/13','2020/6/14',
-    //   ]
-    // },
+    chartData:{
+      // actual:[552,586,3555,4454,552,556,4455],
+      // prediction:[552,546,3585,4424,542,546,35,44,524,56,355,444,2224,421],
+      // timeData : [
+      //   '2020/6/1', '2020/6/2', '2020/6/3', '2020/6/4', '2020/6/5', '2020/6/6', '2020/6/7', '2020/6/8', '2020/6/9', '2020/6/10','2020/6/11',
+      //   '2020/6/12','2020/6/13','2020/6/14',
+      // ]
+    },
       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,25 +307,16 @@ Page({
       // },
     ],
   },
-  //获取新闻列表
-  getNewsList:function(){
-    apiServer.getNewsList().then((res)=>{
-      if(res.statusCode == 200){
-        this.setData({
-          aa:res.data.data
-        })    
-      }
-    })
-  },
+ 
   //事件处理函数
   bindViewTap: function() {
     wx.navigateTo({
       url: '../logs/logs'
     })
   },
-  //沪深
-  getHushen:function(){
-    apiServer.getHushen().then((res) =>{
+  //上证
+  getHz:function(){
+    apiServer.getHz().then((res) =>{
       if(res.statusCode == 200){
         console.log(res);
           this.setData({
@@ -329,6 +325,17 @@ Page({
       }
     })
   },
+  //深证
+  getSz:function(){
+    apiServer.getSz().then((res) =>{
+      if(res.statusCode == 200){
+        console.log(res);
+          this.setData({
+            chartData:this.recursion(res.data.data),
+        })
+      }
+    })
+  },
   recursion:function(row,a=[],b=[],c=[],d){
     for(let i in row.actuals){
     a.unshift(row.actuals[i].industryDate)
@@ -349,9 +356,10 @@ Page({
     //    console.log(res.top);
     // }).exec();
  },
-  onLoad: function () {
-    this.getNewsList();
-    this.getHushen();
+  onLoad: function (options) {
+    this.getHz();
+    this.getSz();
+    getNewsList(this);
     let sysinfo = wx.getSystemInfoSync(),
     windowHeight = sysinfo.windowHeight,
     statusHeight = sysinfo.statusBarHeight, 
@@ -402,6 +410,21 @@ Page({
     //     }
     //   })
     // }
+  },
+   /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+      //下拉刷新,重新初始化,isMerge = false
+      console.log("1312432");
+      getNewsList(this);
+  },
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+    console.log("触发")
+      setPage(this);
   },
   computeScrollViewHeight() {
     var that = this
@@ -641,3 +664,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
 }

+ 5 - 5
pages/index/index.wxml

@@ -5,9 +5,9 @@
 <navBar></navBar>
 <view class="container" style="height:{{height}}px" >
   <view class="swiper-tab">
-    <!-- <view class="swiper-tab-list {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">沪深</view>
-    <view class="swiper-tab-list {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">港股</view> -->
-    <view class="swiper-tab-list">沪深</view>
+    <view class="swiper-tab-list {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">上证</view>
+    <view class="swiper-tab-list {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">深证</view>
+    <!-- <view class="swiper-tab-list">沪深</view> -->
     <!-- <image class="image" src="./images/001.png" bindtap='choose'></image> -->
   </view>
   <!-- <view class="userinfo">
@@ -43,9 +43,9 @@
        <ec-canvas  id="mychart-dom-line" canvas-id="mychart-line" tuData="{{ chartDatas }}" ec="{{ ec }}"></ec-canvas>
      </view>
     </swiper-item>
-    <!-- <swiper-item catchtouchmove='catchTouchMove'>
+    <swiper-item catchtouchmove='catchTouchMove'>
       <ec-canvas  id="mychart-dom-line" canvas-id="mychart-line" tuData="{{ chartData }}" ec="{{ ec }}"></ec-canvas>
-    </swiper-item> -->
+    </swiper-item>
    </swiper>
         <!-- <view class="middleCharts">
           <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" tuData=" {{ chartData }}" ec="{{ ec }}"></ec-canvas>

+ 2 - 2
pages/index/index.wxss

@@ -43,8 +43,8 @@ ec-canvas {
 }
 .swiper-tab {
   width: 100%;
-  margin-left: 80rpx;
-  /* text-align: center; */
+  /* margin-left: 80rpx; */
+  text-align: center;
   line-height: 80rpx;
   position: relative;
   color: #fff;

+ 2 - 2
project.config.json

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