UNPKG

@aplus-frontend/ui

Version:

113 lines (112 loc) 3.59 kB
import { omit as d, isUndefined as s, isFunction as g, isNumber as m } from "lodash-unified"; import { isDef as C } from "../../utils/index.mjs"; const b = 20, y = 50, v = (e) => e.some((i) => !!i.html); function k(e, i) { const t = { ...d(e, [ "columns", "request", "searchForm", "dataSource", "rowKey", "value", "round" ]) }; return t.rowConfig = { isHover: !0, keyField: e.rowKey, isCurrent: !!e.rowHighlightable }, t.columnConfig = {}, v(e.columns || []) && (t.rowConfig.useKey = !0, t.columnConfig.useKey = !0), e.adaptive && (t.autoResize = !0, t.height = "100%"), e.columnResizable && (t.columnConfig.resizable = !0), i && (i.type === "radio" ? t.radioConfig = { highlight: !0, checkMethod({ row: r }) { return i.disabled ? !i.disabled(r) : !0; }, visibleMethod({ row: r }) { return i.shown ? i.shown(r) : !0; }, checkRowKey: i.defaultSelectedRowKeys?.[0], reserve: i.preserveSelectedRowKeys || s(e.dataSource) } : t.checkboxConfig = { highlight: !0, checkMethod({ row: r }) { return i.disabled ? !i.disabled(r) : !0; }, visibleMethod({ row: r }) { return i.shown ? i.shown(r) : !0; }, // tips: 离线表格或者手动设置了缓存都会将此字段设置为true reserve: i.preserveSelectedRowKeys || s(e.dataSource), range: i.range || !1 }), t.border = e.bordered === !1 ? "inner" : !0, e.expandable && (t.expandConfig = d(e.expandable, [ "renderContent", "width", "title" ])), e.footer && (t.showFooter = !0, g(e.footer) ? t.footerMethod = e.footer : t.footerData = e.footer), e.virtual === !1 ? (t.virtualXConfig = { enabled: !1 }, t.virtualYConfig = { enabled: !1 }) : (l(t, "X", e.virtual), l(t, "Y", e.virtual)), t.round = C(e.round) ? e.round : !e.card, t.headerCellConfig = { height: 36, ...t.headerCellConfig || {} }, t.treeConfig && (t.treeConfig = { ...t.treeConfig || {}, /** * 使用非树层级列表,配合transform */ transform: !0 }), t.resizableConfig = { minWidth({ cell: r }) { return R(r, e.size); } }, t; } function l(e, i, t) { const n = i === "X", r = n ? "x" : "y", a = n ? "virtualXConfig" : "virtualYConfig", u = t?.[r], o = u !== !1, f = n ? b : y, c = m(u) && u >= 0 ? u : f; e[a] = { enabled: o, gt: c, oSize: t?.oSize || 0 }; } function x(e) { return e === !0 ? "left" : e; } function z(e, i, t) { const n = e === !0 || !e.type ? "checkbox" : e.type, r = (t === "mini" ? 9 * 2 : 12 * 2) + 16, a = e === !0 ? r : e.columnWidth || r; let u = e === !0 ? void 0 : x(e.fixed); return u || (u === !1 ? u = void 0 : u = i.some( (o) => o.fixed === "left" || o.fixed === !0 ) ? "left" : void 0), { type: n, width: a, fixed: u }; } function F(e) { const i = e?.width || "auto"; return { type: "expand", title: e?.title, width: i }; } function h(e) { if (!e) return 0; const i = getComputedStyle(e); return e.offsetWidth + (Number.parseFloat(i.marginLeft) || 0) + Number.parseFloat(i.marginRight) || 0; } function R(e, i) { if (!e) return "auto"; const t = getComputedStyle(e); let n = i === "medium" ? 12 * 2 : 9 * 2; const r = (Number.parseFloat(t.fontSize) || 14) * 1.6; return n += r, e.querySelector("span.anticon-question-circle") && (n += 20), n += h(e.querySelector(".vxe-cell--sort")) + h(e.querySelector(".vxe-cell--filter")), Math.ceil(n); } export { F as getRowExpandProps, z as getRowSelectionProps, k as toVxeProps };