Commit 4f65a5c2 by liangzhen

图片和pdf展示

1 parent 711f631f
...@@ -261,7 +261,7 @@ export function materialSync(params) { ...@@ -261,7 +261,7 @@ export function materialSync(params) {
//下载 //下载
export function downloadObject(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 => { ...@@ -29,6 +29,7 @@ axios.interceptors.request.use(config => {
console.log(config.url.indexOf('oss/downloadObject')!='-1','config.url') console.log(config.url.indexOf('oss/downloadObject')!='-1','config.url')
if(config.url.indexOf('oss/downloadObject')!='-1'){ if(config.url.indexOf('oss/downloadObject')!='-1'){
config.headers["Content-Type"] ='application/x-www-form-urlencoded' config.headers["Content-Type"] ='application/x-www-form-urlencoded'
config.headers['responseType']='arraybuffer'
} }
// else if(config.url.indexOf('oss/upload')!='-1'){ // else if(config.url.indexOf('oss/upload')!='-1'){
// config.headers["Content-Type"] ='application/form-data' // config.headers["Content-Type"] ='application/form-data'
...@@ -106,7 +107,7 @@ axios.interceptors.response.use(response => { ...@@ -106,7 +107,7 @@ axios.interceptors.response.use(response => {
} }
export function download(url, data = {}) { export function download(url, data = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
axios.post(url, data, { responseType: 'blob' }).then(response => { axios.post(url, data, { responseType: 'arraybuffer' }).then(response => {
if(response){ if(response){
resolve(response.data); resolve(response.data);
} }
......
...@@ -25,10 +25,15 @@ ...@@ -25,10 +25,15 @@
> >
<!-- <p style="height:600px"> {{ item.typeText }}</p> --> <!-- <p style="height:600px"> {{ item.typeText }}</p> -->
<iframe <iframe
v-if="blobType=='pdf'"
:src="iframeUrl" :src="iframeUrl"
frameborder="0" frameborder="0"
style="width: 80%; height: 60vh; margin: auto; display: block" style="width: 80%; height: 60vh; margin: auto; display: block"
></iframe> ></iframe>
<div v-else-if="blobType=='png'||blobType=='jpg'" class="blobImg">
<img :src="iframeUrl" alt="">
</div>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</div> </div>
...@@ -230,6 +235,7 @@ export default { ...@@ -230,6 +235,7 @@ export default {
limitNum: 1, limitNum: 1,
disabled: false, disabled: false,
oldQuestionList: [], //对比列表 oldQuestionList: [], //对比列表
blobType:'pdf',//bolb类型
}; };
}, },
mounted() { mounted() {
...@@ -385,14 +391,20 @@ export default { ...@@ -385,14 +391,20 @@ export default {
if (this.urlList.length <= 0) { if (this.urlList.length <= 0) {
this.iframeUrl = "/nopdf.png"; this.iframeUrl = "/nopdf.png";
} else { } else {
let paramsUrl = { // let paramsUrl = {
fileId: this.urlList[0].id, // fileId: this.urlList[0].id,
url: this.urlList[0].url, // 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(() => { // setTimeout(() => {
// this.oldQuestionList = JSON.parse(JSON.stringify(this.questionList)); // this.oldQuestionList = JSON.parse(JSON.stringify(this.questionList));
...@@ -404,12 +416,18 @@ export default { ...@@ -404,12 +416,18 @@ export default {
console.log("切换", tab.name, this.urlList); console.log("切换", tab.name, this.urlList);
this.urlList.forEach(async (item) => { this.urlList.forEach(async (item) => {
if (item.typeCode == tab.name) { if (item.typeCode == tab.name) {
let paramsUrl = { // let paramsUrl = {
fileId: item.id, // fileId: item.id,
url: item.url, // url: item.url,
}; // };
let resUrl = await presignedUrl(paramsUrl); // let resUrl = await presignedUrl(paramsUrl);
this.iframeUrl = "/pdf/web/viewer.html?file=" + resUrl.msg; 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 { } else {
// this.iframeUrl ="" // this.iframeUrl =""
this.iframeUrl = "/nopdf.png"; this.iframeUrl = "/nopdf.png";
...@@ -824,4 +842,10 @@ export default { ...@@ -824,4 +842,10 @@ export default {
margin-left: 10px; margin-left: 10px;
border: none; border: none;
} }
.blobImg{
width: 100%;
img{
width: 100%;
}
}
</style> </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!