@@ -207,16 +207,11 @@ const ClipBoardRef = ref()
207
207
// <生命周期&初始化>
208
208
const initAll = async () => {
209
209
isLoading .value = true
210
- console .log (" FileMgr.vue-1" )
211
210
212
211
await gotoDir (props .adapter .getCurrentDirectory (), true )
213
- console .log (" FileMgr.vue-2" )
214
212
watch (viewOptions , (newVal , oldVal ) => {
215
213
// 保存viewOptions
216
- console .log (" FileMgr.vue-3" )
217
- tryToSaveViewOptions (oldVal ).then (() => {
218
- console .log (" FileMgr.vue-4" )
219
- })
214
+ tryToSaveViewOptions (oldVal )
220
215
}, { deep: true })
221
216
222
217
isLoading .value = false
@@ -237,7 +232,7 @@ const mergeOptions = () => {
237
232
const options = reactive (mergeOptions ())
238
233
239
234
onMounted (async () => {
240
- await initAll ()
235
+ initAll ()
241
236
})
242
237
243
238
// <核心功能-文件相关>
@@ -250,34 +245,20 @@ watch(() => props.directory, async (newVal) => {
250
245
const gotoDir = async (arg : Addr , pushHistory : boolean ) => {
251
246
isLoading .value = true
252
247
// 保存布局选项
253
- console .log (" [2]FileMgr.vue-1" )
254
-
255
248
await tryToSaveViewOptions ()
256
- console .log (" [2]FileMgr.vue-2" )
257
249
258
250
// adapter切换当前目录
259
251
await props .adapter .changeCurrentDirectory (arg )
260
- console .log (" [2]FileMgr.vue-3" )
261
-
262
252
// 更改currentFileTable
263
253
currentDir .value = arg
264
- console .log (" [2]FileMgr.vue-4" )
265
-
266
254
currentFileTable .value = await props .adapter .getCurrentFileTable ()
267
- console .log (" [2]FileMgr.vue-5" )
268
255
269
256
// 加载新的布局选项
270
257
await tryToGetAndApplyViewOptions ()
271
- console .log (" [2]FileMgr.vue-6" )
272
-
273
258
// 取消选择的所有item
274
259
selectedItems .value .clear ()
275
- console .log (" [2]FileMgr.vue-7" )
276
-
277
260
if (pushHistory ) {
278
- console .log (" [2]FileMgr.vue-8" )
279
261
operationHistory .value .push (lodash .cloneDeep (arg ))
280
- console .log (" [2]FileMgr.vue-9" )
281
262
}
282
263
isLoading .value = false
283
264
}
@@ -480,7 +461,7 @@ const handleFileImportClick = () => {
480
461
}
481
462
482
463
// <外观选择相关>
483
- const viewOptions = ref < ViewOptions >( {
464
+ const defaultViewOptions = {
484
465
itemDisplayMode: 1 , // 0 list, 1 item
485
466
itemSize: 5 , // 区间[0,10]的整数, '5' stands for medium size
486
467
sortBy: 0 , // 0 name, 1 timeModify
@@ -489,7 +470,9 @@ const viewOptions = ref<ViewOptions>({
489
470
showHiddenItem: 1 ,
490
471
showExtName: 1 ,
491
472
showThumbnails: 1
492
- })
473
+ }
474
+
475
+ const viewOptions = ref <ViewOptions >(defaultViewOptions )
493
476
494
477
/**
495
478
* 尝试保存布局选项
@@ -498,13 +481,11 @@ const tryToSaveViewOptions = async (optionsIn?: ViewOptions) => {
498
481
if (! props .adapter .setExtraMeta || ! options .allowSavingViewOptions || ! currentFileTable .value ) {
499
482
return
500
483
}
501
- console .log (" FileMgr.vue-5" )
502
484
try {
503
485
await props .adapter .setExtraMeta (
504
486
currentFileTable .value .selfKey ,
505
487
' viewOptions' ,
506
488
Buffer .from (JSON .stringify (viewOptions .value ?? optionsIn )))
507
- console .log (" FileMgr.vue-6-final" )
508
489
} catch (e ) {
509
490
warn (' 尝试保存布局选项失败' + e .toString ())
510
491
}
@@ -518,11 +499,11 @@ const tryToGetAndApplyViewOptions = async () => {
518
499
return
519
500
}
520
501
try {
521
- console .log (' [3]-1' )
522
- console .log (await props .adapter .getExtraMeta (currentFileTable .value .selfKey , ' viewOptions' ))
523
- console .log ((await props .adapter .getExtraMeta (currentFileTable .value .selfKey , ' viewOptions' )).toString ())
502
+ if (! (await props .adapter .hasExtraMeta (currentFileTable .value .selfKey , ' viewOptions' ))) {
503
+ viewOptions .value = defaultViewOptions
504
+ return
505
+ }
524
506
const obj = JSON .parse ((await props .adapter .getExtraMeta (currentFileTable .value .selfKey , ' viewOptions' )).toString ())
525
- console .log (' [3]-2' )
526
507
if (obj ) {
527
508
viewOptions .value = obj
528
509
}
0 commit comments