yanzhen-design-vue
Version:
232 lines (231 loc) • 6.78 kB
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const vue = require("vue");
const lodashEs = require("lodash-es");
const useVxeTableColumnSlotRecord = require("./use-vxe-table-column-slot-record.cjs");
const useVxeTableConfig = require("./use-vxe-table-config.cjs");
const useVxeTableProps = require("./use-vxe-table-props.cjs");
const useVxeTableVirtual = require("./use-vxe-table-virtual.cjs");
function useVxeTableRef(props) {
const tableRef = vue.ref();
const editRows = vue.ref([]);
const editColumns = vue.ref([]);
const { dataSource, rowKey, ...otherCtx } = useVxeTableProps.useVxeTableProps(props);
const { isVxeTable, isElTableTag } = useVxeTableConfig.useVxeTableTagConfig(props);
const fields = vue.computed(() => {
var _a;
const columns = (_a = vue.unref(tableRef)) == null ? void 0 : _a.columns;
if (lodashEs.isArray(columns))
return columns.reduce((prev, { property: prop, ...column }) => {
if (prop) prev.push(prop);
return prev;
}, []);
return [];
});
function getRowid(row) {
var _a;
if (vue.unref(isVxeTable)) {
return (_a = vue.unref(tableRef)) == null ? void 0 : _a.getRowid(row);
}
const _rowKey = vue.unref(rowKey);
if (lodashEs.isFunction(_rowKey)) {
return _rowKey(row);
}
return row == null ? void 0 : row[_rowKey];
}
function getSelectionReserveRows(isFull) {
var _a;
if (vue.unref(isElTableTag)) {
return ((_a = vue.unref(tableRef)) == null ? void 0 : _a.getSelectionRows()) ?? [];
}
return [];
}
function getSelectionRows(isFull) {
if (vue.unref(isElTableTag)) {
const data = vue.unref(dataSource);
const rows = getSelectionReserveRows(isFull);
if (lodashEs.isArray(data)) {
return rows.filter(
(item) => data.some((value) => {
switch (true) {
case value === item:
case getRowid(value) === getRowid(item):
return true;
}
return false;
})
);
}
}
return [];
}
const $methods = {
getRowid,
getSelectionRows,
getSelectionReserveRows
};
const methods = {
loadData(data) {
return Promise.resolve();
},
reloadData(data) {
return Promise.resolve();
},
updateData() {
return Promise.resolve();
},
setRow(rows, record) {
return Promise.resolve();
},
reloadRow(rows, record) {
return Promise.resolve();
},
reloadRowExpand(row) {
return Promise.resolve();
},
reloadExpandContent(row) {
return Promise.resolve();
},
revertData() {
return Promise.resolve();
},
clearEdit() {
editRows.value = [];
editColumns.value = [];
},
setEditRow(row, fieldOrColumn) {
console.log(vue.unref(fields));
row && editRows.value.push(row);
fieldOrColumn && editColumns.value.push(fieldOrColumn);
},
setEditCell(row, fieldOrColumn) {
console.log(vue.unref(fields));
row && editRows.value.push(row);
fieldOrColumn && editColumns.value.push(fieldOrColumn);
},
isEditByRow(row, fieldOrColumn) {
return vue.unref(editRows).includes(row);
},
getCheckboxRecords: getSelectionRows,
getCheckboxReserveRecords: getSelectionReserveRows,
getRadioRecord: getSelectionRows,
getRadioReserveRecord: getSelectionReserveRows
};
const _tableRef = vue.computed(() => {
const _methods = Object.entries(methods).reduce((prev, [key, callback]) => {
prev[key] = function(...args) {
var _a;
const fun = (_a = vue.unref(tableRef)) == null ? void 0 : _a[key];
switch (true) {
case vue.unref(isVxeTable):
return fun(...args);
default:
return callback(...args);
}
};
return prev;
}, {});
return new Proxy(_methods, {
get(target, p, receiver) {
switch (true) {
case (lodashEs.isString(p) && Object.keys(methods).includes(p)):
return vue.unref(Reflect.get(methods, p, receiver));
}
return Reflect.get(vue.unref(tableRef) ?? {}, p, receiver);
}
});
});
return {
...otherCtx,
...$methods,
dataSource,
rowKey,
tableRef,
_tableRef,
methods
};
}
function useVxeTableMethods(props, options) {
const { isElTableTag, isATableTag, isVxeTable } = useVxeTableConfig.useVxeTableTagConfig(props);
const {
dataSource,
loading,
vxeTableProps,
elTableProps,
aTableProps,
tableRef,
_tableRef,
methods: $methods,
getSelectionRows,
getSelectionReserveRows
} = useVxeTableRef(props);
const virtualRef = useVxeTableVirtual.useVxeTableVirtual(_tableRef);
const columnSlotRecordRef = useVxeTableColumnSlotRecord.useVxeTableColumnSlotRecord(_tableRef);
const { isHiddenRecord } = useVxeTableColumnSlotRecord.useVxeTableColumnSlotRecord(_tableRef);
function isHiddenByRow(record, name) {
const hidden = isHiddenRecord(record, name);
if (hidden !== void 0) return hidden;
return false;
}
function isVirtualHiddenByRow(record, name) {
const hidden = isHiddenRecord(record, name);
if (hidden !== void 0) return hidden;
return vue.unref(virtualRef).isVirtualHidden(record, name);
}
function hiddenCellClassName(record) {
const hidden = isHiddenByRow(record);
return hidden ? "is-hidden" : void 0;
}
const newRef = {
data: dataSource,
getSelectionRows,
getSelectionReserveRows,
isHiddenByRow,
isVirtualHiddenByRow,
getTableRef,
virtualNodeRect: vue.unref(virtualRef).virtualNodeRect,
cellNodeRect: vue.unref(columnSlotRecordRef).cellNodeRect
};
const $table = {
$table: tableRef,
$methods,
...vue.unref(_tableRef),
...newRef
};
function getTableRef() {
switch (true) {
case vue.unref(isVxeTable):
return vue.unref(tableRef);
default:
return vue.readonly($table);
}
}
const tableProxy = new Proxy($table, {
get(target, p, receiver) {
switch (true) {
case (lodashEs.isString(p) && Object.keys($table).includes(p)):
return vue.unref(Reflect.get(target, p, receiver));
}
return Reflect.get(vue.unref(tableRef) ?? {}, p, receiver);
}
});
const tableExpose = vue.readonly(tableProxy);
return {
...$table,
tableRef,
_tableRef,
elTableProps,
aTableProps,
vxeTableProps,
isElTableTag,
isATableTag,
loading,
dataSource,
virtualRef,
columnSlotRecordRef,
hiddenCellClassName,
expose: tableExpose
};
}
exports.useVxeTableMethods = useVxeTableMethods;
exports.useVxeTableRef = useVxeTableRef;