App.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div v-if="isShow" id="nav">
  3. <div class="back" @click="goBack">
  4. <nut-icon name="left"></nut-icon>
  5. </div>
  6. {{ title }}
  7. </div>
  8. <router-view />
  9. </template>
  10. <script lang="ts">
  11. import { defineComponent, ref, watch, computed } from 'vue';
  12. import { useRoute, useRouter } from 'vue-router';
  13. import { isMobile } from '@/sites/assets/util';
  14. export default defineComponent({
  15. name: 'app',
  16. setup() {
  17. const title = ref('NutUI');
  18. // 获取当前路由
  19. const route = useRoute();
  20. const router = useRouter();
  21. //返回demo页
  22. const goBack = () => {
  23. router.back();
  24. };
  25. // 是否显示 title
  26. const isShow = computed(() => {
  27. return (
  28. title.value && title.value != '/' && !title.value.includes('-taro')
  29. );
  30. });
  31. // 当当前路由发生变化时,调用回调函数
  32. watch(
  33. () => route,
  34. () => {
  35. // const { origin, hash, pathname } = window.top.location;
  36. const { hash } = window.top.location;
  37. if (!isMobile && route.hash != hash) {
  38. // window.top.location.replace(`${origin}${pathname}#/${route.hash}`);
  39. title.value =
  40. (route?.meta?.ComponentName as string) || (route.name as string);
  41. } else {
  42. title.value =
  43. (route?.meta?.ComponentName as string) || (route.name as string);
  44. }
  45. },
  46. {
  47. immediate: true,
  48. deep: true
  49. }
  50. );
  51. return { title, isShow, goBack };
  52. }
  53. });
  54. </script>
  55. <style lang="scss">
  56. #app {
  57. background: #fff;
  58. height: 100%;
  59. width: 100%;
  60. display: flex;
  61. flex-direction: column;
  62. #nav {
  63. position: fixed;
  64. z-index: 10;
  65. left: 0;
  66. right: 0;
  67. height: 57px;
  68. line-height: 57px;
  69. text-align: center;
  70. background: $white;
  71. font-weight: bold;
  72. font-size: 20px;
  73. color: rgba(51, 51, 51, 1);
  74. box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.07);
  75. .back {
  76. position: absolute;
  77. left: 0;
  78. height: 100%;
  79. width: 50px;
  80. display: flex;
  81. align-items: center;
  82. justify-content: center;
  83. cursor: pointer;
  84. }
  85. }
  86. .demo {
  87. height: 100%;
  88. background: #f7f8fa;
  89. overflow-x: hidden;
  90. overflow-y: auto;
  91. padding: 57px 17px 0 17px;
  92. &.full {
  93. padding: 57px 0 0 0;
  94. h2 {
  95. padding-left: 27px;
  96. }
  97. }
  98. &.bg-w {
  99. background: #fff;
  100. }
  101. &::-webkit-scrollbar {
  102. width: 0;
  103. background: transparent;
  104. }
  105. > h2 {
  106. margin-top: 30px;
  107. margin-bottom: 10px;
  108. font-size: 14px;
  109. color: rgba(144, 156, 164, 1);
  110. padding: 0 10px;
  111. font-weight: normal;
  112. }
  113. > p {
  114. font-size: 12px;
  115. }
  116. .card {
  117. padding: 25px 18px;
  118. background: rgba(255, 255, 255, 1);
  119. }
  120. }
  121. }
  122. </style>