|
|
@@ -36,10 +36,7 @@ |
|
|
|
<div class="text-white text-3xl font-medium mb-6"> |
|
|
|
{{ t("contact.title") }} |
|
|
|
</div> |
|
|
|
<form |
|
|
|
@submit="handleSubmit" |
|
|
|
class="flex flex-col gap-6" |
|
|
|
> |
|
|
|
<form @submit="handleSubmit" class="flex flex-col gap-6"> |
|
|
|
<div class="relative"> |
|
|
|
<input |
|
|
|
v-model="form.name" |
|
|
@@ -314,26 +311,25 @@ const form = ref({ |
|
|
|
async function handleSubmit(event: Event) { |
|
|
|
// 阻止表单默认提交行为,防止重复提交 |
|
|
|
event.preventDefault(); |
|
|
|
|
|
|
|
|
|
|
|
if (isSubmitting.value) { |
|
|
|
return; // 如果已经在提交中,不重复处理 |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
isSubmitting.value = true; |
|
|
|
submitSuccess.value = false; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 验证验证码 |
|
|
|
const isCaptchaValid = captcha.validateCaptcha(); |
|
|
|
|
|
|
|
|
|
|
|
if (!isCaptchaValid) { |
|
|
|
isSubmitting.value = false; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 使用单独的异步函数发送邮件,减少嵌套 |
|
|
|
await sendEmail(); |
|
|
|
|
|
|
|
} catch (error) { |
|
|
|
console.error("Error during form submission:", error); |
|
|
|
showFormStatus("error", t("contact.submitError")); |
|
|
@@ -348,9 +344,31 @@ async function handleSubmit(event: Event) { |
|
|
|
async function sendEmail() { |
|
|
|
try { |
|
|
|
const result = await wrapAsync(async () => { |
|
|
|
const message_template = ` |
|
|
|
📨 来自Hanye官网的联系表单 |
|
|
|
|
|
|
|
姓名:${form.value.name} |
|
|
|
邮箱:${form.value.email} |
|
|
|
|
|
|
|
消息内容: |
|
|
|
${form.value.message} |
|
|
|
|
|
|
|
提交时间:${new Date().toLocaleString()} |
|
|
|
来源页面:${window.location.href} |
|
|
|
|
|
|
|
--- |
|
|
|
此邮件由Hanye官网的联系表单自动发送,请勿回复。 |
|
|
|
`; |
|
|
|
const title = `您有一封来自Hanye官网的联系表单`; |
|
|
|
const receiveEmail = "hanye@hanye.cn"; |
|
|
|
|
|
|
|
// 对包含HTML标签的参数进行URL编码 |
|
|
|
const encodedMessage = encodeURIComponent(message_template); |
|
|
|
const encodedTitle = encodeURIComponent(title); |
|
|
|
|
|
|
|
// 发送邮件 |
|
|
|
const response = await fetch( |
|
|
|
`https://digital.sohomall.jp/prod-api/system/zsEmail/sendEmailWeb?receiveEmail=${form.value.email}&context=${form.value.message}&title=[Hanye Website]${form.value.name}`, |
|
|
|
`https://digital.sohomall.jp/prod-api/system/zsEmail/sendEmailWeb?receiveEmail=${receiveEmail}&context=${encodedMessage}&title=${encodedTitle}`, |
|
|
|
{ |
|
|
|
method: "GET", |
|
|
|
headers: { |
|
|
@@ -366,7 +384,7 @@ async function sendEmail() { |
|
|
|
email: "", |
|
|
|
message: "", |
|
|
|
}; |
|
|
|
captcha.state.userInput = ''; // 清空验证码输入 |
|
|
|
captcha.state.userInput = ""; // 清空验证码输入 |
|
|
|
captcha.generateCaptcha(); // 成功后刷新验证码 |
|
|
|
submitSuccess.value = true; |
|
|
|
showFormStatus("success", t("contact.submitSuccess")); |
|
|
@@ -376,7 +394,7 @@ async function sendEmail() { |
|
|
|
throw new Error("Failed to send email"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
} catch (error) { |
|
|
|
console.error("Error sending email:", error); |