forked from mxx1111/mdlook
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCssEditor.vue
More file actions
759 lines (675 loc) · 24.3 KB
/
Copy pathCssEditor.vue
File metadata and controls
759 lines (675 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
<script setup lang="ts">
import { Check, CheckSquare, Download, Edit3, Ellipsis, Eye, Plus, Upload, X } from '@lucide/vue'
import { exportMergedTheme } from '@md/core'
import { themeMap, themeOptionsMap } from '@md/shared'
import { useConfirmStore } from '@/stores/confirm'
import { useCssEditorStore } from '@/stores/cssEditor'
import { useEditorStore } from '@/stores/editor'
import { useRenderStore } from '@/stores/render'
import { useThemeStore } from '@/stores/theme'
import { useUIStore } from '@/stores/ui'
import { copyPlain } from '@/utils/clipboard'
const confirmStore = useConfirmStore()
const cssEditorStore = useCssEditorStore()
const uiStore = useUIStore()
const renderStore = useRenderStore()
const editorStore = useEditorStore()
const themeStore = useThemeStore()
const { isMobile } = storeToRefs(uiStore)
const { cssContentConfig, isSelectMode, selectedIds } = storeToRefs(cssEditorStore)
// 控制是否启用动画
const enableAnimation = ref(false)
const importThemeInputRef = ref<HTMLInputElement | null>(null)
// 监听 CssEditor 开关状态变化
watch(() => uiStore.isShowCssEditor, () => {
if (isMobile.value) {
// 在移动端,用户操作时启用动画
enableAnimation.value = true
}
})
// 监听设备类型变化,重置动画状态
watch(() => isMobile.value, () => {
enableAnimation.value = false
})
const isOpenEditDialog = ref(false)
const editInputVal = ref(``)
const inlineEditId = ref<string | null>(null)
const inlineEditVal = ref(``)
let inlineInputRef: HTMLInputElement | null = null
function setInlineInputRef(el: unknown) {
inlineInputRef = el as HTMLInputElement | null
}
function startInlineRename(tab: { id: string, title: string }) {
inlineEditId.value = tab.id
inlineEditVal.value = tab.title
nextTick(() => {
inlineInputRef?.select()
})
}
function commitInlineRename() {
const id = inlineEditId.value
if (!id)
return
const trimmed = inlineEditVal.value.trim()
if (!trimmed) {
toast.error(`方案名不可为空`)
inlineEditId.value = null
return
}
const currentTab = cssContentConfig.value.tabs.find(t => t.id === id)
if (currentTab && trimmed !== currentTab.title) {
currentTab.title = trimmed
currentTab.name = trimmed
currentTab.updateDatetime = new Date()
toast.success(`修改成功`)
}
inlineEditId.value = null
}
function cancelInlineRename() {
inlineEditId.value = null
}
async function scrollToActiveTab() {
await nextTick()
const activeTab = document.querySelector('.cssEditor-wrapper .css-tab-active')
if (activeTab) {
activeTab.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' })
}
}
function rename(name: string) {
editInputVal.value = name
isOpenEditDialog.value = true
}
function editTabName() {
if (!(editInputVal.value).trim()) {
toast.error(`编辑失败,方案名不可为空`)
return
}
cssEditorStore.renameTab(editInputVal.value)
isOpenEditDialog.value = false
toast.success(`修改成功`)
}
const isOpenAddDialog = ref(false)
const addInputVal = ref(``)
// 新建方案时选择的基础主题
const baseThemeForNew = ref<'blank' | 'default' | 'grace' | 'simple'>('blank')
async function addTab() {
if (!(addInputVal.value).trim()) {
toast.error(`新建失败,方案名不可为空`)
return
}
// 根据选择的基础主题来初始化内容
let initialContent = ''
if (baseThemeForNew.value === 'blank') {
initialContent = '' // 空白方案
}
else {
// 基于内置主题
initialContent = themeMap[baseThemeForNew.value]
}
const newTabName = addInputVal.value
// addCssContentTab 会自动设置 active 并触发回调
cssEditorStore.addCssContentTab(newTabName, initialContent)
isOpenAddDialog.value = false
toast.success(`新建成功`)
// 重置为空白
baseThemeForNew.value = 'blank'
// 滚动到新创建的 tab
scrollToActiveTab()
}
function removeHandler(targetId: string) {
confirmStore.confirm({
title: '提示',
description: '此操作将删除该自定义方案,是否继续?',
onConfirm: () => {
const tabs = cssContentConfig.value.tabs
if (tabs.length === 1) {
toast.warning(`至少保留一个方案`)
return
}
let activeId = cssContentConfig.value.active
if (activeId === targetId) {
tabs.forEach((tab, index) => {
if (tab.id === targetId) {
const nextTab = tabs[index + 1] || tabs[index - 1]
if (nextTab) {
activeId = nextTab.id
}
}
})
}
cssEditorStore.tabChanged(activeId)
cssContentConfig.value.tabs = tabs.filter(tab => tab.id !== targetId)
toast.success(`删除成功`)
},
})
}
function addHandler() {
addInputVal.value = `方案${cssContentConfig.value.tabs.length + 1}`
baseThemeForNew.value = 'blank' // 重置选择
isOpenAddDialog.value = true
}
function openImportTheme() {
importThemeInputRef.value?.click()
}
async function importThemeFile(event: Event) {
const input = event.target as HTMLInputElement
const file = input.files?.[0]
input.value = ''
if (!file)
return
const content = await file.text()
const name = file.name.replace(/\.css$/i, '').trim() || `导入方案`
cssEditorStore.addCssContentTab(name, content)
toast.success(`已导入「${name}」`)
scrollToActiveTab()
}
const isOpenViewThemeDialog = ref(false)
const selectedViewTheme = ref<'default' | 'grace' | 'simple'>('default')
const contextMenuTargetId = ref<string | null>(null)
const showContextMenu = ref(false)
const contextMenuPos = ref({ x: 0, y: 0 })
function onContextMenu(e: MouseEvent, tabId: string) {
e.preventDefault()
e.stopPropagation()
contextMenuTargetId.value = tabId
contextMenuPos.value = { x: e.clientX, y: e.clientY }
showContextMenu.value = true
}
function closeContextMenu() {
showContextMenu.value = false
contextMenuTargetId.value = null
}
function contextMenuRename() {
const tab = cssContentConfig.value.tabs.find(t => t.id === contextMenuTargetId.value)
if (tab) {
rename(tab.name)
}
closeContextMenu()
}
function contextMenuExport() {
if (contextMenuTargetId.value) {
cssEditorStore.exportSingleTab(contextMenuTargetId.value)
}
closeContextMenu()
}
function contextMenuDelete() {
if (contextMenuTargetId.value) {
removeHandler(contextMenuTargetId.value)
}
closeContextMenu()
}
function enterSelectModeFromContextMenu() {
if (contextMenuTargetId.value) {
cssEditorStore.toggleSelectMode()
cssEditorStore.toggleSelectTab(contextMenuTargetId.value)
}
closeContextMenu()
}
const allSelected = computed(
() => cssContentConfig.value.tabs.length > 0 && selectedIds.value.length === cssContentConfig.value.tabs.length,
)
function openBatchDelConfirm() {
const n = selectedIds.value.length
const description = n === 1
? `此操作将删除「${cssContentConfig.value.tabs.find(t => t.id === selectedIds.value[0])?.title ?? ''}」,是否继续?`
: `此操作将删除已选的 ${n} 个方案,是否继续?`
confirmStore.confirm({
title: '提示',
description,
confirmText: '确定删除',
destructive: true,
onConfirm: () => {
cssEditorStore.batchDeleteTabs()
},
})
}
function handleTabClick(tabId: string) {
if (isSelectMode.value) {
cssEditorStore.toggleSelectTab(tabId)
}
else {
tabChanged(tabId)
}
}
function exitSelectMode() {
cssEditorStore.toggleSelectMode()
}
function openViewThemeDialog() {
selectedViewTheme.value = 'default'
isOpenViewThemeDialog.value = true
}
// 复制主题 CSS
async function copyThemeCSS() {
const css = themeMap[selectedViewTheme.value]
await copyPlain(css)
toast.success('已复制到剪贴板')
}
// 基于当前查看的主题新建方案
function createFromViewTheme() {
isOpenViewThemeDialog.value = false
// 设置基础主题并打开新建对话框
baseThemeForNew.value = selectedViewTheme.value
addInputVal.value = `基于${themeOptionsMap[selectedViewTheme.value].label}主题`
isOpenAddDialog.value = true
}
function tabChanged(tabId: string | number) {
cssEditorStore.tabChanged(tabId as string)
// 切换后滚动到活跃的 tab
scrollToActiveTab()
}
// 初始化 CSS 编辑器
onMounted(() => {
// CSS 内容更新回调
const handleCssUpdate = () => {
// 1. 使用新主题系统应用 CSS
themeStore.applyCurrentTheme()
// 2. 触发编辑器刷新,重新渲染内容
themeStore.updateCodeTheme()
const raw = editorStore.getContent()
renderStore.render(raw)
}
// 设置切换方案时的回调(与编辑时使用相同的逻辑)
cssEditorStore.setOnTabChangedCallback(handleCssUpdate)
// 初始化 CSS 编辑器
cssEditorStore.initCssEditor(handleCssUpdate)
// 初始化时滚动到活跃的 tab
scrollToActiveTab()
// 点击外部关闭右键菜单
document.addEventListener('click', closeContextMenu)
})
onUnmounted(() => {
document.removeEventListener('click', closeContextMenu)
})
// 导出合并后的主题
function exportCurrentTheme() {
const currentTab = cssContentConfig.value.tabs.find(tab => tab.id === cssContentConfig.value.active)
if (!currentTab) {
toast.error(`未找到当前方案`)
return
}
const currentThemeName = currentTab.title || currentTab.name
const currentPresetCss = themeMap[themeStore.theme as keyof typeof themeMap]
const currentDesignCss = themeStore.currentDesignTheme?.articleCss
// 使用新的导出函数(包含 default 基础)
const baseTheme = themeStore.theme === `default`
? themeMap.default
: `${themeMap.default}\n\n${currentPresetCss ?? currentDesignCss ?? ``}`
exportMergedTheme(
currentTab.content,
baseTheme,
{
primaryColor: themeStore.primaryColor,
fontFamily: themeStore.fontFamily,
fontSize: themeStore.fontSize,
},
currentThemeName,
)
}
</script>
<template>
<!-- 移动端遮罩层 -->
<div
v-if="isMobile && uiStore.isShowCssEditor"
class="fixed inset-0 bg-black/50 z-40"
@click="uiStore.isShowCssEditor = false"
/>
<div
v-show="isMobile ? uiStore.isShowCssEditor : true"
class="cssEditor-wrapper h-full flex flex-col overflow-y-auto"
:class="{
'fixed top-0 right-0 w-full h-full z-100 bg-background border-l shadow-lg mobile-css-editor': isMobile,
'animate': isMobile && enableAnimation,
}"
:style="isMobile ? { transform: uiStore.isShowCssEditor ? 'translateX(0)' : 'translateX(100%)' } : undefined"
>
<!-- Tab 栏 + 工具栏合并 -->
<div class="flex items-center h-9 px-2 shrink-0 border-b border-border">
<div class="flex-1 flex items-center gap-0 overflow-x-auto custom-scrollbar min-w-0 h-full">
<div
v-for="item in cssContentConfig.tabs"
:key="item.id"
class="group/tab relative flex items-center gap-1.5 shrink-0 h-full px-3 text-xs transition-colors duration-150"
:class="[
cssContentConfig.active === item.id && !isSelectMode ? 'css-tab-active text-foreground font-medium' : 'text-muted-foreground hover:text-foreground',
isSelectMode && selectedIds.includes(item.id) ? 'bg-accent text-accent-foreground' : '',
]"
@click="handleTabClick(item.id)"
@dblclick.stop="startInlineRename(item)"
@contextmenu="onContextMenu($event, item.id)"
>
<span
v-if="isSelectMode"
class="inline-flex items-center justify-center size-4 rounded border transition-colors mr-1"
:class="selectedIds.includes(item.id) ? 'bg-primary border-primary text-primary-foreground' : 'border-border'"
>
<Check v-if="selectedIds.includes(item.id)" class="size-3" />
</span>
<input
v-if="inlineEditId === item.id"
:ref="setInlineInputRef"
v-model="inlineEditVal"
class="w-[80px] bg-transparent outline-none border-b border-primary text-xs"
@click.stop
@keyup.enter="commitInlineRename"
@keyup.escape="cancelInlineRename"
@blur="commitInlineRename"
>
<span v-else class="truncate max-w-[100px]">{{ item.title }}</span>
<span
v-if="cssContentConfig.active === item.id && !isSelectMode"
class="absolute bottom-0 left-2 right-2 h-[2px] rounded-full bg-primary"
/>
<DropdownMenu v-if="cssContentConfig.active === item.id && !isSelectMode">
<DropdownMenuTrigger as-child>
<span
class="inline-flex items-center justify-center size-4 rounded text-muted-foreground/60 hover:text-foreground hover:bg-black/5 dark:hover:bg-white/10 transition-colors duration-100 cursor-pointer"
@click.stop
>
<Ellipsis class="size-3" />
</span>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" class="w-32">
<DropdownMenuItem @click.stop="rename(item.name)">
<Edit3 class="mr-2 size-4" /> 重命名
</DropdownMenuItem>
<DropdownMenuItem @click.stop="cssEditorStore.exportSingleTab(item.id)">
<Download class="mr-2 size-4" /> 导出
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
v-if="cssContentConfig.tabs.length > 1"
class="text-destructive focus:text-destructive"
@click.stop="removeHandler(item.id)"
>
<X class="mr-2 size-4" /> 删除
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<!-- 工具按钮组 -->
<div class="flex items-center shrink-0">
<!-- 新增 Tab -->
<button
class="inline-flex items-center justify-center size-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-150"
@click="addHandler"
>
<Plus class="size-3.5" />
</button>
<!-- 内置主题 -->
<button
class="inline-flex items-center justify-center size-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-150"
@click="openViewThemeDialog"
>
<Eye class="size-3.5" />
</button>
<!-- 导出主题 -->
<button
class="inline-flex items-center justify-center size-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-150"
@click="exportCurrentTheme"
>
<Download class="size-3.5" />
</button>
<!-- 导入主题 -->
<input
ref="importThemeInputRef"
type="file"
accept="text/css,.css"
class="hidden"
@change="importThemeFile"
>
<button
class="inline-flex items-center justify-center size-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-150"
@click="openImportTheme"
>
<Upload class="size-3.5" />
</button>
<!-- 关闭 -->
<button
class="inline-flex items-center justify-center size-7 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors duration-150"
@click="uiStore.isShowCssEditor = false"
>
<X class="size-3.5" />
</button>
</div>
</div>
<!-- CSS编辑器内容区域 -->
<div class="flex-1 min-h-0">
<textarea
id="cssEditor"
type="textarea"
placeholder="Your custom css here."
/>
</div>
<!-- 选择模式底部操作栏 -->
<Transition name="slide-up">
<div
v-if="isSelectMode"
class="shrink-0 border-t border-border bg-background px-3 pt-2 pb-3 space-y-2"
>
<div class="flex items-center justify-between text-xs">
<span class="text-muted-foreground">
已选
<strong class="text-foreground font-semibold">{{ selectedIds.length }}</strong>
个
</span>
<div class="flex items-center gap-2 text-muted-foreground">
<button
class="hover:text-foreground transition-colors"
@click="allSelected ? cssEditorStore.clearSelection() : cssEditorStore.selectAllTabs()"
>
{{ allSelected ? '取消全选' : '全选' }}
</button>
<span class="opacity-30">·</span>
<button class="hover:text-foreground transition-colors" @click="exitSelectMode">
完成
</button>
</div>
</div>
<div class="flex">
<button
class="flex flex-1 items-center justify-center rounded-md py-2 text-muted-foreground transition-colors hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-35"
title="导出"
:disabled="!selectedIds.length"
@click="cssEditorStore.batchExportTabs"
>
<Download class="size-4" />
</button>
<div class="mx-1 self-center h-5 w-px bg-border/60 shrink-0" />
<button
class="flex flex-1 items-center justify-center rounded-md py-2 text-destructive/60 transition-colors hover:bg-destructive/8 hover:text-destructive disabled:pointer-events-none disabled:opacity-35"
:title="selectedIds.length >= cssContentConfig.tabs.length ? '至少保留一个方案' : '删除'"
:disabled="!selectedIds.length || selectedIds.length >= cssContentConfig.tabs.length"
@click="openBatchDelConfirm()"
>
<X class="size-4" />
</button>
</div>
</div>
</Transition>
<!-- 右键菜单 -->
<Teleport to="body">
<div
v-if="showContextMenu"
class="fixed z-50 min-w-[120px] rounded-md border border-border bg-background p-1 shadow-md animate-in fade-in-0 zoom-in-95"
:style="{ left: `${contextMenuPos.x}px`, top: `${contextMenuPos.y}px` }"
@click.stop
>
<button
class="flex w-full items-center rounded-sm px-2 py-1.5 text-xs text-foreground hover:bg-accent transition-colors"
@click="contextMenuRename"
>
<Edit3 class="mr-2 size-3.5" /> 重命名
</button>
<button
class="flex w-full items-center rounded-sm px-2 py-1.5 text-xs text-foreground hover:bg-accent transition-colors"
@click="contextMenuExport"
>
<Download class="mr-2 size-3.5" /> 导出
</button>
<div class="my-1 h-px bg-border" />
<button
v-if="cssContentConfig.tabs.length > 1"
class="flex w-full items-center rounded-sm px-2 py-1.5 text-xs text-destructive hover:bg-destructive/8 transition-colors"
@click="contextMenuDelete"
>
<X class="mr-2 size-3.5" /> 删除
</button>
<button
class="flex w-full items-center rounded-sm px-2 py-1.5 text-xs text-foreground hover:bg-accent transition-colors"
@click="enterSelectModeFromContextMenu"
>
<CheckSquare class="mr-2 size-3.5" /> 多选
</button>
</div>
</Teleport>
<!-- 新增弹窗 -->
<Dialog v-model:open="isOpenAddDialog">
<DialogContent class="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>新建自定义 CSS</DialogTitle>
<DialogDescription>
请输入方案名称,并选择初始模板
</DialogDescription>
</DialogHeader>
<div class="space-y-4">
<div class="space-y-2">
<label class="text-sm font-medium">方案名称</label>
<Input v-model="addInputVal" placeholder="输入方案名称" @keyup.enter="addTab" />
</div>
<div class="space-y-2">
<label class="text-sm font-medium">初始模板</label>
<Select v-model="baseThemeForNew">
<SelectTrigger>
<SelectValue placeholder="选择初始模板" />
</SelectTrigger>
<SelectContent>
<SelectItem value="blank">
空白方案
</SelectItem>
<SelectItem value="default">
基于经典主题
</SelectItem>
<SelectItem value="grace">
基于优雅主题
</SelectItem>
<SelectItem value="simple">
基于简洁主题
</SelectItem>
</SelectContent>
</Select>
<p class="text-xs text-muted-foreground">
选择一个内置主题作为起点,可以在其基础上进行修改
</p>
</div>
</div>
<DialogFooter>
<Button variant="outline" @click="isOpenAddDialog = false">
取消
</Button>
<Button @click="addTab()">
创建
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
<!-- 重命名弹窗 -->
<Dialog v-model:open="isOpenEditDialog">
<DialogContent class="sm:max-w-[425px]">
<DialogHeader>
<DialogTitle>编辑方案名称</DialogTitle>
<DialogDescription>
请输入新的方案名称
</DialogDescription>
</DialogHeader>
<Input v-model="editInputVal" @keyup.enter="editTabName" />
<DialogFooter>
<Button variant="outline" @click="isOpenEditDialog = false">
取消
</Button>
<Button @click="editTabName">
保存
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
<!-- 查看内置主题对话框 -->
<Dialog v-model:open="isOpenViewThemeDialog">
<DialogContent class="sm:max-w-4xl max-h-[90vh] flex flex-col" @open-auto-focus.prevent>
<DialogHeader>
<DialogTitle>查看内置主题样式</DialogTitle>
<DialogDescription>
查看并复制内置主题的 CSS 代码,或基于它们创建新方案
</DialogDescription>
</DialogHeader>
<div class="space-y-4 flex-1 min-h-0 flex flex-col">
<!-- 主题选择器 -->
<div class="space-y-2">
<label class="text-sm font-medium">选择主题</label>
<Select v-model="selectedViewTheme">
<SelectTrigger class="w-full mt-2 sm:w-[200px] focus-visible:ring-0 focus-visible:ring-offset-0">
<SelectValue placeholder="选择主题" />
</SelectTrigger>
<SelectContent>
<SelectItem value="default">
{{ themeOptionsMap.default.label }}
</SelectItem>
<SelectItem value="grace">
{{ themeOptionsMap.grace.label }}
</SelectItem>
<SelectItem value="simple">
{{ themeOptionsMap.simple.label }}
</SelectItem>
</SelectContent>
</Select>
</div>
<!-- CSS 代码查看器 -->
<div class="flex-1 min-h-0 border rounded-lg overflow-auto">
<pre class="h-full overflow-auto p-4 bg-muted text-sm"><code>{{ themeMap[selectedViewTheme] }}</code></pre>
</div>
</div>
<DialogFooter class="flex-col sm:flex-row gap-2">
<Button variant="outline" @click="isOpenViewThemeDialog = false">
关闭
</Button>
<Button variant="outline" @click="copyThemeCSS">
复制全部
</Button>
<Button variant="outline" @click="createFromViewTheme">
基于此主题新建
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</template>
<style lang="less" scoped>
/* 隐藏滚动条但保持滚动功能 */
.custom-scrollbar {
/* Firefox */
scrollbar-width: none;
/* Chrome, Edge, Safari */
&::-webkit-scrollbar {
display: none;
}
}
/* 移动端CSS编辑器动画 - 只有添加了 animate 类才启用 */
.mobile-css-editor.animate {
transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
.mobile-css-editor {
box-sizing: border-box;
padding-top: env(safe-area-inset-top);
padding-bottom: env(safe-area-inset-bottom);
}
/* 底部操作栏动画 */
.slide-up-enter-active,
.slide-up-leave-active {
transition: transform 200ms ease, opacity 200ms ease;
}
.slide-up-enter-from,
.slide-up-leave-to {
transform: translateY(100%);
opacity: 0;
}
</style>