text 导出
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { w as withInstall } from "../badge/index2.js";
|
||||
import { defineComponent, useSlots, ref, computed, resolveComponent, openBlock, createElementBlock, Fragment, createElementVNode, normalizeStyle, normalizeClass, withModifiers, renderList, createCommentVNode, unref, createBlock, createVNode, mergeProps, isRef, createTextVNode, toDisplayString, withCtx, renderSlot, withKeys, createSlots, watch, withDirectives, vShow, nextTick, onMounted, onBeforeUnmount } from "vue";
|
||||
import { _ as _sfc_main$2E, a as _sfc_main$5 } from "../checkbox/index2.js";
|
||||
import { u as utils, w as writeFileSync } from "../_chunks/xlsx/index.js";
|
||||
import { _ as _sfc_main$5 } from "../checkbox/index2.js";
|
||||
import { _ as _sfc_main$a } from "../dropdown/index2.js";
|
||||
import { _ as _sfc_main$b } from "../empty/index2.js";
|
||||
import { _ as _sfc_main$2W } from "../_chunks/@layui/index.js";
|
||||
import { _ as _sfc_main$6 } from "../tooltip/index2.js";
|
||||
import { _ as _sfc_main$4 } from "../radio/index2.js";
|
||||
import { _ as _export_sfc } from "../dropdownMenu/index2.js";
|
||||
@@ -303,7 +305,7 @@ const _sfc_main$3 = defineComponent({
|
||||
style: normalizeStyle({ "margin-right": __props.currentIndentSize + "px" })
|
||||
}, null, 4)) : createCommentVNode("", true),
|
||||
__props.expandSpace && !__props.data[__props.childrenColumnName] && !unref(slot).expand && columnIndex === __props.expandIndex ? (openBlock(), createElementBlock("span", _hoisted_2$2)) : createCommentVNode("", true),
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2E), {
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2W), {
|
||||
key: 2,
|
||||
class: "layui-table-cell-expand-icon",
|
||||
type: unref(expandIconType),
|
||||
@@ -341,7 +343,7 @@ const _sfc_main$3 = defineComponent({
|
||||
style: normalizeStyle({ "margin-right": __props.currentIndentSize + "px" })
|
||||
}, null, 4)) : createCommentVNode("", true),
|
||||
__props.expandSpace && !__props.data[__props.childrenColumnName] && !unref(slot).expand && columnIndex === __props.expandIndex ? (openBlock(), createElementBlock("span", _hoisted_4$2)) : createCommentVNode("", true),
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2E), {
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2W), {
|
||||
key: 2,
|
||||
class: "layui-table-cell-expand-icon",
|
||||
type: unref(expandIconType),
|
||||
@@ -380,7 +382,7 @@ const _sfc_main$3 = defineComponent({
|
||||
style: normalizeStyle({ "margin-right": __props.currentIndentSize + "px" })
|
||||
}, null, 4)) : createCommentVNode("", true),
|
||||
__props.expandSpace && !__props.data[__props.childrenColumnName] && !unref(slot).expand && columnIndex === __props.expandIndex ? (openBlock(), createElementBlock("span", _hoisted_6$2)) : createCommentVNode("", true),
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2E), {
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2W), {
|
||||
key: 2,
|
||||
class: "layui-table-cell-expand-icon",
|
||||
type: unref(expandIconType),
|
||||
@@ -423,7 +425,7 @@ const _sfc_main$3 = defineComponent({
|
||||
style: normalizeStyle({ "margin-right": __props.currentIndentSize + "px" })
|
||||
}, null, 4)) : createCommentVNode("", true),
|
||||
__props.expandSpace && !__props.data[__props.childrenColumnName] && !unref(slot).expand && columnIndex === __props.expandIndex ? (openBlock(), createElementBlock("span", _hoisted_8$2)) : createCommentVNode("", true),
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2E), {
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2W), {
|
||||
key: 2,
|
||||
class: "layui-table-cell-expand-icon",
|
||||
type: unref(expandIconType),
|
||||
@@ -483,7 +485,7 @@ const _sfc_main$3 = defineComponent({
|
||||
style: normalizeStyle({ "margin-right": __props.currentIndentSize + "px" })
|
||||
}, null, 4)) : createCommentVNode("", true),
|
||||
__props.expandSpace && !__props.data[__props.childrenColumnName] && !unref(slot).expand && columnIndex === __props.expandIndex ? (openBlock(), createElementBlock("span", _hoisted_10$2)) : createCommentVNode("", true),
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2E), {
|
||||
(unref(slot).expand || __props.data[__props.childrenColumnName]) && columnIndex === __props.expandIndex ? (openBlock(), createBlock(unref(_sfc_main$2W), {
|
||||
key: 2,
|
||||
class: "layui-table-cell-expand-icon",
|
||||
type: unref(expandIconType),
|
||||
@@ -645,10 +647,10 @@ const _sfc_main$2 = defineComponent({
|
||||
onChange: change
|
||||
}, {
|
||||
prev: withCtx(() => [
|
||||
createVNode(unref(_sfc_main$2E), { type: "layui-icon-left" })
|
||||
createVNode(unref(_sfc_main$2W), { type: "layui-icon-left" })
|
||||
]),
|
||||
next: withCtx(() => [
|
||||
createVNode(unref(_sfc_main$2E), { type: "layui-icon-right" })
|
||||
createVNode(unref(_sfc_main$2W), { type: "layui-icon-right" })
|
||||
]),
|
||||
_: 1
|
||||
}, 8, ["total", "show-page", "show-skip", "show-limit", "show-count", "show-refresh", "limits", "theme", "pages", "count", "modelValue", "limit"]);
|
||||
@@ -1171,61 +1173,51 @@ const _sfc_main = defineComponent({
|
||||
window.location.reload();
|
||||
document.body.innerHTML = oldContent;
|
||||
};
|
||||
const exportData = () => {
|
||||
var tableStr = ``;
|
||||
for (let tableHeadColumn of tableHeadColumns.value) {
|
||||
tableStr += "<tr>";
|
||||
for (let column of tableHeadColumn) {
|
||||
tableStr += `<td colspan=${column.colspan} rowspan=${column.rowspan}>${column.title}</td>`;
|
||||
function exportElcel(list, header, name) {
|
||||
const ws = utils.json_to_sheet(list, {
|
||||
header,
|
||||
skipHeader: true
|
||||
});
|
||||
console.log(ws);
|
||||
var tmpWB = {
|
||||
SheetNames: ["sheet"],
|
||||
Sheets: {
|
||||
sheet: Object.assign({}, ws, {})
|
||||
}
|
||||
};
|
||||
writeFileSync(tmpWB, name + ".xlsx", {
|
||||
bookType: "xlsx",
|
||||
type: "binary"
|
||||
});
|
||||
}
|
||||
const exportData = () => {
|
||||
let head = [];
|
||||
let list = [];
|
||||
let title = {};
|
||||
for (let tableHeadColumn of tableHeadColumns.value) {
|
||||
for (let column of tableHeadColumn) {
|
||||
title[column.key] = column.title;
|
||||
head.push(column.key);
|
||||
}
|
||||
tableStr += "</tr>";
|
||||
}
|
||||
list.push(title);
|
||||
tableDataSource.value.forEach((item, rowIndex) => {
|
||||
tableStr += "<tr>";
|
||||
let info = {};
|
||||
tableBodyColumns.value.forEach((tableColumn, columnIndex) => {
|
||||
Object.keys(item).forEach((name) => {
|
||||
if (tableColumn.key === name) {
|
||||
const rowColSpan = props.spanMethod(item, tableColumn, rowIndex, columnIndex);
|
||||
const rowspan = rowColSpan ? rowColSpan[0] : 1;
|
||||
const colspan = rowColSpan ? rowColSpan[1] : 1;
|
||||
if (rowspan != 0 && colspan != 0) {
|
||||
tableStr += `<td colspan=${colspan} rowspan=${rowspan}${tableColumn.valueType == "str" ? " x:str" : ""}>${item[name] || ""}</td>`;
|
||||
}
|
||||
info[name] = item[name];
|
||||
}
|
||||
});
|
||||
if (tableColumn.type == "number") {
|
||||
const rowColSpan = props.spanMethod(item, tableColumn, rowIndex, columnIndex);
|
||||
const rowspan = rowColSpan ? rowColSpan[0] : 1;
|
||||
const colspan = rowColSpan ? rowColSpan[1] : 1;
|
||||
if (rowspan != 0 && colspan != 0) {
|
||||
tableStr += `<td colspan=${colspan} rowspan=${rowspan}>${rowIndex + 1}</td>`;
|
||||
}
|
||||
info[item.key] = rowIndex + 1;
|
||||
}
|
||||
});
|
||||
tableStr += "</tr>";
|
||||
list.push(info);
|
||||
});
|
||||
var worksheet = "Sheet1";
|
||||
var uri = "data:application/vnd.ms-excel;base64,";
|
||||
var exportTemplate = `<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel"
|
||||
xmlns="http://www.w3.org/TR/REC-html40">
|
||||
<head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
|
||||
<x:Name>${worksheet}</x:Name>
|
||||
<x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
|
||||
</x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
|
||||
</head>
|
||||
<body>
|
||||
<table syle="table-layout: fixed;word-wrap: break-word; word-break: break-all;">${tableStr}</table>
|
||||
</body>
|
||||
</html>`;
|
||||
let a = document.createElement("a");
|
||||
a.href = uri + base64(exportTemplate);
|
||||
a.download = (props.download || "\u4E0B\u8F7D\u6587\u4EF6") + ".xls";
|
||||
a.click();
|
||||
exportElcel(list, head, props.download || "\u4E0B\u8F7D\u6587\u4EF6");
|
||||
return;
|
||||
};
|
||||
function base64(s2) {
|
||||
return window.btoa(unescape(encodeURIComponent(s2)));
|
||||
}
|
||||
const sortTable = (e, key, sort, issoul = false) => {
|
||||
let currentSort = e.target.parentNode.getAttribute("lay-sort");
|
||||
if (sort === "desc") {
|
||||
|
||||
Reference in New Issue
Block a user