11import { computed , reactive , ref } from 'vue'
22import { defineStore } from 'pinia'
3- import { ElMessageBox } from 'element-plus'
3+ import { dayjs , ElMessageBox } from 'element-plus'
44
55import { FILE_MAP } from '@/utils/option'
66import { getFileSuffix } from '@/utils/file'
77
88import { useOpenStore } from './open'
9+ import { useUserStore } from './user'
910
1011interface ViewModel {
1112 path : string
1213 diff : boolean
1314 keep : boolean
1415 list : string [ ]
16+ wait : boolean
17+ size ?: number
18+ date ?: dayjs . Dayjs
19+ }
20+
21+ interface AddOption {
22+ history ?: boolean
23+ keep ?: ViewModel [ 'keep' ]
24+ list ?: ViewModel [ 'list' ]
25+ size ?: ViewModel [ 'size' ]
26+ date ?: ViewModel [ 'date' ]
1527}
1628
1729export const useEditorStore = defineStore ( 'editor' , ( ) => {
1830 const open = useOpenStore ( )
31+ const user = useUserStore ( )
1932
2033 const view = reactive < ViewModel [ ] > ( [ ] )
2134
2235 const active = ref ( '' )
2336
2437 const index = computed ( ( ) => view . findIndex ( ( i ) => i . path === active . value ) )
2538
26- const add = (
27- path : ViewModel [ 'path' ] ,
28- opt : { keep ?: boolean ; history ?: boolean ; list ?: string [ ] } = {
29- keep : true ,
30- history : true ,
31- list : [ ] ,
32- } ,
33- ) => {
39+ const add = ( path : ViewModel [ 'path' ] , opt : AddOption = { keep : true , history : true , list : [ ] } ) => {
3440 if ( ! path ) {
3541 return
3642 }
@@ -42,7 +48,15 @@ export const useEditorStore = defineStore('editor', () => {
4248 const index = view . findIndex ( ( i ) => i . path === path )
4349
4450 if ( index === - 1 ) {
45- view . push ( { path, diff : false , keep, list } )
51+ view . push ( {
52+ path,
53+ diff : false ,
54+ keep,
55+ list,
56+ wait : user . cfg . fileBigWait > 0 && opt . size !== undefined && opt . size > user . cfg . fileBigWait ,
57+ size : opt . size ,
58+ date : opt . date ,
59+ } )
4660 }
4761
4862 active . value = path
0 commit comments