|
@@ -1,14 +1,23 @@
|
|
|
-<script setup lang="tsx">
|
|
|
-import { h } from 'vue'
|
|
|
-import { NMenu } from 'naive-ui'
|
|
|
-import { RouterLink } from 'vue-router'
|
|
|
+<script setup lang="jsx">
|
|
|
+import { h, watch, ref } from 'vue'
|
|
|
+import { useRoute, useRouter } from 'vue-router';
|
|
|
+import { NMenu, NScrollbar } from 'naive-ui'
|
|
|
import SvgIcon from '@/components/SvgIcon/index.vue'
|
|
|
|
|
|
-function renderIcon(props: {name: string, size?: number, class?: string[], color?: string}) {
|
|
|
+const route = useRoute();
|
|
|
+const router = useRouter();
|
|
|
+
|
|
|
+const activeMenuKey = ref(route.path);
|
|
|
+
|
|
|
+watch(() => route.path, currentPath => {
|
|
|
+ activeMenuKey.value = currentPath;
|
|
|
+})
|
|
|
+
|
|
|
+function renderIcon(props) {
|
|
|
return () => h(SvgIcon, { ...props })
|
|
|
}
|
|
|
|
|
|
-function renderChildrenIcon({ name, size = 20 }:{ name:string, size?: number }) {
|
|
|
+function renderChildrenIcon({ name, size = '20' }) {
|
|
|
return () => (
|
|
|
<div class="flex items-center justify-center">
|
|
|
{ renderIcon({ name, size, class: ['icon-default'] })() }
|
|
@@ -17,11 +26,11 @@ function renderChildrenIcon({ name, size = 20 }:{ name:string, size?: number })
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-function renderLabel (val: string) {
|
|
|
- return (<span class="pl-1 test">{ val }</span>);
|
|
|
+function renderLabel (val, url) {
|
|
|
+ return url ? (<a href={ url } target="_blank" class="pl-1">{ val }</a>) : (<span class="pl-1">{ val }</span>) ;
|
|
|
}
|
|
|
|
|
|
-const menuOptions: MenuOption[] = [
|
|
|
+const menuOptions = [
|
|
|
{
|
|
|
label: () => renderLabel('智慧总控'),
|
|
|
icon: renderIcon({name: 'menu-control'}),
|
|
@@ -30,7 +39,7 @@ const menuOptions: MenuOption[] = [
|
|
|
{
|
|
|
label: () => renderLabel('专家问答'),
|
|
|
icon: renderIcon({name: 'menu-answers'}),
|
|
|
- key: '/'
|
|
|
+ key: '/answer'
|
|
|
},
|
|
|
{
|
|
|
label: () => renderLabel('智能分析'),
|
|
@@ -40,7 +49,7 @@ const menuOptions: MenuOption[] = [
|
|
|
{
|
|
|
label:() => renderLabel('水质报警'),
|
|
|
icon: renderChildrenIcon({ name: 'menu-analyse-water' }),
|
|
|
- key: 'key1',
|
|
|
+ key: '/water-warn',
|
|
|
},
|
|
|
{
|
|
|
label: '生化报警',
|
|
@@ -67,12 +76,32 @@ const menuOptions: MenuOption[] = [
|
|
|
{
|
|
|
label: () => renderLabel('用户中心'),
|
|
|
icon: renderIcon({ name: 'menu-help' }),
|
|
|
- key: '/'
|
|
|
+ key: '/',
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ label: '账号管理',
|
|
|
+ icon: renderChildrenIcon({ name: 'menu-analyse-order' }),
|
|
|
+ key: '/account1',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '意见反馈',
|
|
|
+ icon: renderChildrenIcon({ name: 'menu-analyse-order' }),
|
|
|
+ key: '/account2',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ // renderLabel('关于我们', 'https://www.sequoialibra.com/')
|
|
|
+ label: '关于我们',
|
|
|
+ icon: renderChildrenIcon({ name: 'menu-analyse-order' }),
|
|
|
+ url: 'https://www.sequoialibra.com/',
|
|
|
+ key: '/account3',
|
|
|
+ },
|
|
|
+ ]
|
|
|
},
|
|
|
]
|
|
|
|
|
|
-const handleUpdateValue = () => {
|
|
|
- console.log(123123);
|
|
|
+const handleUpdateValue = (key, { url }) => {
|
|
|
+ if (url) return window.open(url);
|
|
|
+ router.push(key);
|
|
|
}
|
|
|
|
|
|
</script>
|
|
@@ -82,9 +111,12 @@ const handleUpdateValue = () => {
|
|
|
<n-menu
|
|
|
:options="menuOptions"
|
|
|
:icon-size="30"
|
|
|
+ v-model:value="activeMenuKey"
|
|
|
@update:value="handleUpdateValue"
|
|
|
>
|
|
|
</n-menu>
|
|
|
+
|
|
|
+
|
|
|
</n-scrollbar>
|
|
|
</template>
|
|
|
|