123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- // pages/scan/scan.js
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- scanFunctionUse: true,
- show: false,
- scanTimer: null,
- rescanTimer: null
- },
- // 用户不允许使用摄像头时触发
- error () {
- console.log('eooro');
- app.globalData.auth.camera = false
- },
- // 在扫码识别成功时触发,仅在 mode="scanCode" 时生效
- handlescancode (e) {
- if (this.data.scanFunctionUse) {
- this.setData({
- scanFunctionUse: false,
- show: true
- })
- console.log('扫码识别成功');
- }
- },
- // 重新扫码
- handleRescan () {
- this.setData({
- show: false
- })
- this.data.rescanTimer = setTimeout(() => {
- this.setData({
- scanFunctionUse: true
- })
- clearTimeout(this.data.rescanTimer)
- }, 800);
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options, 'options');
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow(option) {
- if (!app.globalData.auth.camera) {
- wx.getSetting({
- success (res) {
- console.log(res.authSetting['scope.camera'], 'getSetting')
- if (!res.authSetting['scope.camera']) {
- wx.showModal({
- title: '系统提示',
- content: '请打开相机权限',
- success (res) {
- if (res.confirm) {
- console.log('用户点击确定')
- wx.openSetting({
- success (res) {
- console.log(res, 'openSetting')
- app.globalData.auth.camera = res.authSetting['scope.camera']
- }
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- }
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- this.setData({
- show: false,
- scanFunctionUse: true
- })
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|