mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-10 02:40:23 +08:00
finish getFileBlob
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -18,3 +18,4 @@
|
||||
.DS_Store
|
||||
|
||||
/data
|
||||
paper-manager
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defHttp } from '/@/utils/http/axios'
|
||||
import { defHttp, paperHttp } from '/@/utils/http/axios'
|
||||
import { getFileListModel, AnalyzeFile, FileListGroupItem } from './model/fileListModel'
|
||||
import { DownloadFile, FileStatus } from './model/fileModel'
|
||||
|
||||
@@ -57,6 +57,16 @@ export const downloadFile = (id: number) => {
|
||||
return defHttp.get<DownloadFile>({ url: Api.DlFile, params: { id: id } })
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Download file to blob
|
||||
*/
|
||||
export const getFileBlob = (url: string) => {
|
||||
return paperHttp.get<any>({
|
||||
responseType: 'blob',
|
||||
url: url,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Get file status
|
||||
*/
|
||||
|
||||
@@ -258,10 +258,11 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
|
||||
}
|
||||
export const defHttp = createAxios()
|
||||
|
||||
// other api url
|
||||
// export const otherHttp = createAxios({
|
||||
// requestOptions: {
|
||||
// apiUrl: 'xxx',
|
||||
// urlPrefix: 'xxx',
|
||||
// },
|
||||
// });
|
||||
// download paper
|
||||
export const paperHttp = createAxios({
|
||||
requestOptions: {
|
||||
apiUrl: '',
|
||||
urlPrefix: '',
|
||||
isTransformResponse: false,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -15,15 +15,13 @@
|
||||
import { PageWrapper } from '/@/components/Page'
|
||||
import { useECharts } from '/@/hooks/web/useECharts'
|
||||
import { renderAsync } from 'docx-preview'
|
||||
import { downloadFile, getFileStatus } from '/@/api/page'
|
||||
import { downloadFile, getFileStatus, getFileBlob } from '/@/api/page'
|
||||
import { useMessage } from '/@/hooks/web/useMessage'
|
||||
import { useGo } from '/@/hooks/web/usePage'
|
||||
import { useTabs } from '/@/hooks/web/useTabs'
|
||||
import { PageEnum } from '/@/enums/pageEnum'
|
||||
import { useI18n } from '/@/hooks/web/useI18n'
|
||||
import { downloadByData } from '/@/utils/file/download'
|
||||
import { getToken } from '/@/utils/auth'
|
||||
import axios from 'axios'
|
||||
|
||||
const { t } = useI18n()
|
||||
|
||||
@@ -86,13 +84,7 @@
|
||||
try {
|
||||
const ret = await downloadFile(Number(params.value.id))
|
||||
if (ret && ret.url) {
|
||||
const token = getToken() as string
|
||||
const { data } = await axios({
|
||||
method: 'get',
|
||||
responseType: 'blob',
|
||||
url: ret.url,
|
||||
headers: { Authorization: token },
|
||||
})
|
||||
const data = await getFileBlob(ret.url)
|
||||
if (data) {
|
||||
loadDocx(data)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user