yanzhen-design-vue
Version:
90 lines (89 loc) • 2.65 kB
JavaScript
import { useSlots, toRefs, computed, unref, ref } from "vue";
import { isFunction } from "lodash-es";
import { handleElColumnProps, handleAColumnProps, handleVxeColumnProps } from "./utils/handleTableProps.mjs";
import { useVxeTableConfig, useVxeTableTagConfig } from "./hooks/use-vxe-table-config.mjs";
function useVxeTableColumn(props, emit) {
const $slots = useSlots();
const $table = useVxeTableConfig("table");
const config = useVxeTableConfig("config");
const { visible } = toRefs(props);
const { isATableTag, isElTableTag } = useVxeTableTagConfig(props);
const className = computed(() => {
return [`is-align-${props.align ?? "left"}`].join(" ");
});
const labelClassName = computed(() => {
return [`is-align-${props.headerAlign ?? props.align ?? "left"}`, "table-cell-label"].join(" ");
});
function isEditByRow({ row }) {
var _a, _b;
const isEditByRow2 = (_b = (_a = unref($table)) == null ? void 0 : _a.getTableRef()) == null ? void 0 : _b.isEditByRow;
if (isFunction(isEditByRow2)) {
return isEditByRow2(row);
}
return false;
}
const type = computed(() => {
const type2 = props.type;
if (unref(isElTableTag)) {
switch (type2) {
case "checkbox":
case "radio":
return "selection";
case "expand":
return type2;
case "seq":
return "index";
}
}
return type2;
});
const reserveSelection = computed(() => {
var _a, _b, _c, _d;
switch (unref(type)) {
case "checkbox":
return (_b = (_a = unref(config)) == null ? void 0 : _a.checkboxConfig) == null ? void 0 : _b.reserve;
case "radio":
return (_d = (_c = unref(config)) == null ? void 0 : _c.radioConfig) == null ? void 0 : _d.reserve;
}
return false;
});
const elColumnProps = computed(() => {
return handleElColumnProps(props);
});
const aColumnProps = computed(() => {
return handleAColumnProps(props);
});
const vxeColumnProps = computed(() => {
return handleVxeColumnProps(props, unref($table));
});
function isHiddenByRow(record, name) {
var _a, _b;
return (_b = (_a = unref($table)) == null ? void 0 : _a.isHiddenByRow) == null ? void 0 : _b.call(_a, record, name);
}
const columnSlotStubRef = ref();
const ctx = {
columnSlotStubRef,
type,
$slots,
elColumnProps,
aColumnProps,
vxeColumnProps,
reserveSelection,
className,
labelClassName,
visible,
isElTableTag,
isATableTag
};
const methods = {
isEditByRow,
isHiddenByRow
};
return {
ctx,
methods
};
}
export {
useVxeTableColumn
};