flat: 一体机兼容,添加全局事件扫码回调等

This commit is contained in:
Apcallover
2025-12-17 15:16:48 +08:00
parent 8ccdcbf93b
commit 3d826aec86
6 changed files with 184 additions and 4 deletions

View File

@@ -0,0 +1,65 @@
import {
$api
} from "./globalFunction";
import baseDB from '@/utils/db.js';
import useUserStore from '@/stores/useUserStore';
export class IncreaseRevie {
constructor(arg) {
this.myEventCallback = this.myCallback.bind(this);
this._debounceTimer = null;
this.init();
}
init() {
this.close();
setTimeout(() => {
if (window.hh?.on) {
window.hh.on('initQRListener', this.myEventCallback);
}
}, 1000);
}
close() {
if (window.hh?.off) {
window.hh.off('initQRListener', this.myEventCallback);
}
if (this._debounceTimer) {
clearTimeout(this._debounceTimer);
this._debounceTimer = null;
}
}
myCallback(res) {
if (this._debounceTimer) {
clearTimeout(this._debounceTimer);
}
this._debounceTimer = setTimeout(() => {
this.handleDebouncedCallback(res);
this._debounceTimer = null;
}, 300);
}
async handleDebouncedCallback(res) {
if (res.data) {
const code = res.data.qrQode
console.log('二维码code', code);
// 把code给到后端后端拿code兑换用户信息给前端返回token进行登录
// 一体机用户需要清空indexDB
// useUserStore()
// .loginSetToken(resData.token)
// .then((resume) => {
// if (resume.data.jobTitleId) {
// useUserStore().initSeesionId();
// safeReLaunch('/pages/index/index');
// } else {
// safeReLaunch('/pages/login/login');
// }
// });
// baseDB.resetAndReinit(); // 清空indexdb
} else {
$api.msg('识别失败')
}
}
}