leftWindow.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <scroll-view class="sidebar" scroll-y="true">
  3. <uni-data-menu ref="menu" :value="currentMenu" :staticMenu="staticMenu" collection="opendb-admin-menus"
  4. :page-size="500" :field="field" orderby="sort asc" active-text-color="#409eff" @select="select">
  5. </uni-data-menu>
  6. </scroll-view>
  7. </template>
  8. <script>
  9. import {
  10. mapState,
  11. mapActions
  12. } from 'vuex'
  13. import config from '@/admin.config.js'
  14. export default {
  15. data() {
  16. return {
  17. ...config.sideBar,
  18. field: 'url as value, name as text, menu_id, parent_id, sort, icon, permission',
  19. currentMenu: '/'
  20. }
  21. },
  22. computed: {
  23. ...mapState('app', ['inited', 'navMenu', 'active']),
  24. ...mapState('user', ['userInfo']),
  25. },
  26. // #ifdef H5
  27. watch: {
  28. $route: {
  29. immediate: true,
  30. handler(newRoute, oldRoute) {
  31. const path = newRoute.fullPath
  32. if (path) {
  33. this.currentMenu = this.splitFullPath(path)
  34. }
  35. }
  36. },
  37. userInfo: {
  38. // immediate: true,
  39. handler(newVal, oldVal) {
  40. if (newVal) {
  41. // 当用户信息发生变化后,重新加载左侧menu
  42. this.$nextTick(function() {
  43. this.$refs.menu.load()
  44. })
  45. }
  46. }
  47. }
  48. },
  49. // #endif
  50. methods: {
  51. ...mapActions({
  52. setRoutes: 'app/setRoutes'
  53. }),
  54. select(e, routes) {
  55. let url = e.value
  56. if (!url) {
  57. url = this.active
  58. }
  59. this.clickMenuItem(url)
  60. console.log('select', routes);
  61. this.setRoutes(routes)
  62. // #ifdef H5
  63. // #ifdef VUE3
  64. uni.hideLeftWindow()
  65. // #endif
  66. // #endif
  67. },
  68. clickMenuItem(url) {
  69. // #ifdef H5
  70. if (url.indexOf('http') === 0) {
  71. return window.open(url)
  72. }
  73. // #endif
  74. // url 开头可用有 / ,也可没有
  75. if (url[0] !== '/' && url.indexOf('http') !== 0) {
  76. url = '/' + url
  77. }
  78. console.log('跳转页面');
  79. // TODO 后续要调整
  80. uni.redirectTo({
  81. url: url,
  82. fail: () => {
  83. uni.showModal({
  84. title: '提示',
  85. content: '页面 ' + url + ' 跳转失败',
  86. showCancel: false
  87. })
  88. }
  89. })
  90. },
  91. splitFullPath(path) {
  92. if (!path) {
  93. path = '/'
  94. }
  95. return path.split('?')[0]
  96. },
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. .sidebar {
  102. position: fixed;
  103. // top: var(--top-window-height); // useless
  104. width: 240px;
  105. height: calc(100vh - (var(--top-window-height)));
  106. box-sizing: border-box;
  107. border-right: 1px solid darken($left-window-bg-color, 8%);
  108. background-color: $left-window-bg-color;
  109. padding-bottom: 10px;
  110. }
  111. .sidebar ::-webkit-scrollbar {
  112. display: none;
  113. // scrollbar-width: thin;
  114. }
  115. .title {
  116. margin-left: 5px;
  117. }
  118. </style>