Procházet zdrojové kódy

添加脉诊仪器操作

cc12458 před 3 měsíci
rodič
revize
94e2d3aa66

+ 45 - 0
@types/global.d.ts

@@ -0,0 +1,45 @@
+export {};
+declare global {
+  export interface Platform extends EventTarget {
+    pulse(userId?: string): Promise<{
+      id: string;
+      url: string;
+      date?: string;
+      result?: string;
+    }>;
+
+    injection(config?: { callbackFn?: (key: string) => string }): void;
+
+    __execution__map__: Map<string, any>;
+
+    __execution__<M>(key: keyof PlatformAIO, ...args: any[]): Promise<M>;
+  }
+
+  /**
+   * webview 设备注入的 全局对象
+   */
+  export interface PlatformAIO {
+    pulse(callback: string, userId?: string): boolean;
+  }
+
+  interface Window {
+    platform: Platform;
+    /**
+     * webview 设备注入的 全局对象
+     */
+    platformAIO: PlatformAIO;
+  }
+
+  declare var platform: Platform;
+
+  /**
+   * Promise 扩展
+   */
+  interface PromiseConstructor {
+    withResolvers<T>(): {
+      promise: Promise<T>;
+      resolve: (value: T | PromiseLike<T>) => void;
+      reject: (reason?: any) => void;
+    };
+  }
+}

+ 62 - 12
src/loader/bridge.loader.ts

@@ -11,36 +11,88 @@ export interface globalAIO {
 
 declare var window: Window & typeof globalThis & { AIO: globalAIO };
 
+if (typeof Promise.withResolvers !== 'function') {
+  Promise.withResolvers = function <T>() {
+    let resolve!: (value: T | PromiseLike<T>) => void;
+    let reject!: (reason?: any) => void;
+
+    const promise = new Promise<T>((res, rej) => {
+      resolve = res;
+      reject = rej;
+    });
+
+    return { promise, resolve, reject };
+  };
+}
+
+const platformInjection: Platform['injection'] = (config) => {
+  const callbackFn = config?.callbackFn ?? ((key) => `AIO_${key}_${Date.now()}_${Math.random().toString(36).slice(2)}`);
+  const clearFn = (key: string) => platform.__execution__map__.delete(key);
+
+  platform.__execution__map__ ??= new Map();
+  // @ts-ignore
+  platform.__execution__ ??= function (key, ...args) {
+    const callbackId = callbackFn(key);
+    const { promise, ...executor } = Promise.withResolvers<string>();
+    try {
+      if (!window.platformAIO[key](callbackId, ...args)) throw new ReferenceError(`执行 ${key} 方法失败`);
+    } catch (e) {
+      executor.reject(e);
+    }
+    this.__execution__map__.set(callbackId, executor);
+    promise.then(
+      () => clearFn(key),
+      () => clearFn(key)
+    );
+    return promise.then((response) => {
+      try {
+        const res = JSON.parse(response);
+        if (res && typeof res === 'object') {
+          if (res?.code === 0) return res.data;
+          return Promise.reject(res);
+        }
+        return res as string;
+      } catch (e) {
+        return response;
+      }
+    });
+  };
+  platform.pulse ??= (id) => platform.__execution__('pulse', id);
+};
+
 
 export default function bridgeLoader(): DEV.Loader {
+  window.platform ??= new EventTarget() as Platform;
+  if (typeof window.platform.injection !== 'function') window.platform.injection = platformInjection;
+  window.platform.injection();
+
   async function scan(value: string, route?: RouteLocation) {
     const { Toast } = await import(`@/platform/toast.ui`);
     const toast = Toast.loading(100, { message: '加载中' });
     const data = await scanAccountMethod(value).catch(() => {});
 
-    if ( data ) {
-      const path = data?.path ?? (
-        route?.path === '/screen' ? await processMethod() : route?.path
-      );
+    if (data) {
+      const path = data?.path ?? (route?.path === '/screen' ? await processMethod() : route?.path);
       const key = Date.now();
-      sessionStorage.setItem(`scan_${ key }`, JSON.stringify(data));
+      sessionStorage.setItem(`scan_${key}`, JSON.stringify(data));
       await router.replace({ path, query: { scan: key } });
       Toast.success('扫码成功');
     }
     toast.close();
   }
 
-
   return async function() {
     window.AIO ??= {} as globalAIO;
 
     window.AIO.scan = (value) => {
-      if ( !value ) return -1;
+      if (!value) return -1;
 
       const route = unref(router.currentRoute);
 
-      if ( !route.meta?.scan ) {
-        import(`@/platform/notify.ui`).then(({ Notify }) => { Notify.warning(`请返回首页后,再进行扫码!`); });
+      if (!route.meta?.scan) {
+        import(`@/platform/notify.ui`).then(({ Notify }) => {
+          Notify.warning(`请返回首页后,再进行扫码!`);
+        });
         return 1;
       }
       scan(value, route);
@@ -48,9 +100,7 @@ export default function bridgeLoader(): DEV.Loader {
     };
 
     window.AIO.print = (value) => {
-      (
-        window as any
-      ).sixWisdom.printPdfByUrl(value);
+      (window as any).sixWisdom.printPdfByUrl(value);
     };
   };
 }

+ 20 - 4
src/pages/screen.page.vue

@@ -1,7 +1,7 @@
 <script setup lang="ts">
-import { Dialog, Notify } from '@/platform';
+import { Dialog, Notify, Toast } from '@/platform';
 
-import { copyrightMethod, processMethod, registerVisitorMethod } from '@/request/api';
+import { copyrightMethod, processMethod, pulseMethod, registerVisitorMethod } from '@/request/api';
 
 import { useVisitor }     from '@/stores';
 import getBubbles         from '@/tools/bubble';
@@ -9,12 +9,12 @@ import { useElementSize } from '@vueuse/core';
 import { useRequest }     from 'alova/client';
 import p5                 from 'p5';
 
-
 const router = useRouter();
 const Visitor = useVisitor();
 
 const title = import.meta.env.SIX_APP_TITLE;
 const { data: visitor, loading: registering, send: register } = useRequest(registerVisitorMethod, { immediate: false, });
+const { data: pulseConfig } = useRequest(pulseMethod, { initialData: { show: false } });
 const { data: copyright, send: load } = useRequest(copyrightMethod).onError(async ({ error }) => {
   await Dialog.show({
     message: error.message,
@@ -181,6 +181,16 @@ onBeforeRouteLeave((to, from) => {
   if (to.path === '/register' || Visitor.patientId) return true;
   return register().then((data) => !!data, () => false);
 });
+
+async function handlePulse() {
+  try {
+    const result = await window.platform.pulse('user-test');
+    Toast.show(`脉诊:${result.id}`, { position: 'bottom' });
+    console.log('log-->', result);
+  } catch (e: any) {
+    Notify.warning(e?.message);
+  }
+}
 </script>
 <template>
   <div class="wrapper">
@@ -190,7 +200,7 @@ onBeforeRouteLeave((to, from) => {
         <img class="mx-auto h-full object-scale-down" style="width: 32vw;" src="@/assets/images/title.png" :alt="title">
       </div>
       <div class="flex-auto flex flex-col">
-        <div class="flex-auto flex justify-center items-center">
+        <div class="flex-auto flex justify-center items-center gap-10">
           <!--<van-button class="decorate" :loading="loading || registering" @click="handle()">开始检测</van-button>-->
           <div class="van-button decorate" @click="!(loading || registering) && handle()">
             <div class="van-button__content">
@@ -198,6 +208,12 @@ onBeforeRouteLeave((to, from) => {
               <span v-else class="van-button__text">开始检测</span>
             </div>
           </div>
+          <div v-if="pulseConfig.show" class="van-button decorate" @click="!(loading || registering) && handlePulse()">
+            <div class="van-button__content">
+              <van-loading v-if="loading || registering" />
+              <span v-else class="van-button__text">脉诊</span>
+            </div>
+          </div>
         </div>
         <div class="flex-none text-xl p-8 text-center" v-html="copyright"></div>
       </div>

+ 13 - 0
src/request/api/flow.api.ts

@@ -17,6 +17,19 @@ export function copyrightMethod() {
   });
 }
 
+export function pulseMethod() {
+  return HTTP.Post<{ show: boolean }, { tabletRequiredPageOperationElements: string[] }>(
+    `/fdhb-tablet/warrantManage/getPageSets`, void 0, {
+      cacheFor, name: `variate:pulse`,
+      params: { k: 'pulse' },
+      transform(data, headers) {
+        return {
+          show: data?.tabletRequiredPageOperationElements?.includes('start_check_page_pulsebutton'),
+        };
+      },
+    });
+}
+
 export function processMethod() {
   const path = unref(Router.currentRoute).path;
   return HTTP.Post<string, { tabletProcessModules?: string[]; }>(`/fdhb-tablet/warrantManage/getPageSets`, {}, {