Sfoglia il codice sorgente

refactor(typescript): 更新 TypeScript 配置和组件类型定义

- 修改 next-env.d.ts 中的引用路径语法
- 移除 products 页面中未使用的 MenuItem 接口
- 为 hardwareProductList 添加明确的类型注解
- 在 PcoreProducts 组件中为产品列表项添加 key 属性
- 将 tsconfig.json 中的 jsx 配置从 react-jsx 改为 preserve
nahida 5 mesi fa
parent
commit
886740b4dc
4 ha cambiato i file con 5 aggiunte e 9 eliminazioni
  1. 1 1
      next-env.d.ts
  2. 2 7
      src/app/products/page.tsx
  3. 1 0
      src/components/PcoreProducts.tsx
  4. 1 1
      tsconfig.json

+ 1 - 1
next-env.d.ts

@@ -1,6 +1,6 @@
 /// <reference types="next" />
 /// <reference types="next/image-types/global" />
-import "./.next/types/routes.d.ts";
+/// <reference path="./.next/types/routes.d.ts" />
 
 // NOTE: This file should not be edited
 // see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

+ 2 - 7
src/app/products/page.tsx

@@ -3,13 +3,8 @@ import MainTitle from "@/components/MainTitle"
 import ProductMenu from "@/components/products/ProductMenuClient"
 import {serverGet} from "@/utils/request";
 import AnimatedSection from "@/components/AnimatedSection";
-
-import ProductionNew from "@/components/ProductionNew";
 import React, {Suspense} from "react";
 
-interface MenuItem {
-}
-
 export default async function ProductShowcase() {
 
     const res = await serverGet<ProductCategory[]>("/webSite/getProductCategoryAndType", null, {
@@ -21,9 +16,9 @@ export default async function ProductShowcase() {
     if (res.code !== 200) {
         return <div>服务器错误</div>
     }
-    let hardwareProductList = []
+    const hardwareProductList: { key: string; label: string }[] = []
     for (let i = 0; i < res.data.length; i++) {
-        let a = res.data[i].productTypes.map((item) => ({
+        const a = res.data[i].productTypes.map((item) => ({
             key: item.productTypeName,
             label: item.productTypeName,
             // children: item.productCenters.map((center) => ({

+ 1 - 0
src/components/PcoreProducts.tsx

@@ -23,6 +23,7 @@ export default function CoreProducts({products}: ProductMenuProps) {
             <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
                 {products.map((product) => (
                     <div
+                        key={product.productId}
                         className="border border-gray-200 rounded-sm p-6 flex flex-col items-center text-center hover:shadow-md transition-shadow duration-300"
                     >
                         <h3 className="font-bold text-lg mb-1 text-gray-800">{product.productName}</h3>

+ 1 - 1
tsconfig.json

@@ -15,7 +15,7 @@
     "moduleResolution": "bundler",
     "resolveJsonModule": true,
     "isolatedModules": true,
-    "jsx": "react-jsx",
+    "jsx": "preserve",
     "incremental": true,
     "plugins": [
       {