btnMenu.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view>
  3. <uni-icons type="list" size="30" @click="showDrawer"></uni-icons>
  4. <uni-drawer ref="showLeft" mode="left" :width="320">
  5. <uni-collapse ref="collapse" accordion v-model="data.activeMenu">
  6. <uni-collapse-item :title="item.title" v-for="item in data.list" :key="item.title">
  7. <view v-for="cIt in item.children" :key="item.title" @click="handleClick(cIt)">
  8. <view class="content">
  9. <text class="text" :class="{active: data.activePath}">{{cIt.title}}</text>
  10. </view>
  11. </view>
  12. </uni-collapse-item>
  13. </uni-collapse>
  14. <view class="close">
  15. <button @click="closeDrawer('showLeft')"><text class="word-btn-white">关闭Drawer</text></button>
  16. </view>
  17. </uni-drawer>
  18. </view>
  19. </template>
  20. <script setup>
  21. import {
  22. ref,
  23. reactive
  24. } from "vue"
  25. const showLeft = ref(null)
  26. import { onLoad } from "@dcloudio/uni-app"
  27. const data = reactive({
  28. list: [{
  29. title: '1',
  30. url: '',
  31. children: [{
  32. title: '1-1',
  33. url: '/pages/dqgzDangjiangongzuo/dqgzDangjiangongzuo'
  34. }, {
  35. title: '1-2',
  36. url: 'http://www.baidu.com',
  37. type: 'link'
  38. }, {
  39. title: '1-3',
  40. url: ''
  41. }, {
  42. title: '1-4',
  43. url: ''
  44. }, ]
  45. },
  46. {
  47. title: '2',
  48. url: '',
  49. children: [{
  50. title: '2-1',
  51. url: ''
  52. }, {
  53. title: '2-2',
  54. url: ''
  55. }, {
  56. title: '2-3',
  57. url: ''
  58. }, {
  59. title: '2-4',
  60. url: ''
  61. }]
  62. }
  63. ],
  64. activeMenu: null,
  65. activePath: '',
  66. })
  67. onLoad(() => {
  68. data.activePath = getCurrentPages().route;
  69. data.activeMenu = data.list.find(item => item.children.some(cit => cit.url == data.activePath));
  70. console.log( 'ccc:', data.activeMenu, data.activePath )
  71. })
  72. function showDrawer() {
  73. showLeft.value.open();
  74. }
  75. function closeDrawer() {
  76. showLeft.value.close();
  77. }
  78. function handleClick(data) {
  79. console.log(`菜单:${data.title};路径:${data.url}`);
  80. if (data.type == 'link') {
  81. window.location.href = data.url;
  82. return;
  83. }
  84. if (data.url) {
  85. uni.navigateTo({
  86. url: data.url
  87. })
  88. }
  89. }
  90. </script>
  91. <style>
  92. </style>