Your Name 3 years ago
parent
commit
56bbadac68

+ 2
- 1
src/components/ContextMenu.vue View File

14
 import { computed, reactive, ref } from 'vue'
14
 import { computed, reactive, ref } from 'vue'
15
 import { Modal } from 'ant-design-vue'
15
 import { Modal } from 'ant-design-vue'
16
 import eventBus from '@/utils/eventBus'
16
 import eventBus from '@/utils/eventBus'
17
+import { trimSuffix } from '@/utils/file';
17
 
18
 
18
 const emit = defineEmits(['newFile', 'newFolder', 'deleteFile'])
19
 const emit = defineEmits(['newFile', 'newFolder', 'deleteFile'])
19
 
20
 
50
   const option = event.option
51
   const option = event.option
51
   if (option.id === 'deleteFile') {
52
   if (option.id === 'deleteFile') {
52
     if (menuRef.value && menuRef.value.name) {
53
     if (menuRef.value && menuRef.value.name) {
53
-      const noteName = menuRef.value.name.replace(/\.html$/, '')
54
+      const noteName = trimSuffix(menuRef.value.name)
54
       Modal.confirm({
55
       Modal.confirm({
55
         title: `确定删除日记 ${noteName} ?`,
56
         title: `确定删除日记 ${noteName} ?`,
56
         onOk() {
57
         onOk() {

+ 2
- 4
src/components/SubMenu.vue View File

23
 
23
 
24
 <script setup>
24
 <script setup>
25
 import eventBus from '@/utils/eventBus'
25
 import eventBus from '@/utils/eventBus'
26
+import { trimSuffix } from '@/utils/file';
27
+
26
 const props = defineProps({
28
 const props = defineProps({
27
   menus: {
29
   menus: {
28
     type: Array,
30
     type: Array,
37
   eventBus.dispatchEvent('menu.contextMenu', { event, menu, type })
39
   eventBus.dispatchEvent('menu.contextMenu', { event, menu, type })
38
 }
40
 }
39
 
41
 
40
-const trimSuffix = name => {
41
-  return name.replace(/\.html$/, '')
42
-}
43
-
44
 </script>
42
 </script>
45
 
43
 
46
 
44
 

+ 3
- 2
src/layouts/components/SiderBar.vue View File

25
 import ContextMenu from '@/components/ContextMenu.vue';
25
 import ContextMenu from '@/components/ContextMenu.vue';
26
 import SubMenu from '@/components/SubMenu.vue';
26
 import SubMenu from '@/components/SubMenu.vue';
27
 import eventBus from '@/utils/eventBus'
27
 import eventBus from '@/utils/eventBus'
28
+import { appendSuffix } from '@/utils/file';
28
 
29
 
29
 const props = defineProps({
30
 const props = defineProps({
30
   menuStyle: {
31
   menuStyle: {
63
 // 创建新文件
64
 // 创建新文件
64
 const createNewFile = ({ menu: parentMenu, name: newFileName }) => {
65
 const createNewFile = ({ menu: parentMenu, name: newFileName }) => {
65
   const parentPath = parentMenu ? parentMenu.path : ''
66
   const parentPath = parentMenu ? parentMenu.path : ''
66
-  const newFilePath = parentPath ? `${parentPath}/${newFileName}.html` : `${newFileName}.html`
67
+  const newFilePath = parentPath ? `${parentPath}/${newFileName}` : newFileName
67
 
68
 
68
-  newNote(user, newFilePath, repo)
69
+  newNote(user, appendSuffix(newFilePath), repo)
69
 }
70
 }
70
 
71
 
71
 // 创建新目录
72
 // 创建新目录

+ 13
- 0
src/utils/file.js View File

1
+
2
+const suffix = 'note';
3
+
4
+// 去掉后缀
5
+export const trimSuffix = name => {
6
+  const regex = new RegExp(`.${suffix}`);
7
+  return name.replace(regex, '')
8
+}
9
+
10
+// 添加后缀
11
+export const appendSuffix = name => {
12
+  return `${name}.${suffix}`
13
+}