123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- const { visitorQrCode } = require("/utils/api/auth_api")
- const app = getApp()
- import QRCode from "/utils/util/weapp-qrcode"
- Page({
- data() {
- return {
- // 0为待获取状态,1为获取二维码显示状态
- status: 0,
- qrcodeList: [],
- // 选中的索引
- selectIndex: -1,
- // 显示的二维码,0表示单机二维码,1表示联机二维码
- showQrCodePosition: 0,
- // 账号id
- adminId: null,
- qrcodeTitles: ['单机二维码', '联机二维码']
- }
- },
- onLoad() {
- let launchOptions = my.getLaunchOptionsSync()
- if(!launchOptions.query) {
- launchOptions = my.getEnterOptionsSync()
- }
- // my.alert({
- // title: "launchOptions",
- // content: JSON.stringify(launchOptions)
- // });
- if(launchOptions.query && launchOptions.query.a) {
- let id = null
- try {
- id = Number(launchOptions.query.a)
- } catch (err) {
- id = null
- }
- this.setData({
- adminId: id
- })
- }
- },
- authClick() {
- const authPopup = this.$selectComponent('#authPopup')
- authPopup.open('芯易行通行管理系统')
- },
- // 授权获取三要素结果
- authResult(e) {
- if(e.detail && e.detail.code === 200) {
- // const params = {
- // userId: e.detail.data.userId,
- // username: e.detail.data.username,
- // idNumber: e.detail.data.idNumber,
- // phone: e.detail.data.phone,
- // avatar: e.detail.data.avatar || null,
- // personPictures: e.detail.data.personPictures || null,
- // photoBase64: e.detail.data.photoBase64 || null
- // }
- this.getVistorQrcode(e.detail.data.idNumber, e.detail.data.username, e.detail.data.phone)
- } else {
- my.alert({
- title: '提示',
- content: '身份授权认证失败!'
- })
- }
- },
- // 创建二维码
- creatQrCode(id, text) {
- return new Promise((resolve, reject) => {
- if(!id || !text) {
- reject()
- return
- }
- new QRCode(id, {
- text: text,
- width: 250,
- //canvas 画布的宽
- height: 250,
- //canvas 画布的高
- padding: 0,
- // 生成二维码四周自动留边宽度,不传入默认为0
- correctLevel: QRCode.CorrectLevel.L,
- // 二维码可辨识度
- callback: res => {
- resolve(res.path)
- }
- })
- })
- },
- async getVistorQrcode(idNumber, name, phone) {
- if(!idNumber || !name || !phone) {
- my.showToast({
- type: 'none',
- title: '授权获取信息补全,请重试'
- })
- return
- }
- const result = await visitorQrCode({idNumber, name, phone, adminId: this.data.adminId})
- this.setData({
- status: (result && result.data && result.data.length > 0) ? 1 : 0,
- selectIndex: (result && result.data && result.data.length > 0) ? 0 : -1,
- qrcodeList: result.data ? result.data.map(item => {
- const title = []
- const qrcode = []
- if(item.ethQrcode) {
- title.push(item.zfbMiniEthTitle || this.data.qrcodeTitles[0])
- qrcode.push(item.ethQrcode)
- }
- if(item.vguangQrcode) {
- title.push(item.zfbMiniVguangTitle || this.data.qrcodeTitles[1])
- qrcode.push(item.vguangQrcode)
- }
- item.titles = title
- item.qrcodes = qrcode
- item.qrcodesPath = []
- return item
- }) : []
- })
- if(!this.data.qrcodeList || this.data.qrcodeList.length <= 0) {
- my.showToast({
- type: 'none',
- content: '暂无访客二维码信息!'
- })
- return
- }
- if(this.data.selectIndex >= 0) {
- this.updateQrcode(this.data.selectIndex)
- }
- },
- updateQrcode(index) {
- const that = this
- setTimeout(async () => {
- const tempList = JSON.parse(JSON.stringify(this.data.qrcodeList))
- my.showLoading({
- content: '二维码加载中...'
- })
- for(let i = 0; i < tempList.length; i++) {
- if(index === i) {
- if(!tempList[i].qrcodes || tempList[i].qrcodes.length <= 0) {
- break
- }
- if(tempList[i].qrcodesPath && tempList[i].qrcodesPath.length > 0) {
- break
- }
- for(let j = 0; j < tempList[i].qrcodes.length; j++) {
- const qrcodePath = await that.creatQrCode('qrcode', tempList[i].qrcodes[j])
- tempList[i].qrcodesPath.push(qrcodePath)
- }
- }
- }
- my.hideLoading()
- that.setData({
- showQrCodePosition: 0,
- qrcodeList: tempList
- })
- }, 500)
- },
- onQrcodeSelectChange(event) {
- this.setData({
- selectIndex: event.detail.value
- })
- this.updateQrcode(this.data.selectIndex)
- },
- onQrcodeTabsChange(event) {
- const type = event.currentTarget.dataset.type
- if(this.data.showQrCodePosition === type) {
- return
- }
- this.setData({
- showQrCodePosition: type
- })
- }
- })
|