Commit 5793e3cf authored by zhanglw's avatar zhanglw

excel在线编辑样式

parent ba093436
...@@ -62,7 +62,8 @@ ...@@ -62,7 +62,8 @@
<!-- 表单渲染 --> <!-- 表单渲染 -->
<el-dialog append-to-body :close-on-click-modal="false" :before-close="cancelForm" :visible.sync="visible" :title="openFile.fileName" width="1600px" top="1vh"> <el-dialog append-to-body :close-on-click-modal="false" :before-close="cancelForm" :visible.sync="visible" :title="openFile.fileName" width="1600px" top="1vh">
<div v-if="openFile.isLoading" style="width: 100%;text-align: center">正在读取文件...</div> <div v-if="openFile.isLoading" style="width: 100%;text-align: center">正在读取文件...</div>
<div id="x-spreadsheet-excel"></div> <!-- <div id="x-spreadsheet-excel"></div>-->
<excel-spread-sheet ref="ExcelSpreadSheet" SheetName="sheet1" :ColumnWidth="300" style="width:100%;height:80vh"></excel-spread-sheet>
<div slot="footer" class="dialog-footer" style="text-align: center"> <div slot="footer" class="dialog-footer" style="text-align: center">
<el-button @click="cancelForm">关闭</el-button> <el-button @click="cancelForm">关闭</el-button>
<el-button type="primary" @click="updataEcxel">保存</el-button> <el-button type="primary" @click="updataEcxel">保存</el-button>
...@@ -118,11 +119,14 @@ import Spreadsheet from "x-data-spreadsheet"; ...@@ -118,11 +119,14 @@ import Spreadsheet from "x-data-spreadsheet";
import 'x-data-spreadsheet/dist/locale/zh-cn'; import 'x-data-spreadsheet/dist/locale/zh-cn';
import {Tools, HttpReq, Dates} from '@/assets/js/common.js'; import {Tools, HttpReq, Dates} from '@/assets/js/common.js';
import ExcelSpreadSheet from "./excelSpreadSheet.vue";
export default { export default {
name: 'visitPeople', components: { ExcelSpreadSheet },
name: 'mineFile',
data() { data() {
return { return {
colors: [{color: '#f56c6c', percentage: 20}, {color: '#e6a23c', percentage: 40}, {color: '#5cb87a', percentage: 60}, {color: '#1989fa', percentage: 80}, {color: '#6f7ad3', percentage: 100}],
title: '', title: '',
fileUploadApi: '', fileUploadApi: '',
headers: {'Authorization': getToken()}, headers: {'Authorization': getToken()},
...@@ -138,7 +142,7 @@ export default { ...@@ -138,7 +142,7 @@ export default {
total: 0, total: 0,
tableData: [], tableData: [],
openFile: { openFile: {
fileName: '', fileName: 'excel',
isLoading: false, isLoading: false,
percentage: 0 percentage: 0
}, },
...@@ -157,6 +161,9 @@ export default { ...@@ -157,6 +161,9 @@ export default {
}) })
}, },
methods: { methods: {
loadExcelFile(e) {
this.file = e.target.files[0]
},
openLog(item) { openLog(item) {
this.logVisible = true this.logVisible = true
HttpReq.truckDispatching.scQueryByUrl({url:item.url}).then((res) => { HttpReq.truckDispatching.scQueryByUrl({url:item.url}).then((res) => {
...@@ -272,9 +279,22 @@ export default { ...@@ -272,9 +279,22 @@ export default {
reader.readAsArrayBuffer(blob); reader.readAsArrayBuffer(blob);
}); });
}, },
arrayBufferToBase64(buffer) {
let binary = '';
let bytes = new Uint8Array( buffer );
let len = bytes.byteLength;
for (let i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
},
updataEcxel() { updataEcxel() {
const exceljsWorkbook = this.$refs.ExcelSpreadSheet.dataXstoEjs()
exceljsWorkbook.xlsx.writeBuffer().then((buffer) => {
// 将ArrayBuffer转换为Base64字符串
const base64 = this.arrayBufferToBase64(buffer);
HttpReq.truckDispatching.scUploadExcelByBase64({ HttpReq.truckDispatching.scUploadExcelByBase64({
base64: XLSX.write(this.xtos(this.xs.getData()), {bookType: 'xlsx', type: 'base64'}), base64: base64,
url: this.openFile.url url: this.openFile.url
}).then((res) => { }).then((res) => {
this.$notify({ this.$notify({
...@@ -286,6 +306,7 @@ export default { ...@@ -286,6 +306,7 @@ export default {
this.cancelForm() this.cancelForm()
} }
}) })
});
}, },
viewTable(item) { viewTable(item) {
this.openFile = item this.openFile = item
...@@ -304,23 +325,8 @@ export default { ...@@ -304,23 +325,8 @@ export default {
this.reconnect(); this.reconnect();
}, 15000); }, 15000);
HttpReq.truckDispatching.downloadExcelOrFbx({url: item.url, type: this.query.type}).then((res) => { HttpReq.truckDispatching.downloadExcelOrFbx({url: item.url, type: this.query.type}).then((res) => {
if(!this.xs){
Spreadsheet.locale('zh-cn');
this.xs = new Spreadsheet("#x-spreadsheet-excel", {
view:{
width: () =>{return 1600},
height: () =>{return 800}
},
style: {
align: 'center',
valign: 'middle',
}
})
}
this.blobToArrayBuffer(res).then(arrayBuffer => { this.blobToArrayBuffer(res).then(arrayBuffer => {
// 外部引用sheetjs提供全局变量XLSX this.$refs.ExcelSpreadSheet.loadExcelFileStream(arrayBuffer)
let wb = XLSX.read(arrayBuffer)
this.xs.loadData(this.stox(wb))
}) })
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment