/*
|
* @Description:图片流d url获取 和文件流url生成
|
* @Version: 2.0
|
* @Autor: wuyun
|
* @Date: 2022-09-06 13:51:31
|
* @LastEditors: wuyun
|
* @LastEditTime: 2023-02-20 17:30:40
|
*/
|
import axios from 'axios'
|
import { useUserInfo } from '@/stores/modules/userInfo'
|
import commonApi from '@/api/commonApi'
|
|
const userInfoStore = useUserInfo()
|
export function getImgFlowUrl(id: string) {
|
const config: any = {
|
headers: {
|
'Content-Type': 'application/json;charset=UTF-8',
|
token: userInfoStore.getAdminToken
|
},
|
responseType: 'blob'
|
}
|
|
return new Promise((resolve, reject) => {
|
axios
|
.post('api/admin/common/filePreview', { fileId: id }, config)
|
.then((res: any) => {
|
resolve(res)
|
})
|
.catch((error) => {
|
reject(error)
|
})
|
})
|
}
|
|
export function getImgFlowUrlT(id: string) {
|
const config: any = {
|
headers: {
|
'Content-Type': 'application/json;charset=UTF-8',
|
token: userInfoStore.getAdminToken
|
},
|
responseType: 'blob'
|
}
|
|
return new Promise((resolve, reject) => {
|
axios
|
.post('api/admin/common/url', { fileId: id }, config)
|
.then((res: any) => {
|
|
resolve(res)
|
})
|
.catch((error) => {
|
reject(error)
|
})
|
})
|
}
|
|
// PDF预览方法
|
export function getFileFlowUrl(id: string) {
|
return new Promise((resolve, reject) => {
|
commonApi.getFileFlowById({ fileId: id }).then((res: any) => {
|
let fileURL = ''
|
var blob: any = new Blob([res.data], { type: 'application/pdf' })
|
if (window.webkitURL != undefined) {
|
// webkit or chrome
|
try {
|
fileURL = window.webkitURL.createObjectURL(blob)
|
} catch (error) {
|
}
|
} else if (window.URL != undefined) {
|
// mozilla(firefox)
|
try {
|
fileURL = window.URL.createObjectURL(blob)
|
} catch (error) {
|
}
|
}
|
window.open(fileURL)
|
resolve(res)
|
}).catch((error) => {
|
reject(error)
|
})
|
|
})
|
}
|