UNPKG

@aplus-frontend/ui

Version:

153 lines (152 loc) 4.59 kB
import { getTableRenderProps as m, objectToString as P } from "../../ap-table/utils.mjs"; import { rendererMap as c } from "../renderer/index.mjs"; import { isNumber as f, isFunction as y } from "lodash-unified"; import { ref as R, unref as C, computed as T } from "vue"; import "../components/body-cell/index.vue.mjs"; import "../components/header-cell/index.vue.mjs"; import "../components/tooltip/index.vue.mjs"; import "../../config-provider/index.mjs"; import { dataIndexToField as I } from "../../ap-grid/utils/col.mjs"; import { isDef as S } from "../../utils/index.mjs"; import { useGlobalConfig as _ } from "../../config-provider/hooks/use-global-config.mjs"; import { useNamespace as G } from "../../config-provider/hooks/use-namespace.mjs"; import W from "../components/body-cell/index.vue2.mjs"; import z from "../components/tooltip/index.vue2.mjs"; import v from "../components/header-cell/index.vue2.mjs"; function F(r) { return f(r) && r > 1; } function M(r, l) { if (l.bodyCellTooltip) return y(l.bodyCellTooltip) ? l.bodyCellTooltip(r.value, r.data) : l.bodyCellTooltip; if (l.renderText) return l.renderText({ value: r.value, record: r.data, column: l, text: r.value }); const n = l.valueType || "text", d = c[n]; if (d) { const p = m( { ...l, valueType: n }, { value: r.value, text: r.value, record: r.data, column: r.column, rowIndex: r.node?.rowIndex, pinned: r.node?.rowPinned } ); return d(p); } return P(r.value); } const X = (r, l, n) => { const d = _("valueTypeMap"), u = R(), { em: p } = G("ag-grid"), h = (t) => { const i = { cellRenderer: W, cellRendererParams: { column: t, extraValueType: C(d) } }; if (t.customRender) return i; if (t.renderText) return { valueFormatter: (o) => t.renderText({ value: o.value, record: o.data, column: t, text: o.value }) }; const a = t.valueType || "text", e = c[a]; return e ? { valueFormatter: (o) => { const s = m( { ...t, valueType: a }, { value: o.value, text: o.value, record: o.data, column: o.column, rowIndex: o.node?.rowIndex, pinned: o.node?.rowPinned } ); return e(s); } } : i; }, b = (t) => { const i = {}, a = t.bodyCellTooltip || !t.customRender && (t.ellipsis === !0 || t.ellipsis === "tooltip" || f(t.ellipsis)), e = f(t.ellipsis) && t.ellipsis > 1, o = f(t.ellipsis) ? t.ellipsis : 1; return i.tooltipValueGetter = a ? (s) => M(s, t) : void 0, i.wrapText = !t.ellipsis || e, i.cellStyle = { "--ag-grid-line-clamp": o }, i.tooltipComponent = z, i.tooltipComponentParams = { lineClamp: o, gridWrapperRef: u }, i; }, g = T(() => { const t = C(r); function i(a) { return a.map((e) => { const o = { field: I(e.dataIndex), colId: S(e.key) ? String(e.key) : void 0, sortable: !!e.sorter, comparator: e.sorter === !0 ? () => 0 : e.sorter, headerComponentParams: { column: e }, resizable: e.resizable, width: e.width, minWidth: e.minWidth, maxWidth: e.maxWidth, flex: e.width ? void 0 : 1, // 如果没有设置确切的宽度,则设置为可自由伸缩列 pinned: e.fixed || null, // undefined to null colSpan: e.colSpan, cellClass: n((s) => { const x = e.cellClass || "", D = y(x) ? x(s.data, s.node) : x; return [ `${p("cell", e.align || "left")}`, F(e.ellipsis) ? p("cell", "multiline") : null, D ].flat().filter(Boolean); }), autoHeight: !0, // 设置自动计算高度以自适应多行换行的场景 ...b(e), ...h(e) }; return e.children?.length ? { ...o, headerGroupComponent: v, headerGroupComponentParams: { column: e }, children: i(e.children) } : o; }); } return i(t); }), w = T( () => ({ headerComponent: v, resizable: l.columnResizable, suppressMovable: !0, cellDataType: !1 }) ); return { columnDefs: g, defaultColDef: w, gridWrapperRef: u }; }; export { X as useColumnsDef };