left-window.uvue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="left-window-style" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
  3. <view class="second-menu">
  4. <keep-alive>
  5. <component :is="active" :hasLeftWin="hasLeftWin" :leftWinActive="leftWinActive"></component>
  6. </keep-alive>
  7. </view>
  8. </view>
  9. </template>
  10. <script lang="uts">
  11. import componentPage from '@/pages/tabBar/component.uvue'
  12. import API from '@/pages/tabBar/API.uvue'
  13. import CSS from '@/pages/tabBar/CSS.uvue'
  14. import templatePage from '@/pages/tabBar/template.uvue'
  15. import { state, setMatchLeftWindow, setActive, setLeftWinActive } from '@/store/index.uts'
  16. let isPcObserver
  17. export default {
  18. data() {
  19. return {
  20. nav: [
  21. 'component',
  22. 'API',
  23. 'CSS',
  24. 'template'
  25. ],
  26. isPC: false
  27. }
  28. },
  29. components: {
  30. componentPage,
  31. API,
  32. CSS,
  33. templatePage
  34. },
  35. computed: {
  36. active() : string {
  37. return state.active
  38. },
  39. hasLeftWin() : boolean {
  40. return !state.noMatchLeftWindow
  41. },
  42. leftWinActive() : string {
  43. return state.leftWinActive.split('/')[3]
  44. },
  45. isDarkMode() : boolean {
  46. return state.isDarkMode
  47. }
  48. },
  49. mounted() {
  50. isPcObserver = uni.createMediaQueryObserver(this)
  51. isPcObserver.observe({
  52. minWidth: 768
  53. }, matched => {
  54. this.isPC = matched
  55. })
  56. this.handlerRoute(this.$route)
  57. },
  58. unmounted() {
  59. isPcObserver.disconnect()
  60. },
  61. watch: {
  62. isPC: {
  63. immediate: true,
  64. handler(newMatches : boolean) {
  65. setMatchLeftWindow(newMatches)
  66. }
  67. },
  68. $route(newRoute) {
  69. this.handlerRoute(newRoute)
  70. }
  71. },
  72. methods: {
  73. handlerRoute(newRoute) {
  74. if (this.isPC) {
  75. if (!newRoute.matched.length) {
  76. uni.redirectTo({
  77. url: '/pages/error/404'
  78. })
  79. } else {
  80. setLeftWinActive(newRoute.path)
  81. let active = newRoute.path.split('/')[2]
  82. if (this.nav.includes(active)) {
  83. if (active === 'component') {
  84. active = 'componentPage'
  85. }
  86. if (active === 'template') {
  87. active = 'templatePage'
  88. }
  89. setActive(active)
  90. }
  91. }
  92. }
  93. }
  94. }
  95. }
  96. </script>
  97. <style>
  98. .left-window-style {
  99. min-height: calc(100vh - var(--top-window-height));
  100. background-color: var(--background-color,#ffffff);
  101. }
  102. .second-menu {
  103. width: 350px;
  104. background-color: #F8F8F8;
  105. }
  106. </style>