From 129fecf9a1cc53fc4d8d7ec6d7751e78571e73d0 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期四, 21 八月 2025 17:34:13 +0800
Subject: [PATCH] 出库后刷新
---
src/components/tool/file-preview.vue | 122 +++++++++++++++++++++++++---------------
1 files changed, 75 insertions(+), 47 deletions(-)
diff --git a/src/components/tool/file-preview.vue b/src/components/tool/file-preview.vue
index 37705f8..517c6b3 100644
--- a/src/components/tool/file-preview.vue
+++ b/src/components/tool/file-preview.vue
@@ -1,50 +1,42 @@
<template>
<div>
<div v-if="isImage">
- <img :src="fileUrl" alt="Image Preview" />
+ <img :src="imgUrl" alt="Image Preview" />
</div>
<div v-if="isPdf">
- <object :data="fileUrl" type="application/pdf" width="100%" height="600px">
+ <object :data="fileUrl" type="application/pdf" width="100%" height="750px">
<p>鎮ㄧ殑娴忚鍣ㄤ笉鏀寔 PDF 棰勮銆�<a :href="fileUrl">涓嬭浇 PDF 鏂囦欢</a></p>
</object>
</div>
+ <a ref="pdfLink" :href="fileUrl" target="_blank" style="display: none;"></a>
<div v-if="isDoc">
<p v-if="!isDocShow">鏂囨。鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p>
<a :href="fileUrl" v-if="!isDocShow">涓嬭浇鏂囦欢</a>
- <vue-office-docx
- :src="fileUrl"
- style="height: 100vh;"
- @rendered="renderedHandler"
- @error="errorHandler"
- />
+ <vue-office-docx v-else :src="fileUrl" style="height: 100vh;" @rendered="renderedHandler" @error="errorHandler" />
</div>
<div v-if="isXls">
<p v-if="!isDocShow">鏂囨。鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p>
<a :href="fileUrl" v-if="!isDocShow">涓嬭浇鏂囦欢</a>
- <vue-office-excel
- :src="fileUrl"
- :options="options"
- style="height: 100vh;"
- @rendered="renderedHandler"
- @error="errorHandler"
- />
+ <vue-office-excel v-else :src="fileUrl" :options="options" style="height: 100vh;" @rendered="renderedHandler"
+ @error="errorHandler" />
</div>
<div v-if="isZipOrRar">
<p>鍘嬬缉鏂囦欢鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p>
<a :href="fileUrl">涓嬭浇鏂囦欢</a>
</div>
<div v-if="isCsv">
- <p v-if="csvList.length==0">CSV 鏂囦欢鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p>
- <a :href="fileUrl" v-if="csvList.length==0">涓嬭浇鏂囦欢</a>
- <el-tabs type="border-card" v-if="csvList.length>0" tab-position="bottom">
- <el-tab-pane :label="item.sheetName" v-for="(item,index) in csvList" :key="index">
+ <p v-if="csvList.length == 0">CSV 鏂囦欢鏃犳硶鐩存帴棰勮锛岃涓嬭浇鏌ョ湅銆�</p>
+ <a :href="fileUrl" v-if="csvList.length == 0">涓嬭浇鏂囦欢</a>
+ <el-tabs type="border-card" v-if="csvList.length > 0" tab-position="bottom">
+ <el-tab-pane :label="item.sheetName" v-for="(item, index) in csvList" :key="index">
<el-table :data="item.tableData" height="75vh">
- <el-table-column :label="m.label" :prop="m.prop" v-for="(m,i) in item.column" :key="i" min-width="120px" show-overflow-tooltip>
+ <el-table-column :label="m.label" :prop="m.prop" v-for="(m, i) in item.column" :key="i" min-width="120px"
+ show-overflow-tooltip>
<template slot-scope="scope" slot="header">
<div>
- <el-tooltip :content="m.label" placement="top">
+ <el-tooltip :content="m.label" placement="top">
<div class="oneLine">
- <span>{{m.label}}</span>
+ <span>{{ m.label }}</span>
</div>
</el-tooltip>
</div>
@@ -82,70 +74,97 @@
required: true
},
},
- data(){
+ data() {
return {
- isDocShow:true,
- options:{
+ isDocShow: true,
+ options: {
xls: false, //棰勮xlsx鏂囦欢璁句负false锛涢瑙坸ls鏂囦欢璁句负true
minColLength: 0, // excel鏈�灏戞覆鏌撳灏戝垪锛屽鏋滄兂瀹炵幇xlsx鏂囦欢鍐呭鏈夊嚑鍒楋紝灏辨覆鏌撳嚑鍒楋紝鍙互灏嗘鍊艰缃负0.
minRowLength: 0, // excel鏈�灏戞覆鏌撳灏戣锛屽鏋滄兂瀹炵幇鏍规嵁xlsx瀹為檯鍑芥暟娓叉煋锛屽彲浠ュ皢姝ゅ�艰缃负0.
widthOffset: 10, //濡傛灉娓叉煋鍑烘潵鐨勭粨鏋滄劅瑙夊崟鍏冩牸瀹藉害涓嶅锛屽彲浠ュ湪榛樿娓叉煋鐨勫垪琛ㄥ搴︿笂鍐嶅姞 Npx瀹�
heightOffset: 10, //鍦ㄩ粯璁ゆ覆鏌撶殑鍒楄〃楂樺害涓婂啀鍔� Npx楂�
- beforeTransformData: (workbookData) => {return workbookData}, //搴曞眰閫氳繃exceljs鑾峰彇excel鏂囦欢鍐呭锛岄�氳繃璇ラ挬瀛愬嚱鏁帮紝鍙互瀵硅幏鍙栫殑excel鏂囦欢鍐呭杩涜淇敼锛屾瘮濡傛煇涓崟鍏冩牸鐨勬暟鎹樉绀轰笉姝g‘锛屽彲浠ュ湪姝よ嚜琛屼慨鏀规瘡涓崟鍏冩牸鐨剉alue鍊笺��
- transformData: (workbookData) => {return workbookData}, //灏嗚幏鍙栧埌鐨別xcel鏁版嵁杩涜澶勭悊涔嬪悗涓旀覆鏌撳埌椤甸潰涔嬪墠锛屽彲閫氳繃transformData瀵瑰嵆灏嗘覆鏌撶殑鏁版嵁鍙婃牱寮忚繘琛屼慨鏀癸紝姝ゆ椂姣忎釜鍗曞厓鏍肩殑text鍊煎氨鏄嵆灏嗘覆鏌撳埌椤甸潰涓婄殑鍐呭
+ beforeTransformData: (workbookData) => { return workbookData }, //搴曞眰閫氳繃exceljs鑾峰彇excel鏂囦欢鍐呭锛岄�氳繃璇ラ挬瀛愬嚱鏁帮紝鍙互瀵硅幏鍙栫殑excel鏂囦欢鍐呭杩涜淇敼锛屾瘮濡傛煇涓崟鍏冩牸鐨勬暟鎹樉绀轰笉姝g‘锛屽彲浠ュ湪姝よ嚜琛屼慨鏀规瘡涓崟鍏冩牸鐨剉alue鍊笺��
+ transformData: (workbookData) => { return workbookData }, //灏嗚幏鍙栧埌鐨別xcel鏁版嵁杩涜澶勭悊涔嬪悗涓旀覆鏌撳埌椤甸潰涔嬪墠锛屽彲閫氳繃transformData瀵瑰嵆灏嗘覆鏌撶殑鏁版嵁鍙婃牱寮忚繘琛屼慨鏀癸紝姝ゆ椂姣忎釜鍗曞厓鏍肩殑text鍊煎氨鏄嵆灏嗘覆鏌撳埌椤甸潰涓婄殑鍐呭
},
- csvList:[],//csv鏂囦欢鏁版嵁
+ csvList: [],//csv鏂囦欢鏁版嵁
+ imgUrl: ''
}
},
computed: {
isImage() {
- return /\.(jpg|jpeg|png|gif)$/i.test(this.fileUrl);
+ let state = /\.(jpg|jpeg|png|gif)$/i.test(this.fileUrl)
+ this.imgUrl = this.fileUrl
+ if (state) {
+ this.imgUrl = this.fileUrl.replaceAll('word', 'img')
+ }
+ return state;
},
isPdf() {
- return /\.pdf$/i.test(this.fileUrl);
+ let state = /\.pdf$/i.test(this.fileUrl)
+ if (state) {
+ this.$nextTick(() => {
+ this.$refs.pdfLink.click();
+ if (this.$parent.lookDialogVisible) {
+ this.$parent.lookDialogVisible = false
+ } else if (this.$parent.$parent.lookDialogVisible) {
+ this.$parent.$parent.lookDialogVisible = false
+ }
+ })
+ }
+ return state;
},
isDoc() {
return /\.(doc|docx)$/i.test(this.fileUrl);
},
- isXls(){
- return /\.(xls|xlsx)$/i.test(this.fileUrl);
+ isXls() {
+ let state = /\.(xls|xlsx)$/i.test(this.fileUrl)
+ if (state) {
+ if (/\.(xlsx)$/i.test(this.fileUrl)) {
+ this.options.xls = false
+ } else {
+ this.options.xls = true
+ }
+ }
+ return state;
},
isZipOrRar() {
return /\.(zip|rar)$/i.test(this.fileUrl);
},
isCsv() {
let state = /\.csv$/i.test(this.fileUrl)
- if(state){
+ if (state) {
this.loadCSVData();
// this.main()
}
return state;
},
isSupported() {
- return this.isImage || this.isPdf || this.isDoc || this.isZipOrRar || this.isCsv||this.isXls;
+ return this.isImage || this.isPdf || this.isDoc || this.isZipOrRar || this.isCsv || this.isXls;
}
},
- methods:{
+ methods: {
renderedHandler() {
- console.log("娓叉煋瀹屾垚")
- this.isDocShow = true
+ console.log("娓叉煋瀹屾垚")
+ this.isDocShow = true
+ this.resetStyle()
},
errorHandler() {
- console.log("娓叉煋澶辫触")
- this.isDocShow = false
+ console.log("娓叉煋澶辫触")
+ this.isDocShow = false
},
async loadCSVData() {
this.$axios.post(this.$api.insOrderPlan.preview, {
id: this.currentFile.id,
- }).then( res => {
+ }).then(res => {
let arr = res.data
- arr = arr.map(m=>{
+ arr = arr.map(m => {
let obj = {
- sheetName:m.sheetName,
- tableData:[],
- column:[]
+ sheetName: m.sheetName,
+ tableData: [],
+ column: []
}
- obj.tableData = this.formatCSVToTable(m.content.replaceAll('null',' '))
+ obj.tableData = this.formatCSVToTable(m.content.replaceAll('null', ' '))
+ // .replaceAll('MIN','=MIN').replaceAll('MAX','=MAX').replaceAll('AVERAGE','=AVERAGE')
for (let item in obj.tableData[0]) {
obj.column.push({
label: item,
@@ -155,11 +174,11 @@
return obj
})
this.csvList = arr
- }).catch( err => {
+ }).catch(err => {
console.log(err)
})
},
- formatCSVToTable(str){
+ formatCSVToTable(str) {
const result = [];
const jsonObj = str.split("\n");
let arrHeader = [];
@@ -196,6 +215,15 @@
}
return result
},
+ resetStyle() {
+ const elements = document.querySelectorAll('[style*="pt"]');
+ for (const element of elements) {
+ const style = element.getAttribute('style');
+ if (!!style) {
+ element.setAttribute('style', style.replace(/pt/g, 'px'));
+ }
+ }
+ },
}
}
</script>
--
Gitblit v1.9.3