lvkun996 3 лет назад
Родитель
Сommit
60230f6868

+ 2 - 1
.eslintrc.js

@@ -12,6 +12,7 @@ module.exports = {
     ecmaVersion: 2020
   },
   rules: {
-    'vue/multi-word-component-names': 0
+    'vue/multi-word-component-names': 0,
+    '@typescript-eslint/no-empty-function': 'off'
   }
 }

+ 8 - 0
src/hooks/bom.ts

@@ -0,0 +1,8 @@
+
+/**
+ * UseTitle 是一个接受字符串并将文档标题设置为该字符串的函数。
+ * @param {string} title - 文档标题
+ */
+export const useTitle = (title: string) => {
+  document.title = title
+}

+ 0 - 0
src/hooks/effect.ts


+ 0 - 0
src/hooks/index.ts


+ 0 - 0
src/hooks/state.ts


+ 108 - 2
src/layout/layout.vue

@@ -1,7 +1,113 @@
 <template>
-    <div class="layout" > 223</div>
+    <a-layout class="a-layout" >
+        <Navbar />
+        <a-layout>
+        <a-layout-sider
+            width="200"
+            style="background: #fff"
+            breakpoint="lg"
+            collapsed-width="0"
+            @collapse="onCollapse"
+            @breakpoint="onBreakpoint"
+        >
+            <a-menu
+            v-model:selectedKeys="selectedKeys2"
+            v-model:openKeys="openKeys"
+            mode="inline"
+            :style="{ height: '100%', borderRight: 0 }"
+            >
+            <a-sub-menu key="sub1">
+                <template #title>
+                <span>
+                    <user-outlined />
+                    subnav 1
+                </span>
+                </template>
+                <a-menu-item key="1">option1</a-menu-item>
+                <a-menu-item key="2">option2</a-menu-item>
+                <a-menu-item key="3">option3</a-menu-item>
+                <a-menu-item key="4">option4</a-menu-item>
+            </a-sub-menu>
+            <a-sub-menu key="sub2">
+                <template #title>
+                <span>
+                    <laptop-outlined />
+                    subnav 2
+                </span>
+                </template>
+                <a-menu-item key="5">option5</a-menu-item>
+                <a-menu-item key="6">option6</a-menu-item>
+                <a-menu-item key="7">option7</a-menu-item>
+                <a-menu-item key="8">option8</a-menu-item>
+            </a-sub-menu>
+            <a-sub-menu key="sub3">
+                <template #title>
+                <span>
+                    <notification-outlined />
+                    subnav 3
+                </span>
+                </template>
+                <a-menu-item key="9">option9</a-menu-item>
+                <a-menu-item key="10">option10</a-menu-item>
+                <a-menu-item key="11">option11</a-menu-item>
+                <a-menu-item key="12">option12</a-menu-item>
+            </a-sub-menu>
+            </a-menu>
+        </a-layout-sider>
+        <a-layout style="padding: 0 24px 24px">
+            <a-breadcrumb style="margin: 16px 0">
+                <a-breadcrumb-item>Home</a-breadcrumb-item>
+                <a-breadcrumb-item>List</a-breadcrumb-item>
+                <a-breadcrumb-item>App</a-breadcrumb-item>
+            </a-breadcrumb>
+            <a-layout-content
+            :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }"
+            >
+                <RouterView></RouterView>
+            </a-layout-content>
+        </a-layout>
+        </a-layout>
+  </a-layout>
 </template>
 
-<script setup lang="ts" >
+<script  lang="ts" setup >
+import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons-vue'
+import { defineComponent, ref } from 'vue'
+import router from '@/router/index'
+import Navbar from './navbar.vue'
+
+const onCollapse = () => {}
+const onBreakpoint = () => {}
+
+console.log(router.options.routes)
+
+const selectedKeys1 = ref<string[]>(['2'])
+
+const collapsed = ref<boolean>(false)
 
 </script>
+
+<style>
+
+.a-layout {
+    width: 100vw;
+    height: 100vh;
+}
+
+#components-layout-demo-top-side-2 .logo {
+  float: left;
+  width: 120px;
+  height: 31px;
+  margin: 16px 24px 16px 0;
+  background: rgba(255, 255, 255, 0.3);
+}
+
+.ant-row-rtl #components-layout-demo-top-side-2 .logo {
+  float: right;
+  margin: 16px 0 16px 24px;
+}
+
+.site-layout-background {
+  background: #fff;
+}
+</style>

+ 33 - 0
src/layout/navbar.vue

@@ -0,0 +1,33 @@
+<template>
+  <a-layout-header class="header">
+      <div class="logo" />
+      <a-menu
+          theme="dark"
+          mode="horizontal"
+          :style="{ lineHeight: '64px' }"
+      >
+          <a-menu-item
+              v-for="route in navbarRoutes"
+              :key="route.path"
+          >
+              {{route.name}}
+          </a-menu-item>
+      </a-menu>
+  </a-layout-header>
+</template>
+
+<script lang="ts" setup >
+import { computed } from 'vue'
+import router from '@/router/index'
+
+const navbarRoutes = computed(() => router.options.routes.map(route => {
+  return {
+    path: route.path,
+    name: route.name
+  }
+}))
+</script>
+
+<style lang="less" scoped >
+
+</style>

+ 76 - 0
src/layout/sider.vue

@@ -0,0 +1,76 @@
+<template>
+  <a-row>
+    <a-col>
+      <a-layout-sider
+            width="200"
+            style="background: #fff"
+            breakpoint="lg"
+            collapsed-width="0"
+            @collapse="onCollapse"
+            @breakpoint="onBreakpoint"
+        >
+            <a-menu
+            v-model:selectedKeys="selectedKeys2"
+            v-model:openKeys="openKeys"
+            mode="inline"
+            :style="{ height: '100%', borderRight: 0 }"
+            >
+            <a-sub-menu key="sub1">
+                <template #title>
+                <span>
+                    <user-outlined />
+                    subnav 1
+                </span>
+                </template>
+                <a-menu-item key="1">option1</a-menu-item>
+                <a-menu-item key="2">option2</a-menu-item>
+                <a-menu-item key="3">option3</a-menu-item>
+                <a-menu-item key="4">option4</a-menu-item>
+            </a-sub-menu>
+            <a-sub-menu key="sub2">
+                <template #title>
+                <span>
+                    <laptop-outlined />
+                    subnav 2
+                </span>
+                </template>
+                <a-menu-item key="5">option5</a-menu-item>
+                <a-menu-item key="6">option6</a-menu-item>
+                <a-menu-item key="7">option7</a-menu-item>
+                <a-menu-item key="8">option8</a-menu-item>
+            </a-sub-menu>
+            <a-sub-menu key="sub3">
+                <template #title>
+                <span>
+                    <notification-outlined />
+                    subnav 3
+                </span>
+                </template>
+                <a-menu-item key="9">option9</a-menu-item>
+                <a-menu-item key="10">option10</a-menu-item>
+                <a-menu-item key="11">option11</a-menu-item>
+                <a-menu-item key="12">option12</a-menu-item>
+            </a-sub-menu>
+            </a-menu>
+        </a-layout-sider>
+    </a-col>
+  </a-row>
+</template>
+
+<script lang="ts" setup  >
+import { ref, computed } from 'vue'
+import router from '@/router/index'
+
+const onCollapse = () => {}
+const onBreakpoint = () => {}
+
+const selectedKeys2 = ref<string[]>(['1'])
+const openKeys = ref<string[]>(['sub1'])
+
+const silders = router.options.routes.find(route => route.path == '/')?.children
+
+</script>
+
+<style lang="less" scoped >
+
+</style>

+ 1 - 0
src/main.ts

@@ -1,6 +1,7 @@
 import { createApp } from 'vue'
 import App from './App.vue'
 import router from './router'
+import '@/router/before'
 import { createPinia } from 'pinia'
 import antd from 'ant-design-vue'
 import 'ant-design-vue/dist/antd.css'

+ 12 - 0
src/pages/Dashboard/index.vue

@@ -0,0 +1,12 @@
+<template>
+  <div class="Dashboard" >
+    Dashboard
+  </div>
+</template>
+
+<script lang="ts" setup >
+
+</script>
+
+<style lang="less" scoped >
+</style>

+ 6 - 0
src/router/before.ts

@@ -0,0 +1,6 @@
+import { useTitle } from '@/hooks/bom'
+import router from './index'
+
+router.beforeEach((to, from, next) => {
+  next()
+})

+ 12 - 4
src/router/index.ts

@@ -1,10 +1,18 @@
-import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
+import { createRouter, createWebHistory } from 'vue-router'
 
-const routes: Array<RouteRecordRaw> = [
+const routes: Array<Router.RoutesProps> = [
   {
     path: '/',
-    name: 'home',
-    component: () => import('@/layout/layout.vue')
+    name: '首页',
+    title: '首页',
+    component: () => import('@/layout/layout.vue'),
+    children: [
+      {
+        path: '/',
+        name: '仪表盘',
+        component: () => import('@/pages/Dashboard/index.vue')
+      }
+    ]
   }
 ]
 

+ 6 - 0
src/router/typeing.d.ts

@@ -0,0 +1,6 @@
+
+namespace Router {
+  type RoutesProps = RouteRecordRaw & {
+    title: string
+  }
+}