瀏覽代碼

bind username

y595705120 3 年之前
父節點
當前提交
cd6f5df424
共有 6 個文件被更改,包括 93 次插入19 次删除
  1. 20 12
      app.js
  2. 57 0
      pages/index/index.js
  3. 3 3
      pages/index/index.wxml
  4. 11 2
      pages/rili/index.js
  5. 1 1
      project.config.json
  6. 1 1
      sitemap.json

+ 20 - 12
app.js

@@ -57,9 +57,21 @@ App({
       return;
     }
     let _this = this
-    let openid = wx.getStorageSync('@openid');
-    if( !openid ) return cb && cb({code:401});
-    let param = {"openid": openid};
+    let token = wx.getStorageSync('@token');
+    if(!token) return;
+    wx.login({
+      success(wxres) {
+        if( !wxres.code){
+          util.showMsg("登入失败")
+        }else{
+          _this.doLoginByCode( wxres.code, cb )
+        }
+      }
+    })
+  },
+  doLoginByCode( code, cb ){
+    let param = {code};
+    let _this = this;
     _this.formPost('Auth.wxLogin', param).then( res =>{
       if (res.code == 200) {
         _this.setUserInfo(res.data);
@@ -78,7 +90,7 @@ App({
   formPost: function (action, data) {
     let _this = this
     let userInfo = this.globalData.userInfo||{}
-    let user_id = userInfo.uid||0;
+    let user_id = userInfo.userId||0;
     let token = userInfo.token||'';
     let timestamp = Date.now()
     action = action.toLowerCase()
@@ -130,16 +142,12 @@ App({
     })
   },
   checkNavigateTo: function(url){
-    let openid = wx.getStorageSync('@openid');
-    if( !openid ) return this.gotoLogin()
+    let token = wx.getStorageSync('@token');
+    if( !token ) return this.gotoLogin()
     wx.navigateTo({url})
   },
-  setUserInfo: function (info) {
-    let {token, user} = info
-    console.log("setUserInfo", token, user)
+  setUserInfo: function (user) {
     this.globalData.userInfo = user;
-    wx.setStorageSync('@token', token)
-    wx.setStorageSync('@userId', user.userId )
-    this.loadDepartments()
+    wx.setStorageSync('@token', user.token)
   }
 })

+ 57 - 0
pages/index/index.js

@@ -1,6 +1,7 @@
 //index.js
 
 const util = require("../../utils/util")
+const md5 = require("../../utils/md5")
 
 //获取应用实例
 const app = getApp()
@@ -9,6 +10,8 @@ Page({
   data: {
     buyModel:false,
     system: "",
+    username:'',
+    password:'',
     userInfo:{},
   },
   onLoad: function(){
@@ -17,11 +20,65 @@ Page({
       console.log("login", res)
     })
   },
+  wxLogin(){
+    let that = this
+    wx.login({
+      success(wxres) {
+        if( !wxres.code){
+          util.showMsg("登入失败")
+        }else{
+          that.doLoginByCode( wxres.code )
+        }
+      }
+    })
+  },
+  doLoginByCode( code ){
+    app.formPost( "Auth.WxLogin", {code}).then( (res)=>{
+      if( res.code == 200){
+        this.setData( {userInfo: res.data})
+        app.setUserInfo( res.data )
+        this.goDefaultPage()
+      }
+    })
+  },
+  register( e ){
+    let that = this
+    wx.login({
+      success(wxres) {
+        if (wxres.code) {
+          that.doRegister( wxres.code, e.detail.value )
+        }
+      }
+    })
+  },
+  doRegister( code, info ){
+    let param = {
+      code: code,
+      username:   info.username,
+      password: md5.md5(info.password).toLowerCase(),
+    }
+    app.formPost( 'Auth.Register', param).then( res =>{
+      if( res.code == 200 ){
+        let studyUser= res.data
+        app.setUserInfo( studyUser )
+        util.showSuccess("实名认证成功")
+        this.goDefaultPage()
+        this.setData({studyUser})
+      }else{
+        util.showMsg( res.msg  )
+      }
+    })
+  },
   onPullDownRefresh() {
     if (!this.loading) {
       this.indexLoad( this.stopPullDownRefresh )
     }
   },
+  goDefaultPage(){
+    wx.switchTab({
+      url: 'pages/rili/index',
+    })
+  },
   onShareAppMessage: function(){
   }
 })

+ 3 - 3
pages/index/index.wxml

@@ -14,9 +14,9 @@
   </view>
 
   <view  class="login-form">
-    <form  bindsubmit="doIdentify" >
-      <i-input name="phone" title="用户" class="p20" maxlength="20" />
-      <i-input name="passwd" title="密码" class="p50" type="password" maxlength="100" />
+    <form  bindsubmit="register" >
+      <i-input name="username" title="用户" class="p20" maxlength="20" />
+      <i-input name="password" title="密码" class="p50" type="password" maxlength="100" />
       <button  class="i-btn  i-btn-primary i-btn-square mt40" form-type="submit">绑定账号</button>
     </form>
   </view>

+ 11 - 2
pages/rili/index.js

@@ -1,5 +1,5 @@
 import { jump } from '../../component/calendar/index.js';
-
+const app = getApp()
 const conf = {
   data: {
     calendarConfig: {
@@ -9,7 +9,7 @@ const conf = {
   },
   doSomeThing() {
     // 调用日历方法
-    this.calendar.enableArea(['2018-10-7', '2018-10-28']);
+    this.calendar.enableArea(['2022-3-7', '2022-4-7']);
   }
 };
 Page({
@@ -21,6 +21,15 @@ Page({
   afterTapDay(e) {
     console.log('afterTapDay', e.detail); // => { currentSelect: {}, allSelectedDays: [] }
   },
+  onLoad: function(){
+    app.checkLogin(res=>{
+      if( !res.userId ){
+        wx.navigateTo({
+          url: '/pages/index/index',
+        })
+      }
+    })
+  },
   /**
    * 当日历滑动时触发(适用于周/月视图)
    * 可在滑动时按需在该方法内获取当前日历的一些数据

+ 1 - 1
project.config.json

@@ -41,7 +41,7 @@
   },
   "compileType": "miniprogram",
   "libVersion": "2.8.0",
-  "appid": "wxb5577767d780051d",
+  "appid": "wx147197ea9d0b992b",
   "projectname": "%E5%86%85%E4%B8%9A%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F",
   "debugOptions": {
     "hidedInDevtools": []

+ 1 - 1
sitemap.json

@@ -1,5 +1,5 @@
 {
-  "desc": "内业管理系统",
+  "desc": "莅临&外出",
   "rules": [{
   "action": "allow",
   "page": "*"