@@ -97,6 +104,8 @@
import { authMixin } from "@/mixin/authMixin";
import LxHeader from "@/components/LxHeader";
import {AlignmentType, convertInchesToTwip, Document, HeadingLevel, Packer, Paragraph, TextRun} from "docx";
+ import * as XLSX from "xlsx";
+ import { saveAs } from "file-saver";
export default {
mixins: [authMixin],
components: {
@@ -246,87 +255,33 @@
}
},
- async exportDocx () {
- const makeText = (dayData) => {
- let children = [];
- children.push(
- new Paragraph({
- text: `${this.$moment(this.selectDate).format('YYYY年MM月DD日')}调度指令执行情况`,
- heading: HeadingLevel.HEADING_1,
- alignment: AlignmentType.CENTER,
- spacing: {
- after: 400
- }
- })
- )
+ async exportExcel(sheetName) {
+ if (this.tableData) {
+ const data = this.tableData.map(i => ([
+ this.areas.get(i.equipment.area),
+ i.equipment.name,
+ '河道处',
+ ...i._sortData.map(j => ((j.length > 0) ? j.map(k => (`${ this.$moment(k.act_start_time).format('HH:mm') } ~ ${ this.$moment(k.act_end_time).format('HH:mm') } ${ k.content || " " } ${ this.abilities.get(k.leibie) }\n`)).toString() : "")
+ )])
+ );
+ data.unshift(["所属区域","工程名称","管理单位",...this.weekName]);
+ data.unshift(["所属区域","工程名称","管理单位",...this.weekRange]);
+ const wb = XLSX.utils.book_new();
+ let ws = XLSX.utils.aoa_to_sheet(data);
+ ws["!merges"] = [{ s: { r: 0, c: 0 }, e: { r: 1, c: 0 } },{ s: { r: 0, c: 1 }, e: { r: 1, c: 1 } },{ s: { r: 0, c: 2 }, e: { r: 1, c: 2 } }]
+ ws["!cols"] = [{ wch: 30 }, { wch: 30 },{ wch: 10 },{ wch: 50 },{ wch: 50 },{ wch: 50 },{ wch: 50 },{ wch: 50 },{ wch: 50 },{ wch: 50 }]
+ XLSX.utils.book_append_sheet(wb, ws, sheetName);
+ const wbout = XLSX.write(wb, {
+ bookType: "xlsx",
+ bookSST: true,
+ type: "array",
+ });
+ saveAs(
+ new Blob([wbout], { type: "application/octet-stream" }),
+ `${sheetName}.xlsx`
+ );
}
- const document = new Document({
- sections: [
- {
- children: [
- new Paragraph({
- text: `${this.$moment(this.selectDate).format('YYYY年MM月DD日')}调度指令执行情况`,
- heading: HeadingLevel.HEADING_1,
- alignment: AlignmentType.CENTER,
- spacing: {
- after: 400
- }
- }),
- new Paragraph({
- indent: {
- firstLine: convertInchesToTwip(0.5)
- },
- spacing: {
- before: 200,
- line: 500
- },
- children: [
- new TextRun({
- text: "今日小雨转晴,北风2级,气温22℃~29℃。水情信息:8:00新塘3.06m,环城河北3.02m,觅渡桥2.99m,人民桥3.00m;16:00新塘3.03m,环城河北2.90m,觅渡桥2.92m,人民桥2.95m。",
- size: 18,
- })
- ]
- }),
- ...this.transfers.map((i, index) => (
- [
- new Paragraph({
- spacing: {
- before: 200,
- line: 400
- },
- children: [
- new TextRun({
- text: `${this.numberToChinese(index+1)}、${i.equipment_id_equipments_id_relation?.name}`,
- size: 28,
- bold: true,
- }),
- ]
- }),
- new Paragraph({
- spacing: {
- before: 200,
- line: 400
- },
- indent: {
- firstLine: convertInchesToTwip(0.5)
- },
- children: [
- new TextRun({
- text: `1、时间:${this.$moment(i.act_start_time).format('YYYY-MM-DD HH:mm')} - ${this.$moment(i.act_end_time).format('YYYY-MM-DD HH:mm')} 2、实际执行情况:${i.content}`,
- size: 18,
- })
- ]
- })
- ]
- )).flat()
- ]
- },
- ]
- })
-
- const blob = await Packer.toBlob(document)
- saveAs(blob, 'test.docx')
- }
+ },
},
created() {
this.getAbility()
diff --git a/src/views/system/components/Timeline.vue b/src/views/system/components/Timeline.vue
index 27b180f..a4d5ca0 100644
--- a/src/views/system/components/Timeline.vue
+++ b/src/views/system/components/Timeline.vue
@@ -14,7 +14,7 @@