فهرست منبع

登录逻辑修改

menc 2 سال پیش
والد
کامیت
36bdbeb909
8فایلهای تغییر یافته به همراه261 افزوده شده و 136 حذف شده
  1. 58 26
      base/httputil.js
  2. 11 11
      pages/denglu/denglu.js
  3. 30 5
      pages/index/index.js
  4. 2 2
      pages/index/index.wxml
  5. 64 65
      pages/me/me.js
  6. 70 23
      pages/notice/notice.js
  7. 4 4
      pages/notice/notice.wxml
  8. 22 0
      pages/notice/notice_details.wxml

+ 58 - 26
base/httputil.js

@@ -94,13 +94,9 @@ function loginSuccess(res) {
 
 
 function send_post(url, data, successfun) {
+
   console.log("令牌:", app.globalToken)
-  // if(app.globalToken==null){
-  //   wx.reLaunch({
-  //     url: '../denglu/denglu',
-  //   })
-  // }
-  //如果令牌为空或过期,需要重新请求
+  
   wx.request({
     url: BASE_Server + url, //仅为示例,并非真实的接口地址 
     method: "POST",
@@ -145,27 +141,14 @@ function post(url, data, successfun) {
   })
 }
 
-// function wxpost(url, data, successfun) {
-//   wx.request({
-//     url: BASE_Server + url, //仅为示例,并非真实的接口地址
-//     method: "POST",
-//     header: {
-//       'content-type': 'application/json',
-//       'Authorization': 'Bearer ' + app.globalToken
-//     },
-//     data: data,
-//     success(res) {
-//       successfun(res.data)
-//     }
-//   })
-// }
 
 function get(url, data, successfun) {
   wx.request({
     url: BASE_Server + url, //仅为示例,并非真实的接口地址
-    method: "Get",
+    method: "GET",
     header: {
-      'content-type': 'application/x-www-form-urlencoded'
+      'content-type': 'application/x-www-form-urlencoded',
+      'Authorization': 'Bearer ' + app.globalToken
     },
     params: data,
     success(res) {
@@ -179,6 +162,33 @@ function get(url, data, successfun) {
   })
 }
 
+
+function send_get(url, data, successfun) {
+  console.log("令牌:", app.globalToken)
+  wx.request({
+    url: BASE_Server + url, //仅为示例,并非真实的接口地址 
+    method: "GET",
+    header: {
+      'content-type': 'application/json',
+      'Authorization': 'Bearer ' + app.globalToken
+    },
+    data: data,
+    success(res) {
+      // var d = decodeURIComponent(decodeURIComponent(res.data.data))
+      // var json = JSON.parse(d)
+      console.log("TAG","返回数据:"+res.data)
+      authToken(res.data)
+      successfun(res.data)
+    },
+    fail(res){
+      wx.showToast({
+        title: "网络请求失败",
+      })
+    }
+
+  })
+}
+
 function send_postdecode(url, data, successfun) {
   wx.request({
     url: BASE_Server + url, //仅为示例,并非真实的接口地址
@@ -236,6 +246,7 @@ module.exports = {
   post: post,
   // wxpost: wxpost,
   get: get,
+  send_get:send_get,
   send_postdecode: send_postdecode,
 
 
@@ -257,9 +268,30 @@ function hideLoading() {
 }
 
 function authToken(res){
-  if(res.code==300){
-    wx.reLaunch({
-      url: '../denglu/denglu',
+  if(res.code==401){//登录token过期状态码
+    wx.clearStorage({
+      success:(res)=>{
+      wx.reLaunch({
+            url: '../denglu/denglu',
+          })
+      }
     })
+    
   }
-}
+}
+ 
+
+// function wxpost(url, data, successfun) {
+//   wx.request({
+//     url: BASE_Server + url, //仅为示例,并非真实的接口地址
+//     method: "POST",
+//     header: {
+//       'content-type': 'application/json',
+//       'Authorization': 'Bearer ' + app.globalToken
+//     },
+//     data: data,
+//     success(res) {
+//       successfun(res.data)
+//     }
+//   })
+// }

+ 11 - 11
pages/denglu/denglu.js

@@ -30,7 +30,7 @@ Page({
     })
   },
   bindViewlogin(){
-    if(!this.data.userName||!this.data.password){
+    if(!this.data.userName){
       wx.showToast({
         title: '请输入用户名',
         icon:'none',
@@ -49,11 +49,12 @@ Page({
     let that=this;
     console.log("要提交给服务器的用户名和密码是",this.data.wxCode+"_"+this.data.userName+"_"+this.data.password);
     var data = {
-      wxCode: this.data.wxCode,
+      // wxCode: this.data.wxCode,
       // wxNickName: this.data.userName,
       // wxAvatarUrl: info.avatarUrl
       userName:this.data.userName,
       password:this.data.password,
+      openid:this.data.openid,
     }
     http.send_post("/system/minapp/AppLoginController/bindWxUser", data, that.bindSuccess)
   },
@@ -61,7 +62,6 @@ Page({
   bindSuccess(res) {
     let that = this
     if (res.code != 200) {
-      that.openid = res.openid
       wx.showToast({
         title: res.msg,
         icon: "none"
@@ -71,10 +71,12 @@ Page({
       // })
       
     } else {
+      // that.data.openid = res.openid
       app.globalToken = res.data.access_token
       console.log("登陆成功的令牌:",app.globalToken)
       wx.setStorageSync('userName', that.data.userName)
       wx.setStorageSync('password', that.data.password)
+      wx.setStorageSync('access_token', app.globalToken)
       app.isLoginSuccess=true;
       this.setData({
         isBindSuccess : true
@@ -95,18 +97,16 @@ Page({
 
   getOpenIdBywxCode(){
     let that=this
-   var data = {
-    wxCode: that.data.wxCode,
-  }
-  console.log("login_wxCode",":"+that.data.wxCode)
-  http.send_post("/minapp/AppLoginController/getSessionKeyOropenid", data, this.openIdSuccess)
+    var data = {
+      wxCode: that.data.wxCode,
+    }  
+    http.send_post("/system/minapp/AppLoginController/getSessionKeyOropenid", data, this.openIdSuccess)
   },
   openIdSuccess(res){
     let that = this
-    if (res.code != 200) {
+    if (res!=null&&res.openid!=null) {
       that.data.openid = res.openid
-      console.log("login_wxOpenid",":"+that.data.openid )
-
+      wx.setStorageSync('openid', res.openid)
     }
   },
  

+ 30 - 5
pages/index/index.js

@@ -43,8 +43,8 @@ Page({
     //功能数据-孙一石
     //记录首页点击-登录后继续跳转
     dofun: null,
-    xunjianImgCount: '000,000'
-
+    xunjianImgCount: '000,000',
+    NoticeTitle:"登录查看公告"
   },
 
   onLoad() {
@@ -58,6 +58,15 @@ Page({
   },
 
   onShow(){
+    let token =wx.getStorageSync('access_token')
+    if(token==''||token==null){
+      app.globalToken=null
+      wx.showToast({
+        title: '尚未登录,登录后即可使用',
+        icon:'none'
+      })
+    }
+    
     this.initIndexPage();
   },
 
@@ -186,13 +195,29 @@ Page({
   },
 
   initIndexPage() {
+    if(app.globalToken==null||app.globalToken==''){
+      return
+    }
+   
     http.send_post("/system/AppIndexController/getIndexPageData", null, this.initIndexPageSuccess)
   },
  
   initIndexPageSuccess(res) {
-    this.setData({
-      xunjianImgCount: res.xunjianImgCount
-    })
+    if(res.code==200){
+      this.setData({
+          xunjianImgCount: res.xunjianImgCount,
+        })
+    if(res.noticeList.length>0){
+      this.setData({
+        NoticeTitle:res.noticeList[0].noticeTitle
+      })
+    }else{
+      this.setData({
+        NoticeTitle:"暂无公告"
+      })
+    }
+    }
+  
   },
 
   // getSysUserInfo(info) {

+ 2 - 2
pages/index/index.wxml

@@ -53,8 +53,8 @@
   <!-- 通知公告 -->
   <view class="tzgg">
     <image class="img" src="{{host}}/images/xcx_lb.png" />
-    <b>[待办]</b>
-    <text>隐患排查已整改,请核查!</text>
+    <!-- <b>[待办]</b> -->
+    <text>{{NoticeTitle}}</text>
     <view class="more" data-fun="bindViewGengDuo" bindtap="init_userInfo">更多></view>
   </view>
   <!-- 中间图片banner -->

+ 64 - 65
pages/me/me.js

@@ -56,42 +56,6 @@ Page({
       })
     }
   },
-  // init_userInfo() {
-
-  //   let that = this
-  //   if (app.globalToken == null) {
-  //     wx.getUserProfile({
-  //       desc: 'desc',
-  //       success: (res) => {
-  //         this.getSysUserInfo(res.userInfo)
-  //         that.setData({
-  //           userInfo : res.userInfo
-  //         })
-  //       },
-  //       fail: res => {
-  //         console.log(res)
-  //       },
-  //     })
-  //   }
-  // },
-  // getSysUserInfo(info) {
-  //   let that = this
-  //   wx.login({
-  //     success(res) {
-  //       var code = res.code
-  //       var data = {
-  //         wxCode: code,
-  //         wxNickName: info.nickName,
-  //         wxAvatarUrl: info.avatarUrl
-  //       }
-        
-  //       http.send_post("/auth/applogin", data, that.loginSuccess)
-  //     },
-  //     fail(res) {
-  //       console.log("ffff", res)
-  //     }
-  //   })
-  // },
 
 bindViewClear(){
   wx.showModal({
@@ -108,15 +72,13 @@ bindViewClear(){
     }
   })
 },
+
 clear(){
   wx.clearStorage({
     success: (res) => {
       wx.showToast({
         title: '清理成功',
       })
-      wx.removeStorageSync('userName');
-      wx.removeStorageSync('password');
-      wx.removeStorageSync('openid');
       app.globalToken=null;
       app.isLoginSuccess=false;
      this.setData({
@@ -125,7 +87,6 @@ clear(){
       userName :"未登录",
       password: null,
       openid: null
-     
      })
     wx.reLaunch({
       url: '../denglu/denglu'
@@ -133,31 +94,7 @@ clear(){
     },
   })
 },
-  // modalCancel(){
-  //   this.setData({
-  //     isShowAccoutDialog : false
-  //   })
-  // },
-  // modalSubmit(){
-  //   let obj = new Object()
-  //   obj.openid = this.openid
-  //   obj.userName = this.userName
-  //   obj.password = this.password
-  //   http.send_post("/system/minapp/AppLoginController/bindWxUser",obj,this.modalSubmitSuccess)
-  // },
-  // modalSubmitSuccess(res){
-  //   wx.showToast({
-  //     title: res.msg,
-  //     icon: "none"
-  //   })
-  //   if (res.code == 200) {
-  //     this.setData({
-  //       isShowAccoutDialog : false,
-  //       isBindSuccess : true
-  //     })
-  //   }
-
-  // },
+  
  
   /**
    * 生命周期函数--监听页面初次渲染完成
@@ -201,4 +138,66 @@ clear(){
   onShareAppMessage() {
 
   }
+
+  // init_userInfo() {
+
+  //   let that = this
+  //   if (app.globalToken == null) {
+  //     wx.getUserProfile({
+  //       desc: 'desc',
+  //       success: (res) => {
+  //         this.getSysUserInfo(res.userInfo)
+  //         that.setData({
+  //           userInfo : res.userInfo
+  //         })
+  //       },
+  //       fail: res => {
+  //         console.log(res)
+  //       },
+  //     })
+  //   }
+  // },
+  // getSysUserInfo(info) {
+  //   let that = this
+  //   wx.login({
+  //     success(res) {
+  //       var code = res.code
+  //       var data = {
+  //         wxCode: code,
+  //         wxNickName: info.nickName,
+  //         wxAvatarUrl: info.avatarUrl
+  //       }
+        
+  //       http.send_post("/auth/applogin", data, that.loginSuccess)
+  //     },
+  //     fail(res) {
+  //       console.log("ffff", res)
+  //     }
+  //   })
+  // },
+  // modalCancel(){
+  //   this.setData({
+  //     isShowAccoutDialog : false
+  //   })
+  // },
+  // modalSubmit(){
+  //   let obj = new Object()
+  //   obj.openid = this.openid
+  //   obj.userName = this.userName
+  //   obj.password = this.password
+  //   http.send_post("/system/minapp/AppLoginController/bindWxUser",obj,this.modalSubmitSuccess)
+  // },
+  // modalSubmitSuccess(res){
+  //   wx.showToast({
+  //     title: res.msg,
+  //     icon: "none"
+  //   })
+  //   if (res.code == 200) {
+  //     this.setData({
+  //       isShowAccoutDialog : false,
+  //       isBindSuccess : true
+  //     })
+  //   }
+
+  // },
 })

+ 70 - 23
pages/notice/notice.js

@@ -13,29 +13,49 @@ Page({
      */
     loadingData: false,
     enterpriseList: [],
+    isRefresh: true,
+    total: 0,
     pageNum: 1 // 页码
   },
   onLoad: function () {
     // wx.showLoading({
     //   title: '加载中'
     // })
-    this.loadData(this.data.pageNum)
+    this.loadData()
   },
   //加载数据
-  loadData: function (num) {
-    http.send_post("/system/AppEnterpriseController/getInitEnterpriseList", null, this.getQiyeEnterpriseListSuccess)
+  loadData: function () {
+    let obj = new Object()
+    obj.pageNum = this.data.pageNum
+    obj.pageSize = 10
+    obj.reasonable= false
+    http.send_get("/system/AppNoticeController/getNotice", obj, this.getQiyeEnterpriseListSuccess)
 
 
   },
 
   getQiyeEnterpriseListSuccess(res) {
 
-    console.log("####" + this.pageNum)
-    this.setData({
-      enterpriseList: res.rows,
+console.log("@@@@",res)
+     // 显示加载图标
+     wx.showLoading({
+      title: '玩命加载中',
     })
     var that = this
-    if (this.data.pageNum == 1) {
+
+    if(res.data.rows.length==0){
+      wx.showToast({
+        title: '暂无更多数据',
+        icon:"none"
+      })
+    }
+    if (this.data.isRefresh) {
+      this.setData({
+        enterpriseList: res.data.rows,
+        total: res.data.total
+      })
+
+
       // 隐藏导航栏加载框
       setTimeout(function () {
         that.setData({
@@ -44,10 +64,14 @@ Page({
         wx.hideNavigationBarLoading();
         // 停止下拉动作
         wx.stopPullDownRefresh();
+        wx.hideLoading()
 
       }, 1000)
 
     } else {
+      this.setData({
+        enterpriseList: this.data.enterpriseList.concat(res.data.rows)
+      })
       // 隐藏加载框
 
       setTimeout(function () {
@@ -59,9 +83,8 @@ Page({
         wx.hideLoading();
       }, 1000)
 
-
-
     }
+
   },
   onPullDownRefresh: function () {
     // 显示顶部刷新图标
@@ -72,37 +95,61 @@ Page({
       return;
     }
     that.setData({
-      pageNum: 1
+      pageNum: 1,
+      isRefresh: true
     })
-    this.loadData(this.data.pageNum)
+    this.loadData()
   },
   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
-    var loadingData = this.data.loadingData
-    // 显示加载图标
-    wx.showLoading({
-      title: '玩命加载中',
-    })
-    var hidden = this.data.hidden
+    let that = this
+    var loadingData = that.data.loadingData
+   
+    var hidden = that.data.hidden
     // 页数+1
-    this.setData({
-      pageNum: this.data.pageNum + 1
+    that.setData({
+      pageNum: that.data.pageNum + 1,
+      isRefresh: false
     })
     if (hidden) {
-      this.setData({
+      that.setData({
         hidden: false
       });
-      console.info(this.data.hidden);
+      console.info(that.data.hidden);
     }
 
     if (loadingData) {
       return;
     }
-    this.setData({
+    that.setData({
       loadingData: true
     });
-    this.loadData(this.data.pageNum);
+
+    
+    //console.log("@@@@"+Math.ceil(this.data.total/10))
+   // if(Math.ceil(that.data.total/10)>=that.data.pageNum){
+      that.loadData();
+  
+    // }else{
+     
+    //   setTimeout(function () {
+    //     that.setData({
+    //       hidden: true,
+    //     });
+
+    //   }, 2000)
+    // }
+
+   
   },
+
+
+  bindViewDetails() {
+
+    wx.navigateTo({
+      url: '../notice/notice_details?busEnterpriseId=' +"d"
+    })
+  }
 })

+ 4 - 4
pages/notice/notice.wxml

@@ -4,10 +4,10 @@
 
 <!-- 列表 -->
 <view class="list_vi">
-    <view class="list_li" bindtap="bindViewDetails" wx:for="{{enterpriseList}}" wx:key="index" data-enterpriseid="{{item.busEnterpriseId}}">
-      <i class="list_icon iconfont icon-queding" wx:if="{{item.riskCount == 0}}"></i>
-      <i class="list_icon iconfont icon-yingjipingtai" wx:if="{{item.riskCount > 0}}"></i>
-      <text>{{item.businessName}}</text>
+    <view class="list_li" bindtap="bindViewDetails" wx:for="{{enterpriseList}}" wx:key="index" data-noticeId="{{item.noticeId}}">
+      <!-- <i class="list_icon iconfont icon-queding" wx:if="{{item.riskCount == 0}}"></i>
+      <i class="list_icon iconfont icon-yingjipingtai" wx:if="{{item.riskCount > 0}}"></i> -->
+      <text>{{item.noticeTitle}}</text>
       <i class="iconfont icon-xiangyou list_right"></i>
     </view>
     <view class='data-loading' hidden='{{hidden}}'>

+ 22 - 0
pages/notice/notice_details.wxml

@@ -0,0 +1,22 @@
+
+
+
+
+<!-- 列表 -->
+<view class="list_vi">
+    <view class="list_li" bindtap="bindViewDetails" wx:for="{{enterpriseList}}" wx:key="index" data-noticeId="{{item.noticeId}}">
+      <!-- <i class="list_icon iconfont icon-queding" wx:if="{{item.riskCount == 0}}"></i>
+      <i class="list_icon iconfont icon-yingjipingtai" wx:if="{{item.riskCount > 0}}"></i> -->
+      <text>{{item.noticeTitle}}</text>
+      <i class="iconfont icon-xiangyou list_right"></i>
+    </view>
+    <view class='data-loading' hidden='{{hidden}}'>
+    数据加载中...
+  </view>
+    </view>
+
+
+
+
+
+