Hanye官网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

contact.vue 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <template>
  2. <div>
  3. <div class="w-full h-[55px] sm:h-[72px]"></div>
  4. <ErrorBoundary :error="error">
  5. <div v-if="isLoading" class="flex justify-center py-12">
  6. <div
  7. class="animate-spin h-8 w-8 border-4 border-cyan-400 rounded-full border-t-transparent"
  8. ></div>
  9. </div>
  10. <div v-else>
  11. <div class="max-w-full xl:px-2 lg:px-2 md:px-4 px-4 mt-6 mb-20">
  12. <div class="max-w-screen-2xl mx-auto">
  13. <nuxt-link
  14. :to="`${homepagePath}/`"
  15. class="justify-start text-white/60 text-base font-normal"
  16. >{{ t("common.home") }}</nuxt-link
  17. >
  18. <span class="text-white/60 text-base font-normal px-2"> / </span>
  19. <nuxt-link
  20. :to="`${homepagePath}/contact`"
  21. class="text-white text-base font-normal"
  22. >{{ t("contact.title") }}</nuxt-link
  23. >
  24. </div>
  25. </div>
  26. <div
  27. class="max-w-full mb-12 md:mb-20 lg:mb-32 xl:px-2 lg:px-2 md:px-4 px-4"
  28. >
  29. <div class="max-w-screen-2xl mx-auto">
  30. <div class="w-full grid grid-cols-1 md:grid-cols-2 gap-8">
  31. <!-- 联系表单 -->
  32. <div
  33. class="bg-zinc-900 rounded-lg p-8 transition-all duration-300 hover:bg-zinc-800 hover:shadow-lg"
  34. >
  35. <div class="text-white text-3xl font-medium mb-6">
  36. {{ t("contact.title") }}
  37. </div>
  38. <form
  39. @submit="handleSubmit"
  40. class="flex flex-col gap-6"
  41. >
  42. <div class="relative">
  43. <input
  44. v-model="form.name"
  45. type="text"
  46. id="name"
  47. class="peer block w-full appearance-none bg-transparent border-0 border-b-2 px-1 pt-5 pb-2 text-base text-gray-100 focus:outline-none focus:ring-0 placeholder-transparent transition-colors duration-300 focus:border-b-[3px] border-gray-600 focus:border-cyan-400"
  48. :placeholder="t('contact.name')"
  49. required
  50. />
  51. <label
  52. for="name"
  53. class="absolute left-1 top-5 origin-[0] -translate-y-4 scale-75 transform text-sm duration-300 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:font-medium text-gray-400 peer-focus:text-cyan-400"
  54. >
  55. {{ t("contact.name") }}
  56. </label>
  57. </div>
  58. <div class="relative">
  59. <input
  60. v-model="form.email"
  61. type="email"
  62. id="email"
  63. class="peer block w-full appearance-none bg-transparent border-0 border-b-2 px-1 pt-5 pb-2 text-base text-gray-100 focus:outline-none focus:ring-0 placeholder-transparent transition-colors duration-300 focus:border-b-[3px] border-gray-600 focus:border-cyan-400"
  64. :placeholder="t('contact.email')"
  65. required
  66. />
  67. <label
  68. for="email"
  69. class="absolute left-1 top-5 origin-[0] -translate-y-4 scale-75 transform text-sm duration-300 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:font-medium text-gray-400 peer-focus:text-cyan-400"
  70. >
  71. {{ t("contact.email") }}
  72. </label>
  73. </div>
  74. <div class="relative">
  75. <textarea
  76. v-model="form.message"
  77. id="message"
  78. class="peer block w-full appearance-none bg-transparent border-0 border-b-2 px-1 pt-5 pb-2 text-base text-gray-100 focus:outline-none focus:ring-0 placeholder-transparent h-36 resize-none transition-colors duration-300 focus:border-b-[3px] border-gray-600 focus:border-cyan-400"
  79. :placeholder="t('contact.message')"
  80. required
  81. ></textarea>
  82. <label
  83. for="message"
  84. class="absolute left-1 top-5 origin-[0] -translate-y-4 scale-75 transform text-sm duration-300 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:font-medium text-gray-400 peer-focus:text-cyan-400"
  85. >
  86. {{ t("contact.message") }}
  87. </label>
  88. </div>
  89. <!-- 验证码部分 -->
  90. <div class="relative pt-2">
  91. <div class="flex items-center space-x-3">
  92. <div class="flex-grow relative">
  93. <input
  94. type="text"
  95. id="captcha"
  96. v-model="captcha.state.userInput"
  97. class="peer block w-full appearance-none bg-transparent border-0 border-b-2 px-1 pt-5 pb-2 text-base text-gray-100 focus:outline-none focus:ring-0 placeholder-transparent transition-colors duration-300 focus:border-b-[3px]"
  98. :class="[
  99. captcha.error.value
  100. ? 'border-red-500 focus:border-red-500'
  101. : 'border-gray-600 focus:border-cyan-400',
  102. ]"
  103. :placeholder="t('contact.captcha')"
  104. required
  105. autocomplete="off"
  106. aria-describedby="captcha-error"
  107. :aria-invalid="captcha.error.value ? 'true' : 'false'"
  108. />
  109. <label
  110. for="captcha"
  111. class="absolute left-1 top-5 origin-[0] -translate-y-4 scale-75 transform text-sm duration-300 peer-placeholder-shown:translate-y-0 peer-placeholder-shown:scale-100 peer-focus:-translate-y-4 peer-focus:scale-75 peer-focus:font-medium"
  112. :class="[
  113. captcha.error.value
  114. ? 'text-red-400 peer-focus:text-red-400'
  115. : 'text-gray-400 peer-focus:text-cyan-400',
  116. ]"
  117. >
  118. {{ t("contact.captcha") }}
  119. </label>
  120. </div>
  121. <div
  122. class="flex-shrink-0 cursor-pointer select-none rounded-md overflow-hidden transition-all duration-200 ease-in-out hover:shadow-md active:scale-100"
  123. v-html="captcha.captchaSvg.value"
  124. @click="refreshCaptcha"
  125. :title="t('contact.refreshCaptcha')"
  126. style="line-height: 0"
  127. ></div>
  128. <button
  129. type="button"
  130. @click="refreshCaptcha"
  131. class="flex-shrink-0 p-2 text-gray-500 hover:text-cyan-400 focus:outline-none focus-visible:ring-2 focus-visible:ring-cyan-400 focus-visible:ring-offset-2 focus-visible:ring-offset-gray-800 rounded-full hover:bg-gray-700/50 transition-all duration-200 ease-in-out"
  132. :aria-label="t('contact.refreshCaptcha')"
  133. :title="t('contact.refreshCaptcha')"
  134. >
  135. <svg
  136. xmlns="http://www.w3.org/2000/svg"
  137. class="h-5 w-5"
  138. fill="none"
  139. viewBox="0 0 24 24"
  140. stroke="currentColor"
  141. stroke-width="2"
  142. >
  143. <path
  144. stroke-linecap="round"
  145. stroke-linejoin="round"
  146. d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
  147. />
  148. </svg>
  149. </button>
  150. </div>
  151. <p
  152. v-if="captcha.error.value"
  153. id="captcha-error"
  154. class="mt-1.5 text-xs text-red-400 sm:text-sm"
  155. >
  156. {{ captcha.error.value }}
  157. </p>
  158. </div>
  159. <!-- 表单提交状态提示 -->
  160. <div
  161. v-if="formStatus.show"
  162. class="px-1 py-2 rounded-md transition-all duration-300"
  163. :class="[
  164. formStatus.type === 'success'
  165. ? 'bg-green-500/20 text-green-400'
  166. : 'bg-red-500/20 text-red-400',
  167. ]"
  168. >
  169. {{ formStatus.message }}
  170. </div>
  171. <button
  172. type="submit"
  173. class="bg-cyan-400 text-zinc-900 relative text-base font-normal py-4 px-8 rounded-lg transition-all duration-300 hover:shadow-lg hover:bg-cyan-500"
  174. :disabled="isSubmitting"
  175. >
  176. {{
  177. isSubmitting
  178. ? t("contact.submitting")
  179. : t("contact.submit")
  180. }}
  181. </button>
  182. </form>
  183. </div>
  184. <!-- 公司信息和营业时间 -->
  185. <div class="flex flex-col gap-8">
  186. <div
  187. class="bg-zinc-900 rounded-lg p-8 transition-all duration-300 hover:bg-zinc-800 hover:shadow-lg"
  188. >
  189. <div class="text-white text-3xl font-medium mb-6">
  190. {{ t("about.companyInfo.name") }}
  191. </div>
  192. <div class="flex flex-col gap-4">
  193. <div class="flex items-center gap-4">
  194. <div class="text-white/60 text-base font-normal">
  195. {{ t("about.overview.companyName") }}
  196. </div>
  197. <div class="text-white text-base font-normal">
  198. {{ t("about.companyInfo.companyName") }}
  199. </div>
  200. </div>
  201. <div class="flex items-center gap-4">
  202. <div class="text-white/60 text-base font-normal">
  203. {{ t("about.overview.location") }}
  204. </div>
  205. <div class="text-white text-base font-normal">
  206. {{ t("about.companyInfo.location") }}
  207. </div>
  208. </div>
  209. <div class="flex items-center gap-4">
  210. <div class="text-white/60 text-base font-normal">
  211. {{ t("about.overview.tel") }}
  212. </div>
  213. <div class="text-white text-base font-normal">
  214. 86)024-8399-0696
  215. </div>
  216. </div>
  217. <div class="flex items-center gap-4">
  218. <div class="text-white/60 text-base font-normal">
  219. {{ t("about.overview.email") }}
  220. </div>
  221. <div class="text-white text-base font-normal">
  222. hanye@hanye.cn
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. <div
  228. class="bg-zinc-900 rounded-lg p-8 transition-all duration-300 hover:bg-zinc-800 hover:shadow-lg"
  229. >
  230. <div class="text-white text-3xl font-medium mb-6">
  231. {{ t("about.overview.businessHours") }}
  232. </div>
  233. <div class="text-white text-base font-normal">
  234. {{ t("about.companyInfo.businessHours") }}
  235. </div>
  236. </div>
  237. </div>
  238. </div>
  239. </div>
  240. </div>
  241. </div>
  242. </ErrorBoundary>
  243. </div>
  244. </template>
  245. <script setup lang="ts">
  246. /**
  247. * 联系页面
  248. * 展示公司信息和联系表单
  249. */
  250. import { useErrorHandler } from "~/composables/useErrorHandler";
  251. import { useCaptcha } from "~/composables/useCaptcha";
  252. const { t, locale } = useI18n();
  253. const homepagePath = computed(() => {
  254. return locale.value === "zh" ? "" : `/${locale.value}`;
  255. });
  256. const { error, isLoading, wrapAsync } = useErrorHandler();
  257. const captcha = useCaptcha();
  258. const isSubmitting = ref(false);
  259. const submitSuccess = ref(false);
  260. // 确保页面载入后验证码正确初始化
  261. onMounted(() => {
  262. // 给页面元素加载的时间
  263. setTimeout(() => {
  264. refreshCaptcha();
  265. }, 100);
  266. });
  267. // 表单状态信息
  268. const formStatus = reactive({
  269. show: false,
  270. type: "success",
  271. message: "",
  272. });
  273. /**
  274. * 刷新验证码
  275. */
  276. function refreshCaptcha() {
  277. captcha.generateCaptcha();
  278. }
  279. // 显示表单状态信息
  280. function showFormStatus(type: "success" | "error", message: string) {
  281. formStatus.show = true;
  282. formStatus.type = type;
  283. formStatus.message = message;
  284. // 5秒后自动隐藏
  285. setTimeout(() => {
  286. formStatus.show = false;
  287. }, 5000);
  288. }
  289. const form = ref({
  290. name: "",
  291. email: "",
  292. message: "",
  293. });
  294. /**
  295. * 处理表单提交
  296. */
  297. async function handleSubmit(event: Event) {
  298. // 阻止表单默认提交行为,防止重复提交
  299. event.preventDefault();
  300. if (isSubmitting.value) {
  301. return; // 如果已经在提交中,不重复处理
  302. }
  303. isSubmitting.value = true;
  304. submitSuccess.value = false;
  305. try {
  306. // 验证验证码
  307. const isCaptchaValid = captcha.validateCaptcha();
  308. if (!isCaptchaValid) {
  309. isSubmitting.value = false;
  310. return;
  311. }
  312. // 使用单独的异步函数发送邮件,减少嵌套
  313. await sendEmail();
  314. } catch (error) {
  315. console.error("Error during form submission:", error);
  316. showFormStatus("error", t("contact.submitError"));
  317. } finally {
  318. isSubmitting.value = false;
  319. }
  320. }
  321. /**
  322. * 发送邮件的函数
  323. */
  324. async function sendEmail() {
  325. try {
  326. const result = await wrapAsync(async () => {
  327. // 发送邮件
  328. const response = await fetch(
  329. `https://digital.sohomall.jp/prod-api/system/zsEmail/sendEmailWeb?receiveEmail=${form.value.email}&context=${form.value.message}&title=[Hanye Website]${form.value.name}`,
  330. {
  331. method: "GET",
  332. headers: {
  333. "Content-Type": "application/json",
  334. },
  335. }
  336. );
  337. if (response.status === 200) {
  338. // 清空表单
  339. form.value = {
  340. name: "",
  341. email: "",
  342. message: "",
  343. };
  344. captcha.state.userInput = ''; // 清空验证码输入
  345. captcha.generateCaptcha(); // 成功后刷新验证码
  346. submitSuccess.value = true;
  347. showFormStatus("success", t("contact.submitSuccess"));
  348. return { success: true };
  349. } else {
  350. showFormStatus("error", t("contact.submitError"));
  351. throw new Error("Failed to send email");
  352. }
  353. });
  354. return result;
  355. } catch (error) {
  356. console.error("Error sending email:", error);
  357. showFormStatus("error", t("contact.submitError"));
  358. throw error;
  359. }
  360. }
  361. // SEO优化
  362. useHead({
  363. title: t("contact.title") + " - Hanye",
  364. meta: [
  365. {
  366. name: "description",
  367. content: t("contact.description"),
  368. },
  369. {
  370. name: "keywords",
  371. content: t("contact.keywords"),
  372. },
  373. ],
  374. });
  375. </script>