Parcourir la source

兼容旧版本 app

cc12458 il y a 3 semaines
Parent
commit
9dc94f978e
3 fichiers modifiés avec 9 ajouts et 5 suppressions
  1. 5 4
      src/loader/bridge.loader.ts
  2. 0 1
      src/modules/report/report.page.vue
  3. 4 0
      src/platform/index.ts

+ 5 - 4
src/loader/bridge.loader.ts

@@ -1,7 +1,7 @@
 import { processMethod, scanAccountMethod } from '@/request/api';
 import router                               from '@/router';
 
-import { platformIsAIO } from '@/platform';
+import { platformIsAIO, platformIsAIO_1 } from '@/platform';
 
 export function waitFor(condition: () => boolean | Promise<boolean>, timeout: number = 300 * 1000) {
   const start = Date.now();
@@ -25,8 +25,8 @@ export default function bridgeLoader(): DEV.Loader {
   window.AIO ??= {};
   window.AIO.scan ??= (value) => {
     if (!value) return -1;
-    const event = new CustomEvent('scan', { detail: { code: value, state: 0, type: -1 } });
-    Bridge.getInstance().dispatchEvent(event);
+    const event = new CustomEvent('scan', { detail: { code: 0, data: { code: value, state: 0, type: -1 } } });
+    window.bridge.dispatchEvent(event);
     return 0;
   };
   window.AIO.print ??= (value) => {
@@ -34,9 +34,10 @@ export default function bridgeLoader(): DEV.Loader {
   };
 
   return async function () {
+    if (platformIsAIO_1()) window.bridge = new EventTarget() as InstanceType<typeof Bridge>;
     if (platformIsAIO()) {
       await waitFor(() => window.bridge != null);
-      Bridge.getInstance().addEventListener('scan', async ({ detail }) => {
+      window.bridge.addEventListener('scan', async ({ detail }) => {
         if (detail.code !== 0 || detail.data?.code == null) return;
         const route = unref(router.currentRoute);
         if (route.meta?.scan) {

+ 0 - 1
src/modules/report/report.page.vue

@@ -58,7 +58,6 @@ async function print() {
       window.AIO?.print?.(url)
     }
     Toast.success(`开始打印`);
-    Toast.success(`开始打印`);
   } catch ( e ) {
     Notify.warning(`打印失败 (${ e.message })`, { duration: 1500 });
     setTimeout(() => {

+ 4 - 0
src/platform/index.ts

@@ -7,6 +7,10 @@ export function platformIsAIO() {
   return /Six\/applet \(AIO;.+\)/i.test(userAgent) || /aio\/\w+/i.test(userAgent);
 }
 
+export function platformIsAIO_1() {
+  return /aio\/1\.0/i.test(userAgent);
+}
+
 export function getSerialNumberSync() {
   const match = userAgent.match(/sn\/(\w+)/i);
   return match?.[ 1 ] ?? (