@@ -10,6 +10,8 @@ import { useState } from 'react';
1010import  Link  from  'next/link' ; 
1111import  {  usePathname  }  from  'next/navigation' ; 
1212import  clsx  from  'clsx' ; 
13+ import  React  from  'react' ; 
14+ import  {  message  }  from  'antd' ; 
1315
1416// Map of links to display in the side navigation. 
1517// Depending on the size of the application, this would be stored in a database. 
@@ -23,18 +25,17 @@ const links = [
2325  // { name: 'Customers', href: '/dashboard/customers', icon: UserGroupIcon }, 
2426] ; 
2527
26- export   default   function   NavLinks ( )  { 
28+ const   NavLinks :  React . FC   =   ( )   =>  { 
2729  const  pathname  =  usePathname ( ) ; 
2830  const  [ isModalOpen ,  setModalOpen ]  =  useState ( false ) ; 
2931  const  [ inputValue ,  setInputValue ]  =  useState ( '' ) ; 
30- 
3132  const  [ file ,  setFile ]  =  useState < File  |  null > ( null ) ; 
3233  const  [ isGithubLink ,  setIsGithubLink ]  =  useState ( true ) ;  // 控制输入类型 
34+   const  [ messageApi ,  contextHolder ]  =  message . useMessage ( ) ; //antd-message的hooks调用 
3335
3436  //暂定上传数据类型为react表单类型 
3537  const  handleSubmit  =  async  ( e : React . FormEvent < HTMLFormElement > )  =>  { 
3638    e . preventDefault ( ) ; 
37- 
3839    const  formData  =  new  FormData ( ) ; 
3940    if  ( isGithubLink )  { 
4041      formData . append ( 'githubLink' ,  inputValue ) ; 
@@ -44,29 +45,33 @@ export default function NavLinks() {
4445
4546    try  { 
4647      //用fetch向服务器发声POST请求,提交用户输入的内容 
47-       const  response  =  await  fetch ( '/api/submi ' ,  {    // 待替换为服务器API 
48+       const  response  =  await  fetch ( '/api/submit ' ,  {  //待替换为后端服务API 
4849        method : 'POST' , 
49-         //请求体,将对象转换为json字符串  
50+         //请求体 
5051        body : formData , 
5152      } ) ; 
53+       //console.log('Response:', response); // 输出响应 
54+ 
5255      //响应处理,根据响应结果显示提示信息,并重置输入框或关闭弹窗 
5356      if  ( response . ok )  { 
54-         alert ( '内容提交成功!' ) ; //提交成功后重置输入框的值,并关闭弹窗 
57+         messageApi . success ( '提交成功' ) ; //提交成功后重置输入框的值,并关闭弹窗 
58+         console . log ( '提交成功' ) ; 
5559        setInputValue ( '' ) ; 
5660        setFile ( null ) ; 
5761        setModalOpen ( false ) ; 
5862      }  else  { 
59-         alert ( '提交失败, 请重试。'  ) ; 
63+         messageApi . error ( '提交失败, 请重试'  ,   2 ) ; 
6064      } 
6165    }  catch  ( error )  { 
62-       console . error ( '提交错误:'  ,   error ) ; 
63-       alert ( '提交失败,请检查网络连接。' ) ; 
66+       messageApi . error ( '提交失败,请检查网络连接'  ) ; 
67+       //console.log ('提交失败,请检查网络连接。', error );
6468    } 
6569  } ; 
6670
6771  //渲染部分 
6872  return  ( 
6973    < > 
74+       { contextHolder } 
7075      { links . map ( ( link )  =>  { 
7176        const  LinkIcon  =  link . icon ; 
7277        return  ( 
@@ -185,4 +190,6 @@ export default function NavLinks() {
185190      ) } 
186191    </ > 
187192  ) ; 
188- } 
193+ } 
194+ 
195+ export  default  NavLinks ; 
0 commit comments