|
68 | 68 | </pro-layout> |
69 | 69 | </template> |
70 | 70 |
|
71 | | -<script lang="ts"> |
72 | | -import { computed, defineComponent, reactive, ref, watchEffect, onMounted } from 'vue'; |
| 71 | +<script setup lang="ts"> |
| 72 | +import { computed, reactive, ref, watchEffect, onMounted } from 'vue'; |
73 | 73 | import { useRouter } from 'vue-router'; |
74 | 74 | import { message, Button, Input, Switch, Select, Avatar, Space, Badge, Menu } from 'ant-design-vue'; |
75 | | -import { getMenuData, clearMenuItem, WaterMark, FooterToolbar } from '@ant-design-vue/pro-layout'; |
76 | | -import type { RouteContextProps } from '@ant-design-vue/pro-layout'; |
| 75 | +import { getMenuData, clearMenuItem, type RouteContextProps } from '@ant-design-vue/pro-layout'; |
77 | 76 |
|
78 | 77 | const i18n = (t: string) => t; |
79 | 78 |
|
80 | | -export default defineComponent({ |
81 | | - name: 'BasicLayout', |
82 | | - components: { |
83 | | - FooterToolbar, |
84 | | - WaterMark, |
| 79 | +const watermarkContent = ref('Pro Layout'); |
| 80 | +const loading = ref(false); |
| 81 | +const router = useRouter(); |
| 82 | +const { menuData } = getMenuData(clearMenuItem(router.getRoutes())); |
85 | 83 |
|
86 | | - [Button.name]: Button, |
87 | | - [Input.name]: Input, |
88 | | - [Input.Search.name]: Input.Search, |
89 | | - [Switch.name]: Switch, |
90 | | - [Select.name]: Select, |
91 | | - ['a-slect-option']: Select.Option, |
92 | | - [Space.name]: Space, |
93 | | - [Badge.name]: Badge, |
94 | | - [Avatar.name]: Avatar, |
95 | | - [Menu.Item.name]: Menu.Item, |
96 | | - }, |
97 | | - setup() { |
98 | | - const loading = ref(false); |
99 | | - const watermarkContent = ref('Pro Layout'); |
100 | | - const router = useRouter(); |
101 | | - const { menuData } = getMenuData(clearMenuItem(router.getRoutes())); |
102 | | -
|
103 | | - const baseState = reactive<Omit<RouteContextProps, 'menuData'>>({ |
104 | | - selectedKeys: [], |
105 | | - openKeys: [], |
106 | | - // default |
107 | | - collapsed: false, |
108 | | - }); |
109 | | -
|
110 | | - const state = reactive({ |
111 | | - menuData, |
112 | | - splitMenus: false, |
113 | | - // title: 'ProLayout', |
114 | | - // logo: 'https://alicdn.antdv.com/v2/assets/logo.1ef800a8.svg', |
115 | | - navTheme: 'light', |
116 | | - layout: 'side', |
117 | | - fixSiderbar: false, |
118 | | - fixedHeader: true, |
119 | | - }); |
120 | | - const breadcrumb = computed(() => |
121 | | - router.currentRoute.value.matched.concat().map((item) => { |
122 | | - return { |
123 | | - path: item.path, |
124 | | - breadcrumbName: item.meta.title || '', |
125 | | - }; |
126 | | - }) |
127 | | - ); |
| 84 | +const baseState = reactive<Omit<RouteContextProps, 'menuData'>>({ |
| 85 | + selectedKeys: [], |
| 86 | + openKeys: [], |
| 87 | + // default |
| 88 | + collapsed: false, |
| 89 | +}); |
128 | 90 |
|
129 | | - const handleCollapsed = (collapsed?: boolean) => { |
130 | | - console.log('collapsed', collapsed); |
131 | | - baseState.collapsed = collapsed; |
| 91 | +const state = reactive({ |
| 92 | + menuData, |
| 93 | + splitMenus: false, |
| 94 | + // title: 'ProLayout', |
| 95 | + // logo: 'https://alicdn.antdv.com/v2/assets/logo.1ef800a8.svg', |
| 96 | + navTheme: 'light', |
| 97 | + layout: 'mix', |
| 98 | + fixSiderbar: true, |
| 99 | + fixedHeader: true, |
| 100 | +}); |
| 101 | +const breadcrumb = computed(() => |
| 102 | + router.currentRoute.value.matched.concat().map((item) => { |
| 103 | + return { |
| 104 | + path: item.path, |
| 105 | + breadcrumbName: item.meta.title || '', |
132 | 106 | }; |
133 | | - watchEffect(() => { |
134 | | - if (router.currentRoute) { |
135 | | - const matched = router.currentRoute.value.matched.concat(); |
136 | | - baseState.selectedKeys = matched.filter((r) => r.name !== 'index').map((r) => r.path); |
137 | | - baseState.openKeys = matched.filter((r) => r.path !== router.currentRoute.value.path).map((r) => r.path); |
138 | | - } |
139 | | - }); |
| 107 | + }) |
| 108 | +); |
140 | 109 |
|
141 | | - function handlePageLoadingClick() { |
142 | | - loading.value = true; |
143 | | - setTimeout(() => { |
144 | | - loading.value = false; |
145 | | - }, 2000); |
146 | | - } |
147 | | -
|
148 | | - onMounted(() => { |
149 | | - setTimeout(() => { |
150 | | - watermarkContent.value = 'New Mark'; |
151 | | - }, 2000); |
152 | | - }); |
| 110 | +watchEffect(() => { |
| 111 | + if (router.currentRoute) { |
| 112 | + const matched = router.currentRoute.value.matched.concat(); |
| 113 | + baseState.selectedKeys = matched.filter((r) => r.name !== 'index').map((r) => r.path); |
| 114 | + baseState.openKeys = matched.filter((r) => r.path !== router.currentRoute.value.path).map((r) => r.path); |
| 115 | + } |
| 116 | +}); |
153 | 117 |
|
154 | | - return { |
155 | | - i18n, |
156 | | - watermarkContent, |
157 | | - baseState, |
158 | | - state, |
159 | | - loading, |
160 | | - breadcrumb, |
| 118 | +const handleCollapsed = (collapsed?: boolean) => { |
| 119 | + baseState.collapsed = collapsed; |
| 120 | +}; |
| 121 | +const handlePageLoadingClick = () => { |
| 122 | + loading.value = true; |
| 123 | + setTimeout(() => { |
| 124 | + loading.value = false; |
| 125 | + }, 2000); |
| 126 | +}; |
161 | 127 |
|
162 | | - handlePageLoadingClick, |
163 | | - handleCollapsed, |
164 | | - handleSearch: () => { |
165 | | - message.info('search..'); |
166 | | - }, |
167 | | - }; |
168 | | - }, |
| 128 | +onMounted(() => { |
| 129 | + setTimeout(() => { |
| 130 | + watermarkContent.value = 'New Mark'; |
| 131 | + }, 2000); |
169 | 132 | }); |
| 133 | +
|
| 134 | +const handleSearch = () => { |
| 135 | + message.info('search..'); |
| 136 | +}; |
170 | 137 | </script> |
0 commit comments