index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view id="main">
  3. <main-menu class="main-menu" :class="{ 'menu-show': menuShow }" @clickSub="routePath"/>
  4. <component class="main-content" :is="currentComponent"></component>
  5. </view>
  6. </template>
  7. <script>
  8. import MainMenu from "./components/menu"
  9. import routerMixin from "./mixins/router.js"
  10. export default {
  11. components: {
  12. MainMenu
  13. },
  14. mixins: [routerMixin],
  15. data() {
  16. return {
  17. // 菜单是否折叠
  18. menuShow: false,
  19. }
  20. },
  21. onLoad(options) {
  22. this.checkPath(options)
  23. //#ifdef H5
  24. document.addEventListener('keydown', e => {
  25. const keyCode = e.keyCode || e.which || e.charCode
  26. if(keyCode === 27 || keyCode === 112) this.toggleMenuShow()
  27. })
  28. //#endif
  29. },
  30. methods: {
  31. // 切换菜单显示
  32. toggleMenuShow() {
  33. this.menuShow = !this.menuShow
  34. },
  35. // 检查入场的参数 path,并且明确子组件,模拟路由
  36. checkPath(options) {
  37. if(!options.path) this.routePath({ path: `withdraw` })
  38. else this.navigate(options)
  39. },
  40. routePath({ path, params }) {
  41. let paramStr = ""
  42. if(params) {
  43. Object.keys(params).forEach(key => {
  44. paramStr += `${key}=${params[key]}&`
  45. })
  46. // console.log(paramStr)
  47. }
  48. uni.redirectTo({
  49. url: `/module/main/index?path=${path}&${paramStr}`
  50. })
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang='less' scoped>
  56. @transformWidth: 40px;
  57. #main {
  58. position: relative;
  59. display: flex;
  60. height: 100%;
  61. .main-menu {
  62. position: absolute;
  63. left: 0;
  64. top: 0;
  65. height: 100%;
  66. z-index: 2;
  67. transform: translate(calc(-100% + @transformWidth - 4px), 0);
  68. transition: transform 0.1s linear;
  69. box-shadow: 0 0 8px 0 green;
  70. &:hover {
  71. transform: translate(0);
  72. }
  73. }
  74. .menu-show {
  75. transform: translate(0);
  76. }
  77. .main-content {
  78. width: calc(100% - @transformWidth);
  79. height: 100%;
  80. transform: translate(@transformWidth, 0);
  81. overflow-x: scroll;
  82. }
  83. }
  84. </style>