leftWindow.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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" where="enable==true" 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. userInfo () {
  25. return this.$uniIdPagesStore.store.userInfo
  26. }
  27. },
  28. watch: {
  29. // #ifdef H5
  30. $route: {
  31. immediate: true,
  32. handler(newRoute, oldRoute) {
  33. const path = newRoute.fullPath
  34. if (path) {
  35. this.currentMenu = this.splitFullPath(path)
  36. }
  37. }
  38. },
  39. // #endif
  40. userInfo: {
  41. // immediate: true,
  42. handler(newVal, oldVal) {
  43. if (newVal) {
  44. // 当用户信息发生变化后,重新加载左侧menu
  45. this.$nextTick(function() {
  46. this.$refs.menu.load()
  47. })
  48. }
  49. }
  50. }
  51. },
  52. methods: {
  53. ...mapActions({
  54. setRoutes: 'app/setRoutes'
  55. }),
  56. select(e, routes) {
  57. let url = e.value
  58. if (!url) {
  59. url = this.active
  60. }
  61. this.clickMenuItem(url)
  62. this.setRoutes(routes)
  63. // #ifdef H5
  64. // #ifdef VUE3
  65. uni.hideLeftWindow()
  66. // #endif
  67. // #endif
  68. },
  69. clickMenuItem(url) {
  70. // #ifdef H5
  71. if (url.indexOf('http') === 0) {
  72. return window.open(url)
  73. }
  74. // #endif
  75. // url 开头可用有 / ,也可没有
  76. if (url[0] !== '/' && url.indexOf('http') !== 0) {
  77. url = '/' + url
  78. }
  79. // #ifndef H5
  80. if (url === "/") {
  81. url = config.index.url;
  82. }
  83. // #endif
  84. // TODO 后续要调整
  85. uni.redirectTo({
  86. url: url,
  87. fail: () => {
  88. uni.showModal({
  89. title: '提示',
  90. content: '页面 ' + url + ' 跳转失败',
  91. showCancel: false
  92. })
  93. }
  94. })
  95. },
  96. splitFullPath(path) {
  97. if (!path) {
  98. path = '/'
  99. }
  100. return path.split('?')[0]
  101. },
  102. }
  103. }
  104. </script>
  105. <style lang="scss">
  106. .sidebar {
  107. position: fixed;
  108. // top: var(--top-window-height); // useless
  109. width: 240px;
  110. height: calc(100vh - (var(--top-window-height)));
  111. box-sizing: border-box;
  112. border-right: 1px solid darken($left-window-bg-color, 8%);
  113. background-color: $left-window-bg-color;
  114. padding-bottom: 10px;
  115. }
  116. /* #ifdef H5 */
  117. .sidebar ::-webkit-scrollbar {
  118. display: none;
  119. // scrollbar-width: thin;
  120. }
  121. /* #endif */
  122. .title {
  123. margin-left: 5px;
  124. }
  125. </style>