index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <div class="p-fill-order">
  3. <h3 class="ptc-title">Fill Order</h3>
  4. <component :is="Component" @go="go" />
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent, onUnmounted } from 'vue'
  9. import { initProducts } from './store'
  10. export default defineComponent({
  11. name: 'FillOrder',
  12. beforeRouteEnter(to, from, next) {
  13. initProducts().then(next)
  14. },
  15. })
  16. </script>
  17. <script setup lang="ts">
  18. import { ref, computed, watch } from 'vue'
  19. import { useRoute } from 'vue-router'
  20. import StepOne from './StepOne.vue'
  21. import StepTwo from './StepTwo.vue'
  22. import StepThree from './StepThree.vue'
  23. import { state, resetState } from './store'
  24. const step = ref(0)
  25. const Component = computed(() => [StepOne, StepTwo, StepThree][step.value])
  26. const { from, invitee } = useRoute().query as any
  27. state.form.from = from
  28. state.form.invitor = invitee
  29. // 此处不直接传入resetState是有必要的,否则resetState在整个应用生命周期只会执行一次
  30. onUnmounted(() => resetState())
  31. watch(step, () => window.scrollTo(0, 0))
  32. function go(delta = 1) {
  33. step.value += delta
  34. }
  35. </script>
  36. <style lang="scss">
  37. .p-fill-order {
  38. background: #f7f7f7;
  39. .detail {
  40. display: flex;
  41. align-items: flex-end;
  42. .s1,
  43. .s2 {
  44. font-size: 40px;
  45. font-weight: bold;
  46. color: #1a1a1a;
  47. }
  48. .s2 {
  49. margin: 0 20px 0 48px;
  50. }
  51. .s3 {
  52. font-size: 28px;
  53. color: #1a1a1a;
  54. }
  55. .s4 {
  56. margin-left: auto;
  57. font-size: 32px;
  58. font-weight: bold;
  59. color: $primary-color;
  60. }
  61. }
  62. }
  63. </style>