Your Name před 3 roky
rodič
revize
56bbadac68

+ 2
- 1
src/components/ContextMenu.vue Zobrazit soubor

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

+ 2
- 4
src/components/SubMenu.vue Zobrazit soubor

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

+ 3
- 2
src/layouts/components/SiderBar.vue Zobrazit soubor

@@ -25,6 +25,7 @@ import { useModel } from '@zjxpcyc/vue-tiny-store'
25 25
 import ContextMenu from '@/components/ContextMenu.vue';
26 26
 import SubMenu from '@/components/SubMenu.vue';
27 27
 import eventBus from '@/utils/eventBus'
28
+import { appendSuffix } from '@/utils/file';
28 29
 
29 30
 const props = defineProps({
30 31
   menuStyle: {
@@ -63,9 +64,9 @@ const handleOpenChange = (keys) => {
63 64
 // 创建新文件
64 65
 const createNewFile = ({ menu: parentMenu, name: newFileName }) => {
65 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 Zobrazit soubor

@@ -0,0 +1,13 @@
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
+}