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.
311 lines (310 loc) • 13.2 kB
JavaScript
;
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 import_panel_exports = {};
__export(import_panel_exports, {
default: () => import_panel_default
});
module.exports = __toCommonJS(import_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 import_panel_default = (
/* define-vxe-component start */
(0, import_comp.defineVxeComponent)({
name: "VxeTableImportPanel",
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 $xeTable = (0, import_vue.inject)("$xeTable", {});
const { computeImportOpts } = $xeTable.getComputeMaps();
const reactData = (0, import_vue.reactive)({
loading: false
});
const refFileBtn = (0, import_vue.ref)();
const computeSelectName = (0, import_vue.computed)(() => {
const { storeData } = props;
return `${storeData.filename}.${storeData.type}`;
});
const computeHasFile = (0, import_vue.computed)(() => {
const { storeData } = props;
return storeData.file && storeData.type;
});
const computeParseTypeLabel = (0, import_vue.computed)(() => {
const { storeData } = props;
const { type, typeList } = storeData;
if (type) {
const selectItem = import_xe_utils.default.find(typeList, (item) => type === item.value);
return `${selectItem ? selectItem.label : "*.*"}`;
}
return `*.${typeList.map((item) => item.value).join(", *.")}`;
});
const clearFileEvent = () => {
const { storeData } = props;
Object.assign(storeData, {
filename: "",
sheetName: "",
type: ""
});
};
const selectFileEvent = () => {
const { storeData, defaultOptions } = props;
$xeTable.readFile(defaultOptions).then((params) => {
const { file } = params;
Object.assign(storeData, (0, import_utils.parseFile)(file), { file });
}).catch(() => {
});
};
const showEvent = () => {
(0, import_vue.nextTick)(() => {
const targetElem = refFileBtn.value;
if (targetElem) {
targetElem.focus();
}
});
};
const cancelEvent = () => {
const { storeData } = props;
storeData.visible = false;
};
const importEvent = () => {
const { storeData, defaultOptions } = props;
const importOpts = computeImportOpts.value;
reactData.loading = true;
$xeTable.importByFile(storeData.file, Object.assign({}, importOpts, defaultOptions)).then(() => {
reactData.loading = false;
storeData.visible = false;
}).catch(() => {
reactData.loading = false;
});
};
const renderVN = () => {
const $xeGrid = $xeTable.xeGrid;
const $xeGantt = $xeTable.xeGantt;
const { defaultOptions, storeData } = props;
const selectName = computeSelectName.value;
const hasFile = computeHasFile.value;
const importOpts = computeImportOpts.value;
const parseTypeLabel = computeParseTypeLabel.value;
const modelOptions = importOpts.modelOptions || {};
const settingOptions = importOpts.settingOptions || {};
const slots = defaultOptions.slots || {};
const topSlot = slots.top;
const bottomSlot = slots.bottom;
const defaultSlot = slots.default;
const footerSlot = slots.footer;
return VxeUIModalComponent ? (0, import_vue.h)(
VxeUIModalComponent,
{
id: "VXE_IMPORT_MODAL",
modelValue: storeData.visible,
title: (0, import_utils.getDefaultConfig)(modelOptions.title, getI18n("vxe.import.impTitle")),
className: "vxe-table-import-popup-wrapper" + (modelOptions.className ? ` ${modelOptions.className}` : ""),
width: modelOptions.width || 540,
height: modelOptions.height,
minWidth: modelOptions.minWidth || 360,
minHeight: modelOptions.minHeight || 240,
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,
params: defaultOptions.params
};
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", [
(0, import_vue.h)("tr", [
(0, import_vue.h)("td", getI18n("vxe.import.impFile")),
(0, import_vue.h)("td", [
hasFile ? (0, import_vue.h)(
"div",
{
class: "vxe-table-export--selected--file",
title: selectName
},
[
(0, import_vue.h)("span", selectName),
(0, import_vue.h)("i", {
class: getIcon().INPUT_CLEAR,
onClick: clearFileEvent
})
]
) : (0, import_vue.h)(
"button",
{
ref: refFileBtn,
class: "vxe-table-export--select--file",
onClick: selectFileEvent
},
getI18n("vxe.import.impSelect")
)
])
]),
(0, import_vue.h)("tr", [(0, import_vue.h)("td", getI18n("vxe.import.impType")), (0, import_vue.h)("td", parseTypeLabel)]),
settingOptions.showMode === false ? renderEmptyElement($xeTable) : (0, import_vue.h)("tr", [
(0, import_vue.h)("td", getI18n("vxe.import.impMode")),
(0, import_vue.h)("td", [
VxeUISelectComponent ? (0, import_vue.h)(VxeUISelectComponent, {
modelValue: defaultOptions.mode,
options: storeData.modeList,
"onUpdate:modelValue"(value) {
defaultOptions.mode = value;
}
}) : renderEmptyElement($xeTable)
])
])
])
]
)
]
),
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,
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.import.impCancel"),
onClick: cancelEvent
}) : renderEmptyElement($xeTable),
VxeUIButtonComponent ? (0, import_vue.h)(VxeUIButtonComponent, {
status: "primary",
disabled: !hasFile || reactData.loading,
content: getI18n("vxe.import.impConfirm"),
onClick: importEvent
}) : 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"]);
}
});
return renderVN;
}
})
);