rlxf_pass.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. const {
  2. throttle
  3. } = require("../../../utils/throttle/throttle");
  4. const face = require('../../../utils/faceCheck/faceCheck')
  5. const {
  6. updateVisitDeviceUser
  7. } = require('../../../utils/api/api');
  8. import QRCode from '../../../utils/util/weapp-qrcode'
  9. const app = getApp()
  10. Page({
  11. /**
  12. * 页面的初始数据
  13. */
  14. data: {
  15. userInfo: {},
  16. machineInfo_FKJ: wx.getStorageSync('machineInfo_FKJ'),
  17. timeCount: 0,
  18. dateTime: '', //时间戳
  19. qrCode: '', //二维码
  20. timer: null,
  21. },
  22. //切换用户
  23. back() {
  24. wx.showModal({
  25. title: '提示',
  26. content: `确定要切换用户吗?`,
  27. success(res) {
  28. if (res.confirm) {
  29. wx.removeStorageSync('machineInfo_FKJ')
  30. // wx.removeStorageSync('dateCode')
  31. wx.reLaunch({
  32. url: '/pages/temporary_prove_FKJ/index/index'
  33. })
  34. }
  35. }
  36. })
  37. },
  38. //查看头像
  39. preview() {
  40. wx.previewImage({
  41. current: this.data.machineInfo_FKJ.avatar,
  42. urls: [this.data.machineInfo_FKJ.avatar],
  43. })
  44. },
  45. updateTime() {
  46. this.setData({
  47. dateTime: new Date().getTime()
  48. })
  49. console.log(this.data.dateTime);
  50. this.creatQrCode()
  51. },
  52. creatQrCode() {
  53. // wx.showLoading({
  54. // title: '加载中...',
  55. // })
  56. let that = this
  57. new QRCode('myQrcode', {
  58. text: `HHFKJ?userId=${this.data.machineInfo_FKJ.userId}&timestamp=${this.data.dateTime}`,
  59. width: 141, //canvas 画布的宽
  60. height: 141, //canvas 画布的高
  61. padding: 0, // 生成二维码四周自动留边宽度,不传入默认为0
  62. correctLevel: QRCode.CorrectLevel.L, // 二维码可辨识度
  63. callback: (res) => {
  64. console.log(res);
  65. //工具回调数据
  66. // 接下来就可以直接调用微信小程序的api保存到本地或者将这张二维码直接画在海报上面去,看各自需求
  67. // wx.hideLoading()
  68. //将图片路劲放入data中,显示在wxml的image标签上
  69. that.setData({
  70. qrCode: res.path,
  71. })
  72. }
  73. })
  74. },
  75. // 更新访客机用户
  76. updateVisitDeviceUser() {
  77. let {
  78. machineInfo_FKJ
  79. } = this.data
  80. let data = {
  81. workPlace: app.data.workPlace,
  82. carNumber: app.data.carNumber,
  83. userId: machineInfo_FKJ.userId
  84. }
  85. updateVisitDeviceUser(data).then(res => {
  86. if (res.code === 200) {
  87. machineInfo_FKJ.workPlace = app.data.workPlace
  88. machineInfo_FKJ.carNumber = app.data.carNumber
  89. wx.setStorageSync('machineInfo_FKJ', machineInfo_FKJ)
  90. this.setData({
  91. machineInfo_FKJ
  92. })
  93. } else {
  94. wx.showToast({
  95. title: res.msg,
  96. icon: 'none'
  97. })
  98. }
  99. })
  100. },
  101. /**
  102. * 生命周期函数--监听页面加载
  103. */
  104. onLoad: function () {
  105. this.setData({
  106. machineInfo_FKJ: wx.getStorageSync('machineInfo_FKJ')
  107. })
  108. if (app.data.workPlace) {
  109. wx.showModal({
  110. title: '提示',
  111. content: '恭喜认证成功,可刷码快速登记!',
  112. showCancel: false,
  113. })
  114. this.updateVisitDeviceUser()
  115. }
  116. },
  117. /**
  118. * 生命周期函数--监听页面初次渲染完成
  119. */
  120. onReady: function () {
  121. },
  122. /**
  123. * 生命周期函数--监听页面显示
  124. */
  125. onShow: function () {
  126. wx.hideHomeButton()
  127. this.updateTime()
  128. let _this = this
  129. this.setData({
  130. timer: setInterval(function () {
  131. _this.updateTime()
  132. }, 1000 * 30)
  133. })
  134. // setInterval(function () {
  135. // this.updateTime()
  136. // }.bind(this), 1000 * 30);
  137. },
  138. /**
  139. * 生命周期函数--监听页面隐藏
  140. */
  141. onHide: function () {
  142. clearInterval(this.data.timer);
  143. this.setData({
  144. timer: null
  145. })
  146. },
  147. /**
  148. * 生命周期函数--监听页面卸载
  149. */
  150. onUnload: function () {
  151. clearInterval(this.data.timer);
  152. this.setData({
  153. timer: null
  154. })
  155. },
  156. /**
  157. * 页面相关事件处理函数--监听用户下拉动作
  158. */
  159. onPullDownRefresh: function () {
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom: function () {
  165. },
  166. /**
  167. * 用户点击右上角分享
  168. */
  169. onShareAppMessage: function () {
  170. }
  171. })