UNPKG

@aplus-frontend/ui

Version:

153 lines (152 loc) 4.08 kB
import { createVNode as u, Fragment as T } from "vue"; import { isArray as x, isUndefined as E, isString as o, isBoolean as F, isNumber as O, pick as R } from "lodash-unified"; import { valueEnumToArray as S, objectToString as $, getTableTitle as v, getTableRenderType as V, getTableRenderProps as B, getTableCellRenderNode as M } from "../../ap-table/utils.mjs"; import { noRenderAsFormItemValueList as _ } from "../../ap-table/constants.mjs"; import "../../ap-table/components/paragraph-ellipsis/index.vue.mjs"; import j from "../../ap-table/components/paragraph-ellipsis/index.vue2.mjs"; function c(e, t) { if (t) return x(t) ? t.reduce((r, n) => r?.[n], e) : e?.[t]; } function A(e) { if (!E(e)) return x(e) ? e.reduce((t, r) => o(r) ? `${t}${t ? "." : ""}${r}` : `${t}[${r}]`, "") : String(e); } function N(e) { if (e) return e === !0 ? "left" : e; } function q(e) { return F(e) ? { sortable: e } : e ? { sortable: !0, sortType: e?.type, sortBy: e?.by } : { sortable: !1 }; } function I(e) { let t; return F(e.filters) && e.valueEnum ? t = S(e.valueEnum) : t = e.filters, t?.map((r) => ({ label: o(r.text) ? r.text : "", value: r.value })); } function W(e) { if (e) return (t) => e(t.value, t.row); } function k(e, t) { return e ? O(e) ? { tooltip: t, rows: e } : e === !0 || e === "tooltip" ? { tooltip: t, rows: 1 } : { tooltip: null, rows: 1, htmlTitle: e === "title" ? t : "" } : !1; } function z(e, t, r) { if (_.includes(e.valueType)) return r; if (e.copyable || e.ellipsis) { const n = k(e.ellipsis, t), i = $(t); return u(j, { rawValue: i, copyable: e.copyable, ellipsis: n, content: r }, null); } return r; } function y(e, t, r) { const n = R(e, ["width", "minWidth", "align"]); return n.field = A(e.dataIndex), n.fixed = N(e.fixed), n.slots = { header: () => v(e, r, void 0, t) }, n.headerAlign = e.align, n.showOverflow = !1, n.showFooterOverflow = !1, n; } function D(e, t, r) { if (r) return o(r) ? e[r] : r(e, t); } const G = ({ value: e, ...t }, r, n, i = !0) => { const s = V(r), d = B({ ...r, valueType: s }, { value: e, ...t }), l = M(s, d, t.record, n), a = r.renderText?.({ value: e, ...t }) || e, p = r.renderText ? u(T, null, [r.renderText?.({ value: e, ...t })]) : l; let f = i ? z(r, a, p) : p; if (r.customRender) { const w = r._path || [], h = D(t.record, t.rowIndex, t.params?.rowKey); f = r.customRender({ value: e, ...t, column: r, originalNode: f, originalText: a, path: h && [...w, String(h)] }); } return u(T, null, [f]); }; function b(e, t, r, n) { const i = R(e, ["width", "minWidth", "align", "resizable", "className", "headerClassName", "footerClassName", "treeNode"]); i.field = A(e.dataIndex), i.fixed = N(e.fixed), i.headerAlign = e.align, i.footerAlign = e.align, i.showOverflow = !1, i.showFooterOverflow = !1, Object.assign(i, q(e.sorter)), i.filters = I(e), i.filterMultiple = e.filterMultiple, i.filterMethod = W(e.onFilter); const s = ({ row: d, rowIndex: l }) => G({ value: c(d, e.dataIndex), text: c(d, e.dataIndex), record: d, index: l, renderIndex: l, column: e }, e, n); return i.slots = { header: () => v(e, r, void 0, t), default: s, footer: s }, e.html && (delete i.slots.default, delete i.slots.footer, i.type = "html"), e.seq && (i.type = "seq", i.slots = {}), i; } function X(e, t, r, n) { if (!e.children?.length) return b(e, t, r, n); function i(d) { return d.map((l) => { if (l.children?.length) { const a = y(l, t, r); return a.children = i(l.children), a; } return b(l, t, r, n); }); } const s = y(e, t, r); return s.children = i(e.children), s; } export { G as contentCustom, A as dataIndexToField, c as getValueByDataIndex, X as transformCol, N as transformFixed, y as transformToColGroup, b as transformToColumn };