UNPKG

vxe-table

Version:

A PC-end table component based on Vxe UI, supporting copy-paste, data pivot table, and high-performance virtual list table solution.

645 lines (644 loc) • 32.8 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var export_panel_exports = {}; __export(export_panel_exports, { default: () => export_panel_default }); module.exports = __toCommonJS(export_panel_exports); var import_vue = require("vue"); var import_comp = require("../../../ui/src/comp"); var import_core = require("@vxe-ui/core"); var import_xe_utils = __toESM(require("xe-utils")); var import_utils = require("../../../ui/src/utils"); var import_log = require("../../../ui/src/log"); const { errLog } = (0, import_log.createComponentLog)("table"); const { getI18n, getIcon, renderEmptyElement } = import_core.VxeUI; var export_panel_default = ( /* define-vxe-component start */ (0, import_comp.defineVxeComponent)({ name: "VxeTableExportPanel", props: { defaultOptions: { type: Object, default: () => ({}) }, storeData: { type: Object, default: () => ({}) } }, setup(props) { const VxeUIModalComponent = import_core.VxeUI.getComponent("VxeModal"); const VxeUIButtonComponent = import_core.VxeUI.getComponent("VxeButton"); const VxeUISelectComponent = import_core.VxeUI.getComponent("VxeSelect"); const VxeUIInputComponent = import_core.VxeUI.getComponent("VxeInput"); const VxeUICheckboxComponent = import_core.VxeUI.getComponent("VxeCheckbox"); const $xeTable = (0, import_vue.inject)("$xeTable", {}); const { computeExportOpts, computePrintOpts } = $xeTable.getComputeMaps(); const reactData = (0, import_vue.reactive)({ isAll: false, isIndeterminate: false, loading: false }); const xButtonConfirm = (0, import_vue.ref)(); const xInputFilename = (0, import_vue.ref)(); const xInputSheetname = (0, import_vue.ref)(); const computeColWidthModeOptions = (0, import_vue.computed)(() => { return [ { value: "", label: getI18n("vxe.export.wdModes.default") }, { value: "auto", label: getI18n("vxe.export.wdModes.auto") }, { value: "scale", label: getI18n("vxe.export.wdModes.scale") } ]; }); const computeCheckedAll = (0, import_vue.computed)(() => { const { storeData } = props; return storeData.columns.every((column) => column.checked); }); const computeShowSheet = (0, import_vue.computed)(() => { const { defaultOptions } = props; return ["html", "xml", "xlsx", "pdf"].indexOf(defaultOptions.type) > -1; }); const computeSupportMerge = (0, import_vue.computed)(() => { const { storeData, defaultOptions } = props; return !defaultOptions.original && defaultOptions.mode === "current" && (storeData.isPrint || ["html", "xlsx"].indexOf(defaultOptions.type) > -1); }); const computeSupportStyle = (0, import_vue.computed)(() => { const { defaultOptions } = props; return !defaultOptions.original && ["xlsx"].indexOf(defaultOptions.type) > -1; }); const handleOptionCheck = (column) => { const { storeData } = props; const matchObj = import_xe_utils.default.findTree(storeData.columns, (item) => item === column); if (matchObj && matchObj.parent) { const { parent } = matchObj; if (parent.children && parent.children.length) { parent.checked = parent.children.every((column2) => column2.checked); parent.halfChecked = !parent.checked && parent.children.some((column2) => column2.checked || column2.halfChecked); handleOptionCheck(parent); } } }; const checkStatus = () => { const { storeData } = props; const columns = storeData.columns; reactData.isAll = columns.every((column) => column.disabled || column.checked); reactData.isIndeterminate = !reactData.isAll && columns.some((column) => !column.disabled && (column.checked || column.halfChecked)); }; const changeOption = (column) => { const isChecked = !column.checked; import_xe_utils.default.eachTree([column], (item) => { item.checked = isChecked; item.halfChecked = false; }); handleOptionCheck(column); checkStatus(); }; const allColumnEvent = () => { const { storeData } = props; const isAll = !reactData.isAll; import_xe_utils.default.eachTree(storeData.columns, (column) => { if (!column.disabled) { column.checked = isAll; column.halfChecked = false; } }); reactData.isAll = isAll; checkStatus(); }; const showEvent = () => { (0, import_vue.nextTick)(() => { const filenameInp = xInputFilename.value; const sheetnameInp = xInputSheetname.value; const confirmBtn = xButtonConfirm.value; const targetElem = filenameInp || sheetnameInp || confirmBtn; if (targetElem) { targetElem.focus(); } }); checkStatus(); }; const getExportOption = () => { const { storeData, defaultOptions } = props; const { hasMerge, columns } = storeData; const checkedAll = computeCheckedAll.value; const supportMerge = computeSupportMerge.value; const expColumns = import_xe_utils.default.searchTree(columns, (column) => column.checked, { children: "children", mapChildren: "_children", original: true }); return Object.assign({}, defaultOptions, { _columns: expColumns, isMerge: hasMerge && supportMerge && checkedAll ? defaultOptions.isMerge : false }); }; const printEvent = () => { const { storeData } = props; const printOpts = computePrintOpts.value; storeData.visible = false; $xeTable.print(Object.assign({}, printOpts, getExportOption())); }; const exportEvent = () => { const { storeData } = props; const exportOpts = computeExportOpts.value; reactData.loading = true; $xeTable.exportData(Object.assign({}, exportOpts, getExportOption())).then(() => { reactData.loading = false; storeData.visible = false; }).catch(() => { reactData.loading = false; }); }; const cancelEvent = () => { const { storeData } = props; storeData.visible = false; }; const confirmEvent = () => { const { storeData } = props; if (storeData.isPrint) { printEvent(); } else { exportEvent(); } }; const renderVN = () => { const $xeGrid = $xeTable.xeGrid; const $xeGantt = $xeTable.xeGantt; const { defaultOptions, storeData } = props; const { isAll: isAllChecked, isIndeterminate: isAllIndeterminate } = reactData; const { hasTree, hasRowGroup, hasMerge, isPrint, hasColgroup, columns } = storeData; const { isHeader } = defaultOptions; const colVNs = []; const exportOpts = computeExportOpts.value; const printOpts = computePrintOpts.value; const modelOptions = (isPrint ? printOpts : exportOpts).modelOptions || {}; const settingOptions = (isPrint ? printOpts : exportOpts).settingOptions || {}; const checkedAll = computeCheckedAll.value; const showSheet = computeShowSheet.value; const supportMerge = computeSupportMerge.value; const supportStyle = computeSupportStyle.value; const colWidthModeOptions = computeColWidthModeOptions.value; const slots = defaultOptions.slots || {}; const topSlot = slots.top; const bottomSlot = slots.bottom; const defaultSlot = slots.default; const footerSlot = slots.footer; const parameterSlot = slots.parameter; import_xe_utils.default.eachTree(columns, (column) => { const colTitle = (0, import_utils.formatText)(column.getTitle(), 1); const isColGroup = column.children && column.children.length; const isChecked = column.checked; const indeterminate = column.halfChecked; const isHtml = column.type === "html"; colVNs.push( (0, import_vue.h)( "li", { key: column.id, class: [ "vxe-table-export--panel-column-option", `level--${column.level}`, { "is--group": isColGroup, "is--checked": isChecked, "is--indeterminate": indeterminate, "is--disabled": column.disabled } ], title: isHtml ? "" : colTitle, onClick: () => { if (!column.disabled) { changeOption(column); } } }, [ (0, import_vue.h)("span", { class: ["vxe-checkbox--icon", indeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED] }), isHtml ? (0, import_vue.h)("span", { key: "1", class: "vxe-checkbox--label", innerHTML: colTitle }) : (0, import_vue.h)( "span", { key: "0", class: "vxe-checkbox--label" }, colTitle ) ] ) ); }); return VxeUIModalComponent ? (0, import_vue.h)( VxeUIModalComponent, { id: "VXE_EXPORT_MODAL", modelValue: storeData.visible, title: (0, import_utils.getDefaultConfig)(modelOptions.title, getI18n(isPrint ? "vxe.export.printTitle" : "vxe.export.expTitle")), className: "vxe-table-export-popup-wrapper" + (modelOptions.className ? ` ${modelOptions.className}` : ""), width: modelOptions.width || 660, height: modelOptions.height, minWidth: modelOptions.minWidth || 500, minHeight: modelOptions.minHeight || 400, mask: (0, import_utils.getDefaultConfig)(modelOptions.mask, true), lockView: (0, import_utils.getDefaultConfig)(modelOptions.lockView, true), showFooter: (0, import_utils.getDefaultConfig)(modelOptions.showFooter, true), escClosable: (0, import_utils.getDefaultConfig)(modelOptions.escClosable, true), maskClosable: (0, import_utils.getDefaultConfig)(modelOptions.maskClosable, true), position: modelOptions.position, fullscreen: modelOptions.fullscreen, remember: modelOptions.remember, showMinimize: modelOptions.showMinimize, showMaximize: (0, import_utils.getDefaultConfig)(modelOptions.showMaximize, true), resize: (0, import_utils.getDefaultConfig)(modelOptions.resize, true), loading: reactData.loading, "onUpdate:modelValue"(value) { storeData.visible = value; }, onShow: showEvent }, { default: () => { const params = { $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, options: defaultOptions, columns, params: defaultOptions.params }; const hasEmptyData = defaultOptions.mode === "empty"; return (0, import_vue.h)( "div", { class: "vxe-table-export--panel" }, [ topSlot ? (0, import_vue.h)( "div", { class: "vxe-table-export--panel-top" }, $xeTable.callSlot(topSlot, params) ) : renderEmptyElement($xeTable), (0, import_vue.h)( "div", { class: "vxe-table-export--panel-body" }, defaultSlot ? $xeTable.callSlot(defaultSlot, params) : [ (0, import_vue.h)( "table", { class: "vxe-table-export--panel-table", cellspacing: 0, cellpadding: 0, border: 0 }, [ (0, import_vue.h)("tbody", [ [ isPrint || settingOptions.showFileName === false ? renderEmptyElement($xeTable) : (0, import_vue.h)("tr", [ (0, import_vue.h)("td", getI18n("vxe.export.expName")), (0, import_vue.h)("td", [ VxeUIInputComponent ? (0, import_vue.h)(VxeUIInputComponent, { ref: xInputFilename, modelValue: defaultOptions.filename, type: "text", clearable: true, placeholder: getI18n("vxe.export.expNamePlaceholder"), "onUpdate:modelValue"(value) { defaultOptions.filename = value; } }) : renderEmptyElement($xeTable) ]) ]), isPrint || settingOptions.showType === false ? renderEmptyElement($xeTable) : (0, import_vue.h)("tr", [ (0, import_vue.h)("td", getI18n("vxe.export.expType")), (0, import_vue.h)("td", [ VxeUISelectComponent ? (0, import_vue.h)(VxeUISelectComponent, { modelValue: defaultOptions.type, options: storeData.typeList, "onUpdate:modelValue"(value) { defaultOptions.type = value; } }) : renderEmptyElement($xeTable) ]) ]), (isPrint || showSheet) && settingOptions.showSheet !== false ? (0, import_vue.h)("tr", [ (0, import_vue.h)("td", getI18n("vxe.export.expSheetName")), (0, import_vue.h)("td", [ VxeUIInputComponent ? (0, import_vue.h)(VxeUIInputComponent, { ref: xInputSheetname, modelValue: defaultOptions.sheetName, type: "text", clearable: true, placeholder: getI18n("vxe.export.expSheetNamePlaceholder"), "onUpdate:modelValue"(value) { defaultOptions.sheetName = value; } }) : renderEmptyElement($xeTable) ]) ]) : renderEmptyElement($xeTable), settingOptions.showMode === false ? renderEmptyElement($xeTable) : (0, import_vue.h)("tr", [ (0, import_vue.h)("td", getI18n("vxe.export.expMode")), (0, import_vue.h)("td", [ VxeUISelectComponent ? (0, import_vue.h)(VxeUISelectComponent, { modelValue: defaultOptions.mode, options: storeData.modeList.map((item) => { return { value: item.value, label: getI18n(item.label) }; }), "onUpdate:modelValue"(value) { defaultOptions.mode = value; } }) : renderEmptyElement($xeTable) ]) ]), settingOptions.showColumn === false ? renderEmptyElement($xeTable) : (0, import_vue.h)("tr", [ (0, import_vue.h)("td", [getI18n("vxe.export.expColumn")]), (0, import_vue.h)("td", [ (0, import_vue.h)( "div", { class: "vxe-table-export--panel-column" }, [ (0, import_vue.h)( "ul", { class: "vxe-table-export--panel-column-header" }, [ (0, import_vue.h)( "li", { class: [ "vxe-table-export--panel-column-option", { "is--checked": isAllChecked, "is--indeterminate": isAllIndeterminate } ], title: getI18n("vxe.table.allTitle"), onClick: allColumnEvent }, [ (0, import_vue.h)("span", { class: ["vxe-checkbox--icon", isAllIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isAllChecked ? getIcon().TABLE_CHECKBOX_CHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED] }), (0, import_vue.h)( "span", { class: "vxe-checkbox--label" }, getI18n("vxe.export.expCurrentColumn") ) ] ) ] ), (0, import_vue.h)( "ul", { class: "vxe-table-export--panel-column-body" }, colVNs ) ] ) ]) ]), isPrint && settingOptions.showWidthMode !== false ? (0, import_vue.h)("tr", [ (0, import_vue.h)("td", getI18n("vxe.export.widthMode")), (0, import_vue.h)("td", [ VxeUISelectComponent ? (0, import_vue.h)(VxeUISelectComponent, { modelValue: defaultOptions.widthMode, options: colWidthModeOptions, "onUpdate:modelValue"(value) { defaultOptions.widthMode = value; } }) : renderEmptyElement($xeTable) ]) ]) : renderEmptyElement($xeTable), settingOptions.showParameter === false ? renderEmptyElement($xeTable) : (0, import_vue.h)("tr", [ (0, import_vue.h)("td", getI18n("vxe.export.expOpts")), parameterSlot ? (0, import_vue.h)("td", [ (0, import_vue.h)( "div", { class: "vxe-table-export--panel-option-row" }, $xeTable.callSlot(parameterSlot, params) ) ]) : (0, import_vue.h)("td", [ (0, import_vue.h)( "div", { class: "vxe-table-export--panel-option-row" }, VxeUICheckboxComponent ? [ (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: hasEmptyData || isHeader, disabled: hasEmptyData, title: getI18n("vxe.export.expHeaderTitle"), content: getI18n("vxe.export.expOptHeader"), "onUpdate:modelValue"(value) { defaultOptions.isHeader = value; } }), (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: defaultOptions.isFooter, disabled: !storeData.hasFooter, title: getI18n("vxe.export.expFooterTitle"), content: getI18n("vxe.export.expOptFooter"), "onUpdate:modelValue"(value) { defaultOptions.isFooter = value; } }), (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: isHeader ? defaultOptions.isTitle : false, disabled: !isHeader, title: getI18n("vxe.export.expTitleTitle"), content: getI18n("vxe.export.expOptTitle"), "onUpdate:modelValue"(value) { defaultOptions.isTitle = value; } }), (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: isHeader && hasColgroup && supportMerge ? defaultOptions.isColgroup : false, title: getI18n("vxe.export.expColgroupTitle"), disabled: !isHeader || !hasColgroup || !supportMerge, content: getI18n("vxe.export.expOptColgroup"), "onUpdate:modelValue"(value) { defaultOptions.isColgroup = value; } }) ] : [] ), (0, import_vue.h)( "div", { class: "vxe-table-export--panel-option-row" }, VxeUICheckboxComponent ? [ (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: hasEmptyData ? false : defaultOptions.original, disabled: hasEmptyData, title: getI18n("vxe.export.expOriginalTitle"), content: getI18n("vxe.export.expOptOriginal"), "onUpdate:modelValue"(value) { defaultOptions.original = value; } }), (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: hasMerge && supportMerge && checkedAll ? defaultOptions.isMerge : false, title: getI18n("vxe.export.expMergeTitle"), disabled: hasEmptyData || !hasMerge || !supportMerge || !checkedAll, content: getI18n("vxe.export.expOptMerge"), "onUpdate:modelValue"(value) { defaultOptions.isMerge = value; } }), isPrint ? renderEmptyElement($xeTable) : (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: supportStyle ? defaultOptions.useStyle : false, disabled: !supportStyle, title: getI18n("vxe.export.expUseStyleTitle"), content: getI18n("vxe.export.expOptUseStyle"), "onUpdate:modelValue"(value) { defaultOptions.useStyle = value; } }) ] : [] ), (0, import_vue.h)( "div", { class: "vxe-table-export--panel-option-row" }, VxeUICheckboxComponent ? [ (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: hasTree ? defaultOptions.isTreeAllExpanded : false, disabled: hasEmptyData || !hasTree, title: getI18n("vxe.export.expTreeAllExpandTitle"), content: getI18n("vxe.export.expOptTreeAllExpand"), "onUpdate:modelValue"(value) { defaultOptions.isTreeAllExpanded = value; } }), (0, import_vue.h)(VxeUICheckboxComponent, { modelValue: hasRowGroup ? defaultOptions.isRowGroupAllExpanded : false, disabled: hasEmptyData || !hasRowGroup, title: getI18n("vxe.export.expRowGroupAllExpandTitle"), content: getI18n("vxe.export.expOptRowGroupAllExpand"), "onUpdate:modelValue"(value) { defaultOptions.isRowGroupAllExpanded = value; } }) ] : [] ) ]) ]) ] ]) ] ) ] ), bottomSlot ? (0, import_vue.h)( "div", { class: "vxe-table-export--panel-bottom" }, $xeTable.callSlot(bottomSlot, params) ) : renderEmptyElement($xeTable) ] ); }, footer() { const params = { $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt, options: defaultOptions, columns, params: defaultOptions.params }; return (0, import_vue.h)( "div", { class: "vxe-table-export--panel-footer" }, footerSlot ? $xeTable.callSlot(footerSlot, params) : [ (0, import_vue.h)( "div", { class: "vxe-table-export--panel-btns" }, [ VxeUIButtonComponent ? (0, import_vue.h)(VxeUIButtonComponent, { content: getI18n("vxe.export.expCancel"), onClick: cancelEvent }) : renderEmptyElement($xeTable), VxeUIButtonComponent ? (0, import_vue.h)(VxeUIButtonComponent, { ref: xButtonConfirm, status: "primary", content: getI18n(isPrint ? "vxe.export.expPrint" : "vxe.export.expConfirm"), onClick: confirmEvent }) : renderEmptyElement($xeTable) ] ) ] ); } } ) : renderEmptyElement($xeTable); }; (0, import_vue.nextTick)(() => { if (!VxeUIModalComponent) { errLog("vxe.error.reqComp", ["vxe-modal"]); } if (!VxeUIButtonComponent) { errLog("vxe.error.reqComp", ["vxe-button"]); } if (!VxeUISelectComponent) { errLog("vxe.error.reqComp", ["vxe-select"]); } if (!VxeUIInputComponent) { errLog("vxe.error.reqComp", ["vxe-input"]); } if (!VxeUICheckboxComponent) { errLog("vxe.error.reqComp", ["vxe-checkbox"]); } }); return renderVN; } }) );