appointment.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <template>
  2. <div class="p-repaire" :class="{ step0: state.step === 0 }">
  3. <component :is="Component" />
  4. </div>
  5. </template>
  6. <script setup lang="ts">
  7. import { computed, watch, onUnmounted } from 'vue'
  8. import { onBeforeRouteLeave, useRouter, useRoute } from 'vue-router'
  9. import StepOne from './steps/StepOne.vue'
  10. import StepTwo from './steps/StepTwo.vue'
  11. import StepThree from './steps/StepThree.vue'
  12. // import StepFour from './steps/StepFour.vue'
  13. import StepFive from './steps/StepFive.vue'
  14. import { state, resetState } from './store'
  15. import { state as rootState } from '@/store'
  16. const Component = computed(
  17. () => [StepOne, StepTwo, StepThree, StepFive][state.step]
  18. )
  19. const fromPath = history.state.back
  20. const { id, right_id } = useRoute().query as any
  21. id && (state.repairId = id)
  22. right_id && (state.rightId = right_id)
  23. onBeforeRouteLeave((to, from) => {
  24. if (to.path === fromPath && to.path !== '/' && state.step > 0) {
  25. state.step--
  26. return false
  27. } else {
  28. state.step = 0
  29. }
  30. })
  31. onUnmounted(() => resetState())
  32. watch(
  33. () => state.step,
  34. () => {
  35. window.scrollTo(0, 0)
  36. rootState.bgWhite = state.step === 3
  37. }
  38. )
  39. </script>
  40. <style lang="scss" src="./index.scss"></style>