|
@@ -1,11 +1,111 @@
|
|
|
-import React from 'react';
|
|
|
+import React, {useState} from 'react';
|
|
|
import styles from "./ContactUs.module.css";
|
|
|
-// 首页内容组件
|
|
|
+import {t} from "i18next";
|
|
|
+
|
|
|
const ContactUs = () => {
|
|
|
- return (
|
|
|
- <main className={styles.root}>
|
|
|
- </main>
|
|
|
- );
|
|
|
+ const [formData, setFormData] = useState({
|
|
|
+ name: "", email: "", phone: "", country: "", message: ""
|
|
|
+ });
|
|
|
+
|
|
|
+ // 输入时更新数据
|
|
|
+ const handleChange = (e) => {
|
|
|
+ const {name, value} = e.target;
|
|
|
+ setFormData((prev) => ({
|
|
|
+ ...prev, [name]: value
|
|
|
+ }));
|
|
|
+ };
|
|
|
+
|
|
|
+ // 提交表单
|
|
|
+ const handleSubmit = (e) => {
|
|
|
+ e.preventDefault();
|
|
|
+ // 获取当前时间(北京时间)
|
|
|
+ const now = new Date();
|
|
|
+ const beijingTime = new Date(now.getTime() + 8 * 60 * 60 * 1000); // UTC+8
|
|
|
+
|
|
|
+ const formattedTime = beijingTime.toISOString().slice(0, 19).replace("T", " ");
|
|
|
+ // => "2025-09-08 20:31:45"
|
|
|
+ const dataToSubmit = {
|
|
|
+ ...formData,
|
|
|
+ timestamp: formattedTime // YYYY-MM-DD HH:mm:ss
|
|
|
+ };
|
|
|
+ console.log("提交的数据:", dataToSubmit);
|
|
|
+
|
|
|
+ // 示例:提交到后端
|
|
|
+ fetch("http://60.205.235.193:3005/submit", {
|
|
|
+ method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify(dataToSubmit)
|
|
|
+ })
|
|
|
+ .then(res => res.text())
|
|
|
+ .then(msg => {
|
|
|
+ console.log("提交成功:", msg);
|
|
|
+ alert(`${t('submitSuccess')}`);
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.error("提交失败:", err);
|
|
|
+ alert(`${t('submitFailed')}`);
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ return (<main className={styles.root}>
|
|
|
+ <div className={styles.topContainer}>
|
|
|
+ <p className={styles.title}>{t('contactUsTitle')}</p>
|
|
|
+ </div>
|
|
|
+ <form className={styles.contentContainer} onSubmit={handleSubmit}>
|
|
|
+ <p className={styles.title1}>{t('contactUsTitle1')}</p>
|
|
|
+ <p className={styles.content1}>{t('contactUsContent1')}</p>
|
|
|
+
|
|
|
+ <label className={styles.property}>{t('contactProperty1')}</label>
|
|
|
+ <input
|
|
|
+ className={styles.input}
|
|
|
+ type="text"
|
|
|
+ name="name"
|
|
|
+ value={formData.name}
|
|
|
+ onChange={handleChange}
|
|
|
+ required
|
|
|
+ />
|
|
|
+
|
|
|
+ <label className={styles.property}>{t('contactProperty2')}</label>
|
|
|
+ <input
|
|
|
+ className={styles.input}
|
|
|
+ type="text"
|
|
|
+ name="email"
|
|
|
+ value={formData.email}
|
|
|
+ onChange={handleChange}
|
|
|
+ required
|
|
|
+ />
|
|
|
+
|
|
|
+ <label className={styles.property}>{t('contactProperty3')}</label>
|
|
|
+ <input
|
|
|
+ className={styles.input}
|
|
|
+ type="text"
|
|
|
+ name="phone"
|
|
|
+ value={formData.phone}
|
|
|
+ onChange={handleChange}
|
|
|
+ />
|
|
|
+
|
|
|
+ <label className={styles.property}>{t('contactProperty4')}</label>
|
|
|
+ <input
|
|
|
+ className={styles.input}
|
|
|
+ type="text"
|
|
|
+ name="country"
|
|
|
+ value={formData.country}
|
|
|
+ onChange={handleChange}
|
|
|
+ required
|
|
|
+ />
|
|
|
+
|
|
|
+ <label className={styles.property}>{t('contactProperty5')}</label>
|
|
|
+ <textarea
|
|
|
+ className={styles.textarea}
|
|
|
+ name="message"
|
|
|
+ value={formData.message}
|
|
|
+ onChange={handleChange}
|
|
|
+ required
|
|
|
+ />
|
|
|
+
|
|
|
+ <button type="submit" className={styles.button}>
|
|
|
+ {t('contactButton')}
|
|
|
+ </button>
|
|
|
+ </form>
|
|
|
+ </main>);
|
|
|
};
|
|
|
|
|
|
export default ContactUs;
|