diff --git a/components/LanguageContext.tsx b/components/LanguageContext.tsx index c33e942..2e0ecd0 100644 --- a/components/LanguageContext.tsx +++ b/components/LanguageContext.tsx @@ -584,7 +584,8 @@ const translations: Record> = { 'no_history': '暂无历史记录', 'history_notice': '查看报告后将自动保存', 'delete_history': '删除', - 'clear_all': '清空', + 'clear_all': '清空全部', + 'restore_history': '恢复此记录', // 表单标签 'annual_salary_cny': '年薪总包(元)', @@ -818,6 +819,7 @@ const translations: Record> = { 'history_notice': 'Records will be saved after viewing reports', 'delete_history': 'Delete', 'clear_all': 'Clear All', + 'restore_history': 'Restore this record', // Form labels 'annual_salary_cny': 'Annual Salary (CNY)', @@ -1051,6 +1053,7 @@ const translations: Record> = { 'history_notice': 'レポートを見た後、自動的に保存されます', 'delete_history': '削除', 'clear_all': 'すべて削除', + 'restore_history': 'この記録を復元', // フォームラベル 'annual_salary_cny': '年収(元)', diff --git a/components/ShareCard.tsx b/components/ShareCard.tsx index b64e12e..f464aa5 100644 --- a/components/ShareCard.tsx +++ b/components/ShareCard.tsx @@ -4,6 +4,7 @@ import React, { useRef, useState, useEffect } from 'react'; import { ArrowLeft, Download } from 'lucide-react'; import Link from 'next/link'; import { useLanguage } from './LanguageContext'; +import { countryNames } from './LanguageContext'; // 导入countryNames对象 // 扩展接口,支持更多属性 interface ShareCardProps { @@ -194,6 +195,17 @@ const getWorkYearsDesc = (years: string, t: (key: string) => string): string => return t('fresh_graduate'); }; +// 获取当前语言环境下的国家名称 +const getCountryName = (countryCode: string, currentLanguage: string): string => { + if (currentLanguage === 'en') { + return countryNames.en[countryCode] || countryCode || 'Unknown'; + } + if (currentLanguage === 'ja') { + return countryNames.ja[countryCode] || countryCode || '不明'; + } + return countryNames.zh[countryCode] || countryCode || '未知'; +}; + const ShareCard: React.FC = (props) => { const reportRef = useRef(null); const simpleReportRef = useRef(null); // 添加简化版报告的引用 @@ -276,7 +288,7 @@ const ShareCard: React.FC = (props) => { details: [ { label: t('share_work_city'), value: cityName }, { label: t('share_is_hometown'), value: isHomeTown ? t('share_yes') : t('share_no') }, - { label: t('share_country'), value: props.countryName } + { label: t('share_country'), value: getCountryName(props.countryCode, language) } ] }); @@ -693,7 +705,7 @@ const ShareCard: React.FC = (props) => {
{t('share_country')}
-
{props.countryName}
+
{getCountryName(props.countryCode, language)}
{t('share_is_hometown')}
diff --git a/components/calculator.tsx b/components/calculator.tsx index 90d6d8f..3205187 100644 --- a/components/calculator.tsx +++ b/components/calculator.tsx @@ -312,7 +312,31 @@ interface HistoryItem { salary: string; countryCode: string; countryName: string; - jobTitle?: string; // 可选的职位名称 + + // 添加所有需要在分享页面展示的字段 + cityFactor: string; + workHours: string; + commuteHours: string; + restTime: string; + dailySalary: string; + workDaysPerYear: string; + workDaysPerWeek: string; + wfhDaysPerWeek: string; + annualLeave: string; + paidSickLeave: string; + publicHolidays: string; + workEnvironment: string; + leadership: string; + teamwork: string; + degreeType: string; + schoolType: string; + education: string; + homeTown: string; + shuttle: string; + canteen: string; + workYears: string; + jobStability: string; + bachelorType: string; } // 定义表单数据接口 @@ -444,13 +468,52 @@ const SalaryCalculator = () => { const savedHistory = localStorage.getItem('jobValueHistory'); if (savedHistory) { try { - setHistory(JSON.parse(savedHistory)); + const parsedHistory = JSON.parse(savedHistory) as any[]; + + // 处理历史记录,为可能缺失的字段添加默认值 + const normalizedHistory = parsedHistory.map((item: any) => ({ + id: item.id || Date.now().toString(), + timestamp: item.timestamp || Date.now(), + value: item.value || '0', + assessment: item.assessment || 'rating_enter_salary', + assessmentColor: item.assessmentColor || 'text-gray-500', + salary: item.salary || '', + countryCode: item.countryCode || 'CN', + countryName: item.countryName || '中国', + + // 为缺失的分享页面字段添加默认值 + cityFactor: item.cityFactor || formData.cityFactor, + workHours: item.workHours || formData.workHours, + commuteHours: item.commuteHours || formData.commuteHours, + restTime: item.restTime || formData.restTime, + dailySalary: item.dailySalary || '0', // 简化,不使用函数 + workDaysPerYear: item.workDaysPerYear || '250', // 简化,使用默认值 + workDaysPerWeek: item.workDaysPerWeek || formData.workDaysPerWeek, + wfhDaysPerWeek: item.wfhDaysPerWeek || formData.wfhDaysPerWeek, + annualLeave: item.annualLeave || formData.annualLeave, + paidSickLeave: item.paidSickLeave || formData.paidSickLeave, + publicHolidays: item.publicHolidays || formData.publicHolidays, + workEnvironment: item.workEnvironment || formData.workEnvironment, + leadership: item.leadership || formData.leadership, + teamwork: item.teamwork || formData.teamwork, + degreeType: item.degreeType || formData.degreeType, + schoolType: item.schoolType || formData.schoolType, + education: item.education || formData.education, + homeTown: item.homeTown || formData.homeTown, + shuttle: item.shuttle || formData.shuttle, + canteen: item.canteen || formData.canteen, + workYears: item.workYears || formData.workYears, + jobStability: item.jobStability || formData.jobStability, + bachelorType: item.bachelorType || formData.bachelorType + })); + + setHistory(normalizedHistory); } catch (e) { console.error('加载历史记录失败', e); } } } - }, []); + }, [formData]); // 监听访客统计加载 useEffect(() => { @@ -789,11 +852,36 @@ const SalaryCalculator = () => { id: Date.now().toString(), timestamp: Date.now(), value: value.toFixed(2), - assessment: getValueAssessment().text, + assessment: getValueAssessmentKey(), // 使用翻译键而不是已翻译的文本 assessmentColor: getValueAssessment().color, salary: formData.salary, countryCode: selectedCountry, - countryName: getCountryName(selectedCountry) + countryName: getCountryName(selectedCountry), + + // 添加所有需要在分享页面展示的字段 + cityFactor: formData.cityFactor, + workHours: formData.workHours, + commuteHours: formData.commuteHours, + restTime: formData.restTime, + dailySalary: getDisplaySalary(), + workDaysPerYear: calculateWorkingDays().toString(), + workDaysPerWeek: formData.workDaysPerWeek, + wfhDaysPerWeek: formData.wfhDaysPerWeek, + annualLeave: formData.annualLeave, + paidSickLeave: formData.paidSickLeave, + publicHolidays: formData.publicHolidays, + workEnvironment: formData.workEnvironment, + leadership: formData.leadership, + teamwork: formData.teamwork, + degreeType: formData.degreeType, + schoolType: formData.schoolType, + education: formData.education, + homeTown: formData.homeTown, + shuttle: formData.shuttle, + canteen: formData.canteen, + workYears: formData.workYears, + jobStability: formData.jobStability, + bachelorType: formData.bachelorType }; try { @@ -806,7 +894,7 @@ const SalaryCalculator = () => { } return newHistoryItem; - }, [formData.salary, value, getValueAssessment, selectedCountry, history, getCountryName]); + }, [formData, value, getValueAssessmentKey, getValueAssessment, selectedCountry, history, getCountryName, calculateWorkingDays, getDisplaySalary]); // 删除单条历史记录 const deleteHistoryItem = useCallback((id: string, e: React.MouseEvent) => { @@ -941,43 +1029,89 @@ const SalaryCalculator = () => {
{formatDate(item.timestamp)} - {item.countryName} + {getCountryName(item.countryCode)} + {t(item.assessment)}
+