|
@@ -20,18 +20,37 @@ const keyword = ref<string>(dataset.value?.no ?? '');
|
|
|
|
|
|
const ignoreParentScanner = ref(false);
|
|
|
provide('ignoreParentScanner', ignoreParentScanner);
|
|
|
-const update = (event: PlatformEventMap['scan']) => {
|
|
|
- if (ignoreParentScanner.value) {
|
|
|
- event.stopPropagation();
|
|
|
- event.preventDefault();
|
|
|
- } else {
|
|
|
- keyword.value = event.detail.code;
|
|
|
- const toast = showLoadingToast({ message: '查询中...', duration: 0 });
|
|
|
- search().finally(() => toast.close());
|
|
|
+let onCleanup = () => {};
|
|
|
+tryOnBeforeMount(() => {
|
|
|
+ if (window.bridge) {
|
|
|
+ onCleanup = window.bridge.addEventListener('scan', event => {
|
|
|
+ const detail = event.detail;
|
|
|
+ if ( detail.code !== 0 || detail.data?.code == null ) return;
|
|
|
+ if (ignoreParentScanner.value) {
|
|
|
+ event.stopPropagation();
|
|
|
+ event.preventDefault();
|
|
|
+ } else {
|
|
|
+ keyword.value = event.detail.data?.code ?? '';
|
|
|
+ const toast = showLoadingToast({ message: '查询中...', duration: 0 });
|
|
|
+ search().finally(() => toast.close());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (window.platform) {
|
|
|
+ const update = (event: CustomEvent) => {
|
|
|
+ if (ignoreParentScanner.value) {
|
|
|
+ event.stopPropagation();
|
|
|
+ event.preventDefault();
|
|
|
+ } else {
|
|
|
+ keyword.value = event.detail.code;
|
|
|
+ const toast = showLoadingToast({ message: '查询中...', duration: 0 });
|
|
|
+ search().finally(() => toast.close());
|
|
|
+ }
|
|
|
+ };
|
|
|
+ platform.addEventListener('scan', update)
|
|
|
+ onCleanup = () => { platform.removeEventListener('scan', update) }
|
|
|
}
|
|
|
-};
|
|
|
-tryOnBeforeMount(() => platform?.addEventListener('scan', update));
|
|
|
-tryOnUnmounted(() => platform?.removeEventListener('scan', update));
|
|
|
+});
|
|
|
+tryOnUnmounted(() => onCleanup?.());
|
|
|
|
|
|
const {
|
|
|
data,
|