App.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div id="app">
  3. <router-view class="router-view" v-slot="{ Component }">
  4. <transition :name="transitionName">
  5. <!-- 缓存组件,但是进入编辑页面就会有问题 -->
  6. <!-- <keep-alive include="device,deviceSet,role"><component :is="Component" /></keep-alive> -->
  7. <component :is="Component" v-if="!$route.meta.keepAlive" />
  8. </transition>
  9. <keep-alive>
  10. <component :is="Component" v-if="$route.meta.keepAlive" />
  11. </keep-alive>
  12. </router-view>
  13. <nav-bar v-if="tabType"></nav-bar>
  14. </div>
  15. </template>
  16. <script>
  17. import { reactive, toRefs } from "vue";
  18. import { useRouter } from "vue-router";
  19. import { getLocal } from "@/common/js/utils";
  20. import navBar from "@/components/NavBar";
  21. import { ref } from "vue";
  22. export default {
  23. setup() {
  24. const router = useRouter();
  25. const state = reactive({
  26. transitionName: "slide-left",
  27. });
  28. const tabType = ref(true);
  29. router.beforeEach((to, from, next) => {
  30. const token = getLocal("token");
  31. // token为空跳转登陆页面
  32. if (!token && to.path !== "/login") {
  33. // next(`/login?redirect=${to.fullPath}`)
  34. }
  35. if (to.meta.index > from.meta.index) {
  36. state.transitionName = "slide-left"; // 向左滑动
  37. } else if (to.meta.index < from.meta.index) {
  38. // 由次级到主级
  39. state.transitionName = "slide-right";
  40. } else {
  41. state.transitionName = ""; // 同级无过渡效果
  42. }
  43. next();
  44. });
  45. router.afterEach(()=>{
  46. let currentRouteName = router.currentRoute.value.name;
  47. if (currentRouteName === 'home' || currentRouteName === 'device' || currentRouteName === 'robotranking' || currentRouteName === 'user') {
  48. tabType.value = true;
  49. } else {
  50. tabType.value = false;
  51. }
  52. })
  53. return { ...toRefs(state),tabType };
  54. },
  55. components: { navBar }
  56. };
  57. </script>
  58. <style lang="less">
  59. // 宽度动态
  60. // width: -moz-calc(100% - 70px);
  61. // width: -webkit-calc(100% - 70px);
  62. // width: calc(100% - 70px);
  63. /* 导入全局样式 */
  64. @import "./common/style/global.less";
  65. // 改变全局vant的样式
  66. :root {
  67. --van-blue: #4d6add !important;
  68. --vangreen: #4d6add !important;
  69. --van-field-label-color: #404d74 !important;
  70. }
  71. .cust_vantBorder {
  72. .van-cell {
  73. display: flex;
  74. align-items: center;
  75. }
  76. // .van-field__value {
  77. // border: 1px solid #b9bad0;
  78. // border-radius: 2px;
  79. // height: 38px;
  80. // line-height: 38px;
  81. // padding-left: 6px;
  82. // }
  83. .van-field__body {
  84. border: 1px solid #dddde8;
  85. border-radius: 2px;
  86. height: 38px;
  87. line-height: 38px;
  88. padding-left: 6px;
  89. }
  90. }
  91. // 下边框线条
  92. .kBordBott {
  93. border-bottom: 1px solid #fafafd;
  94. }
  95. html,
  96. body,
  97. #app,
  98. div,
  99. span,
  100. p {
  101. // color: #404d74 !important;
  102. }
  103. html {
  104. height: 100%;
  105. // overflow: hidden;
  106. }
  107. body {
  108. height: 100%;
  109. // overflow-x: hidden;
  110. overflow: auto;
  111. }
  112. #app {
  113. height: 100%;
  114. font-family: "Avenir", Helvetica, Arial, sans-serif;
  115. -webkit-font-smoothing: antialiased;
  116. -moz-osx-font-smoothing: grayscale;
  117. // text-align: center;
  118. color: #2c3e50;
  119. }
  120. .router-view {
  121. width: 100%;
  122. height: auto;
  123. position: absolute;
  124. top: 0;
  125. bottom: 0;
  126. margin: 0 auto;
  127. -webkit-overflow-scrolling: touch;
  128. }
  129. .slide-right-enter-active,
  130. .slide-right-leave-active,
  131. .slide-left-enter-active,
  132. .slide-left-leave-active {
  133. height: 100%;
  134. will-change: transform;
  135. transition: all 500ms;
  136. position: absolute;
  137. backface-visibility: hidden;
  138. }
  139. .slide-right-enter {
  140. opacity: 0;
  141. transform: translate3d(-100%, 0, 0);
  142. }
  143. .slide-right-leave-active {
  144. opacity: 0;
  145. transform: translate3d(100%, 0, 0);
  146. }
  147. .slide-left-enter {
  148. opacity: 0;
  149. transform: translate3d(100%, 0, 0);
  150. }
  151. .slide-left-leave-active {
  152. opacity: 0;
  153. transform: translate3d(-100%, 0, 0);
  154. }
  155. .van-badge--fixed {
  156. z-index: 1000;
  157. }
  158. /* 滚动条样式 */
  159. ::-webkit-scrollbar {
  160. /* 1 */
  161. width: 8px;
  162. height: 8px;
  163. background: linear-gradient(to right,
  164. transparent 3px,
  165. #565656 4px,
  166. transparent 6px),
  167. linear-gradient(to bottom, transparent 3px, #565656 4px, transparent 6px);
  168. }
  169. ::-webkit-scrollbar-button {
  170. /* 2 */
  171. width: 8px;
  172. height: 8px;
  173. border-radius: 2px;
  174. background-color: #0667a0;
  175. }
  176. ::-webkit-scrollbar-button:hover {
  177. background-color: #29a7f0;
  178. cursor: pointer;
  179. }
  180. ::-webkit-scrollbar-thumb {
  181. /* 5 */
  182. background-color: #d2d2d2;
  183. border-radius: 2px;
  184. }
  185. ::-webkit-scrollbar-corner {
  186. /* 6 */
  187. width: 8px;
  188. height: 8px;
  189. border-radius: 50%;
  190. background-color: #565656;
  191. }
  192. ::-webkit-scrollbar {
  193. &-thumb {
  194. border-radius: 10px;
  195. background-color: #d2d2d2;
  196. &:hover {
  197. background-color: #bfbfbf;
  198. // background: #A7A7A7;
  199. }
  200. }
  201. &-button {
  202. display: none;
  203. }
  204. &-track {
  205. background: #eee;
  206. border-radius: 10px;
  207. }
  208. }
  209. </style>