Kaynağa Gözat

Merge branch 'master' of http://121.37.83.100:3000/sooka_edyj/sooka_edyj_minapp

zhanghongrui 2 yıl önce
ebeveyn
işleme
f22c3cf7f6
10 değiştirilmiş dosya ile 273 ekleme ve 189 silme
  1. 2 1
      app.js
  2. 3 1
      app.json
  3. 28 33
      base/httputil.js
  4. 92 7
      pages/denglu/denglu.js
  5. 2 2
      pages/denglu/denglu.wxml
  6. 20 27
      pages/index/index.js
  7. 3 3
      pages/index/index.wxss
  8. 116 102
      pages/me/me.js
  9. 7 11
      pages/me/me.wxml
  10. 0 2
      pages/notice/notice.json

+ 2 - 1
app.js

@@ -3,5 +3,6 @@ App({
   globalToken: null,
   globalData:{
     host : "http://ccsjkj.top:4002"
-  }
+  },
+  isLoginSuccess:false,
 })

+ 3 - 1
app.json

@@ -67,5 +67,7 @@
   },
   "style": "v2",
   "sitemapLocation": "sitemap.json",
-  "lazyCodeLoading": "requiredComponents"
+  "lazyCodeLoading": "requiredComponents",
+  "onReachBottomDistance":50
+
 }

+ 28 - 33
base/httputil.js

@@ -5,7 +5,7 @@
 
 
 
- //let BASE_Server = "https://192.168.1.100:18080"
+//  let BASE_Server = "https://192.168.1.100:18080"
 let BASE_Server = "https://sookajs.top:18080"
 
 let app = getApp()
@@ -94,14 +94,9 @@ function loginSuccess(res) {
 
 
 function send_post(url, data, successfun) {
-  console.log("令牌:", app.globalToken)
-  // if(app.globalToken==null){
-  //   wx.reLaunch({
-  //     url: '../denglu/denglu',
-  //   })
-  // }
-  //如果令牌为空或过期,需要重新请求
 
+  console.log("令牌:", app.globalToken)
+  
   wx.request({
     url: BASE_Server + url, //仅为示例,并非真实的接口地址 
     method: "POST",
@@ -146,20 +141,6 @@ 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({
@@ -184,13 +165,6 @@ function get(url, data, successfun) {
 
 function send_get(url, data, successfun) {
   console.log("令牌:", app.globalToken)
-  // if(app.globalToken==null){
-  //   wx.reLaunch({
-  //     url: '../denglu/denglu',
-  //   })
-  // }
-  //如果令牌为空或过期,需要重新请求
-
   wx.request({
     url: BASE_Server + url, //仅为示例,并非真实的接口地址 
     method: "GET",
@@ -294,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)
+//     }
+//   })
+// }

+ 92 - 7
pages/denglu/denglu.js

@@ -1,3 +1,5 @@
+import http from '../../base/httputil'
+const app = getApp()
 // pages/denglu/denglu.js
 Page({
 
@@ -6,12 +8,85 @@ Page({
    */
   data: {
     userName:"",
-    password:""
+    password:"",
+    wxCode:"",
+    openid:"",
+  },
+   /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+    app.isLoginSuccess=false;
+    let that=this;
+    wx.login({
+      success(res) {
+        that.data.wxCode = res.code
+        console.log("login_wxCode_load",":"+that.data.wxCode)
+        that.getOpenIdBywxCode()
+      },
+      fail(res) {
+        console.log("ffff", res)
+      }
+    })
   },
   bindViewlogin(){
-    console.log("要提交给服务器的用户名和密码是",this.data.userName,this.data.password);
+    if(!this.data.userName){
+      wx.showToast({
+        title: '请输入用户名',
+        icon:'none',
+        duration:2000
+      })
+      return
+    }
+    if(!this.data.password){
+      wx.showToast({
+        title: '请输入密码',
+        icon:'none',
+        duration:2000
+      })
+      return
+    }
+    let that=this;
+    console.log("要提交给服务器的用户名和密码是",this.data.wxCode+"_"+this.data.userName+"_"+this.data.password);
+    var data = {
+      // 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)
   },
   
+  bindSuccess(res) {
+    let that = this
+    if (res.code != 200) {
+      wx.showToast({
+        title: res.msg,
+        icon: "none"
+      })
+      // that.setData({
+      //   isShowAccoutDialog : true
+      // })
+      
+    } 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
+      })
+      wx.reLaunch({
+        url: '../index/index',
+      })
+    }
+
+  },
   bindViewUserName(e){
     this.data.userName = e.detail.value;
   },
@@ -19,12 +94,22 @@ Page({
   bindViewPassword(e){
     this.data.password = e.detail.value
   },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
 
+  getOpenIdBywxCode(){
+    let that=this
+    var data = {
+      wxCode: that.data.wxCode,
+    }  
+    http.send_post("/system/minapp/AppLoginController/getSessionKeyOropenid", data, this.openIdSuccess)
+  },
+  openIdSuccess(res){
+    let that = this
+    if (res!=null&&res.openid!=null) {
+      that.data.openid = res.openid
+      wx.setStorageSync('openid', res.openid)
+    }
   },
+ 
 
   /**
    * 生命周期函数--监听页面初次渲染完成
@@ -37,7 +122,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-
+    
   },
 
   /**

+ 2 - 2
pages/denglu/denglu.wxml

@@ -15,8 +15,8 @@
   <!-- 中间内容 -->
   <view class="form_con">
     <view class="form_vi">
-      <input class="weui-input"  placeholder="请输入用户名" bindinput="bindViewUserName"/>
-      <input class="weui-input" password type="text" placeholder="这是一个密码输入框" bindinput="bindViewPassword"/>
+      <input class="weui-input"  placeholder="请输入用户名" bindinput="bindViewUserName" maxlength="11"/>
+      <input class="weui-input" password type="text" placeholder="这是一个密码输入框" bindinput="bindViewPassword" maxlength="15"/>
       <button type="" class="dl_btn" bindtap="bindViewlogin">登录</button>
       <!-- <button type="" class="qx_btn">取消</button> -->
     </view>

+ 20 - 27
pages/index/index.js

@@ -43,9 +43,8 @@ Page({
     //功能数据-孙一石
     //记录首页点击-登录后继续跳转
     dofun: null,
-    xunjianImgCount: 0,
+    xunjianImgCount: '000,000',
     NoticeTitle:"登录查看公告"
-
   },
 
   onLoad() {
@@ -59,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();
   },
 
@@ -195,14 +203,18 @@ Page({
   },
 
   initIndexPage() {
+    if(app.globalToken==null||app.globalToken==''){
+      return
+    }
+   
     http.send_post("/system/AppIndexController/getIndexPageData", null, this.initIndexPageSuccess)
   },
+ 
   initIndexPageSuccess(res) {
-    console.log("@@",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
@@ -212,29 +224,10 @@ Page({
         NoticeTitle:"暂无公告"
       })
     }
-  },
-
-  loginSuccess(res) {
-    if (res.code != 200) {
-      wx.showToast({
-        title: res.msg,
-        icon: "none"
-      })
-    } else {
-      app.globalToken = res.data.access_token
-      //登录成功,获取首页数据
-      this.initIndexPage()
     }
-    console.log("!!!!!", app.globalToken)
-
+  
   },
 
-
-
-
-
-
-
   // getSysUserInfo(info) {
   //   let that = this
   //   wx.login({

+ 3 - 3
pages/index/index.wxss

@@ -101,21 +101,21 @@ page{
   position: relative;
 }
 .top_banner p{
-  font-size: 30rpx;
+  font-size: 20rpx;
   height: 60rpx;
   line-height: 60rpx;
   color: rgba(0, 0, 0, 0.5);
   padding-top: 20rpx;
 }
 .top_banner h1{
-  font-size: 44rpx;
+  font-size: 55rpx;
   height: 60rpx;
   line-height: 60rpx;
   color: rgba(0, 0, 0, 0.9);
   font-weight: 500;
 }
 .top_banner span{
-  font-size: 24rpx;
+  font-size: 20rpx;
   height: 40rpx;
   line-height: 40rpx;
   color: #d2d2d2;

+ 116 - 102
pages/me/me.js

@@ -9,77 +9,69 @@ Page({
   data: {
     isShowAccoutDialog : false,
     isBindSuccess : false,
-    userInfo:null,
-    userName :"点击登录",
+    userName :'未登录',
     password: null,
     openid: null
   },
+  onLoad(e){
+    this.setData({
+      isBindSuccess : app.isLoginSuccess,
+      // userName:
+    })
+    if(app.isLoginSuccess){
+    this.data.userName=wx.getStorageSync('userName')
+    this.setData({
+      userName:this.data.userName
+    })
+    }
+  },
+  onShow() {
+    
+  },
   inputUserName(e){
     this.userName = e.detail.value
   },
   inputPassword(e){
     this.password = e.detail.value
   },
-
-  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)
-        },
+  isLogin(){
+    if(!app.isLoginSuccess){
+      wx.reLaunch({
+        url: '../denglu/denglu',
+      })
+    }else{
+      wx.showModal({
+        title: '提示',
+        content: '确认退出?',
+        complete: (res) => {
+          if (res.cancel) {
+            
+          }
+      
+          if (res.confirm) {
+            this.clear()
+            
+          }
+        }
       })
     }
   },
-  getSysUserInfo(info) {
-    let that = this
-    wx.login({
-      success(res) {
-        var code = res.code
-        var data = {
-          wxCode: code,
-          wxNickName: info.nickName,
-          wxAvatarUrl: info.avatarUrl
-        }
+
+bindViewClear(){
+  wx.showModal({
+    title: '提示',
+    content: '确认清除缓存?',
+    complete: (res) => {
+      if (res.cancel) {
         
-        http.send_post("/auth/applogin", data, that.loginSuccess)
-      },
-      fail(res) {
-        console.log("ffff", res)
       }
-    })
-  },
-  loginSuccess(res) {
-    let that = this
-    if (res.code != 200) {
-      that.openid = res.openid
-      wx.showToast({
-        title: res.msg,
-        icon: "none"
-      })
-      // http.hideLoading()
-      that.setData({
-        isShowAccoutDialog : true
-      })
-      
-    } else {
-      app.globalToken = res.data.access_token
-      console.log("登陆成功的令牌:",app.globalToken )
-      //登录成功,获取首页数据
-      // http.hideLoading()
-      this.setData({
-        isBindSuccess : true
-      })
+  
+      if (res.confirm) {
+        this.clear()
+      }
     }
-  },
+  })
+},
 
 clear(){
   wx.clearStorage({
@@ -87,18 +79,14 @@ clear(){
       wx.showToast({
         title: '清理成功',
       })
-      wx.removeStorageSync('userInfo');
-      wx.removeStorageSync('openid');
       app.globalToken=null;
+      app.isLoginSuccess=false;
      this.setData({
       isShowAccoutDialog : false,
-      isBindSuccess : false,
-      userInfo:null,
-      
-      userName :"游客",
+      isBindSuccess : false,      
+      userName :"未登录",
       password: null,
       openid: null
-     
      })
     wx.reLaunch({
       url: '../denglu/denglu'
@@ -106,51 +94,15 @@ 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
-      })
-    }
-
-  },
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
-    
-  },
-
+  
+ 
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady() {
 
   },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
+ 
 
   /**
    * 生命周期函数--监听页面隐藏
@@ -186,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
+  //     })
+  //   }
+
+  // },
 })

+ 7 - 11
pages/me/me.wxml

@@ -1,14 +1,15 @@
 <view class="container_c">
 <view class="top_con">
-  <image src="{{userInfo.avatarUrl}}" class="wd_img" wx:if="{{!isBindSuccess}}" bindtap="init_userInfo"   ></image>
-   <image src="{{userInfo.avatarUrl}}" class="wd_img" wx:if="{{isBindSuccess}}" ></image>
+  <image src="{{userInfo.avatarUrl}}" class="wd_img"bindtap="isLogin"></image>
+   <!-- <image src="{{userInfo.avatarUrl}}" class="wd_img" wx:if="{{isBindSuccess}}" bindtap="isLogin" ></image> -->
   <view class="top_txt">
     <!-- <div type="userNickName" lang="zh_CN" class="wd_txt">
     {{userInfo.nickName}}
   </div> -->
-  <text class="userNickName"  wx:if="{{!isBindSuccess}}">{{userName}}</text>
-  <text class="userNickName" wx:if="{{isBindSuccess}}" >{{userInfo.nickName}}</text>
-  <text>部门:</text>
+  <text class="userNickName" >{{userName}}</text>
+  <!-- <text class="userNickName"  wx:if="{{isBindSuccess}}">{{userName}}</text> -->
+  <!-- <text class="userNickName" wx:if="{{isBindSuccess}}" >{{userInfo.nickName}}</text> -->
+  <!-- <text>部门:</text> -->
   </view>
   <image src="../images/me.png" class="me_bg"/>
 </view>
@@ -23,7 +24,7 @@
         <i class="iconfont icon-xiangyou"></i>
       </view>
   </view>
-  <view class="tit_one" bindtap="clear" wx:if="{{isBindSuccess}}" >
+  <view class="tit_one" bindtap="bindViewClear" wx:if="{{isBindSuccess}}" >
     <image src="../images/metit1.png" class="metit" />
     <view class="meline">
       <i class="iconfont icon-yunongtongqingchuhuancun" ></i>
@@ -41,11 +42,6 @@
   </view>
 </view>
 
- 
-
-  
-
-
   <!-- <button wx:if="{{!isBindSuccess}}" bindtap="init_userInfo" class="wd_btn">绑定账号</button>
   <label wx:if="{{isBindSuccess}}">账号绑定成功</label> -->
 

+ 0 - 2
pages/notice/notice.json

@@ -10,8 +10,6 @@
   "enablePullDownRefresh": true,
   "onPullDownRefresh": true,
   "onReachBottom": true,
-
   "navigationBarTitleText": "公告"
-
 }