140
140
.file-info-actions {
141
141
margin-top : 20px ;
142
142
}
143
+ .font-preview {
144
+ padding : 20px ;
145
+ max-height : 70vh ;
146
+ overflow-y : auto;
147
+ }
148
+ .preview-text {
149
+ margin-bottom : 20px ;
150
+ }
151
+ .preview-sizes div {
152
+ margin : 10px 0 ;
153
+ }
143
154
</ style >
144
155
</ head >
145
156
< body >
@@ -271,6 +282,22 @@ <h1>ServeFS File Browser</h1>
271
282
:rows ="20 "
272
283
:readonly ="!previewDialog.editable ">
273
284
</ el-input >
285
+ <!-- 字体预览 -->
286
+ < div v-else-if ="previewDialog.isFont " class ="font-preview ">
287
+ < div class ="preview-text ">
288
+ < el-input v-model ="previewText " placeholder ="输入预览文字 ">
289
+ </ el-input >
290
+ </ div >
291
+ < div class ="preview-sizes ">
292
+ < div v-for ="size in [12, 16, 24, 32, 48] " :key ="size ">
293
+ < div > {{ size }}px</ div >
294
+ < div :style ="{
295
+ fontSize: size + 'px',
296
+ fontFamily: previewDialog.fontFamily
297
+ } "> {{ previewText }}</ div >
298
+ </ div >
299
+ </ div >
300
+ </ div >
274
301
<!-- 文件信息卡片 -->
275
302
< div v-else class ="file-info-card ">
276
303
< div class ="file-info-icon ">
@@ -340,6 +367,9 @@ <h1>ServeFS File Browser</h1>
340
367
currentFile : null ,
341
368
isImage : false ,
342
369
isText : false ,
370
+ isFont : false ,
371
+ fontUrl : '' ,
372
+ fontFamily : '' ,
343
373
fileSize : 0 ,
344
374
mimeType : ''
345
375
} ) ;
@@ -348,6 +378,7 @@ <h1>ServeFS File Browser</h1>
348
378
title : '' ,
349
379
message : ''
350
380
} ) ;
381
+ const previewText = ref ( 'Hello 你好 こんにちは 123' ) ;
351
382
352
383
// Get initial path from URL
353
384
const initPath = ( ) => {
@@ -421,11 +452,30 @@ <h1>ServeFS File Browser</h1>
421
452
currentFile : item ,
422
453
isImage : true ,
423
454
isText : false ,
455
+ isFont : false ,
456
+ fontUrl : '' ,
457
+ fontFamily : '' ,
424
458
fileSize : 0 ,
425
459
mimeType : ''
426
460
} ;
427
- } else if ( item . mime_type . startsWith ( 'text/' ) ) {
428
- // 对于文本文件,获取内容并显示在编辑器中
461
+ } else if ( item . name . toLowerCase ( ) . endsWith ( '.ttf' ) ) {
462
+ // TTF 字体文件预览
463
+ previewDialog . value = {
464
+ visible : true ,
465
+ title : item . name ,
466
+ content : '' ,
467
+ editable : false ,
468
+ currentFile : item ,
469
+ isImage : false ,
470
+ isText : false ,
471
+ isFont : true ,
472
+ fontUrl : `/raw/${ item . path } ` ,
473
+ fontFamily : '' ,
474
+ fileSize : item . size ,
475
+ mimeType : 'font/ttf'
476
+ } ;
477
+ } else if ( item . mime_type . startsWith ( 'text/' ) || item . mime_type === 'application/json' ) {
478
+ // 对于文本文件和 JSON 文件,获取内容并显示在编辑器中
429
479
const response = await fetch ( `/api/files/${ item . path } ` ) ;
430
480
const data = await response . json ( ) ;
431
481
if ( data . error ) {
@@ -440,6 +490,9 @@ <h1>ServeFS File Browser</h1>
440
490
currentFile : item ,
441
491
isImage : false ,
442
492
isText : true ,
493
+ isFont : false ,
494
+ fontUrl : '' ,
495
+ fontFamily : '' ,
443
496
fileSize : item . size ,
444
497
mimeType : item . mime_type
445
498
} ;
@@ -452,6 +505,9 @@ <h1>ServeFS File Browser</h1>
452
505
currentFile : item ,
453
506
isImage : false ,
454
507
isText : false ,
508
+ isFont : false ,
509
+ fontUrl : '' ,
510
+ fontFamily : '' ,
455
511
fileSize : item . size ,
456
512
mimeType : item . mime_type
457
513
} ;
@@ -653,6 +709,21 @@ <h1>ServeFS File Browser</h1>
653
709
window . removeEventListener ( 'keydown' , handleKeydown ) ;
654
710
} ) ;
655
711
712
+ watch ( ( ) => previewDialog . value . fontUrl , ( newUrl ) => {
713
+ if ( newUrl && previewDialog . value . isFont ) {
714
+ const fontFamily = 'PreviewFont_' + Date . now ( ) ;
715
+ const style = document . createElement ( 'style' ) ;
716
+ style . textContent = `
717
+ @font-face {
718
+ font-family: '${ fontFamily } ';
719
+ src: url('${ newUrl } ') format('truetype');
720
+ }
721
+ ` ;
722
+ document . head . appendChild ( style ) ;
723
+ previewDialog . value . fontFamily = fontFamily ;
724
+ }
725
+ } ) ;
726
+
656
727
return {
657
728
fileList,
658
729
currentPath,
@@ -674,7 +745,8 @@ <h1>ServeFS File Browser</h1>
674
745
formatFileSize,
675
746
handleFileSelect,
676
747
handleFileDrop,
677
- downloadFile
748
+ downloadFile,
749
+ previewText
678
750
} ;
679
751
}
680
752
} ) ;
0 commit comments