|
1 | 1 | <template> |
2 | 2 | <main> |
3 | | - <el-container class="h-screen relative"> |
| 3 | + <el-container class="h-screen"> |
4 | 4 | <Sidebar :class="{ 'hidden': sidebarOpen, 'z-50 fixed inset-y-0 left-0': !sidebarOpen}" @singOut="singOut" :sidebarList="sidebarList" @getTableData="getTableData"/> |
5 | 5 | <el-container> |
6 | 6 | <el-header class="bg-white border-b flex items-center justify-between md:justify-end" > |
|
17 | 17 | </template> |
18 | 18 |
|
19 | 19 | <script setup> |
20 | | - import { ref, onBeforeMount } from 'vue' |
| 20 | + import { ref, onBeforeMount, watch, onBeforeUnmount, onMounted } from 'vue' |
21 | 21 | import { useRouter } from 'vue-router' |
22 | 22 | import { Menu } from '@element-plus/icons-vue' |
23 | 23 | import { ElMessage } from 'element-plus' |
|
33 | 33 | const toggleSidebar = async () => { |
34 | 34 | sidebarOpen.value = !sidebarOpen.value |
35 | 35 | } |
36 | | -
|
| 36 | + |
37 | 37 | const sidebarList = ref([]) |
38 | | -
|
| 38 | + |
39 | 39 | const singOut = async () =>{ |
40 | 40 | try { |
41 | 41 | const res = await logout() |
|
65 | 65 | // 錯誤處理邏輯可以在這裡添加 |
66 | 66 | } |
67 | 67 | } |
68 | | -
|
| 68 | + |
69 | 69 | const isVisible = ref(false) |
70 | 70 | const openModal = () => { |
71 | 71 | isVisible.value = true |
72 | 72 | } |
73 | 73 | const closeModal = () => { |
74 | 74 | isVisible.value = false |
75 | 75 | } |
| 76 | + |
| 77 | + const isMdScreen = ref(window.innerWidth) |
| 78 | + watch(isMdScreen, (nV) => { |
| 79 | + if (nV >= 768) sidebarOpen.value = true |
| 80 | + }) |
| 81 | + |
| 82 | + const updateScreenSize = () => { |
| 83 | + isMdScreen.value = window.innerWidth |
| 84 | + } |
| 85 | + onMounted(() => { |
| 86 | + window.addEventListener('resize', updateScreenSize) |
| 87 | + }) |
76 | 88 |
|
77 | | -
|
| 89 | + onBeforeUnmount(() => { |
| 90 | + window.removeEventListener('resize', updateScreenSize) |
| 91 | + }) |
| 92 | + |
78 | 93 | onBeforeMount( async () => { |
79 | 94 | try { |
80 | 95 | const tableNamesRes = await tableNames() |
|
0 commit comments