@@ -5,7 +5,6 @@ import CvEditor from './components/CvEditor.vue';
55import { defaultData } from ' ./defaultData' ;
66import type { CvData } from ' ./types' ;
77import { useLocale } from ' ./composables/useLocale' ;
8-
98const cvData = ref <CvData >(defaultData );
109const activeTab = ref (' personal' );
1110const lastSaved = ref <Date | null >(null );
@@ -43,6 +42,8 @@ onMounted(() => {
4342 }
4443 }
4544 startAutoSave ();
45+ // 点击外部关闭数据下拉菜单
46+ document .addEventListener (' click' , closeDataMenu );
4647 // 监听预览 wrapper 尺寸变化(分页变化、数据变化都会触发),同步外层占位高度
4748 nextTick (() => {
4849 if (previewZoomRef .value ) {
@@ -58,6 +59,7 @@ watch(previewScale, () => updateOuterH());
5859onUnmounted (() => {
5960 if (autoSaveInterval ) clearInterval (autoSaveInterval );
6061 if (resizeObserver ) resizeObserver .disconnect ();
62+ document .removeEventListener (' click' , closeDataMenu );
6163});
6264
6365let autoSaveInterval: number | null = null ;
@@ -143,6 +145,25 @@ const handleImportJson = (event: Event) => {
143145 reader .readAsText (file );
144146};
145147
148+ // 加载示例数据(覆盖当前数据,需确认)
149+ const handleLoadSample = () => {
150+ if (! confirm (t (' loadSampleConfirm' ))) return ;
151+ // 深拷贝避免默认数据对象被响应式修改污染
152+ cvData .value = JSON .parse (JSON .stringify (defaultData ));
153+ };
154+
155+ // 数据操作下拉菜单
156+ const showDataMenu = ref (false );
157+ const toggleDataMenu = () => { showDataMenu .value = ! showDataMenu .value ; };
158+ const closeDataMenu = () => { showDataMenu .value = false ; };
159+ const handleImportClick = () => {
160+ closeDataMenu ();
161+ const input = document .getElementById (' import-json' ) as HTMLInputElement | null ;
162+ input ?.click ();
163+ };
164+ const handleExportClick = () => { closeDataMenu (); handleExportJson (); };
165+ const handleSampleClick = () => { closeDataMenu (); handleLoadSample (); };
166+
146167 </script >
147168
148169<template >
@@ -210,26 +231,45 @@ const handleImportJson = (event: Event) => {
210231 <!-- Editor Pane -->
211232 <aside
212233 class =" w-[450px] md:w-[500px] min-w-[350px] border-r border-slate-200 bg-white flex flex-col z-10 shrink-0 no-print shadow-sm h-full relative" >
213- <div class =" h-14 border-b border-slate-200 bg-white flex justify-between items-center px-4 shrink-0" >
214- <h2 class =" text-sm font-bold text-slate-700 capitalize w-20 " ><i
234+ <div class =" h-14 border-b border-slate-200 bg-white flex justify-between items-center px-4 shrink-0 gap-3 " >
235+ <h2 class =" text-sm font-bold text-slate-700 capitalize min-w-0 truncate " ><i
215236 class =" fa-solid fa-pen-to-square text-[#01a3a4] mr-1.5 hidden sm:inline" ></i > {{ activeTab }}</h2 >
216237 <div class =" flex items-center gap-2" >
217238 <input type =" file" id =" import-json" accept =" .json" class =" hidden" @change =" handleImportJson" />
218- <label for =" import-json"
219- class =" px-2 py-1.5 text-[11px] font-semibold text-slate-600 rounded bg-slate-100 hover:bg-slate-200 transition-colors shadow-sm cursor-pointer whitespace-nowrap" >
220- <i class =" fa-solid fa-file-import mr-1" ></i > <span class =" hidden sm:inline" >Import JSON</span >
221- </label >
222- <button @click =" handleExportJson"
223- class =" px-2 py-1.5 text-[11px] font-semibold text-slate-600 rounded bg-slate-100 hover:bg-slate-200 transition-colors shadow-sm whitespace-nowrap" >
224- <i class =" fa-solid fa-file-export mr-1" ></i > <span class =" hidden sm:inline" >Export JSON</span >
225- </button >
239+ <!-- 数据操作下拉菜单(Import / Export / Sample) -->
240+ <div class =" relative" >
241+ <button @click.stop =" toggleDataMenu"
242+ class =" px-2 py-1.5 text-[11px] font-semibold text-slate-600 rounded bg-slate-100 hover:bg-slate-200 transition-colors shadow-sm whitespace-nowrap flex items-center gap-1"
243+ :class =" { 'bg-slate-200': showDataMenu }"
244+ :title =" t('dataOpsHint')" >
245+ <i class =" fa-solid fa-database" ></i > <span class =" hidden sm:inline" >{{ t('dataOps') }}</span >
246+ <i class =" fa-solid fa-chevron-down text-[8px] ml-0.5" ></i >
247+ </button >
248+ <div v-if =" showDataMenu"
249+ class =" absolute right-0 top-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg py-1 min-w-[140px] z-50" >
250+ <button @click.stop =" handleImportClick"
251+ class =" w-full text-left px-3 py-1.5 text-[11px] text-slate-600 hover:bg-slate-50 hover:text-[#01a3a4] flex items-center gap-2" >
252+ <i class =" fa-solid fa-file-import w-3" ></i > {{ t('importJson') }}
253+ </button >
254+ <button @click.stop =" handleExportClick"
255+ class =" w-full text-left px-3 py-1.5 text-[11px] text-slate-600 hover:bg-slate-50 hover:text-[#01a3a4] flex items-center gap-2" >
256+ <i class =" fa-solid fa-file-export w-3" ></i > {{ t('exportJson') }}
257+ </button >
258+ <div class =" border-t border-slate-100 my-1" ></div >
259+ <button @click.stop =" handleSampleClick"
260+ class =" w-full text-left px-3 py-1.5 text-[11px] text-slate-600 hover:bg-slate-50 hover:text-[#01a3a4] flex items-center gap-2"
261+ :title =" t('loadSampleHint')" >
262+ <i class =" fa-solid fa-flask-vial w-3" ></i > {{ t('loadSample') }}
263+ </button >
264+ </div >
265+ </div >
226266 <button @click =" handlePrint"
227267 class =" px-2 py-1.5 text-[11px] font-semibold text-white rounded bg-[#01a3a4] hover:bg-[#01a3a4]/90 transition-colors shadow-sm whitespace-nowrap border border-[#01a3a4]" >
228268 <i class =" fa-solid fa-file-pdf mr-1" ></i > <span class =" hidden sm:inline" >PDF</span >
229269 </button >
230270 <button @click =" handleSave"
231271 class =" px-2 py-1.5 text-[11px] font-semibold text-white rounded bg-green-600 hover:bg-green-700 transition-colors shadow-sm whitespace-nowrap border border-green-600" >
232- <i class =" fa-solid fa-save mr-1" ></i > <span class =" hidden sm:inline" >Save </span >
272+ <i class =" fa-solid fa-save mr-1" ></i > <span class =" hidden sm:inline" >{{ t('save') }} </span >
233273 </button >
234274 </div >
235275 </div >
0 commit comments