|
@@ -71,14 +71,14 @@
|
|
|
</span>
|
|
|
</el-tree>
|
|
|
</div>
|
|
|
- <div
|
|
|
- class="pdf_box"
|
|
|
- v-show="showId != null"
|
|
|
- v-infinite-scroll="loadscroll"
|
|
|
- :infinite-scroll-delay="200"
|
|
|
- :infinite-scroll-distance="50"
|
|
|
- >
|
|
|
- <div id="bodyContainer" v-if="ShowAlist === 'docx'"></div>
|
|
|
+ <div class="office_box" v-show="showId != null">
|
|
|
+ <vue-office-docx
|
|
|
+ style="height: 376px"
|
|
|
+ v-if="ShowAlist === 'docx'"
|
|
|
+ :src="readerResult"
|
|
|
+ @rendered="rendered"
|
|
|
+ @error="errorHandler"
|
|
|
+ />
|
|
|
<vue-office-excel
|
|
|
style="height: 376px;overflow: hidden;"
|
|
|
v-else-if="ShowAlist === 'xlsx'"
|
|
@@ -87,22 +87,13 @@
|
|
|
@error="errorHandler"
|
|
|
:key="12"
|
|
|
/>
|
|
|
- <template v-else>
|
|
|
- <pdf
|
|
|
- class="iframe"
|
|
|
- :src="$tools.splitImgHost(activeItem.url)"
|
|
|
- v-for="i in pdfCounts"
|
|
|
- :key="i"
|
|
|
- :page="i"
|
|
|
- ref="pdf"
|
|
|
- ></pdf>
|
|
|
- <iframe
|
|
|
- id="printIframe"
|
|
|
- :src="$tools.splitImgHost(activeItem.url)"
|
|
|
- frameborder="0"
|
|
|
- style="display: none"
|
|
|
- ></iframe>
|
|
|
- </template>
|
|
|
+ <vue-office-pdf
|
|
|
+ style="height: 376px;"
|
|
|
+ v-else
|
|
|
+ :src="readerResult"
|
|
|
+ @rendered="rendered"
|
|
|
+ @error="errorHandler"
|
|
|
+ />
|
|
|
</div>
|
|
|
<p
|
|
|
class="no_center"
|
|
@@ -116,15 +107,19 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import axios from "axios";
|
|
|
-import { renderAsync } from "docx-preview";
|
|
|
+//引入VueOfficeDocx组件
|
|
|
+import VueOfficeDocx from "@vue-office/docx";
|
|
|
+//引入VueOfficeExcel组件
|
|
|
import VueOfficeExcel from "@vue-office/excel";
|
|
|
+//引入VueOfficePdf组件
|
|
|
+import VueOfficePdf from "@vue-office/pdf";
|
|
|
+//引入相关样式
|
|
|
+import "@vue-office/docx/lib/index.css";
|
|
|
import "@vue-office/excel/lib/index.css";
|
|
|
-import pdf from "vue-pdf";
|
|
|
-import CMapReaderFactory from "vue-pdf/src/CMapReaderFactory.js";
|
|
|
+import axios from "axios";
|
|
|
import Print from "print-js";
|
|
|
export default {
|
|
|
- components: { pdf, VueOfficeExcel },
|
|
|
+ components: { VueOfficeExcel, VueOfficePdf, VueOfficeDocx },
|
|
|
props: {
|
|
|
goodsData: {
|
|
|
type: Object,
|
|
@@ -143,8 +138,7 @@ export default {
|
|
|
},
|
|
|
courseHandoutsData: {},
|
|
|
showId: null, //当前显示pdfID号
|
|
|
- activeItem: {},
|
|
|
- pdfCounts: 0
|
|
|
+ activeItem: {}
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -171,30 +165,14 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- //渲染docx
|
|
|
- docxRender(url, fileName) {
|
|
|
- axios({
|
|
|
- method: "get",
|
|
|
- responseType: "blob", // 设置响应文件格式
|
|
|
- url: url
|
|
|
- }).then(({ data }) => {
|
|
|
- let array = [
|
|
|
- document.getElementById("bodyContainer"),
|
|
|
- document.getElementById("bodyContainers")
|
|
|
- ];
|
|
|
- for (let i = 0; i < array.length; i++) {
|
|
|
- renderAsync(data, array[i]); // 渲染到页面预览
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
rendered() {},
|
|
|
errorHandler(e) {
|
|
|
- this.$message.error("表格内容不支持预览");
|
|
|
+ this.$message.error("内容不支持预览");
|
|
|
console.log("错误", e);
|
|
|
return;
|
|
|
},
|
|
|
//渲染xlsx
|
|
|
- xlsxRender(url, fileName) {
|
|
|
+ officeRender(url, fileName) {
|
|
|
axios({
|
|
|
method: "get",
|
|
|
responseType: "blob", // 设置响应文件格式
|
|
@@ -216,10 +194,6 @@ export default {
|
|
|
};
|
|
|
return false;
|
|
|
},
|
|
|
- getTable(sheetName) {
|
|
|
- var worksheet = this.workbook.Sheets[sheetName];
|
|
|
- this.excelData = xlsxs.utils.sheet_to_json(worksheet);
|
|
|
- },
|
|
|
filterNode(value, data, node) {
|
|
|
let parentNode = node.parent; // 父级node
|
|
|
let labels = [node.label]; // 当前node的名字
|
|
@@ -317,76 +291,33 @@ export default {
|
|
|
}
|
|
|
return obj;
|
|
|
},
|
|
|
- loadscroll() {
|
|
|
- if (!this.pdfCounts && this.activeItem.pdf) {
|
|
|
- if (this.activeItem.pdf >= 4) {
|
|
|
- this.pdfCounts = 4;
|
|
|
- } else {
|
|
|
- this.pdfCounts = this.activeItem.pdf;
|
|
|
- }
|
|
|
- }
|
|
|
- if (this.pdfCounts < this.activeItem.pdf) {
|
|
|
- this.pdfCounts++;
|
|
|
- } else {
|
|
|
- return;
|
|
|
- }
|
|
|
- },
|
|
|
//点击预览加载
|
|
|
loadSeePdf(item) {
|
|
|
+ this.readerResult = null;
|
|
|
console.log(item, "item");
|
|
|
if (Object.keys(item).length == 0) {
|
|
|
this.$message.error("当前选择文件不存在");
|
|
|
return;
|
|
|
}
|
|
|
- if (item.urlName.slice(item.urlName.indexOf(".") + 1) === "docx") {
|
|
|
- this.showId = item.fileId;
|
|
|
- this.activeItem = item;
|
|
|
- this.$emit("backSwitchPdfData", item);
|
|
|
- this.docxRender(this.$tools.splitImgHost(item.url));
|
|
|
- return;
|
|
|
- }
|
|
|
- if (item.urlName.slice(item.urlName.indexOf(".") + 1) === "xlsx") {
|
|
|
+ var str = item.urlName.slice(item.urlName.indexOf(".") + 1);
|
|
|
+ if (str === "docx" || str === "xlsx" || str === "pdf") {
|
|
|
this.showId = item.fileId;
|
|
|
this.activeItem = item;
|
|
|
- this.$emit("backSwitchPdfData", item);
|
|
|
- this.xlsxRender(this.$tools.splitImgHost(item.url));
|
|
|
+ this.$emit("backSwitchOfficeData", item);
|
|
|
+ this.officeRender(this.$tools.splitImgHost(item.url));
|
|
|
return;
|
|
|
}
|
|
|
- if (item.pdf) {
|
|
|
- this.showId = item.fileId;
|
|
|
- this.activeItem = item;
|
|
|
- if (item.pdf >= 4) {
|
|
|
- this.pdfCounts = 4;
|
|
|
- } else {
|
|
|
- this.pdfCounts = item.pdf;
|
|
|
- }
|
|
|
- this.$emit("backSwitchPdfData", item);
|
|
|
- return;
|
|
|
- }
|
|
|
- const loadingTask = pdf.createLoadingTask({
|
|
|
- url: this.$tools.splitImgHost(item.url),
|
|
|
- CMapReaderFactory,
|
|
|
- cMapPacked: true
|
|
|
- });
|
|
|
- loadingTask.promise
|
|
|
- .then(pdf => {
|
|
|
- item.pdf = pdf.numPages;
|
|
|
- this.showId = item.fileId;
|
|
|
- this.activeItem = item;
|
|
|
- if (item.pdf >= 4) {
|
|
|
- this.pdfCounts = 4;
|
|
|
- } else {
|
|
|
- this.pdfCounts = item.pdf;
|
|
|
- }
|
|
|
- this.$emit("backSwitchPdfData", item);
|
|
|
- })
|
|
|
- .catch(err => {});
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
+/deep/ .vue-office-pdf-wrapper {
|
|
|
+ & > canvas {
|
|
|
+ width: 100% !important;
|
|
|
+ }
|
|
|
+}
|
|
|
.el-tree {
|
|
|
background-color: #3f4449;
|
|
|
color: #fff;
|
|
@@ -408,7 +339,7 @@ export default {
|
|
|
align-items: center;
|
|
|
justify-content: space-between;
|
|
|
padding-right: 8px;
|
|
|
-
|
|
|
+
|
|
|
& > .node_label1 {
|
|
|
flex: 1;
|
|
|
width: 1px;
|
|
@@ -479,7 +410,7 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- .pdf_box {
|
|
|
+ .office_box {
|
|
|
flex: 1;
|
|
|
overflow: auto;
|
|
|
}
|