笔记导出功能

This commit is contained in:
daihh
2022-10-18 13:15:39 +08:00
parent 8a8ab315ef
commit 619546c466
4 changed files with 56 additions and 22 deletions

View File

@@ -22,7 +22,7 @@ VUE_APP_BOE_WEB_URL = 'http://192.168.0.11'
VUE_APP_BOE_MOBILE_URL = 'http://192.168.0.11:8082/mobile'
# File路径的基础url
VUE_APP_FILE_BASE_URL = 'http://192.168.0.11:9090/cdn/upload'
VUE_APP_FILE_BASE_URL = 'http://192.168.0.11:9080/cdn/upload'
# File路径的基础url的相对路径加此项是为了不影响之前的路径配置
VUE_APP_FILE_RELATIVE_PATH = '/upload'

View File

@@ -183,6 +183,7 @@ const putJson=function(baseURL,url,data){
export default {
tokenName:TokenName,
request,
get,
post,

View File

@@ -1,5 +1,7 @@
// import ajax from '@/utils/xajax.js'
// import ajax from '../cesource/index.js';
import axios from 'axios'
import { getToken } from '@/utils/token'
import ajax from '../ajax';
const baseURL = process.env.VUE_APP_CESOURCE_BASE_API;
@@ -140,7 +142,29 @@ const exportPdfPre=function (data){
* */
const exportPdf=function (data){
// return ajax.postJson(baseURL,'/xboe/subgroup/m/noteinfo/exportPdf',data);
return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/exportPdf',data);
//return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/exportPdf',data);
var url = baseURL + '/xboe/subgroup/m/noteinfo/exportPdf';
axios({
method: 'post',
url: url,
responseType: 'blob',
headers: { 'XBOE-Access-Token':getToken() }
}).then(res => {
//resolveBlob(res, mimeMap.zip);
const aLink = document.createElement('a')
var blob = new Blob([res], { type: 'application/pdf' })
// //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名;
var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
var contentDisposition = decodeURI(res.headers['content-disposition'])
var result = patt.exec(contentDisposition)
var fileName = result[1]
fileName = fileName.replace(/\"/g, '')
aLink.href = URL.createObjectURL(blob)
aLink.setAttribute('download',fileName) // 设置下载文件名称
document.body.appendChild(aLink)
aLink.click()
document.body.appendChild(aLink)
})
}
/**
@@ -155,7 +179,7 @@ const exportPdf=function (data){
* }
* */
const pagelist=function (query){
return ajax.post('/xboe/subgroup/m/noteinfo/pagelist',query);
return ajax.post(baseURL,'/xboe/subgroup/m/noteinfo/pagelist',query);
}
export default {

View File

@@ -153,7 +153,7 @@
<div class="all-content">
<span v-if="item.contentType != 3">{{ item.content }}</span>
<div v-else>
<template v-for="img in item.content">
<template v-for="img in item.imgList">
<img style="max-height:145px;max-width:140px" :src="fileBaseUrl + img" alt=""/>
</template>
</div>
@@ -227,7 +227,7 @@ export default {
startTime:'',
endTime:'',
datalist:[ ],
exportPreData:[ ],
exportPreData:[],
thu:true,
couresna:[],
courseName:'',
@@ -268,11 +268,19 @@ export default {
this.$message.warning('未查询到满足条件的数据')
return;
}
this.exportPreData = res.result.data;
if(res.result.isImage && e == 2){
this.$message.warning('当前筛选条件下含图片类内容无法导出Excel')
return;
}
res.result.data.forEach((item)=>{
if(item.contentType==3){
item.imgList=item.content.split(',');
}else{
item.imgList=[];
}
})
this.exportPreData = res.result.data;
this.dialogVisible = true;
})
},
@@ -295,23 +303,24 @@ export default {
author:this.userData.avatar,//this.userInfo.avatar,
}
if(this.exportType == '1') {
apiNote.exportPdf(data).then(res=>{
if(res.status) {
this.$message.error('导出失败');
} else {
const link = document.createElement('a');// 创建a标签
// let blob = new Blob([res],{type: 'application/vnd.ms-pdf;charset=UTF-8'}); // 设置文件类型
let blob = new Blob([res],{type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'}); // 设置文件类型
link.style.display = "none";
link.href = URL.createObjectURL(blob); // 创建URL
link.setAttribute("download", "我的笔记.pdf");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
this.dialogVisible = false;
}
apiNote.exportPdf(data);
// apiNote.exportPdf(data).then(res=>{
// if(res.status) {
// this.$message.error('导出失败');
// } else {
// const link = document.createElement('a');// 创建a标签
// // let blob = new Blob([res],{type: 'application/vnd.ms-pdf;charset=UTF-8'}); // 设置文件类型
// let blob = new Blob([res],{type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'}); // 设置文件类型
// link.style.display = "none";
// link.href = URL.createObjectURL(blob); // 创建URL
// link.setAttribute("download", "我的笔记.pdf");
// document.body.appendChild(link);
// link.click();
// document.body.removeChild(link);
// this.dialogVisible = false;
// }
})
// })
} else {
let data = {
orderType:this.orderType,