@@ -23,6 +23,17 @@ import {
23
23
ContextMenuShortcut ,
24
24
ContextMenuTrigger ,
25
25
} from ' @/components/ui/context-menu'
26
+ import {
27
+ Dialog ,
28
+ DialogContent ,
29
+ DialogDescription ,
30
+ DialogFooter ,
31
+ DialogHeader ,
32
+ DialogTitle ,
33
+ DialogTrigger ,
34
+ } from ' @/components/ui/dialog'
35
+ import { Input } from ' @/components/ui/input'
36
+
26
37
import { altKey , altSign , ctrlKey , shiftKey , shiftSign } from ' @/config'
27
38
import { useDisplayStore , useStore } from ' @/stores'
28
39
import {
@@ -32,13 +43,14 @@ import {
32
43
} from ' @/utils'
33
44
import fileApi from ' @/utils/file'
34
45
import CodeMirror from ' codemirror'
46
+ import { Plus , Trash } from ' lucide-vue-next'
35
47
import { storeToRefs } from ' pinia'
36
48
import { onMounted , ref , toRaw , watch } from ' vue'
37
49
import { toast } from ' vue-sonner'
38
50
39
51
const store = useStore ()
40
52
const displayStore = useDisplayStore ()
41
- const { isDark, output, editor, editorContent } = storeToRefs (store )
53
+ const { isDark, output, editor } = storeToRefs (store )
42
54
const { isShowCssEditor } = storeToRefs (displayStore )
43
55
44
56
const {
@@ -201,7 +213,7 @@ function initEditor() {
201
213
const editorDom = document .querySelector <HTMLTextAreaElement >(` #editor ` )!
202
214
203
215
if (! editorDom .value ) {
204
- editorDom .value = editorContent . value
216
+ editorDom .value = store . posts [ store . currentPostIndex ]. content
205
217
}
206
218
editor .value = CodeMirror .fromTextArea (editorDom , {
207
219
mode: ` text/x-markdown ` ,
@@ -248,7 +260,7 @@ function initEditor() {
248
260
clearTimeout (changeTimer .value )
249
261
changeTimer .value = setTimeout (() => {
250
262
onEditorRefresh ()
251
- editorContent . value = e .getValue ()
263
+ store . posts [ store . currentPostIndex ]. content = e .getValue ()
252
264
}, 300 )
253
265
})
254
266
@@ -385,6 +397,16 @@ onMounted(() => {
385
397
onEditorRefresh ()
386
398
mdLocalToRemote ()
387
399
})
400
+
401
+ const isOpen = ref (false )
402
+
403
+ const addPostInputVal = ref (` ` )
404
+
405
+ function addPost() {
406
+ store .addPost (addPostInputVal .value )
407
+ isOpen .value = false
408
+ addPostInputVal .value = ` `
409
+ }
388
410
</script >
389
411
390
412
<template >
@@ -396,10 +418,46 @@ onMounted(() => {
396
418
@end-copy =" endCopy"
397
419
/>
398
420
<main class =" container-main flex-1" >
399
- <div class =" container-main-section grid h-full border-1" :class =" isShowCssEditor ? 'grid-cols-3' : 'grid-cols-2'" >
421
+ <div class =" container-main-section h-full flex border-1" >
422
+ <nav class =" space-y-1 w-50 border-r bg-gray/20 p-2 dark:bg-gray/40" >
423
+ <Dialog v-model:open =" isOpen" >
424
+ <DialogTrigger as-child >
425
+ <Button variant =" outline" class =" w-full" size =" xs" >
426
+ <Plus /> 新增文章
427
+ </Button >
428
+ </DialogTrigger >
429
+ <DialogContent >
430
+ <DialogHeader >
431
+ <DialogTitle >新增文章</DialogTitle >
432
+ <DialogDescription >
433
+ 请输入文章名称
434
+ </DialogDescription >
435
+ </DialogHeader >
436
+ <Input v-model =" addPostInputVal" />
437
+ <DialogFooter >
438
+ <Button @click =" addPost()" >
439
+ 确 定
440
+ </Button >
441
+ </DialogFooter >
442
+ </DialogContent >
443
+ </Dialog >
444
+ <a
445
+ v-for =" (post, index) in store.posts"
446
+ :key =" post.title"
447
+ href =" #"
448
+ :class =" {
449
+ 'bg-primary text-primary-foreground': store.currentPostIndex === index,
450
+ }"
451
+ class =" hover:text-primary-foreground hover:bg-primary/90 dark:bg-muted dark:hover:bg-muted h-8 w-full inline-flex items-center justify-start gap-2 whitespace-nowrap rounded px-4 text-sm transition-colors dark:text-white dark:hover:text-white"
452
+ @click =" store.currentPostIndex = index"
453
+ >
454
+ <span >{{ post.title }}</span >
455
+ <Trash v-if =" index == store.currentPostIndex" class =" ml-auto size-4" @click.stop =" store.delPost(index)" />
456
+ </a >
457
+ </nav >
400
458
<div
401
459
ref =" codeMirrorWrapper"
402
- class =" codeMirror-wrapper border-r-1"
460
+ class =" codeMirror-wrapper flex-1 border-r-1"
403
461
:class =" {
404
462
'order-1': !store.isEditOnLeft,
405
463
}"
@@ -443,7 +501,7 @@ onMounted(() => {
443
501
id =" preview"
444
502
ref =" preview"
445
503
:span =" isShowCssEditor ? 8 : 12"
446
- class =" preview-wrapper p-5"
504
+ class =" preview-wrapper flex-1 p-5"
447
505
>
448
506
<div id =" output-wrapper" :class =" { output_night: !backLight }" >
449
507
<div class =" preview border shadow-xl" >
@@ -457,7 +515,7 @@ onMounted(() => {
457
515
</div >
458
516
</div >
459
517
</div >
460
- <CssEditor />
518
+ <CssEditor class = " flex-1 " />
461
519
</div >
462
520
</main >
463
521
0 commit comments