Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
643d1d7d
Commit
643d1d7d
authored
Sep 08, 2025
by
weiw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:处理文件预览
parent
0859f43d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
32 deletions
+69
-32
src/api/common.ts
+20
-11
src/pages/Chat/components/ChatItem/ChatAnswerAttchment.tsx
+39
-13
src/utils/request.ts
+10
-8
No files found.
src/api/common.ts
View file @
643d1d7d
// src/api/common.ts
import
http
from
'@/utils/request'
/**
* 登录
* @returns
*/
export
function
fetchLoginByUid
(
uid
:
string
)
{
return
http
.
post
(
'/user/api/login/mobile/v1/guest/login'
,
{
...
...
@@ -12,7 +12,6 @@ export function fetchLoginByUid(uid: string) {
/**
* 第三方登录
* @returns
*/
export
function
fetchLoginByToken
(
loginCode
:
any
)
{
return
http
.
post
(
'/user/api/login/mobile/v1/sso_login'
,
{
...
...
@@ -22,16 +21,25 @@ export function fetchLoginByToken(loginCode: any) {
/**
* 获取协议列表
* @returns
*/
export
function
fetchGetAgreementList
()
{
return
http
.
post
(
'/config-center/api/commonconfig/mobile/v1/query_agreement_list'
)
}
/**
* 获取文档链接s
* @param recordId
* @returns
* 获取文档链接
* @param docId
*/
export
function
fetchGetDocumentLink
(
docId
:
string
)
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/get_document'
,
{
ossType
:
'private'
,
docId
,
})
}
/**
* 批量获取文档链接
* @param docIdList
*/
export
function
fetchGetDocumentLinks
(
docIdList
:
string
[])
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/query_batch_document'
,
{
...
...
@@ -41,13 +49,14 @@ export function fetchGetDocumentLinks(docIdList: string[]) {
}
/**
* 获取文档链接
* @param recordId
* @returns
* 下载文件
* @param docId
*/
export
function
fetch
GetDocumentLink
(
docId
:
string
)
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/
get_document
'
,
{
export
function
fetch
DownloadFile
(
docId
:
string
)
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/
download_file
'
,
{
ossType
:
'private'
,
docId
,
},
{
responseType
:
'blob'
,
})
}
src/pages/Chat/components/ChatItem/ChatAnswerAttchment.tsx
View file @
643d1d7d
...
...
@@ -9,7 +9,7 @@ import CardCalculation from '@/assets/card-calculation.png'
import
CardDetailImg
from
'@/assets/card-detail.png'
import
CardPlansImg
from
'@/assets/card-book1111.png'
import
CardProductCompareImg
from
'@/assets/card-product2222.png'
import
{
fetch
GetDocumentLink
}
from
'@/api/common'
import
{
fetch
DownloadFile
}
from
'@/api/common'
import
{
FilePreviewModal
}
from
'@/components/FilePreviewModal'
interface
ChatAnswerAttachmentProps
{
...
...
@@ -40,22 +40,48 @@ export const ChatAnswerAttachment: React.FC<ChatAnswerAttachmentProps> = ({
const
handleClickDocLink
=
async
(
doc
:
any
)
=>
{
try
{
const
docId
=
`
${
doc
.
knowledgeName
}
/
${
doc
.
documentStoreKey
}
`
const
res
=
await
fetchGetDocumentLink
(
docId
)
if
(
res
.
data
)
{
setCurrentDoc
(
doc
)
setDocUrl
(
res
.
data
.
docUrl
)
setPreviewModalOpen
(
true
)
}
const
resBlob
:
any
=
await
fetchDownloadFile
(
docId
)
const
mimeType
=
blobType
(
doc
.
documentAlias
)
// 修正参数
const
blob
=
new
Blob
([
resBlob
.
data
],
{
type
:
mimeType
})
// 创建 fileBlob URL
const
fileBlobUrl
=
URL
.
createObjectURL
(
blob
)
setCurrentDoc
(
doc
)
setDocUrl
(
fileBlobUrl
)
// 传递 blob URL
setPreviewModalOpen
(
true
)
}
catch
(
error
)
{
console
.
error
(
'获取文档链接失败:'
,
error
)
// 如果获取预览链接失败,直接打开新窗口
const
docId
=
`
${
doc
.
knowledgeName
}
/
${
doc
.
documentStoreKey
}
`
const
res
=
await
fetchGetDocumentLink
(
docId
)
if
(
res
.
data
)
{
window
.
open
(
res
.
data
.
docUrl
,
'_blank'
)
}
}
}
function
blobType
(
fileName
:
string
)
{
const
ext
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
'.'
)).
toLowerCase
()
switch
(
ext
)
{
case
'.pdf'
:
return
'application/pdf'
case
'.doc'
:
return
'application/msword'
case
'.docx'
:
return
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
case
'.xls'
:
return
'application/vnd.ms-excel'
case
'.xlsx'
:
return
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
case
'.ppt'
:
return
'application/vnd.ms-powerpoint'
case
'.pptx'
:
return
'application/vnd.openxmlformats-officedocument.presentationml.presentation'
case
'.txt'
:
return
'text/plain;charset=utf-8'
case
'.wps'
:
return
'application/wps-office.wps'
case
'.ett'
:
return
'application/wps-office.ett'
default
:
return
'application/octet-stream'
}
}
...
...
src/utils/request.ts
View file @
643d1d7d
// src/utils/request.ts
import
axios
from
'axios'
import
type
{
AxiosError
,
...
...
@@ -33,13 +34,10 @@ service.interceptors.request.use(
'X-Token'
:
JSON
.
parse
(
token
),
'X-Request-Id'
:
`
${
Date
.
now
()}${
Math
.
random
().
toString
(
36
).
substring
(
2
)}
`
,
'X-Request-By'
:
config
.
url
,
// 'X-App-Type': getAppType() || '',
// 'X-Channel-Code': getChannelCode() || '',
}
return
config
},
(
error
:
AxiosError
)
=>
{
// showToast(error.message)
return
Promise
.
reject
(
error
)
},
)
...
...
@@ -47,8 +45,15 @@ service.interceptors.request.use(
service
.
interceptors
.
response
.
use
(
(
response
:
AxiosResponse
<
any
,
Response
<
ResponseData
>>
)
=>
{
const
{
code
,
message
}
=
response
.
data
if
(
response
.
config
.
responseType
===
'stream'
)
// 处理 blob 响应类型
if
(
response
.
config
.
responseType
===
'blob'
)
{
return
response
}
if
(
response
.
config
.
responseType
===
'stream'
)
{
return
response
}
if
(
code
===
'00000000'
)
{
return
response
.
data
...
...
@@ -56,16 +61,12 @@ service.interceptors.response.use(
else
if
(
code
===
'00000005'
)
{
// 处理登录失效
window
.
localStorage
.
clear
()
// window.location.href = '/sdream-ai'
// window.location.reload()
}
else
{
// showToast(message)
return
Promise
.
reject
(
new
Error
(
message
))
}
},
(
error
:
AxiosError
)
=>
{
// showToast('网络请求异常')
return
Promise
.
reject
(
error
)
},
)
...
...
@@ -95,6 +96,7 @@ export const http = {
delete
<
T
=
any
>
(
url
:
string
,
config
?:
AxiosRequestConfig
):
Promise
<
T
>
{
return
service
.
delete
(
url
,
config
)
},
stream
<
T
=
any
>
(
url
:
string
,
data
:
T
)
{
return
service
.
post
(
url
,
data
,
{
responseType
:
'stream'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment