Commit 4f65a5c2 by liangzhen

图片和pdf展示

1 parent 711f631f
......@@ -261,7 +261,7 @@ export function materialSync(params) {
//下载
export function downloadObject(params) {
return post(`${ARCH_EVALUATION}/oss/downloadObject`, params)
return download(`${ARCH_EVALUATION}/oss/downloadObject`, params)
}
//后评估集中检查
......
......@@ -29,6 +29,7 @@ axios.interceptors.request.use(config => {
console.log(config.url.indexOf('oss/downloadObject')!='-1','config.url')
if(config.url.indexOf('oss/downloadObject')!='-1'){
config.headers["Content-Type"] ='application/x-www-form-urlencoded'
config.headers['responseType']='arraybuffer'
}
// else if(config.url.indexOf('oss/upload')!='-1'){
// config.headers["Content-Type"] ='application/form-data'
......@@ -106,7 +107,7 @@ axios.interceptors.response.use(response => {
}
export function download(url, data = {}) {
return new Promise((resolve, reject) => {
axios.post(url, data, { responseType: 'blob' }).then(response => {
axios.post(url, data, { responseType: 'arraybuffer' }).then(response => {
if(response){
resolve(response.data);
}
......
......@@ -25,10 +25,15 @@
>
<!-- <p style="height:600px"> {{ item.typeText }}</p> -->
<iframe
v-if="blobType=='pdf'"
:src="iframeUrl"
frameborder="0"
style="width: 80%; height: 60vh; margin: auto; display: block"
></iframe>
<div v-else-if="blobType=='png'||blobType=='jpg'" class="blobImg">
<img :src="iframeUrl" alt="">
</div>
</el-tab-pane>
</el-tabs>
</div>
......@@ -230,6 +235,7 @@ export default {
limitNum: 1,
disabled: false,
oldQuestionList: [], //对比列表
blobType:'pdf',//bolb类型
};
},
mounted() {
......@@ -385,14 +391,20 @@ export default {
if (this.urlList.length <= 0) {
this.iframeUrl = "/nopdf.png";
} else {
let paramsUrl = {
fileId: this.urlList[0].id,
url: this.urlList[0].url,
};
// let paramsUrl = {
// fileId: this.urlList[0].id,
// url: this.urlList[0].url,
// };
let resUrl = await presignedUrl(paramsUrl);
// let resUrl = await presignedUrl(paramsUrl);
// this.iframeUrl = "/pdf/web/viewer.html?file=" + resUrl.msg;
this.iframeUrl = "/pdf/web/viewer.html?file=" + resUrl.msg;
let resUrl = await downloadObject({fileId: this.urlList[0].id});
this.blobType=this.urlList[0].fileType
const binaryData = []
binaryData.push(resUrl)
let URL = window.URL.createObjectURL(new Blob(binaryData, { type: this.urlList[0].contentType}))
this.iframeUrl = "/pdf/web/viewer.html?file=" + URL
}
// setTimeout(() => {
// this.oldQuestionList = JSON.parse(JSON.stringify(this.questionList));
......@@ -404,12 +416,18 @@ export default {
console.log("切换", tab.name, this.urlList);
this.urlList.forEach(async (item) => {
if (item.typeCode == tab.name) {
let paramsUrl = {
fileId: item.id,
url: item.url,
};
let resUrl = await presignedUrl(paramsUrl);
this.iframeUrl = "/pdf/web/viewer.html?file=" + resUrl.msg;
// let paramsUrl = {
// fileId: item.id,
// url: item.url,
// };
// let resUrl = await presignedUrl(paramsUrl);
let resUrl = await downloadObject({fileId:item.id});
this.blobType=item.fileType
console.log(item.fileType,'item.fileType')
const binaryData = []
binaryData.push(resUrl)
let URL = window.URL.createObjectURL(new Blob(binaryData, { type:item.contentType}))
this.iframeUrl = URL;
} else {
// this.iframeUrl =""
this.iframeUrl = "/nopdf.png";
......@@ -824,4 +842,10 @@ export default {
margin-left: 10px;
border: none;
}
.blobImg{
width: 100%;
img{
width: 100%;
}
}
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!