@@ -4,9 +4,57 @@ import CvPreview from './components/CvPreview.vue';
44import CvEditor from ' ./components/CvEditor.vue' ;
55import { defaultData } from ' ./defaultData' ;
66import type { CvData } from ' ./types' ;
7+ import { useLocale } from ' ./composables/useLocale' ;
78
89const cvData = ref <CvData >(defaultData );
910const activeTab = ref (' personal' );
11+ const lastSaved = ref <Date | null >(null );
12+ const showSaveToast = ref (false );
13+ const { t, locale, toggleLocale, initLocale } = useLocale ();
14+
15+ // Initialize locale on mount
16+ onMounted (() => {
17+ initLocale ();
18+ // Try to load saved data
19+ const saved = localStorage .getItem (' cv-generator-data' );
20+ if (saved ) {
21+ try {
22+ cvData .value = JSON .parse (saved );
23+ } catch (e ) {
24+ console .warn (' Failed to load saved data' );
25+ }
26+ }
27+ startAutoSave ();
28+ });
29+
30+ onUnmounted (() => {
31+ if (autoSaveInterval ) clearInterval (autoSaveInterval );
32+ });
33+
34+ let autoSaveInterval: number | null = null ;
35+
36+ // Start auto-save
37+ const startAutoSave = () => {
38+ if (autoSaveInterval ) clearInterval (autoSaveInterval );
39+ autoSaveInterval = window .setInterval (() => {
40+ handleSave ();
41+ }, 60000 );
42+ };
43+
44+ // Save to localStorage
45+ const handleSave = () => {
46+ if (cvData .value .personal ) {
47+ const now = new Date ();
48+ const formattedDate = ` ${now .getFullYear ()}.${String (now .getMonth () + 1 ).padStart (2 , ' 0' )}.${String (now .getDate ()).padStart (2 , ' 0' )} ` ;
49+ cvData .value .personal .lastModifiedText = ` Last modified: ${formattedDate } ` ;
50+ }
51+ localStorage .setItem (' cv-generator-data' , JSON .stringify (cvData .value ));
52+ lastSaved .value = new Date ();
53+ showSaveToast .value = true ;
54+ setTimeout (() => {
55+ showSaveToast .value = false ;
56+ }, 2000 );
57+ };
1058
1159const handleIconClick = (tabId : string ) => {
1260 activeTab .value = tabId ;
@@ -23,8 +71,6 @@ const handleIconClick = (tabId: string) => {
2371
2472const handlePrint = () => {
2573 try {
26- // Determine the exact dimensions to lock the scale and avoid bleeding
27- // Setting body zoom to 1 or forcing container to not be constrained
2874 document .body .classList .add (' is-printing' );
2975 window .print ();
3076 document .body .classList .remove (' is-printing' );
@@ -79,8 +125,12 @@ const handleImportJson = (event: Event) => {
79125 <h1 class =" text-lg font-semibold tracking-tight text-slate-900" >CV <span style =" color : #01a3a4 " >Generator</span >
80126 </h1 >
81127 </div >
82- <div class =" flex items-center gap-3 text-sm text-slate-500 font-medium" >
83- Personal CV Generator
128+ <div class =" flex items-center gap-3" >
129+ <button @click =" toggleLocale"
130+ class =" px-4 py-2 text-sm font-bold rounded-lg bg-slate-800 hover:bg-slate-900 text-white transition-colors shadow-md flex items-center gap-2" >
131+ <i class =" fa-solid fa-globe" ></i >
132+ <span >{{ locale === 'en' ? '中文' : 'EN' }}</span >
133+ </button >
84134 </div >
85135 </header >
86136
@@ -148,6 +198,10 @@ const handleImportJson = (event: Event) => {
148198 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]" >
149199 <i class =" fa-solid fa-file-pdf mr-1" ></i > <span class =" hidden sm:inline" >PDF</span >
150200 </button >
201+ <button @click =" handleSave"
202+ 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" >
203+ <i class =" fa-solid fa-save mr-1" ></i > <span class =" hidden sm:inline" >Save</span >
204+ </button >
151205 </div >
152206 </div >
153207 <div class =" flex-1 min-h-0 overflow-y-auto bg-slate-50 custom-scrollbar" >
@@ -162,18 +216,27 @@ const handleImportJson = (event: Event) => {
162216 <CvPreview :data =" cvData " class="shadow-2xl print:shadow-none bg-white w-full print:w-full " />
163217 </div >
164218 </section >
219+
220+ <!-- Save Toast -->
221+ <Transition name="toast">
222+ <div v-if =" showSaveToast"
223+ class =" fixed bottom-4 right-4 bg-green-600 text-white px-4 py-2 rounded-lg shadow-lg flex items-center gap-2 z-50" >
224+ <i class =" fa-solid fa-check-circle" ></i >
225+ <span class =" text-sm font-medium" >{{ t('savedSuccessfully') }}</span >
226+ </div >
227+ </Transition >
165228 </main >
166229
167230 <!-- Status Bar -->
168231 <footer
169232 class =" px-4 py-1.5 bg-white border-t border-slate-200 flex justify-between items-center text-[10px] text-slate-500 no-print shrink-0" >
170233 <div class =" flex items-center gap-4" >
171- <span >Mode: <span class =" font-medium italic" style =" color : #01a3a4 " >Visual Design </span ></span >
172- <span >Auto-save : <span class =" font-medium" style =" color : #01a3a4 " >Active </span ></span >
234+ <span >Mode: <span class =" font-medium italic" style =" color : #01a3a4 " >{{ t('visualDesign') }} </span ></span >
235+ <span >{{ t('autoSave') }} : <span class =" font-medium" style =" color : #01a3a4 " >{{ t('active') }} </span ></span >
173236 </div >
174237 <div class =" flex gap-4" >
175- <span >FontAwesome: Loaded </span >
176- <span >Vue v3 </span >
238+ <span >{{ t('fontAwesomeLoaded') }} </span >
239+ <span >{{ t('vueLoaded') }} </span >
177240 </div >
178241 </footer >
179242 </div >
0 commit comments