侯体宗的博客
  • 首页
  • Hyperf2.1版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

微信小程序实现二维码签到考勤系统

微信(小程序)  /  管理员 发布于 2年前   697

一。手动生成二维码的.js代码

这里要引入一个官方文档wxapp.qrcode.min.js

let drawQrcode = require('../utils/wxapp.qrcode.min.js');//引入wxapp.qrcode.min.js文件createQRcode(canvasWidth, canvasHeight, canvasId, url) {  // 调用qrcode.js里的方法,传入对应参数  drawQrcode({   width: canvasWidth,   height: canvasHeight,   canvasId: canvasId,   text: url  })  console.log(drawQrcode.width) }, setCanvasSize() {  let size = {};  // getSystemInfoSync 微信小程序提供getSystemInfoSync获取设备的信息  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();   //调用createQRcode方法   that_.createQRcode(size.w, size.h, 'mycanvars', url);   wx.hideToast();   clearTimeout(timer);  }, 2000)}, /**  * 生命周期函数--监听页面加载  */ onLoad: function (options) {  //setCanvasSize 拿到画布区域的尺寸(微信小程序不支持dom的操作,所以单独定义方法去获取)  let size = this.setCanvasSize();  // console.log(size);  let url = this.data.placeholder;  //调用createQRcode方法  this.createQRcode(size.w, size.h, 'mycanvars', url); },

二。准备工作,导入数据库表,和unit.js。获取时间

const DB = wx.cloud.database().collection("cows")const TB = wx.cloud.database().collection("log")let i = 0let 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: '已签到,请勿重复签到',    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: '已签退,请勿重复签退',     icon: 'none'    })   }   else{    wx.showToast({     title: '请先签到,签到之后方可签退!',     icon: 'none'    })   }  } },

第四。页面监听签退后会跳出签退页面。重新进入需要监听。

 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)   }  })

到这,一个简单的签到页面就完成了。如有不对的地方,小菜鸟期盼大神的指导。
希望对你们有用处。

总结

以上所述是小编给大家介绍的微信小程序实现二维码签到考勤系统,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

您可能感兴趣的文章:

  • 微信小程序动态生成二维码的实现代码
  • 微信小程序 获取二维码实例详解
  • 微信小程序 二维码canvas绘制实例详解
  • 微信小程序实现签到功能


  • 上一条:
    微信小程序发送订阅消息的方法(php 为例)
    下一条:
    微信小程序indexOf的替换方法(推荐)
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • TP(3/5)
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • 微信小程序前端使用七牛云官方SDK上传七牛云代码示例(0个评论)
    • 百度小程序审核未通过,真机审核存在点击返回键退出小程序...解决方式之一tabBar(0个评论)
    • 百度小程序详情页中使用wxapp-rich-text组件解析html标签并展示出来(0个评论)
    • 百度小程序列表中点击跳转详情页流程步骤(0个评论)
    • 百度小程序封装get post请求等全局函数及实现请求后端api数据循环展示功能(0个评论)
    • 近期文章
    • Laravel 9.13版本发布(0个评论)
    • beego+GeoLite2免费数据库获取ip地址经纬度等定位归属信息(0个评论)
    • redis安全配置之修改端口、添加密码流程步骤及启动使用(0个评论)
    • PHP + Memcache实现简单的统计当前在线人数功能(0个评论)
    • Thinkphp5.1框架中实现Session+Redis会话共享流程步骤(0个评论)
    • go语言中使用Signbit()函数判断一个整数是正数或负数(0个评论)
    • 删库跑路之一链家程序员删除公司9TB数据被判7年,望各大码农警之!(0个评论)
    • Laravel角色和权限:拦截器Gates和策略Policies的解释(0个评论)
    • Laravel 9.12版本发布(0个评论)
    • go语言中实现把数据写入文件函数WriteFile()编写(0个评论)
    • 近期评论
    • 博主 在

      hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 @路过的靓仔:cdn静态资源被墙,已修复..
    • GGGGGGGGG 在

      layui框架常用输入框介绍中评论 写的很好解决问题..
    • 路过的靓仔 在

      hyperf框架常用命令-在centos7中退出命令及在docker容器中退出命令中评论 剩下好多 wait 状态的..
    • 激光豆芽 在

      为什么你不能安逸?国内996为什么没有国外955香?中评论 国内现在无意义的内卷太多了..
    • 激光豆芽 在

      阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 厉害了..
    • 2017-10
    • 2018-01
    • 2020-03
    • 2021-06
    • 2021-10
    • 2022-03
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客