Your Name vor 3 Jahren
Ursprung
Commit
e68a7bd347

+ 1
- 0
package.json Datei anzeigen

@@ -8,6 +8,7 @@
8 8
     "preview": "vite preview"
9 9
   },
10 10
   "dependencies": {
11
+    "@ant-design/icons-vue": "^6.1.0",
11 12
     "@zjxpcyc/vue-tiny-store": "^1.0.1",
12 13
     "ant-design-vue": "^3.2.4",
13 14
     "axios": "^0.27.2",

+ 3
- 3
src/components/SubMenu.vue Datei anzeigen

@@ -1,15 +1,15 @@
1 1
 <template>
2
-  <template v-for="menu in menus" :key="`${menu.path}/${menu.name}`">
2
+  <template v-for="menu in menus" :key="`${menu.path}`">
3 3
     <a-sub-menu
4 4
       v-if="menu.type === 'dir'"
5
-      :key="`/@@mockroot@@/${menu.path}/${menu.name}`"
5
+      :key="`/@@dir@@/${menu.path}`"
6 6
       :title="menu.name"
7 7
     >
8 8
       <template v-if="menu.children">
9 9
         <SubMenu :menus="menu.children" :sub-menu="SubMenu" />
10 10
       </template>
11 11
     </a-sub-menu>
12
-    <a-menu-item v-else :key="`${menu.path}/${menu.name}`">{{ menu.name }}</a-menu-item>
12
+    <a-menu-item v-else :key="`/@@file@@/${menu.path}`">{{ menu.name }}</a-menu-item>
13 13
   </template>
14 14
 </template>
15 15
 

+ 17
- 71
src/layouts/NoteLayout.vue Datei anzeigen

@@ -1,92 +1,38 @@
1 1
 <template>
2
-  <a-layout has-sider>
3
-    <a-layout-sider class="layout-sider" :width="siderWidth">
4
-      <div></div>
5
-      <div>
6
-        <a-menu
7
-          @click="handleMenu"
8
-          @openChange="handleOpenChange"
9
-          :style="menuStyle"
10
-          theme="dark"
11
-          triggerSubMenuAction="click"
12
-        >
13
-          <SubMenu :menus="menus" :sub-menu="SubMenu"></SubMenu>
14
-        </a-menu>
15
-      </div>
16
-    </a-layout-sider>
17
-    <a-layout class="layout-main">
18
-      <a-layout-content>
19
-        <router-view></router-view>
20
-      </a-layout-content>
2
+  <a-layout>
3
+    <a-layout-header>
4
+      <Header />
5
+    </a-layout-header>
6
+    <a-layout>
7
+      <a-layout-sider class="layout-sider" :width="siderWidth">
8
+        <SiderBar :menu-style="menuStyle" />
9
+      </a-layout-sider>
10
+      <a-layout class="layout-main">
11
+        <a-layout-content>
12
+          <router-view></router-view>
13
+        </a-layout-content>
14
+      </a-layout>
21 15
     </a-layout>
22 16
   </a-layout>
23 17
 </template>
24 18
 
25 19
 <script setup>
26
-import { useModel } from '@zjxpcyc/vue-tiny-store'
27
-import SubMenu from '@/components/SubMenu.vue';
20
+import Header from './components/Header.vue'
21
+import SiderBar from './components/SiderBar.vue';
28 22
 
29 23
 const siderWidth = '300px';
30
-const menuStyle = { width: `calc(${siderWidth} - 2px)` };
31
-
32
-const { user } = useModel('user')
33
-const { menus, getMenus, appendMenu } = useModel('menu')
34
-const { getNote } = useModel('note')
35
-
36
-const currentDir = { current: [] }
37
-const currentMenu = { current: {} }
38
-
39
-if (!menus || !menus.length) {
40
-  getMenus(user).then(res => {
41
-    appendMenu(menus, res)
42
-    currentDir.current = res
43
-  })
44
-}
45
-
46
-const handleMenu = (e) => {
47
-  const menuId = e.key
48
-  currentMenu.current = currentDir.current.filter(menu => `${menu.path}/${menu.name}` === menuId)[0]
49
-
50
-  const [name, ...pathArr] = menuId.split('/').reverse()
51
-  const path = pathArr.reverse().join('/')
52
-
53
-
54
-  const fullPath = path === name ? name : menuId
55
-
56
-  getNote(user, fullPath)
57
-}
58
-
59
-const handleOpenChange = (keys) => {
60
-  const [ menuId ] = keys
61
-  const [name, ...pathArr] = menuId.split('/').reverse()
62
-  const path = pathArr.reverse().join('/').replace('/@@mockroot@@/', '')
63
-
64
-  getMenus(user, path).then(res => {
65
-    if (!currentMenu.current.children) {
66
-      currentMenu.current.children = []
67
-    }
68
-
69
-    appendMenu(currentMenu.current.children, res)
70
-    currentDir.current = res
71
-  })
72
-}
24
+const menuStyle = { width: siderWidth, height: '100%' };
73 25
 
74 26
 </script>
75 27
 
76 28
 <style lang="less" scoped>
77 29
 .layout-sider {
78 30
   overflow: auto;
79
-  height: 100vh;
80
-  position: fixed;
81
-  left: 0;
82
-  top: 0;
83
-  bottom: 0;
84 31
 }
85 32
 
86 33
 .layout-main {
87
-  margin-left: v-bind(siderWidth);
88 34
   box-sizing: border-box;
89 35
   padding: 24px;
90
-  height: 100vh;
36
+  height: calc(100vh - 80px);
91 37
 }
92 38
 </style>

+ 42
- 0
src/layouts/components/Header.vue Datei anzeigen

@@ -0,0 +1,42 @@
1
+<template>
2
+  <div></div>
3
+  <div>
4
+    <a-menu theme="dark" mode="horizontal" class="menu-navi">
5
+      <a-menu-item key="save" :disabled="disabledItem.save">
6
+        <template #icon>
7
+          <save-outlined />
8
+        </template>
9
+        保存
10
+      </a-menu-item>
11
+      <a-menu-item key="newfolder" :disabled="disabledItem.newFolder">
12
+        <template #icon>
13
+          <folder-add-outlined />
14
+        </template>
15
+        文件夹
16
+      </a-menu-item>
17
+    </a-menu>
18
+  </div>
19
+</template>
20
+
21
+<script setup>
22
+import { computed } from 'vue'
23
+import { useModel } from '@zjxpcyc/vue-tiny-store'
24
+import { SaveOutlined, FolderAddOutlined } from '@ant-design/icons-vue';
25
+
26
+const { curMenu } = useModel('menu')
27
+const disabledItem = computed(() => {
28
+  return {
29
+    save: !curMenu.value || curMenu.value.type !== 'file',
30
+    newFolder: !curMenu.value || curMenu.value.type !== 'dir',
31
+  }
32
+})
33
+
34
+</script>
35
+
36
+<style lang="less" scoped>
37
+.menu-navi {
38
+  :deep(.ant-menu-item) {
39
+    color: #fff;
40
+  }
41
+}
42
+</style>

+ 74
- 0
src/layouts/components/SiderBar.vue Datei anzeigen

@@ -0,0 +1,74 @@
1
+<template>
2
+  <div></div>
3
+  <div style="height: 100%">
4
+    <a-menu
5
+      @click="handleMenu"
6
+      @openChange="handleOpenChange"
7
+      :style="menuStyle"
8
+      mode="inline"
9
+      triggerSubMenuAction="click"
10
+    >
11
+      <SubMenu :menus="menus" :sub-menu="SubMenu"></SubMenu>
12
+    </a-menu>
13
+  </div>
14
+</template>
15
+
16
+<script setup>
17
+import { useModel } from '@zjxpcyc/vue-tiny-store'
18
+import SubMenu from '@/components/SubMenu.vue';
19
+
20
+const props = defineProps({
21
+  menuStyle: {
22
+    type: Object,
23
+    default: () => {}
24
+  }
25
+})
26
+
27
+const { user } = useModel('user')
28
+const { curMenu, menus, getMenus } = useModel('menu')
29
+const { getNote } = useModel('note')
30
+
31
+if (!menus || !menus.length) {
32
+  getMenus(user).then(res => menus.push(...res || []))
33
+}
34
+
35
+const getDeep = (arr, targ, type) => {
36
+    let found = arr.filter(x => x.type === type && x.path === targ)[0]
37
+    if (found) return found;
38
+
39
+    for (it of arr) {
40
+      if (it.type !== type) continue;
41
+
42
+      const children = it.children || []
43
+      const found = getDeep(children, targ, type)
44
+      if (found) return found
45
+    }
46
+
47
+    return undefined
48
+}
49
+
50
+const handleMenu = (e) => {
51
+  const menuId = e.key
52
+  const path = menuId.replace('/@@file@@/', '')
53
+
54
+  const menu = getDeep(menus, path, 'file')
55
+  curMenu.value = menu
56
+
57
+  getNote(user, path)
58
+}
59
+
60
+const handleOpenChange = (keys) => {
61
+  console.log('------------>', keys)
62
+  const [ menuId ] = keys
63
+  if (!menuId) return;
64
+
65
+  const path = menuId.replace('/@@dir@@/', '')
66
+
67
+  const menu = getDeep(menus, path, 'dir');
68
+  curMenu.value = menu
69
+
70
+  getMenus(user, path).then(res => {
71
+    menu.children = res || []
72
+  })
73
+}
74
+</script>

+ 3
- 6
src/store/model/menu.js Datei anzeigen

@@ -1,21 +1,18 @@
1
-import { reactive } from "vue";
1
+import { reactive, ref } from "vue";
2 2
 import request from '@/utils/request'
3 3
 
4 4
 export default function useMenu() {
5 5
   const menus = reactive([])
6
+  const curMenu = ref()
6 7
 
7 8
   const getMenus = (user, path = '', repo = 'my-note') => {
8 9
     const { access_token } = user.token
9 10
     return request.get(`/api/v5/repos/${user.login}/${repo}/contents/${path}`, { params: { access_token } })
10 11
   }
11 12
 
12
-  const appendMenu = (src, menuList) => {
13
-    menus.push(...menuList || [])
14
-  }
15
-
16 13
   return {
14
+    curMenu,
17 15
     menus,
18 16
     getMenus,
19
-    appendMenu,
20 17
   }
21 18
 }