Hanye官网
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

faq.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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-blue-500 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="/"
  15. class="justify-start text-white/60 text-base font-normal"
  16. >ホーム</nuxt-link
  17. >
  18. <span class="text-white/60 text-base font-normal px-2"> / </span>
  19. <nuxt-link to="/faq" class="text-white text-base font-normal"
  20. >よくある質問</nuxt-link
  21. >
  22. </div>
  23. </div>
  24. <div
  25. class="max-w-full mb-12 md:mb-20 lg:mb-32 xl:px-2 lg:px-2 md:px-4 px-4"
  26. >
  27. <div class="max-w-screen-2xl mx-auto">
  28. <div class="w-full grid grid-cols-1 md:grid-cols-10 gap-8 md:gap-2">
  29. <!-- 左侧分类导航 -->
  30. <div class="col-span-1 md:col-span-2">
  31. <div class="flex flex-col gap-4">
  32. <div class="text-white text-3xl font-medium">カテゴリー</div>
  33. <div class="flex flex-col gap-4 w-fit">
  34. <div
  35. v-for="category in categories"
  36. :key="category"
  37. @click="handleCategoryFilter(category)"
  38. class="opacity-80 justify-start text-white text-base font-normal cursor-pointer hover:opacity-100 transition-all duration-300 px-4 py-2 rounded-lg inline-block"
  39. :class="{
  40. 'opacity-100 font-bold bg-gradient-to-r from-blue-700 to-blue-400 text-white border-0 shadow-lg scale-105 transition-all duration-300':
  41. selectedCategory === category,
  42. 'hover:bg-zinc-800/50': selectedCategory !== category,
  43. }"
  44. >
  45. {{ category }}
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. <!-- 右侧FAQ列表 -->
  51. <div class="col-span-1 md:col-span-8">
  52. <!-- 搜索框 -->
  53. <div class="mb-8 relative">
  54. <input
  55. v-model="searchTerm"
  56. ref="searchInputRef"
  57. type="search"
  58. placeholder="キーワードで検索..."
  59. class="block w-full appearance-none rounded-lg border border-gray-600 bg-zinc-800/70 px-4 py-3 text-base text-gray-100 placeholder-gray-400 shadow-inner transition duration-200 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/50 focus:ring-offset-2 focus:ring-offset-zinc-900"
  60. />
  61. <button
  62. v-if="searchTerm"
  63. @click="clearSearch"
  64. class="absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-8 rounded-full bg-zinc-700/80 hover:bg-blue-500/90 text-gray-300 hover:text-white transition-all duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
  65. aria-label="検索キーワードをクリア"
  66. tabindex="0"
  67. type="button"
  68. >
  69. <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
  70. <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
  71. </svg>
  72. </button>
  73. </div>
  74. <div class="flex flex-col gap-8">
  75. <div
  76. v-for="faq in filteredFaqs"
  77. :key="faq.id"
  78. class="bg-zinc-900 rounded-lg p-8 transition-all duration-300 hover:bg-zinc-800 hover:shadow-lg"
  79. >
  80. <div
  81. class="flex items-center justify-between cursor-pointer"
  82. @click="toggleFaq(faq.id)"
  83. >
  84. <div class="text-white text-xl font-medium">
  85. <template
  86. v-for="(part, i) in highlightKeyword(faq.question)"
  87. :key="i"
  88. >
  89. <span v-if="typeof part === 'string'">{{
  90. part
  91. }}</span>
  92. <component v-else :is="part"></component>
  93. </template>
  94. </div>
  95. <div
  96. class="text-white text-2xl transition-transform duration-300"
  97. :class="{ 'rotate-180': expandedFaqs.includes(faq.id) }"
  98. >
  99. </div>
  100. </div>
  101. <div
  102. v-if="expandedFaqs.includes(faq.id)"
  103. class="mt-4 text-white/80 text-base font-normal leading-relaxed"
  104. >
  105. <template
  106. v-for="(part, i) in highlightKeyword(faq.answer)"
  107. :key="i"
  108. >
  109. <span v-if="typeof part === 'string'">{{ part }}</span>
  110. <component v-else :is="part"></component>
  111. </template>
  112. </div>
  113. </div>
  114. <div
  115. v-if="filteredFaqs.length === 0"
  116. class="text-center text-gray-400 py-8"
  117. >
  118. 該当する質問が見つかりません。
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. </ErrorBoundary>
  127. </div>
  128. </template>
  129. <script setup lang="ts">
  130. /**
  131. * FAQ页面
  132. * 展示常见问题及其答案
  133. */
  134. import { useErrorHandler } from "~/composables/useErrorHandler";
  135. const { error, isLoading, wrapAsync } = useErrorHandler();
  136. // FAQ数据
  137. interface FAQ {
  138. id: number;
  139. category: string;
  140. question: string;
  141. answer: string;
  142. }
  143. const faqs = ref<FAQ[]>([
  144. {
  145. id: 1,
  146. category: "製品について",
  147. question: "製品の保証期間はどのくらいですか?",
  148. answer:
  149. "当社の製品は購入日から1年間の保証期間があります。保証期間内に製品に問題が発生した場合は、無償で修理または交換いたします。",
  150. },
  151. {
  152. id: 2,
  153. category: "製品について",
  154. question: "製品の取扱説明書はどこで入手できますか?",
  155. answer:
  156. "製品の取扱説明書は、当社ウェブサイトの製品ページからダウンロードできます。また、製品パッケージにも同梱されています。",
  157. },
  158. {
  159. id: 3,
  160. category: "購入について",
  161. question: "支払い方法は何がありますか?",
  162. answer:
  163. "クレジットカード、銀行振込、コンビニ決済など、様々な支払い方法をご利用いただけます。詳細はお支払いページをご確認ください。",
  164. },
  165. {
  166. id: 4,
  167. category: "購入について",
  168. question: "返品・交換は可能ですか?",
  169. answer:
  170. "商品到着後7日以内であれば、未使用・未開封の商品に限り返品・交換が可能です。詳細は返品・交換ポリシーをご確認ください。",
  171. },
  172. {
  173. id: 5,
  174. category: "サポートについて",
  175. question: "技術サポートはどのように受けられますか?",
  176. answer:
  177. "メール、電話、オンラインチャットなど、様々な方法で技術サポートをご利用いただけます。営業時間内であれば、即時対応いたします。",
  178. },
  179. {
  180. id: 6,
  181. category: "サポートについて",
  182. question: "修理依頼はどのように行えばよいですか?",
  183. answer:
  184. "修理依頼は、当社ウェブサイトの修理依頼フォームからお申し込みください。修理状況はマイページから確認できます。",
  185. },
  186. ]);
  187. // 分类列表
  188. const categories = ref([
  189. "すべて",
  190. "製品について",
  191. "購入について",
  192. "サポートについて",
  193. ]);
  194. // 选中的分类
  195. const selectedCategory = ref("すべて");
  196. // 展开的FAQ ID列表
  197. const expandedFaqs = ref<number[]>([]);
  198. // 搜索关键词
  199. const searchTerm = ref("");
  200. const searchInputRef = ref<HTMLInputElement | null>(null);
  201. // 过滤后的FAQ列表
  202. const filteredFaqs = computed(() => {
  203. let result = faqs.value;
  204. if (selectedCategory.value !== "すべて") {
  205. result = result.filter(
  206. (faq: FAQ) => faq.category === selectedCategory.value
  207. );
  208. }
  209. if (searchTerm.value.trim()) {
  210. const keyword = searchTerm.value.trim().toLowerCase();
  211. result = result.filter(
  212. (faq: FAQ) =>
  213. faq.question.toLowerCase().includes(keyword) ||
  214. faq.answer.toLowerCase().includes(keyword)
  215. );
  216. }
  217. return result;
  218. });
  219. /**
  220. * 高亮显示匹配的关键字
  221. * @param text 原始文本
  222. * @returns 高亮后的VNode数组
  223. */
  224. function highlightKeyword(text: string): (string | any)[] {
  225. const keyword = searchTerm.value.trim();
  226. if (!keyword) return [text];
  227. // 构建正则,忽略大小写,转义特殊字符
  228. const escaped = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
  229. const reg = new RegExp(escaped, "gi");
  230. const parts = text.split(reg);
  231. const matches = text.match(reg);
  232. if (!matches) return [text];
  233. // 组装高亮
  234. const result: (string | any)[] = [];
  235. parts.forEach((part, i) => {
  236. result.push(part);
  237. if (i < matches.length) {
  238. result.push(
  239. h(
  240. "span",
  241. { class: "text-blue-400 bg-blue-400/10 font-bold" },
  242. matches[i]
  243. )
  244. );
  245. }
  246. });
  247. return result;
  248. }
  249. /**
  250. * 切换FAQ展开状态
  251. */
  252. function toggleFaq(id: number) {
  253. const index = expandedFaqs.value.indexOf(id);
  254. if (index === -1) {
  255. expandedFaqs.value.push(id);
  256. } else {
  257. expandedFaqs.value.splice(index, 1);
  258. }
  259. }
  260. /**
  261. * 处理分类筛选
  262. */
  263. function handleCategoryFilter(category: string) {
  264. selectedCategory.value = category;
  265. }
  266. // 自动展开匹配项
  267. watch([
  268. filteredFaqs,
  269. searchTerm
  270. ], ([faqs, keyword]: [FAQ[], string]) => {
  271. if (keyword.trim()) {
  272. expandedFaqs.value = faqs.map((faq: FAQ) => faq.id);
  273. } else {
  274. expandedFaqs.value = [];
  275. }
  276. });
  277. function clearSearch() {
  278. searchTerm.value = "";
  279. // 让输入框重新聚焦
  280. searchInputRef.value?.focus();
  281. }
  282. // SEO优化
  283. useHead({
  284. title: "常见问题 - Hanye",
  285. meta: [
  286. {
  287. name: "description",
  288. content: "浏览常见问题,获取产品使用和购买相关的帮助。",
  289. },
  290. ],
  291. });
  292. </script>
  293. <style scoped>
  294. /* 添加过渡动画 */
  295. .fade-enter-active,
  296. .fade-leave-active {
  297. transition: opacity 0.3s;
  298. }
  299. .fade-enter-from,
  300. .fade-leave-to {
  301. opacity: 0;
  302. }
  303. </style>