StepWrapper.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <script setup lang="ts">
  2. import { useRequest } from 'alova/client';
  3. import { getDataMethod } from '@/api/pda.api.ts';
  4. import { useStepStore } from '@/stores';
  5. import { useStep } from '@/core/hook/useStep.ts';
  6. const stepStore = useStepStore();
  7. const { dataset, id, mode, title } = storeToRefs(stepStore);
  8. const loaded = computed(() => !!id.value);
  9. const keyword = ref('');
  10. const { menu, tabTitle, next, prev } = useStep(mode, id, title);
  11. watchEffect(() => {
  12. keyword.value = id.value;
  13. nextTick(() => {
  14. if (!id.value) stepStore.$reset();
  15. });
  16. });
  17. const { loading, send: search } = useRequest(getDataMethod, { immediate: false })
  18. .onSuccess(({ data }) => {
  19. dataset.value = data;
  20. next(dataset.value.no);
  21. })
  22. .onError(() => {
  23. keyword.value = '';
  24. });
  25. function onSearch(value?: string) {
  26. if (value) {
  27. keyword.value = value?.trim();
  28. } else {
  29. value = keyword.value;
  30. }
  31. if (value?.trim()) {
  32. search(value.trim(), mode.value);
  33. } else {
  34. showNotify({ message: '请使用设备按钮进行扫码', type: 'warning' });
  35. }
  36. }
  37. defineExpose({
  38. search: onSearch,
  39. back: prev,
  40. });
  41. </script>
  42. <template>
  43. <div class="page page__home flex flex-col size-full">
  44. <van-toast :show="loading" type="loading" forbid-click message="查询中..." />
  45. <header class="flex-none">
  46. <van-nav-bar :title="menu?.title" left-text="返回" left-arrow @click-left="prev()" />
  47. <van-search v-model="keyword" input-align="center" placeholder="请使用设备按钮进行扫码" @search="onSearch()" :readonly="loaded" :show-action="loaded" @cancel="prev()" />
  48. </header>
  49. <slot :title="tabTitle" :component="menu?.component"></slot>
  50. </div>
  51. </template>
  52. <style scoped lang="scss"></style>