微信小程序?qū)崿F(xiàn)二維碼簽到考勤系統(tǒng)
一。手動(dòng)生成二維碼的.js代碼
這里要引入一個(gè)官方文檔wxapp.qrcode.min.js
let drawQrcode = require('../utils/wxapp.qrcode.min.js');//引入wxapp.qrcode.min.js文件 createQRcode(canvasWidth, canvasHeight, canvasId, url) { // 調(diào)用qrcode.js里的方法,傳入對(duì)應(yīng)參數(shù) drawQrcode({ width: canvasWidth, height: canvasHeight, canvasId: canvasId, text: url }) console.log(drawQrcode.width) }, setCanvasSize() { let size = {}; // getSystemInfoSync 微信小程序提供getSystemInfoSync獲取設(shè)備的信息 let res = wx.getSystemInfoSync(); // console.log(res); // 獲取比例 let scale = 686 / 750; let width = res.windowWidth * scale; let height = width; size.w = width; size.h = height; return size; }, formsubmit(e) { let url = e.detail.value.url || this.data.placeholder; // let url = e.detail.value.url ? e.detail.value.url : this.data.placeholder; wx.showToast({ title: '生成中', icon: 'loading', duration: 2000 }) let that_ = this; let timer = setTimeout(() => { let size = that_.setCanvasSize(); //調(diào)用createQRcode方法 that_.createQRcode(size.w, size.h, 'mycanvars', url); wx.hideToast(); clearTimeout(timer); }, 2000)}, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function (options) { //setCanvasSize 拿到畫布區(qū)域的尺寸(微信小程序不支持dom的操作,所以單獨(dú)定義方法去獲?。? let size = this.setCanvasSize(); // console.log(size); let url = this.data.placeholder; //調(diào)用createQRcode方法 this.createQRcode(size.w, size.h, 'mycanvars', url); },
二。準(zhǔn)備工作,導(dǎo)入數(shù)據(jù)庫(kù)表,和unit.js。獲取時(shí)間
const DB = wx.cloud.database().collection("cows") const TB = wx.cloud.database().collection("log") let i = 0 let id='' var util = require('../utils/util.js');
三。寫入簽到簽退按鈕的.js代碼
now(){ var that = this; console.log(that.data.nows) if (i == 0 && that.data.now =='簽到'){ i=1; var time1 = util.formatTime(new Date()) DB.add({ data: { statctime:time1, endtime: '' }, success(res) { id=res._id console.log("簽到成功", res._id) }, fail(res) { console.log("簽到失敗", res) } }) that.setData({ statc: time1, now: '已簽到', color: 'rgb(199, 194, 194)' }) wx.showToast({ title: '簽到成功' }) var timeout= setTimeout(function(){ wx.switchTab({ url: '/pages/arrary/first/ones/ones', }) },1000) } else{ wx.showToast({ title: '已簽到,請(qǐng)勿重復(fù)簽到', icon: 'none' }) } }, nows(){ var that = this; if (i == 1 || that.data.now == '已簽到' && that.data.nows == '簽退'){ i=2; var time2 = util.formatTime(new Date()) DB.doc(id).update({ data: { endtime: time2 }, success(res) { console.log("簽退成功", res) }, fail(res) { console.log("簽退失敗", res) } }) that.setData({ ends: time2, nows: '已簽退', colors: 'rgb(199, 194, 194)' }) wx.showToast({ title: '簽退成功' }) } else { if(i==2){ wx.showToast({ title: '已簽退,請(qǐng)勿重復(fù)簽退', icon: 'none' }) } else{ wx.showToast({ title: '請(qǐng)先簽到,簽到之后方可簽退!', icon: 'none' }) } } },
第四。頁面監(jiān)聽簽退后會(huì)跳出簽退頁面。重新進(jìn)入需要監(jiān)聽。
var that = this wx.cloud.callFunction({ name: "getopenid", success(res) { var openid = res.result.openid DB.get({ success(e) { console.log(e) var lenths = e.data.length; console.log(lenths); var time1 = util.formatTime(new Date()) for (var i = 0; i < lenths; i++) { if (e.data[i]._openid == openid && e.data[i].statctime.substring(0, 10) == time1.substring(0, 10)) { var st = e.data[i].statctime var en = e.data[i].endtime that.setData({ statc: st, now: '已簽到', color: 'rgb(199, 194, 194)', }) } } }, fail(e) { console.log("查詢失敗", e) } }) console.log("獲取成功", res.result.openid) }, fail(res) { console.log("獲取成功", res) } })
到這,一個(gè)簡(jiǎn)單的簽到頁面就完成了。如有不對(duì)的地方,小菜鳥期盼大神的指導(dǎo)。
希望對(duì)你們有用處。
總結(jié)
以上所述是小編給大家介紹的微信小程序?qū)崿F(xiàn)二維碼簽到考勤系統(tǒng),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
輕松玩轉(zhuǎn)BootstrapTable(后端使用SpringMVC+Hibernate)
這篇文章主要和大家輕松玩轉(zhuǎn)BootstrapTable,后端使用SpringMVC+Hibernate,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-09-09Javascript模擬加速運(yùn)動(dòng)與減速運(yùn)動(dòng)代碼分享
這篇文章主要介紹了Javascript加速運(yùn)動(dòng)與減速運(yùn)動(dòng)代碼分享,需要的朋友可以參考下2014-12-12JavaScript中5個(gè)重要的Observer函數(shù)小結(jié)
瀏覽器為開發(fā)者提供了功能豐富的Observer,本文主要介紹了JavaScript中5個(gè)重要的Observer函數(shù)小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01