Skip to content

Commit 106773f

Browse files
committed
fix
1 parent 86799c5 commit 106773f

File tree

7 files changed

+48
-53
lines changed

7 files changed

+48
-53
lines changed

i18n/request.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { getRequestConfig, setRequestLocale } from 'next-intl/server';
2+
import { locales } from '../src/config';
3+
4+
export default getRequestConfig(async ({ requestLocale }) => {
5+
const locale = await requestLocale;
6+
return {
7+
messages: (await import(`../messages/${locale}.json`)).default,
8+
timeZone: 'Asia/Shanghai',
9+
now: new Date(),
10+
setRequestLocale: locale
11+
};
12+
});

next.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
const withNextIntl = require('next-intl/plugin')();
1+
const withNextIntl = require('next-intl/plugin')('./i18n/request.ts');
22

33
/** @type {import('next').NextConfig} */
44
const nextConfig = {
55
images: {
66
unoptimized: true,
77
},
8-
basePath: process.env.NEXT_PUBLIC_BASE_PATH || '',
9-
assetPrefix: process.env.NEXT_PUBLIC_BASE_PATH || '',
8+
basePath: process.env.NODE_ENV === 'production' ? '/wificard' : '',
109
};
1110

1211
module.exports = withNextIntl(nextConfig);

src/app/[locale]/layout.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { NextIntlClientProvider } from 'next-intl';
1+
import { NextIntlClientProvider, AbstractIntlMessages } from 'next-intl';
22
import { notFound } from 'next/navigation';
3-
import { useLocale } from 'next-intl';
43
import '../globals.css';
5-
import { locales } from '../../config';
4+
import { locales, LocaleType } from '../../config';
65

7-
export async function generateStaticParams() {
8-
return Promise.all(
9-
locales.map((locale) => ({ locale }))
10-
);
6+
export function generateStaticParams() {
7+
return locales.map((locale) => ({ locale }));
118
}
129

1310
export const metadata = {
@@ -37,19 +34,21 @@ export const metadata = {
3734
}
3835
};
3936

40-
export default async function LocaleLayout({
41-
children,
42-
params
43-
}: {
37+
type LayoutProps = {
4438
children: React.ReactNode;
45-
params: Promise<{ locale: string }>;
46-
}) {
39+
params: Promise<{ locale: LocaleType }>;
40+
}
41+
42+
export default async function LocaleLayout(props: LayoutProps) {
43+
const { children, params } = props;
4744
const { locale } = await params;
48-
49-
let messages;
45+
46+
if (!locales.includes(locale)) notFound();
47+
48+
let messages: AbstractIntlMessages;
5049
try {
5150
messages = (await import(`../../../messages/${locale}.json`)).default;
52-
} catch (error) {
51+
} catch {
5352
notFound();
5453
}
5554

src/components/WiFiCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function WiFiCard({ scene }: WiFiCardProps) {
3333
}
3434
return 'default';
3535
});
36-
const [customTemplateStyles, setCustomTemplateStyles] = useState<Record<TemplateType, { title: string; description: string }>>({
36+
const [templateStyles, setTemplateStyles] = useState<Record<TemplateType, { title: string; description: string }>>({
3737
default: { title: '', description: '' },
3838
restaurant: { title: '', description: '' },
3939
hotel: { title: '', description: '' },
@@ -181,7 +181,7 @@ export default function WiFiCard({ scene }: WiFiCardProps) {
181181
setPassword(newPassword);
182182
}}
183183
onTemplateStyleUpdate={(newTitle, newDescription) => {
184-
setCustomTemplateStyles(prev => ({
184+
setTemplateStyles((prev: Record<TemplateType, { title: string; description: string }>) => ({
185185
...prev,
186186
[template]: { title: newTitle, description: newDescription }
187187
}));

src/components/WifiPreviewCard.tsx

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { memo, useState, useEffect } from 'react';
3+
import { memo, useState, useEffect, useMemo } from 'react';
44
import { QRCodeSVG } from 'qrcode.react';
55
import { PencilIcon, CheckIcon } from '@heroicons/react/24/outline';
66
import { useTranslations } from 'next-intl';
@@ -25,44 +25,38 @@ function WifiPreviewCard({ ssid, password, hidePassword, qrValue, template, onUp
2525
const [editedTitle, setEditedTitle] = useState('');
2626
const [editedDescription, setEditedDescription] = useState('');
2727

28-
// 使用翻译的模板样式
29-
const TEMPLATE_STYLES: Record<TemplateType, {
30-
title: string;
31-
description: string;
32-
icon: string;
33-
textColor: string;
34-
}> = {
28+
const TEMPLATE_STYLES = useMemo(() => ({
3529
default: {
36-
title: t('templates.default.title'),
37-
description: t('templates.default.description'),
30+
title: '免费 Wi-Fi',
31+
description: '无需密码即可连接',
3832
icon: '📶',
3933
textColor: 'text-gray-900',
4034
},
4135
restaurant: {
42-
title: t('templates.restaurant.title'),
43-
description: t('templates.restaurant.description'),
36+
title: '餐厅 Wi-Fi',
37+
description: '用餐时享用免费网络',
4438
icon: '🍽️',
4539
textColor: 'text-gray-900',
4640
},
4741
hotel: {
48-
title: t('templates.hotel.title'),
49-
description: t('templates.hotel.description'),
42+
title: '酒店 Wi-Fi',
43+
description: '客房和公共区域均可连接',
5044
icon: '🏨',
5145
textColor: 'text-gray-900',
5246
},
5347
hospital: {
54-
title: t('templates.hospital.title'),
55-
description: t('templates.hospital.description'),
48+
title: '医院 Wi-Fi',
49+
description: '患者和访客可免费使用',
5650
icon: '🏥',
5751
textColor: 'text-gray-900',
5852
},
5953
office: {
60-
title: t('templates.office.title'),
61-
description: t('templates.office.description'),
54+
title: '办公 Wi-Fi',
55+
description: '安全可靠的商务网络',
6256
icon: '💼',
6357
textColor: 'text-gray-900',
6458
},
65-
};
59+
}), []);
6660

6761
useEffect(() => {
6862
setEditedTitle(TEMPLATE_STYLES[template].title);

src/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export const locales = ['en', 'zh', 'ja', 'de', 'it', 'es', 'fr'] as const;
1+
export type LocaleType = 'en' | 'zh' | 'ja' | 'de' | 'it' | 'es' | 'fr';
2+
3+
export const locales: LocaleType[] = ['en', 'zh', 'ja', 'de', 'it', 'es', 'fr'];
4+
25
export const defaultLocale = 'en' as const;
36

47
export type Locale = typeof locales[number];

src/i18n.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)