lrf402788946 4 éve
szülő
commit
ded7c20919
5 módosított fájl, 34 hozzáadás és 50 törlés
  1. 10 8
      app.js
  2. 0 1
      pages/bind/index.js
  3. 17 32
      pages/index/index.js
  4. 0 1
      pages/index/index.wxml
  5. 7 8
      pages/work/index.js

+ 10 - 8
app.js

@@ -7,6 +7,10 @@ App({
     wx.setStorageSync('logs', logs)
     var that = this;
     // 登录
+    wx.showLoading({
+      title: '加载中...',
+      mask: true,
+    })
     wx.login({
       success: res => {
         // 发送 res.code 到后台换取 openId, sessionKey, unionId
@@ -20,18 +24,15 @@ App({
             success: function (result) {
               const res = result.data;
               that.globalData.openid = res.openid;
-              if (!res.user) {
-                wx.redirectTo({
-                  url: '/pages/bind/index',
-                })
-              } else {
-                that.globalData.userInfo = res.user;
-              }
+              that.globalData.userInfo = res.user;
             },
             fail: function (error) {
               console.info("获取用户openId失败");
               console.info(error);
-            }
+            },
+            complete() {
+              wx.hideLoading()
+            },
           })
         }
       }
@@ -43,5 +44,6 @@ App({
     unionid: null,
     contentpath: 'https://jytz.jilinjobs.cn/',
     cookie: null,
+    code: null,
   }
 })

+ 0 - 1
pages/bind/index.js

@@ -34,7 +34,6 @@ Page({
       dataType: 'json',
       success: (res) => {
         const r = res.data;
-        console.log(r)
         if (r.errcode == '0') {
           wx.showToast({
             title: '绑定成功',

+ 17 - 32
pages/index/index.js

@@ -4,7 +4,7 @@ const app = getApp()
 
 Page({
   data: {
-    motto: 'Hello World'
+    motto: 'Hello World',
   },
   //事件处理函数
   bindViewTap: function () {
@@ -12,44 +12,29 @@ Page({
       url: '../logs/logs'
     })
   },
-  onLoad: function () {
-  },
   classBtn: function () {
-    console.log(111);
+    const user = app.globalData.userInfo;
+    if (!user) {
+      this.toBind();
+      return;
+    }
     wx.redirectTo({
       url: '../work/index?type=0',
-      success: function (r) {
-        console.log('in success')
-        console.log(r)
-
-      },
-      fail: function (r) {
-        console.log('in fail')
-        console.log(r)
-
-      },
-      complete: function () {
-        console.log(2222);
-      }
     })
   },
   beedroomBtn: function () {
-    console.log(222);
-    var that = this;
+    const user = app.globalData.userInfo;
+    if (!user) {
+      this.toBind();
+      return;
+    }
     wx.redirectTo({
       url: '../work/index?type=1',
-      success: function (r) {
-        console.log('in success')
-        console.log(r)
-
-      },
-      fail: function (r) {
-        console.log('in fail')
-        console.log(r)
-      },
-      complete: function () {
-        console.log(2222);
-      }
     })
-  }
+  },
+  toBind() {
+    wx.redirectTo({
+      url: '/pages/bind/index',
+    })
+  },
 })

+ 0 - 1
pages/index/index.wxml

@@ -1,6 +1,5 @@
 <!--index.wxml-->
 <view class="container">
-  <span>{{userInfo.name}}</span>
   <view class="userinfo">
     <button bindtap="classBtn" type="primary">上课考勤</button>
   </view>

+ 7 - 8
pages/work/index.js

@@ -39,14 +39,15 @@ Page({
     });
   },
   ibeaconBtn: function () {
-    console.log(111);
     var that = this;
+    wx.showLoading({
+      title: '正在签到...',
+      mask: true,
+    })
     wx.startBeaconDiscovery({
       uuids: ['FDA50693-A4E2-4FB1-AFCF-C6EB07647825'],
       success(res) {
-        console.log(res);
         wx.onBeaconUpdate(function (beacons) {
-          console.log('onBeaconUpdate')
           wx.getBeacons({
             success: function (res) {
               console.log('getBeacons');
@@ -71,9 +72,6 @@ Page({
               wx.stopBeaconDiscovery({
                 success: function (res) {
                   console.log('停止扫描');
-                  // console.log('距离啊距离-->' + master);
-                  // if (master < limit) {
-                  console.log('请求啊请求' + master);
                   let newdata = {
                     openid: app.globalData.openid,
                     type: that.data.type,
@@ -91,7 +89,6 @@ Page({
                       //res.data相当于ajax里面的data,为后台返回的数据
                       //如果在sucess直接写this就变成了wx.request()的this了
                       //必须为getdata函数的this,不然无法重置调用函数
-                      console.log(res);
                       if (res.data.errcode == 0) {
                         that.addsuc();
                       } else {
@@ -103,7 +100,9 @@ Page({
                       console.log('签到失败' + err);
                       that.addmsg(err);
                     },//请求失败
-                    complete: function () { }//请求完成后执行的函数
+                    complete: function () {
+                      wx.hideLoading()
+                    }//请求完成后执行的函数
                   })
                   // }
                 }