feat(): 改为vite

This commit is contained in:
2026-03-16 17:58:57 +08:00
parent cd734d8524
commit 1ccbd4e872
74 changed files with 46574 additions and 2145 deletions
+78
View File
@@ -0,0 +1,78 @@
export async function startNfcScan() {
const nfcAdapter = wx.getNFCAdapter();
await nfcAdapter.startDiscovery();
return new Promise((resolve, reject) => {
nfcAdapter.onDiscovered((res) => {
console.log("onDiscovered", res);
const arr = Array.from(new Int8Array(res.id));
resolve(arr);
});
});
}
export class WeixinNfcUtil {
nfcAdapter = null;
discoveredListenerList = [];
/**
* @type {Function}
*/
_discoveredHandler = null;
constructor() {
this.nfcAdapter = wx.getNFCAdapter();
this._discoveredHandler = this.discoveredHandler.bind(this);
this.nfcAdapter.onDiscovered(this._discoveredHandler);
}
/**
* 是否开启NFC
* NOTE 微信无法判断是否开启
* @returns {boolean} true 已开启
*/
static async isNfcEnabled() {
try {
wx.getNFCAdapter();
return true;
} catch (e) {
console.error(e);
return false;
}
}
discoveredHandler(res) {
console.log("onDiscovered", res);
const arr = Array.from(new Int8Array(res.id));
this.discoveredListenerList.forEach((cb) => {
cb(arr);
});
}
/**
*
* @param {Function} cb
*/
addDiscoveredListener(cb) {
this.discoveredListenerList.push(cb);
}
async startNfcScan() {
return await this.nfcAdapter.startDiscovery();
}
async stopNfcScan() {
this.nfcAdapter.offDiscovered(this._discoveredHandler);
return await this.nfcAdapter.stopDiscovery();
}
static async scan() {
const weixinNfcUtil = new WeixinNfcUtil();
return await new Promise(async (resolve, reject) => {
await weixinNfcUtil.startNfcScan();
weixinNfcUtil.addDiscoveredListener((res) => {
weixinNfcUtil.stopNfcScan();
resolve(res);
});
});
}
}