当前位置:网站首页>Qrcodejs2 QR code generation JS
Qrcodejs2 QR code generation JS
2022-06-12 22:27:00 【withkai44】
<div class="qrcode" ref="qrCodeUrl"></div>
<div class="rxpired-box" v-show="rxpired">
<p> Has expired </p>
<Button type="primary" @click="bindRefresh"> Click refresh </Button>
</div>
import QRCode from 'qrcodejs2'
methods: {
// Switching scanning
bindScan(){
if(!this.isScan){
this.isScan = true
this.getSanCodeKey()
}
this.loginType = 1
},
// Generate qr code
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, // The content that needs to be converted into QR code
width: 160,
height: 160,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H
})
},
// Close modal box
closeModel () {
let msg = this.$Message.loading({
content: ' Logon ...',
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);
// Record user login information
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);
// Record user information
this.$store.commit('kefu/setInfo', res.data.kefuInfo)
if(this.$store.state.media.isMobile){
// Mobile page
return this.$router.replace({
path: this.$route.query.redirect || '/kefu/mobile_list' });
}else{
// pc page
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 || ' Login failed ');
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(' Check 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();
}
})
},
// Get customer service scanning code 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)
})
},
// Code scanning login status
getScanStatus(){
scanStatus(this.codeKey).then(async res=>{
// 0 = When the QR code expires, you need to obtain the authorization certificate again
if(res.data.status == 0){
this.timeNum = 0
window.clearInterval(this.scanTime)
this.rxpired = true
}
// 1= Scanning
if(res.data.status == 1){
}
// 3 Scanning succeeded. Logging in
if(res.data.status == 3){
window.clearInterval(this.scanTime)
let expires = this.getExpiresTime(res.data.exp_time);
// Record user login information
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);
// Record user information
this.$store.commit('kefu/setInfo', res.data.kefuInfo)
if(this.$store.state.media.isMobile){
// Mobile page
return this.$router.replace({
path: this.$route.query.redirect || '/kefu/mobile_list' });
}else{
// pc page
return this.$router.replace({
path: this.$route.query.redirect || '/kefu/pc_list' });
}
}
}).catch(error=>{
this.$Modal.error({
title: ' Tips ',
content: error.msg
});
this.timeNum = 0
window.clearInterval(this.scanTime)
this.rxpired = true
})
},
// Refresh QR code
bindRefresh(){
this.$refs.qrCodeUrl.innerHTML = ''
this.rxpired = false
this.getSanCodeKey()
}
},
边栏推荐
- Qt Quick 3D学习:鼠标拾取物体
- 認識的幾比特清華同學都離職了……
- 生成小程序菊花码(生成菊花码、更换中间logo、更改图片尺寸,加文字)
- [leetcode] sword finger offer II 020 Number of palindrome substrings
- Configuring Dingding notification of SQL audit platform archery
- Generate the chrysanthemum code of the applet (generate the chrysanthemum code, change the middle logo, change the image size, and add text)
- 认识的几位清华同学都离职了……
- Web3 principle and decentralization
- USB mechanical keyboard changed to Bluetooth Keyboard
- 【LeetCode】300.最长上升子序列
猜你喜欢
Leetcode: the maximum number of building change requests that can be reached (if you see the amount of data, you should be mindless)
C语言:如何给全局变量起一个别名?
(downloadable) Research Report on the development and utilization of government data (2021), a glimpse of the development of Government Office
【Web技术】1348- 聊聊水印实现的几种方式
Photoshop:PS如何实现放大图片不模糊
How to specify your webpage's language so Google Chrome doesn't offer to translate it
Have you really learned the common ancestor problem recently?
80 lines of code to realize simple rxjs
[web technology] 1348- talk about several ways to implement watermarking
Ansible foundation and common modules (I)
随机推荐
Qt Quick 3D学习:鼠标拾取物体
The programmer dedicated to promoting VIM has left. Father of vim: I will dedicate version 9.0 to him
Afraid to write documents? AI plug-in for automatically generating code documents
Mysql concat_ WS, concat function use
孙老师版本JDBC(2022年6月12日21:34:25)
Implementation of master-slave replication and master-master replication for MySQL and MariaDB databases
【LeetCode】103. Zigzag sequence traversal of binary tree
Use group_ Dplyr issues when using group_ by(multiple variables)
证券开户有风险吗?怎么开户安全呢?
C语言:如何给全局变量起一个别名?
Research Report on water sports shoes industry - market status analysis and development prospect forecast
Leetcode: the maximum number of building change requests that can be reached (if you see the amount of data, you should be mindless)
【概率论与数理统计】期末复习抱佛脚:公式总结与简单例题(完结)
How to perform disaster recovery and recovery for kubernetes cluster? (22)
JVM foundation > CMS garbage collector
Shardingsphere-proxy-5.0.0 deployment table implementation (I)
Producer consumer model under multithreading model
leetcodeSQL:574. Elected
The annual salary of 500000 is one line, and the annual salary of 1million is another line
Several Tsinghua students I know have left