diff --git a/app/share/page.tsx b/app/share/page.tsx index 0195351..0248578 100644 --- a/app/share/page.tsx +++ b/app/share/page.tsx @@ -1,11 +1,14 @@ "use client"; import { useSearchParams } from 'next/navigation'; -import ShareCard from '@/components/ShareCard'; +import dynamic from 'next/dynamic'; import React, { Suspense } from 'react'; import { LanguageProvider } from '@/components/LanguageContext'; import { LanguageSwitcher } from '@/components/LanguageSwitcher'; +// 动态导入ShareCard组件,禁用SSR +const ShareCard = dynamic(() => import('@/components/ShareCard'), { ssr: false }); + // 一个包装组件,负责从URL参数获取数据 function ShareCardWrapper() { const searchParams = useSearchParams(); diff --git a/components/ShareCard.tsx b/components/ShareCard.tsx index 0377d61..9e5e862 100644 --- a/components/ShareCard.tsx +++ b/components/ShareCard.tsx @@ -2,7 +2,6 @@ import React, { useRef, useState, useEffect } from 'react'; import { ArrowLeft, Download } from 'lucide-react'; -import html2canvas from 'html2canvas'; import Link from 'next/link'; import { useLanguage } from './LanguageContext'; @@ -202,9 +201,20 @@ const ShareCard: React.FC = (props) => { const [fadeIn, setFadeIn] = useState(false); const { t, language } = useLanguage(); + // 客户端渲染标志 + const [isClient, setIsClient] = useState(false); + + // 确保只在客户端执行 + useEffect(() => { + setIsClient(true); + }, []); + // 页面载入动画效果 useEffect(() => { - setFadeIn(true); + // 确保只在客户端执行 + if (typeof window !== 'undefined') { + setFadeIn(true); + } }, []); // 生成个性化评价 @@ -508,6 +518,10 @@ const ShareCard: React.FC = (props) => { // 获取简化版报告元素 const element = simpleReportRef.current; + // 动态导入html2canvas,确保只在客户端加载 + const html2canvasModule = await import('html2canvas'); + const html2canvas = html2canvasModule.default; + // 使用html2canvas生成图片 const canvas = await html2canvas(element, { scale: 2, @@ -557,7 +571,7 @@ const ShareCard: React.FC = (props) => {
{/* 标题 */}
-
{getEmoji(parseFloat(props.value))}
+
{isClient ? getEmoji(parseFloat(props.value)) : '😊'}

{t('share_your_job_worth_report')}

@@ -565,13 +579,13 @@ const ShareCard: React.FC = (props) => { {props.value} - {t(getAssessmentKey(props.assessment))} + {isClient ? t(getAssessmentKey(props.assessment)) : ''}
{/* 性价比评语卡片 */}
- {personalizedComments.map((comment, index) => ( + {isClient && personalizedComments.map((comment, index) => (
{comment.emoji}
@@ -618,172 +632,174 @@ const ShareCard: React.FC = (props) => {
{/* 简化版报告,仅用于下载,在页面中隐藏 */} -
-
-
- {/* 报告头部 - 渐变背景 */} -
-
-
{getEmoji(parseFloat(props.value))}
-

{t('share_job_worth_report')}

-
- - {props.value} - {t(getAssessmentKey(props.assessment))} - + {isClient && ( +
+
+
+ {/* 报告头部 - 渐变背景 */} +
+
+
{getEmoji(parseFloat(props.value))}
+

{t('share_job_worth_report')}

+
+ + {props.value} - {t(getAssessmentKey(props.assessment))} + +
-
- - {/* 报告内容 */} -
- {/* 数据表格 */} -
- {/* 基础信息 */} -
-

- 📊 {t('share_basic_info')} -

-
-
-
{t('share_work_city')}
-
{getCityName(props.cityFactor, t)}
-
-
-
{t('share_country')}
-
{props.countryName}
-
-
-
{t('share_is_hometown')}
-
{props.homeTown === 'yes' ? t('share_yes') : t('share_no')}
-
-
-
{t('share_daily_salary')}
-
{props.currencySymbol}{props.dailySalary}/{t('share_day')}
-
-
-
{t('share_working_days_per_year')}
-
{props.workDaysPerYear} {t('share_days')}
-
-
-
- - {/* 工作时间 */} -
-

- ⏱️ {t('share_work_hours_title')} -

-
-
- {t('share_daily_work_hours')} - {props.workHours} {t('share_hours')} -
-
- {t('share_daily_commute_hours')} - {props.commuteHours} {t('share_hours')} -
-
- {t('share_rest_time')} - {props.restTime} {t('share_hours')} -
-
- {t('share_weekly_work_days')} - {props.workDaysPerWeek} {t('share_days')} -
-
-
- - {/* 工作环境 */} -
-

- 🏢 {t('share_work_environment_title')} -

-
-
- {t('share_office_environment')} - {getWorkEnvironmentDesc(props.workEnvironment, t)} -
-
- {t('share_leadership_relation')} - {getLeadershipDesc(props.leadership, t)} -
-
- {t('share_colleague_relationship')} - {getTeamworkDesc(props.teamwork, t)} -
-
- {t('share_canteen_quality')} - {getCanteenDesc(props.canteen, t)} -
-
-
- - {/* 教育背景 */} -
-

- 📚 {t('share_education_and_experience')} -

-
-
-
{t('share_highest_degree')}
-
{getDegreeDesc(props.degreeType, t)}
-
-
-
{t('share_school_type_label')}
-
{getSchoolTypeDesc(props.schoolType, props.degreeType, t)}
-
-
-
{t('share_work_years_label')}
-
{getWorkYearsDesc(props.workYears, t)}
-
-
-
{t('share_contract_type_label')}
-
{getJobStabilityDesc(props.jobStability, t)}
-
-
-
- - {/* 结论 */} -
-
-

- 💎 {t('share_final_assessment')} + + {/* 报告内容 */} +
+ {/* 数据表格 */} +
+ {/* 基础信息 */} +
+

+ 📊 {t('share_basic_info')}

-
-
{getEmoji(parseFloat(props.value))}
-
- {props.value} - {t(getAssessmentKey(props.assessment))} +
+
+
{t('share_work_city')}
+
{getCityName(props.cityFactor, t)}
+
+
+
{t('share_country')}
+
{props.countryName}
+
+
+
{t('share_is_hometown')}
+
{props.homeTown === 'yes' ? t('share_yes') : t('share_no')}
+
+
+
{t('share_daily_salary')}
+
{props.currencySymbol}{props.dailySalary}/{t('share_day')}
+
+
+
{t('share_working_days_per_year')}
+
{props.workDaysPerYear} {t('share_days')}
-

- {parseFloat(props.value) < 1.0 - ? t('share_value_low') - : parseFloat(props.value) <= 2.0 - ? t('share_value_medium') - : t('share_value_high') - } -

+
+ + {/* 工作时间 */} +
+

+ ⏱️ {t('share_work_hours_title')} +

+
+
+ {t('share_daily_work_hours')} + {props.workHours} {t('share_hours')} +
+
+ {t('share_daily_commute_hours')} + {props.commuteHours} {t('share_hours')} +
+
+ {t('share_rest_time')} + {props.restTime} {t('share_hours')} +
+
+ {t('share_weekly_work_days')} + {props.workDaysPerWeek} {t('share_days')} +
+
+
+ + {/* 工作环境 */} +
+

+ 🏢 {t('share_work_environment_title')} +

+
+
+ {t('share_office_environment')} + {getWorkEnvironmentDesc(props.workEnvironment, t)} +
+
+ {t('share_leadership_relation')} + {getLeadershipDesc(props.leadership, t)} +
+
+ {t('share_colleague_relationship')} + {getTeamworkDesc(props.teamwork, t)} +
+
+ {t('share_canteen_quality')} + {getCanteenDesc(props.canteen, t)} +
+
+
+ + {/* 教育背景 */} +
+

+ 📚 {t('share_education_and_experience')} +

+
+
+
{t('share_highest_degree')}
+
{getDegreeDesc(props.degreeType, t)}
+
+
+
{t('share_school_type_label')}
+
{getSchoolTypeDesc(props.schoolType, props.degreeType, t)}
+
+
+
{t('share_work_years_label')}
+
{getWorkYearsDesc(props.workYears, t)}
+
+
+
{t('share_contract_type_label')}
+
{getJobStabilityDesc(props.jobStability, t)}
+
+
+
+ + {/* 结论 */} +
+
+

+ 💎 {t('share_final_assessment')} +

+
+
{getEmoji(parseFloat(props.value))}
+
+ {props.value} - {t(getAssessmentKey(props.assessment))} +
+
+

+ {parseFloat(props.value) < 1.0 + ? t('share_value_low') + : parseFloat(props.value) <= 2.0 + ? t('share_value_medium') + : t('share_value_high') + } +

+
-
- - {/* 页脚 */} -
-
-
-
{t('share_custom_made')}
-
worthjob.zippland.com
+ + {/* 页脚 */} +
+
+
+
{t('share_custom_made')}
+
worthjob.zippland.com
+
+
-
-
+ )}

); }; diff --git a/components/calculator.tsx b/components/calculator.tsx index 0b72ec0..3ee4bc5 100644 --- a/components/calculator.tsx +++ b/components/calculator.tsx @@ -1108,7 +1108,7 @@ const SalaryCalculator = () => {
-

v5.1.0

+

v5.1.1