qrcodejs2二维码生成js

qrcodejs2二维码生成jsdivclass code box divclass qrcode ref qrCodeUrl divclass rxpired box v show rxpired p 已过期 p divclass rxpired box v show rxpired divclass qrcode ref qrCodeUrl divclass code box

在这里插入图片描述

<div class="qrcode" ref="qrCodeUrl"> 
     div> <div class="rxpired-box" v-show="rxpired"> <p>已过期 
      p> <Button type="primary" @click="bindRefresh">点击刷新 
       Button>  
        div> 
import QRCode from 'qrcodejs2' 
methods: { 
    // 切换扫码 bindScan(){ 
    if(!this.isScan){ 
    this.isScan = true this.getSanCodeKey() } this.loginType = 1 }, // 生成二维码 creatQrCode() { 
    let url= `${window.location.protocol}//${window.location.host}/pages/users/scan_login/index?key=${this.codeKey}`; var qrcode = new QRCode(this.$refs.qrCodeUrl, { 
    text: url, // 需要转换为二维码的内容 width: 160, height: 160, colorDark: '#000000', colorLight: '#ffffff', correctLevel: QRCode.CorrectLevel.H }) }, // 关闭模态框 closeModel () { 
    let msg = this.$Message.loading({ 
    content: '登录中...', duration: 0 }); AccountLogin({ 
    account: this.formInline.username, password: this.formInline.password, imgcode: this.formInline.code }).then(async res => { 
    msg(); let expires = this.getExpiresTime(res.data.exp_time); // 记录用户登陆信息 setCookies('kefu_uuid', res.data.kefuInfo.uid, expires); setCookies('kefu_token', res.data.token, expires); setCookies('kefu_expires_time', res.data.exp_time, expires); setCookies('kefuInfo', res.data.kefuInfo, expires); // 记录用户信息 this.$store.commit('kefu/setInfo', res.data.kefuInfo) if(this.$store.state.media.isMobile){ 
    //手机页面 return this.$router.replace({ 
    path: this.$route.query.redirect || '/kefu/mobile_list' }); }else{ 
    // pc页面 return this.$router.replace({ 
    path: this.$route.query.redirect || '/kefu/pc_list' }); } }).catch(res => { 
    msg(); let data = res === undefined ? { 
   } : res; this.errorNum++; this.captchas(); this.$Message.error(data.msg || '登录失败'); if (this.jigsaw) this.jigsaw.reset(); }); }, getExpiresTime (expiresTime) { 
    let nowTimeNum = Math.round(new Date() / 1000); let expiresTimeNum = expiresTime - nowTimeNum; return parseFloat(parseFloat(parseFloat(expiresTimeNum / 60) / 60) / 24); }, closefail () { 
    if (this.jigsaw) this.jigsaw.reset(); this.$Message.error('校验错误'); }, handleResize (event) { 
    this.fullWidth = document.documentElement.clientWidth }, captchas: function () { 
    this.imgcode = Setting.apiBaseURL + '/captcha_pro?' + Date.parse(new Date()); }, handleSubmit (name) { 
    this.$refs[name].validate((valid) => { 
    if (valid) { 
    this.closeModel(); } }) }, // 获取客服扫码key getSanCodeKey(){ 
    getSanCodeKey().then(res=>{ 
    this.codeKey = res.data.key this.creatQrCode() this.scanTime = setInterval(()=>{ 
    this.timeNum++ if(this.timeNum>=60){ 
    this.timeNum = 0 window.clearInterval(this.scanTime) this.rxpired = true }else{ 
    this.getScanStatus() } },1000) }).catch(error=>{ 
    this.timeNum = 0 window.clearInterval(this.scanTime) this.rxpired = true this.$Message.error(error.msg) }) }, // 扫码登录情况 getScanStatus(){ 
    scanStatus(this.codeKey).then(async res=>{ 
    // 0 = 二维码过期需要重新获取授权凭证 if(res.data.status == 0){ 
    this.timeNum = 0 window.clearInterval(this.scanTime) this.rxpired = true } // 1=正在扫描 if(res.data.status == 1){ 
    } // 3 扫描成功正在登录 if(res.data.status == 3){ 
    window.clearInterval(this.scanTime) let expires = this.getExpiresTime(res.data.exp_time); // 记录用户登陆信息 setCookies('kefu_uuid', res.data.kefuInfo.uid, expires); setCookies('kefu_token', res.data.token, expires); setCookies('kefu_expires_time', res.data.exp_time, expires); setCookies('kefuInfo', res.data.kefuInfo, expires); // 记录用户信息 this.$store.commit('kefu/setInfo', res.data.kefuInfo) if(this.$store.state.media.isMobile){ 
    //手机页面 return this.$router.replace({ 
    path: this.$route.query.redirect || '/kefu/mobile_list' }); }else{ 
    // pc页面 return this.$router.replace({ 
    path: this.$route.query.redirect || '/kefu/pc_list' }); } } }).catch(error=>{ 
    this.$Modal.error({ 
    title: '提示', content: error.msg }); this.timeNum = 0 window.clearInterval(this.scanTime) this.rxpired = true }) }, // 刷新二维码 bindRefresh(){ 
    this.$refs.qrCodeUrl.innerHTML = '' this.rxpired = false this.getSanCodeKey() } }, 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/220335.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 下午8:44
下一篇 2026年3月17日 下午8:44


相关推荐

  • HDU 1548 A strange lift 搜索[通俗易懂]

    HDU 1548 A strange lift 搜索

    2022年2月1日
    39
  • 豆包大模型上车赛力斯自有品牌

    豆包大模型上车赛力斯自有品牌

    2026年3月12日
    3
  • Linux 反汇编工具,逆向与反汇编工具

    Linux 反汇编工具,逆向与反汇编工具逆向与反汇编工具了解反汇编的一些背景知识后 再深入学习 IDAPro 之前 介绍其他一些用于二进制文件的逆向工程工具 会对我们学习有所帮助 这些工具大多在 IDA 之前发布 并且仍然可用于快速分析二进制文件 以及审查 IDA 的分析结果 如我们所见 IDA 将这些工具的诸多功能整合到它的用户界面中 为逆向工程提供了一个集成环境 最后 尽管 IDA 确实包含一个集成调试器 在这里我们不会讨论 因为在第 24 25 和 2

    2026年3月19日
    2
  • Ubuntu安装redis详细教程

    Ubuntu安装redis详细教程apt 安装本文 Ubuntu 环境 20 04 NoLSBmodules DistributorI UbuntuDescri Ubuntu20 04 1LTSRelease 20 04Codename focal 关于如何更换 Ubuntu 的软件更新源 请看我这篇文章 安装 redissudoapt getinstall yredis server 设置密码 sudovim etc redis redis redis co

    2026年3月17日
    2
  • 前缀和——(1)什么是前缀和和一维前缀和

    前缀和——(1)什么是前缀和和一维前缀和什么是前缀和前缀和 PrefixSum 的定义为 对于一个给定的数列 A 它的前缀和数列 S 是通过递推能求出来得部分和 例如 C 实现 假设数组 a 和前缀和数组 s 都已经定义 inti 初始条件 a 0 0 s 0 0 for i 1 i lt n i cin gt gt a i s i s

    2026年3月16日
    1
  • 设计模式之职责链模式

    相信大家都玩过类似于“斗地主”的纸牌游戏,某人出牌给他的下家,下家看看手中的牌,如果要不起,则将出牌请求转发给他的下家,其下家再进行判断。一个循环下来,如果其他人都要不起该牌,则最初的出牌者可以打出新

    2021年12月28日
    66

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号