Files
lcb/pages/signup/code.js
T
2024-05-31 16:54:03 +08:00

161 lines
2.9 KiB
JavaScript

// pages/signup/code.js
import _ from '../../commons/js/commons'
const timer = require('../../commons/js/lib/wxTimer');
var wxTimer = null
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
navBar: {
title: '客户签到',
txtColor: '#fff',
bgColor: '#1a1c26',
isShowBg: true,
showHomeIcon: true
},
qrcode_img: '',
qrcode_count_time: 30,
wxTimerList: {},
wxTimer: null,
nowTime: "",
item: {},
info: "",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
let that = this
wx.getScreenBrightness({
success: (res) => {
that.setData({
ori_screen_bright: res.value
})
}
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
this.getappSignConf()
},
onHide() {
if (wxTimer) {
wxTimer.stop();
wxTimer = null
}
this.setData({
wxTimerList: {},
wxTimer: null,
})
this.resetScreenBright()
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
if (wxTimer) {
wxTimer.stop();
wxTimer = null
}
this.setData({
wxTimerList: {},
wxTimer: null,
})
this.resetScreenBright()
},
/**
* 接口请求小程序码
*/
getappSignConf() {
if (this.loading) return
wx.showLoading({
title: '重新生成中...',
mask: true
})
if (wxTimer) {
wxTimer.stop();
wxTimer = null
}
this.setData({
wxTimerList: {},
wxTimer: null,
loading: true
})
/////接口方法
_.apiQuery.getappSignConf().then(res => {
this.setData({
qrcode_img: res.data.qcode,
qrcode_count_time: parseInt(res.data.qrcode_count_time),
loading: false,
info: res.data
}, () => {
wx.hideLoading()
this.getTimes(this.data.qrcode_count_time).then(() => {
this.getappSignConf()
})
this.setScreenBright()
})
})
},
/**
* 设置亮度
*/
setScreenBright() {
wx.setScreenBrightness({
value: 1
})
},
/**
* 恢复亮度
*/
resetScreenBright() {
wx.setScreenBrightness({
value: this.data.ori_screen_bright
})
},
/**
* 生成倒计时
*/
getTimes(seconds) {
let that = this
return new Promise(function (resolve, reject) {
wxTimer = new timer({
name: 'wxTimer',
leftTime: seconds,
complete: function () {
setTimeout(() => {
that.setData({
// 'submitFlag': false,
wxTimerList: {}
})
resolve()
}, 1000);
},
})
wxTimer.start(that);
})
},
//推送链接
pushLink(e) {
if (e.currentTarget.dataset.url) {
_.$router.openUrlScheme(e.currentTarget.dataset.url)
}
},
})