@@ -13,15 +13,16 @@ import { Message } from '@/shared/utils/message';
1313import  {  convertImgPath  }  from  '@/common/util' ; 
1414import  {  TENANT_ID  }  from  '@/pages/chatPreview/components/send-editor/common/config' ; 
1515import  UploadImg  from  '@/components/file-upload' ; 
16- 
16+ import  serviceConfig  from  "@/shared/http/httpConfig" ; 
17+ import  {  uploadChatFile  }  from  '@/shared/http/aipp' ; 
1718/** 
1819 * 复制应用 
1920 * 
2021 * @param  copyRef 当前组件的ref. 
2122 * @return  {JSX.Element } 
2223 * @constructor  
2324 */ 
24- 
25+ const   {   AIPP_URL   }   =   serviceConfig ; 
2526const  CopyApp  =  ( {  copyRef } )  =>  { 
2627  const  {  t }  =  useTranslation ( ) ; 
2728  const  [ form ]  =  Form . useForm ( ) ; 
@@ -30,25 +31,43 @@ const CopyApp = ({ copyRef }) => {
3031  const  [ loading ,  setLoading ]  =  useState ( false ) ; 
3132  const  [ appInfo ,  setAppInfo ]  =  useState ( { } ) ; 
3233  const  navigate  =  useHistory ( ) . push ; 
34+   const  tenantId  =  TENANT_ID ; 
3335
3436  useImperativeHandle ( copyRef ,  ( )  =>  { 
3537    return  { 
3638      openModal : ( appInfo )  =>  dataInit ( appInfo ) , 
3739    } ; 
3840  } ) ; 
39-   
4041  // 初始化数据 
4142  const  dataInit  =  ( appInfo )  =>  { 
4243    setAppInfo ( appInfo ) ; 
4344    form . setFieldsValue ( { 
4445      name : appInfo . name , 
45-       icon : appInfo . attributes ?. icon , 
46+       icon : '' , 
4647    } ) ; 
47-     if  ( appInfo . attributes ?. icon )  { 
48-       setFilePath ( appInfo . attributes . icon ) ; 
48+ 
49+     if  ( appInfo . attributes . icon )  { 
50+        reuploadIcon ( appInfo . attributes . icon ) 
4951    } 
5052    setOpen ( true ) ; 
53+ 
5154  } 
55+   //重新上传图片 
56+   const  reuploadIcon  =  async  ( iconUrl )  =>  { 
57+     const  res  =  await  fetch ( iconUrl ) ; 
58+     const  blob  =  await  res . blob ( ) ; 
59+     const  file  =  new  File ( [ blob ] ,  "clone.png" ,  {  type : blob . type  } ) ; 
60+     const  formData  =  new  FormData ( ) ; 
61+     formData . append ( "file" ,  file ) ; 
62+     let  uploadRes  =  await  uploadChatFile ( TENANT_ID ,  appInfo . id ,  formData ,  { 
63+       'attachment-filename' : encodeURI ( file . name ) , 
64+       'Content-Type' : 'multipart/form-data' , 
65+     } ) ; 
66+     if  ( uploadRes . code  ===  0 )  { 
67+       const  realPath  =  uploadRes . data . file_path . replace ( / ^ .* [ \\ / ] / ,  "" ) ; 
68+       setFilePath ( realPath ) ;  //存文件名 
69+     } 
70+   } ; 
5271  // 复制应用 
5372  const  handleCopyApp  =  async  ( )  =>  { 
5473    try  { 
@@ -58,7 +77,7 @@ const CopyApp = ({ copyRef }) => {
5877      const  copyParam  =  { 
5978        name : formParams . name , 
6079        description : attributes . description , 
61-         icon : '' , 
80+         icon : filePath , 
6281        app_type : attributes . app_type , 
6382        app_built_type : appBuiltType , 
6483        type, 
@@ -98,10 +117,13 @@ const CopyApp = ({ copyRef }) => {
98117        < Form  form = { form }  layout = 'vertical'  autoComplete = 'off'  className = 'edit-form-content' > 
99118          < Form . Item  label = { t ( 'icon' ) }  name = 'icon' > 
100119            < div  className = 'avatar' > 
101-               < UploadImg   
120+               < UploadImg 
102121                appId = { appInfo . id } 
103-                 icon = { appInfo . attributes ?. icon } 
104-                 uploadSuccess = { ( path : string )  =>  setFilePath ( path ) } 
122+                 icon = { `${ AIPP_URL }  /${ tenantId }  /file?filePath=/var/share/${ filePath }  &fileName=${ filePath }  ` } 
123+                 uploadSuccess = { ( path : string )  => { 
124+                   const  realPath  =  path . replace ( / ^ .* [ \\ / ] / ,  "" ) ; 
125+                   setFilePath ( realPath ) ; 
126+                 } } 
105127              /> 
106128            </ div > 
107129          </ Form . Item > 
@@ -119,7 +141,7 @@ const CopyApp = ({ copyRef }) => {
119141          > 
120142            < Input  /> 
121143          </ Form . Item > 
122-         </ Form >   
144+         </ Form > 
123145      </ div > 
124146    </ Modal > 
125147  </ > 
0 commit comments