yanzhen-design-vue
Version:
163 lines (162 loc) • 5.21 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const lodashEs = require("lodash-es");
const utils = require("@yanzhen-libs/utils");
const commonKey = ["type", "formatter", "separator", "visible"];
function filterColumnUndefined(column) {
for (const [key, value] of Object.entries(column)) {
if (value === void 0) {
delete column[key];
}
}
return column;
}
function handleAColumnProps(props) {
const { field, key, title, width, showOverflow, align, sortable, className } = props;
const info = {
key: key ?? field,
dataIndex: field,
title,
width,
align,
sortable,
ellipsis: showOverflow,
className: lodashEs.isString(className) ? className : void 0,
resizable: true
};
const column = {
...info,
...lodashEs.omit(props, ...Object.keys(info), ...commonKey)
};
return filterColumnUndefined(column);
}
function handleElColumnProps(props) {
const { field, title, width, showOverflow, align, sortable, className } = props;
const info = {
prop: field,
label: title,
width,
align,
sortable,
showOverflowTooltip: showOverflow,
className: lodashEs.isString(className) ? className : void 0,
resizable: true
};
const column = {
...info,
...lodashEs.omit(props, ...Object.keys(info), ...commonKey)
};
return filterColumnUndefined(column);
}
function handleVxeColumnProps(props, tableRef) {
var _a, _b;
const scroll = (_b = (_a = vue.unref(tableRef)) == null ? void 0 : _a.getScroll) == null ? void 0 : _b.call(_a);
const { minWidth, width } = props;
const vxeProps = {
showOverflow: props.showOverflow,
showHeaderOverflow: props.showHeaderOverflow,
showFooterOverflow: props.showFooterOverflow
};
switch (true) {
case (utils.isEmptyValue(minWidth) && utils.isEmptyValue(width)):
vxeProps.minWidth = 110;
break;
}
if ((scroll == null ? void 0 : scroll.virtualX) === true) {
vxeProps.showHeaderOverflow = true;
vxeProps.showFooterOverflow = true;
}
if ((scroll == null ? void 0 : scroll.virtualY) === true) {
console.log("isVirtualY");
vxeProps.showOverflow = true;
vxeProps.showHeaderOverflow = true;
vxeProps.showFooterOverflow = true;
}
const _props = lodashEs.omit(props, ...Object.keys(vxeProps));
return { ..._props, ...vxeProps };
}
function handleVxeTableProps(props, tableRef, ...mergeArgs) {
var _a, _b;
const el = (_a = vue.unref(tableRef)) == null ? void 0 : _a.$el;
const scrollX = lodashEs.mergeWith(
{
enabled: true,
scrollToLeftOnChange: true,
gt: 5,
oSize: 2
},
props == null ? void 0 : props.scrollX
);
const scrollY = lodashEs.mergeWith(
{
enabled: true,
mode: "wheel",
scrollToLeftOnChange: true,
gt: 5,
oSize: 2
},
props == null ? void 0 : props.scrollY
);
if (lodashEs.isElement(el)) {
const clientRect = (_b = el == null ? void 0 : el.getBoundingClientRect) == null ? void 0 : _b.call(el);
if (clientRect && (clientRect == null ? void 0 : clientRect.width) > 0) {
const width = utils.getNumeric(clientRect.width);
const gt = Math.floor(width / 60);
scrollX.gt = gt < 5 ? 5 : gt;
}
if (clientRect && (clientRect == null ? void 0 : clientRect.height) > 0) {
const height = utils.getNumeric(clientRect.height);
const gt = Math.floor(height / 40);
scrollY.gt = gt < 5 ? 5 : gt;
}
}
const vxeProps = {
showOverflow: true,
showHeaderOverflow: true,
showFooterOverflow: true,
scrollX,
scrollY
};
const mergeData = mergeArgs.reduce((prev, value) => {
if (lodashEs.isPlainObject(value)) {
for (const [key, val] of Object.entries(value)) {
if (!utils.isEmptyValue(val)) {
prev[key] = prev[key] ? prev[key].concat([val]) : [].concat([val]);
}
}
}
return prev;
}, {});
function createMergePropsFn(name = "class", datas = []) {
return function(...args) {
let data = {};
for (const _data of datas) {
switch (true) {
case lodashEs.isFunction(_data):
data = vue.mergeProps(data, { [name]: _data(...args) });
break;
case (lodashEs.isString(_data) || lodashEs.isPlainObject(_data)):
data = vue.mergeProps(data, { [name]: _data });
break;
}
}
return data[name];
};
}
for (const [key, datas] of Object.entries(mergeData)) {
const value = vxeProps[key];
if (key.toLowerCase().includes("class")) {
vxeProps[key] = createMergePropsFn("class", [value, props[key], ...datas]);
} else if (key.toLowerCase().includes("style")) {
vxeProps[key] = createMergePropsFn("style", [value, props[key], ...datas]);
}
}
const _props = lodashEs.omit(props, ...Object.keys(vxeProps));
console.log(vxeProps, _props, "handleVxeTableProps");
return { ..._props, ...vxeProps };
}
exports.handleAColumnProps = handleAColumnProps;
exports.handleElColumnProps = handleElColumnProps;
exports.handleVxeColumnProps = handleVxeColumnProps;
exports.handleVxeTableProps = handleVxeTableProps;