lrf402788946 4 éve
commit
b145e46591

+ 14 - 0
.gitignore

@@ -0,0 +1,14 @@
+# Windows
+[Dd]esktop.ini
+Thumbs.db
+$RECYCLE.BIN/
+
+# macOS
+.DS_Store
+.fseventsd
+.Spotlight-V100
+.TemporaryItems
+.Trashes
+
+# Node.js
+node_modules/

+ 47 - 0
app.js

@@ -0,0 +1,47 @@
+//app.js
+App({
+  onLaunch: function () {
+    // 展示本地存储能力
+    var logs = wx.getStorageSync('logs') || []
+    logs.unshift(Date.now())
+    wx.setStorageSync('logs', logs)
+    var that = this;
+    // 登录
+    wx.login({
+      success: res => {
+        // 发送 res.code 到后台换取 openId, sessionKey, unionId
+        if (res.code) {
+          //获取openId
+          // 需要放到服务端去请求
+          wx.request({
+            url: that.globalData.contentpath + 'api/train/appAuth?js_code=' + res.code,
+            method: 'GET',
+            header: { 'content-type': 'application/json' },
+            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;
+              }
+            },
+            fail: function (error) {
+              console.info("获取用户openId失败");
+              console.info(error);
+            }
+          })
+        }
+      }
+    })
+  },
+  globalData: {
+    userInfo: null,
+    openid: null,
+    unionid: null,
+    contentpath: 'https://jytz.jilinjobs.cn/',
+    cookie: null,
+  }
+})

+ 16 - 0
app.json

@@ -0,0 +1,16 @@
+{
+  "pages": [
+    "pages/index/index",
+    "pages/bind/index",
+    "pages/work/index",
+    "pages/logs/logs"
+  ],
+  "window": {
+    "backgroundTextStyle": "light",
+    "navigationBarBackgroundColor": "#fff",
+    "navigationBarTitleText": "培训会考勤",
+    "navigationBarTextStyle": "black"
+  },
+  "style": "v2",
+  "sitemapLocation": "sitemap.json"
+}

+ 11 - 0
app.wxss

@@ -0,0 +1,11 @@
+/**app.wxss**/
+@import "weui.wxss";
+.container {
+  height: 100%;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: space-between;
+  padding: 200rpx 0;
+  box-sizing: border-box;
+} 

+ 119 - 0
pages/bind/index.js

@@ -0,0 +1,119 @@
+// pages/bind/index.js
+const app = getApp()
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    name: "",
+    mobile: "",
+    userInfo: {},
+  },
+
+  bindName(e) {
+    this.setData({
+      name: e.detail.value
+    })
+  },
+  bindMobile(e) {
+    this.setData({
+      mobile: e.detail.value
+    })
+  },
+
+  async toBind() {
+    const obj = { name: this.data.name, mobile: this.data.mobile, appopenid: app.globalData.openid };
+    wx.request({
+      url: app.globalData.contentpath + 'api/train/user/appbind',
+      header: {//请求头
+        "Content-Type": "application/json"
+      },
+      data: JSON.stringify(obj),
+      method: 'POST',
+      dataType: 'json',
+      success: (res) => {
+        const r = res.data;
+        console.log(r)
+        if (r.errcode == '0') {
+          wx.showToast({
+            title: '绑定成功',
+            icon: 'success',
+            duration: 3000
+          })
+          app.globalData.userInfo = r.data;
+          const userInfo = app.globalData.userInfo;
+          if (userInfo) {
+            wx.navigateTo({
+              url: '/pages/index/index',
+            })
+          }
+        } else {
+          wx.showToast({
+            title: r.errmsg || "绑定失败",
+            icon: 'errror',
+            duration: 3000
+          })
+        }
+      },
+      fail: (res) => {
+        console.log(res);
+
+      }
+    })
+
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
pages/bind/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 8 - 0
pages/bind/index.wxml

@@ -0,0 +1,8 @@
+<!--index.wxml-->
+<view class="container">
+ <form>
+  <input bindinput="bindName" placeholder="请输入姓名"/>
+  <input bindinput="bindMobile" placeholder="请输入手机号"/>
+  <button bindtap="toBind" type="primary">绑定</button>
+ </form>
+</view>

+ 5 - 0
pages/bind/index.wxss

@@ -0,0 +1,5 @@
+/* pages/bind/index.wxss */
+input {
+  border: 1px solid #ccc;
+  margin:10px;
+}

BIN
pages/images/qiandao.jpg


+ 55 - 0
pages/index/index.js

@@ -0,0 +1,55 @@
+//index.js
+//获取应用实例
+const app = getApp()
+
+Page({
+  data: {
+    motto: 'Hello World'
+  },
+  //事件处理函数
+  bindViewTap: function () {
+    wx.navigateTo({
+      url: '../logs/logs'
+    })
+  },
+  onLoad: function () {
+  },
+  classBtn: function () {
+    console.log(111);
+    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;
+    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);
+      }
+    })
+  }
+})

+ 3 - 0
pages/index/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 10 - 0
pages/index/index.wxml

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

+ 22 - 0
pages/index/index.wxss

@@ -0,0 +1,22 @@
+/**index.wxss**/
+.userinfo {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+
+.userinfo-avatar {
+  width: 128rpx;
+  height: 128rpx;
+  margin: 20rpx;
+  border-radius: 50%;
+}
+
+.userinfo-nickname {
+  color: #aaa;
+}
+
+.usermotto {
+  margin-top: 50px;
+}
+

+ 15 - 0
pages/logs/logs.js

@@ -0,0 +1,15 @@
+//logs.js
+const util = require('../../utils/util.js')
+
+Page({
+  data: {
+    logs: []
+  },
+  onLoad: function () {
+    this.setData({
+      logs: (wx.getStorageSync('logs') || []).map(log => {
+        return util.formatTime(new Date(log))
+      })
+    })
+  }
+})

+ 4 - 0
pages/logs/logs.json

@@ -0,0 +1,4 @@
+{
+  "navigationBarTitleText": "查看启动日志",
+  "usingComponents": {}
+}

+ 6 - 0
pages/logs/logs.wxml

@@ -0,0 +1,6 @@
+<!--logs.wxml-->
+<view class="container log-list">
+  <block wx:for="{{logs}}" wx:for-item="log">
+    <text class="log-item">{{index + 1}}. {{log}}</text>
+  </block>
+</view>

+ 8 - 0
pages/logs/logs.wxss

@@ -0,0 +1,8 @@
+.log-list {
+  display: flex;
+  flex-direction: column;
+  padding: 40rpx;
+}
+.log-item {
+  margin: 10rpx;
+}

+ 123 - 0
pages/work/index.js

@@ -0,0 +1,123 @@
+//index.js
+//获取应用实例
+const app = getApp()
+
+Page({
+  data: {
+    motto: 'Hello World',
+    type: '',
+    sucmsg: false,
+    warmsg: false,
+    errmsg: '',
+  },
+  //事件处理函数
+  bindViewTap: function () {
+    wx.navigateTo({
+      url: '../logs/logs'
+    })
+  },
+  onLoad: function (option) {
+    console.log(app.globalData.userInfo)
+    this.setData({
+      type: option.type
+    })
+  },
+  addsuc: function () {
+    this.setData({
+      sucmsg: true,
+      warmsg: false,
+    });
+  },
+  addmsg: function (errmsg) {
+    let msg = '';
+    if (errmsg.errCode == 11001) msg = '请打开蓝牙功能';
+    else msg = errmsg.errMsg;
+    this.setData({
+      warmsg: true,
+      sucmsg: false,
+      errmsg: msg,
+    });
+  },
+  ibeaconBtn: function () {
+    console.log(111);
+    var that = this;
+    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');
+              console.log(res)
+              if (res.errMsg != 'getBeacons:ok') {
+                that.addmsg({ errMsg: '获取蓝牙设备失败' });
+                return;
+              }
+              var master = 100000;
+              var mastername = '0';
+              var beaconList = [];
+              var limit = 5;
+              for (var i = 0; i < res.beacons.length; i++) {
+                var beacon = res.beacons[i];
+                if (beacon.accuracy < limit) {
+                  beaconList.push(beacon.minor);
+                }
+              }
+              console.log(res.beacons)
+              console.log('附近--');
+              console.log(beaconList);
+              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,
+                    ibeacon: beaconList
+                  };
+                  wx.request({
+                    url: app.globalData.contentpath + 'api/train/attendance/attendancecreate',
+                    header: {//请求头
+                      "Content-Type": "application/json"
+                    },
+                    data: newdata,
+                    method: 'POST',
+                    dataType: 'json',
+                    success: function (res) {
+                      //res.data相当于ajax里面的data,为后台返回的数据
+                      //如果在sucess直接写this就变成了wx.request()的this了
+                      //必须为getdata函数的this,不然无法重置调用函数
+                      console.log(res);
+                      if (res.data.errcode == 0) {
+                        that.addsuc();
+                      } else {
+                        console.log('签到失败' + res.data.errmsg);
+                        that.addmsg({ errMsg: res.data.errmsg });
+                      }
+                    },
+                    fail: function (err) {
+                      console.log('签到失败' + err);
+                      that.addmsg(err);
+                    },//请求失败
+                    complete: function () { }//请求完成后执行的函数
+                  })
+                  // }
+                }
+              });
+            }
+          })
+        })
+
+      },
+      fail(res) {
+        console.log('function in fail')
+        console.log(res);
+        that.addmsg(res);
+      }
+    })
+  }
+})

+ 3 - 0
pages/work/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 29 - 0
pages/work/index.wxml

@@ -0,0 +1,29 @@
+<!--index.wxml-->
+<view class="page">
+  <view class="fadeIn {{hideToast ? 'fadeOut' : ''}}" wx:if="{{toast}}">
+		<view class="weui-mask_transparent"></view>
+		<view class="weui-toast">
+			<i class="weui-icon-success-no-circle weui-icon_toast"></i>
+			<view class="weui-toast__content">已完成</view>
+		</view>
+	</view>
+  <view class="userinfo" bindtap="ibeaconBtn">
+  <image class="qiandaoImage" src="../images/qiandao.jpg" ></image>
+  <p class="qiandao">签到</p>
+    <!-- <button bindtap="ibeaconBtn" type="primary">签到</button> -->
+  </view>
+  <view wx:if="{{warmsg}}" class="weui-msg">
+		<view class="weui-msg__icon-area"><i class="weui-icon-warn weui-icon_msg"></i></view>
+		<view class="weui-msg__text-area">
+			<h2 class="weui-msg__title">签到失败</h2>
+			<view class="weui-msg__desc">{{errmsg}}</view>
+		</view>
+	</view>
+  <view wx:if="{{sucmsg}}" class="weui-msg">
+		<view class="weui-msg__icon-area"><i class="weui-icon-success weui-icon_msg"></i></view>
+		<view class="weui-msg__text-area">
+			<h2 class="weui-msg__title">签到成功</h2>
+			<view class="weui-msg__desc"></view>
+		</view>
+	</view>
+</view>

+ 35 - 0
pages/work/index.wxss

@@ -0,0 +1,35 @@
+/**index.wxss**/
+.userinfo {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+
+.userinfo-avatar {
+  width: 128rpx;
+  height: 128rpx;
+  margin: 20rpx;
+  border-radius: 50%;
+}
+
+.userinfo-nickname {
+  color: #aaa;
+}
+
+.usermotto {
+  margin-top: 50px;
+}
+
+.qiandaoImage{
+  margin: 115rpx auto 0 auto;
+  width: 300rpx;
+  height: 300rpx;
+}
+
+.qiandao{
+  margin: -70px 0 0 0;
+text-align: center;
+color: #fff;
+font-size: 20px;
+
+}

+ 61 - 0
project.config.json

@@ -0,0 +1,61 @@
+{
+	"description": "项目配置文件",
+	"packOptions": {
+		"ignore": []
+	},
+	"setting": {
+		"urlCheck": true,
+		"es6": true,
+		"enhance": false,
+		"postcss": true,
+		"preloadBackgroundData": false,
+		"minified": true,
+		"newFeature": true,
+		"coverView": true,
+		"nodeModules": false,
+		"autoAudits": false,
+		"showShadowRootInWxmlPanel": true,
+		"scopeDataCheck": false,
+		"uglifyFileName": false,
+		"checkInvalidKey": true,
+		"checkSiteMap": true,
+		"uploadWithSourceMap": true,
+		"compileHotReLoad": false,
+		"babelSetting": {
+			"ignore": [],
+			"disablePlugins": [],
+			"outputPath": ""
+		},
+		"useIsolateContext": true,
+		"useCompilerModule": false,
+		"userConfirmedUseCompilerModuleSwitch": false
+	},
+	"compileType": "miniprogram",
+	"libVersion": "2.11.0",
+	"appid": "wx3b5ac763ada73e0e",
+	"projectname": "train-ibea",
+	"debugOptions": {
+		"hidedInDevtools": []
+	},
+	"isGameTourist": false,
+	"simulatorType": "wechat",
+	"simulatorPluginLibVersion": {},
+	"condition": {
+		"search": {
+			"current": -1,
+			"list": []
+		},
+		"conversation": {
+			"current": -1,
+			"list": []
+		},
+		"game": {
+			"currentL": -1,
+			"list": []
+		},
+		"miniprogram": {
+			"current": -1,
+			"list": []
+		}
+	}
+}

+ 7 - 0
sitemap.json

@@ -0,0 +1,7 @@
+{
+  "desc": "关于本文件的更多信息,请参考文档 https://developers.weixin.qq.com/miniprogram/dev/framework/sitemap.html",
+  "rules": [{
+  "action": "allow",
+  "page": "*"
+  }]
+}

+ 19 - 0
utils/util.js

@@ -0,0 +1,19 @@
+const formatTime = date => {
+  const year = date.getFullYear()
+  const month = date.getMonth() + 1
+  const day = date.getDate()
+  const hour = date.getHours()
+  const minute = date.getMinutes()
+  const second = date.getSeconds()
+
+  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
+}
+
+const formatNumber = n => {
+  n = n.toString()
+  return n[1] ? n : '0' + n
+}
+
+module.exports = {
+  formatTime: formatTime
+}

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 6 - 0
weui.wxss