|
@@ -10,12 +10,12 @@
|
10
|
10
|
>
|
11
|
11
|
<a-menu-item-group key="g1">
|
12
|
12
|
<template #title>
|
13
|
|
- <div>我的日记</div>
|
|
13
|
+ <div @contextmenu.prevent.stop="event => onContextMenu(event)">我的日记</div>
|
14
|
14
|
</template>
|
15
|
15
|
</a-menu-item-group>
|
16
|
16
|
<SubMenu :menus="fileTree" :sub-menu="SubMenu"></SubMenu>
|
17
|
17
|
</a-menu>
|
18
|
|
- <ContextMenu :newFile="createNewFile" :newFolder="createNewFolder" />
|
|
18
|
+ <ContextMenu @newFile="createNewFile" @newFolder="createNewFolder" />
|
19
|
19
|
</div>
|
20
|
20
|
</template>
|
21
|
21
|
|
|
@@ -36,8 +36,8 @@ const props = defineProps({
|
36
|
36
|
|
37
|
37
|
const { user } = useModel('user')
|
38
|
38
|
const { curMenu, menus, getMenus } = useModel('menu')
|
39
|
|
-const { fileArr, fileTree, getNote, getFiles } = useModel('note')
|
40
|
|
-const { newFile, newFolder } = useModel('repo')
|
|
39
|
+const { fileArr, fileTree, getNote, newNote, getFiles, newFolder } = useModel('note')
|
|
40
|
+const { newFile } = useModel('repo')
|
41
|
41
|
|
42
|
42
|
const repo = 'my-note'
|
43
|
43
|
const rootPath = ''
|
|
@@ -53,45 +53,33 @@ const handleMenu = (e) => {
|
53
|
53
|
}
|
54
|
54
|
|
55
|
55
|
const handleOpenChange = (keys) => {
|
56
|
|
- const [ menuId ] = keys
|
57
|
|
- if (!menuId) return;
|
|
56
|
+ const menuId = keys.slice().pop()
|
|
57
|
+ if (!menuId) return true;
|
58
|
58
|
|
59
|
59
|
const path = menuId.replace('/@@dir@@/', '')
|
60
|
|
- getFiles(user, path, repo)
|
|
60
|
+ const menu = fileArr.filter(x => x.path === path && x.type === 'dir')[0]
|
|
61
|
+ if (!menu.children) {
|
|
62
|
+ getFiles(user, path, repo)
|
|
63
|
+ }
|
61
|
64
|
}
|
62
|
65
|
|
63
|
66
|
// 创建新文件
|
64
|
|
-const createNewFile = (parentMenu, newFileName) => {
|
65
|
|
- const parentPath = parentMenu.path
|
|
67
|
+const createNewFile = ({ menu: parentMenu, name: newFileName }) => {
|
|
68
|
+ const parentPath = parentMenu ? parentMenu.path : ''
|
66
|
69
|
const newFilePath = parentPath ? `${parentPath}/${newFileName}.html` : `${newFileName}.html`
|
67
|
70
|
|
68
|
|
- newFile('又是一篇崭新的日记...', newFilePath, user).then(() => {
|
69
|
|
- getMenus(user, parentPath).then(res => {
|
70
|
|
- const newDIR = (res || []).filter(x => x.path.indexOf('.gitignore') === -1)
|
71
|
|
- if (curMenu.value) {
|
72
|
|
- curMenu.value.children = newDIR
|
73
|
|
- } else {
|
74
|
|
- menus.splice().push(...newDIR || [])
|
75
|
|
- }
|
76
|
|
- })
|
77
|
|
- })
|
|
71
|
+ newNote(user, newFilePath, repo)
|
78
|
72
|
}
|
79
|
73
|
|
80
|
74
|
// 创建新目录
|
81
|
|
-const createNewFolder = (parentMenu, newFolderName) => {
|
82
|
|
- const parentPath = parentMenu.path
|
|
75
|
+const createNewFolder = ({ menu: parentMenu, name: newFolderName }) => {
|
|
76
|
+ const parentPath = parentMenu ? parentMenu.path : ''
|
83
|
77
|
const newFilePath = parentPath ? `${parentPath}/${newFolderName}` : newFolderName
|
84
|
|
-
|
85
|
|
- newFolder(newFilePath, user).then(() => {
|
86
|
|
- getMenus(user, parentPath).then(res => {
|
87
|
|
- const newDIR = (res || []).filter(x => x.path.indexOf('.gitignore') === -1)
|
88
|
|
- if (curMenu.value) {
|
89
|
|
- curMenu.value.children = newDIR
|
90
|
|
- } else {
|
91
|
|
- menus.push(...newDIR || [])
|
92
|
|
- }
|
93
|
|
- })
|
94
|
|
- })
|
|
78
|
+ newFolder(user, newFilePath, repo)
|
95
|
79
|
}
|
96
|
80
|
|
|
81
|
+
|
|
82
|
+const onContextMenu = (event) => {
|
|
83
|
+ eventBus.dispatchEvent('menu.contextMenu', { event })
|
|
84
|
+}
|
97
|
85
|
</script>
|