...
|
...
|
@@ -10,21 +10,52 @@ class NewQrcode extends Page { |
|
|
this.selector = {
|
|
|
$qrcodePic: $('.qrcode-pic'),
|
|
|
$autoScroll: $('.auto-scroll'),
|
|
|
$scrollWords: $('.scroll-words')
|
|
|
$scrollWords: $('.scroll-words'),
|
|
|
$reload: $('.reload')
|
|
|
};
|
|
|
|
|
|
this.qrText = '';
|
|
|
this.auto = '';
|
|
|
this.init();
|
|
|
}
|
|
|
|
|
|
init() {
|
|
|
this.drawQrcode();
|
|
|
this.autoScroll();
|
|
|
this.bindEvents();
|
|
|
this.autoReload();
|
|
|
}
|
|
|
|
|
|
bindEvents() {
|
|
|
this.selector.$reload.on('click', this.reload.bind(this));
|
|
|
}
|
|
|
|
|
|
autoReload() {
|
|
|
this.auto = setInterval(() => {
|
|
|
this.reload();
|
|
|
}, 110 * 1000); // 110秒自动刷新一次
|
|
|
}
|
|
|
|
|
|
reload() {
|
|
|
this.ajax({
|
|
|
url: '/home/newQrcode/reload',
|
|
|
}).then(result => {
|
|
|
if (result) {
|
|
|
this.qrText = result;
|
|
|
this.selector.$qrcodePic.find('canvas').remove();
|
|
|
this.drawQrcode();
|
|
|
clearInterval(this.auto);
|
|
|
this.autoReload();
|
|
|
}
|
|
|
}).catch(error => {
|
|
|
console.error(error);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
drawQrcode() {
|
|
|
this.selector.$qrcodePic.qrcode({
|
|
|
render: 'canvas', // 显示方式,canvas,image和div
|
|
|
text: this.selector.$qrcodePic.data('qr'), // 二维码的内容
|
|
|
text: this.qrText || this.selector.$qrcodePic.data('qr'), // 二维码的内容
|
|
|
size: parseInt(420, 10), // 大小
|
|
|
ecLevel: 'H', // 纠错级别
|
|
|
});
|
...
|
...
|
@@ -34,7 +65,7 @@ class NewQrcode extends Page { |
|
|
let containerWidth = this.selector.$autoScroll.width();
|
|
|
let innerWidth = this.selector.$scrollWords.width();
|
|
|
|
|
|
if (innerWidth <= containerWidth) {
|
|
|
if (innerWidth <= (containerWidth + 1)) {
|
|
|
this.selector.$scrollWords.removeClass('go-scroll');
|
|
|
}
|
|
|
}
|
...
|
...
|
|