tongyan.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <script setup lang="ts">
  2. import { computed } from 'vue'
  3. import { ref } from 'vue'
  4. import { RouterView, useRoute, useRouter } from 'vue-router'
  5. const route = useRoute()
  6. const router = useRouter()
  7. const offset = ref({ x: 22, y: window.innerHeight - 100 })
  8. const showBackIcon = computed(() => !['home'].includes((route.name || '') as string))
  9. const back = () => {
  10. if (window.history.state.back) {
  11. router.go(-1)
  12. } else {
  13. router.replace({
  14. name: 'home'
  15. })
  16. }
  17. }
  18. </script>
  19. <template>
  20. <router-view v-slot="{ Component }">
  21. <keep-alive include="tongyan">
  22. <component :is="Component" />
  23. </keep-alive>
  24. </router-view>
  25. <van-floating-bubble
  26. v-if="showBackIcon"
  27. v-model:offset="offset"
  28. axis="xy"
  29. magnetic="x"
  30. @click="back"
  31. >
  32. <img draggable="false" class="back-icon" src="@/assets/images/tongyan/icon_back@2x-min.png" />
  33. </van-floating-bubble>
  34. </template>
  35. <style lang="scss">
  36. @import '@/assets/base.scss';
  37. .van-floating-bubble {
  38. --van-floating-bubble-size: 116px;
  39. --van-floating-bubble-border-radius: 0;
  40. --van-floating-bubble-background: transparent;
  41. }
  42. .back-icon {
  43. width: 100%;
  44. }
  45. </style>