UNPKG

@aplus-frontend/ui

Version:

500 lines (499 loc) 15.1 kB
import { defineComponent as We, useSlots as De, ref as h, computed as n, unref as o, toRef as $e, createVNode as c, Fragment as te, watch as x, createElementBlock as B, openBlock as p, normalizeStyle as A, normalizeClass as f, createCommentVNode as ae, createElementVNode as E, mergeProps as k, createSlots as le, withCtx as w, renderList as ne, createBlock as se, resolveDynamicComponent as je, renderSlot as v, normalizeProps as He, guardReactiveProps as _e } from "vue"; import { Divider as Ue, Table as qe } from "@aplus-frontend/antdv"; import { useToken as Me } from "@aplus-frontend/antdv/es/theme/internal"; import { ApForm as Ge } from "../ap-form/index.mjs"; import { noRenderAsFormItemValueList as de } from "./constants.mjs"; import "../config-provider/index.mjs"; import { useTablePaging as Je } from "./hooks/use-table-paging-ng.mjs"; import { isUndefined as m, omit as ue, isBoolean as Qe } from "lodash-unified"; import { getColumnOrder as ie, updateFormProps as Xe, getFieldProps as Ye, getSearchFormItemRenderNode as Ze, recursionApColumns as ce, getTableTitle as er, getTableRenderType as rr, getTableRenderProps as or, getTableCellRenderNode as tr, apColumnToColumn as ar, falseToUndefined as lr, objectToString as nr } from "./utils.mjs"; import sr from "./hooks/use-table-content-height.mjs"; import dr from "./hooks/use-table-row-selection.mjs"; import { getScrollbarSize as ur, isDef as pe } from "../utils/index.mjs"; import "./components/setting/modal/index.vue.mjs"; import "./components/paragraph-ellipsis/index.vue.mjs"; import { useProvideApTable as ir } from "./context.mjs"; import "../scroll-bar/index.mjs"; import { useStickyScroll as cr } from "./hooks/use-sticky-scroll.mjs"; import { getValidVNodeList as pr } from "../utils/slot.mjs"; import { useDevWarning as fr } from "../utils/warning.mjs"; import { useNamespace as mr } from "../config-provider/hooks/use-namespace.mjs"; import { useGlobalConfig as gr } from "../config-provider/hooks/use-global-config.mjs"; import br from "./components/paragraph-ellipsis/index.vue2.mjs"; import yr from "./components/setting/modal/index.vue2.mjs"; import Sr from "../scroll-bar/index.vue.mjs"; const _r = /* @__PURE__ */ We({ name: "ApTable", __name: "ap-table", props: { dropdownPrefixCls: {}, loading: { type: [Boolean, Object], default: void 0 }, bordered: { type: Boolean, default: !1 }, locale: {}, onChange: {}, onResizeColumn: {}, getPopupContainer: {}, scroll: {}, sortDirections: { default: () => ["ascend", "descend"] }, showSorterTooltip: { type: [Boolean, Object], default: !1 }, prefixCls: {}, rowKey: { type: [String, Function], default: "key" }, tableLayout: {}, rowClassName: {}, title: {}, footer: {}, id: {}, showHeader: { type: Boolean, default: !0 }, components: {}, customRow: {}, customHeaderRow: {}, direction: {}, expandFixed: { type: [String, Boolean], default: !1 }, expandColumnWidth: {}, expandedRowKeys: {}, defaultExpandedRowKeys: {}, expandedRowRender: {}, expandRowByClick: { type: Boolean, default: !1 }, expandIcon: {}, onExpand: {}, onExpandedRowsChange: {}, defaultExpandAllRows: { type: Boolean, default: !1 }, indentSize: { default: 15 }, expandIconColumnIndex: {}, showExpandColumn: { type: Boolean, default: !0 }, expandedRowClassName: {}, childrenColumnName: { default: "children" }, rowExpandable: {}, sticky: { type: [Boolean, Object] }, transformCellText: {}, columns: {}, rowSelection: { type: [Boolean, Object] }, card: { type: Boolean, default: !1 }, params: {}, searchFormRender: {}, request: {}, onLoad: {}, defaultData: {}, dataSource: {}, onLoadingChange: {}, searchForm: { type: [Boolean, Object], default: void 0 }, beforeSearchSubmit: {}, pagination: { type: [Boolean, Object], default: void 0 }, searchFormWrapperStyle: {}, tableWrapperStyle: {}, manual: { type: Boolean, default: void 0 }, size: { default: "small" }, adaptive: { type: Boolean, default: !1 }, columnResizable: { type: Boolean, default: !1 }, settings: { type: [Boolean, Object], default: void 0 } }, setup(fe, { expose: me }) { const r = fe; let K = 0; const g = De(), [, ge] = Me(); fr("ApTable")(!1, "breaking", "ApTable has been EOL, Please use AgGrid(https://aplus.aplnk.com/aplus-ui/components/ag-grid/) instead."); const { e: I, b: u, be: L, m: be, cssVar: ye } = mr("ap-table"), O = gr("valueTypeMap"), { height: Se, contentRef: he } = sr(), W = h(), D = h(), { isStickyMode: $, scrollBarRef: R } = cr(W), z = h(r.size), s = h([]), j = h([]), H = ur(), _ = n(() => (K++, r.columns?.filter((e) => !e.hideInSearch && e.dataIndex && (e.valueType || e.customRenderFormItem) && !de.includes(e.valueType))?.sort((e, a) => { let t = ie(e.order); return ie(a.order) - t; })?.map((e) => { const a = Xe(e, Ye(e.fieldProps, {})), t = { ...e, fieldProps: { label: e.title, name: e.dataIndex, // tips: 在表格中的查询表单项默认是带边框的 bordered: !0, ...a || {}, _signal: K }, renderNode: void 0 }; return t.renderNode = Ze(t, o(O)), t; }) || [])), we = n(() => ce(o(s), (e) => { if (e.sorter === !0) return e.key || e?.dataIndex; }).filter(Boolean)), ve = n(() => ce(o(s), (e) => { if (e.filters && !e.onFilter) return e.key || e?.dataIndex; }).filter(Boolean)), Re = n(() => m(r.dataSource) ? b.records : r.dataSource), Ce = n(() => pe(r.manual) ? r.manual : pr(g.searchFormExtra?.() || []).some((a) => a.type?.name === "ApView")), { rowSelection: C, selectedRows: T, ...F } = dr({ fixed: !0, ...r.rowSelection === !0 ? {} : r.rowSelection, rowKey: r.rowKey, dataSource: Re }), { formRef: i, submit: P, reset: N, tableProps: U, refresh: q, data: b, setDataSource: Te, getColumnSFConfig: M, sortedInfo: Fe, filteredInfo: xe, setPaging: Be, getPaging: ke, submitWith: G } = Je({ async request(e) { if (!C.value.preserveSelectedRowKeys && m(r.dataSource) && F.clearAll(), !m(r.dataSource)) return { data: r.dataSource || [], total: r.dataSource.length || 0 }; const a = await r.request?.(e); return r.onLoad?.(a?.data || []), { data: a?.data || [], total: a?.total || 0 }; }, filterFields: ve, sortFields: we, params: $e(r, "params"), defaultData: r.defaultData, manual: o(Ce), formatParams: r.beforeSearchSubmit, pagination: r.pagination }); ir({ columns: n(() => s.value), columnsBackup: n(() => j.value), size: n(() => z.value), updateColumns(e) { s.value = e; }, updateSize(e) { z.value = e; }, dataSource: n(() => o(b).records), getSearchFormValues: X, setSearchFormValues: Q, submit: P, submitWith: G, reset: N, refresh: q, getSearchFormSorterItems: Y, setSearchFormSorterItems: Z, resetSearchFormSorterItems: ee }); const Ie = () => { let e = r.columns?.filter((t) => !t.hideInTable) || []; function a(t, d) { return t.map((l) => ({ resizable: pe(l.resizable) ? l.resizable : r.columnResizable, ...ue(ar(l), ["ellipsis"]), // tips: 此函数内部依赖查询&筛选的相应式值 ...M(l), fixed: d ? d.fixed : l.fixed, title: er(l, L("table-header", "title"), g.headerCell, o(ge).colorTextTertiary), customRender({ value: y, ...S }) { const re = rr(l), Ke = or({ ...l, valueType: re }, { value: y, ...S }), Le = tr(re, Ke, S.record, o(O)), oe = l.renderText?.({ value: y, ...S }) || y, Oe = l.renderText ? c(te, null, [l.renderText?.({ value: y, ...S })]) : Le; let V = Ae(l, oe, Oe); return l.customRender && (V = l.customRender({ value: y, ...S, column: l, originalNode: V, originalText: oe })), V; }, children: a(l.children || [], d || l) })); } return a(e); }, ze = () => { function e(a) { for (const t of a) t.children?.length ? e(t.children) : M(t, !0); } e(s.value); }; x(() => [r.columns, r.columnResizable], () => { const e = Ie(); s.value = e, j.value = e; }, { deep: !0, immediate: !0 }), x(() => [Fe.value, xe.value], () => { ze(); }, { deep: !0 }); const Pe = n(() => { if (r.adaptive && (b.total > 0 || r.dataSource?.length)) return { y: o(Se), x: r.scroll?.x || "100%" }; if (r.scroll) return r.scroll; }), Ne = n(() => { if (r.tableLayout) return r.tableLayout; if (r.columns?.some((e) => e.ellipsis)) return "fixed"; }), J = n(() => { const e = o(U), a = o(C); return { ...r, ...e, rowSelection: r.rowSelection === !0 || r.rowSelection?.mode === "internal" ? { ...a, // tips 如果是前端分页,则默认会走缓存 preserveSelectedRowKeys: m(r.dataSource) ? a.preserveSelectedRowKeys : !0 } : lr(r.rowSelection), loading: m(r.loading) ? e.loading : r.loading, pagination: r.pagination === !1 ? !1 : e.pagination, scroll: o(Pe) }; }), Ve = n(() => [u(), r.card ? null : u("wrapper"), r.adaptive ? u("adaptive") : null, $.value && R.value?.visible ? be(`sticky-${H === 0 ? "absolute" : "relative"}`) : null].filter(Boolean)); function Ae(e, a, t) { if (de.includes(e.valueType)) return t; const d = nr(a); return e.copyable || e.ellipsis ? c(br, { copyable: e.copyable, rawValue: d, ellipsis: e.ellipsis ? Qe(e.ellipsis) ? { tooltip: t, rows: 1 } : { ...e.ellipsis, tooltip: t } : !1, content: t }, null) : t; } x(() => o(b).loading, (e) => { r.onLoadingChange?.(e); }), x(() => r.dataSource, (e) => { Te(e); }, { immediate: !0 }); function Q(e) { i.value?.apForm?.setFieldsValue?.(e); } function X(e = !1) { const a = e ? "getFieldsValueTransformed" : "getFieldsValue"; return i.value?.apForm?.[a]?.(!0); } function Y() { return i.value?.getSorterItems() || []; } function Z(e) { i.value?.setSorterItems(e); } function ee() { i.value?.resetSorterItems(); } function Ee() { return o(s); } return me({ submit: () => P(), reset: () => N(), refresh: () => q(), submitWith: () => G(), setSearchFormValues: Q, getSearchFormValues: X, setPaging: Be, getPaging: ke, getShownColumns: Ee, dataSource: n(() => o(b).records), rowSelection: { selectedRows: n(() => o(T)), ...F }, scrollBar: { x: { getCurrentScroll: () => R?.value?.currentScroll ?? 0, scroll: (e) => R?.value?.scroll?.(e) }, y: void 0 }, getSearchFormSorterItems: Y, setSearchFormSorterItems: Z, resetSearchFormSorterItems: ee }), (e, a) => (p(), B("div", { ref_key: "tableWrapperRef", ref: W, class: f(Ve.value), style: A(o(ye)({ "scroll-bar-width": `${o(H)}px` })) }, [o(m)(e.dataSource) && e.searchForm !== !1 && _.value.length > 0 ? (p(), B("div", { key: 0, class: f(e.card ? o(I)("search-wrapper") : null), style: A(e.searchFormWrapperStyle) }, [c(o(Ge).SearchForm, k(e.searchForm || {}, { ref_key: "formRef", ref: i, "custom-reset": "", "submit-loading": o(U).loading, onSubmit: o(P), onReset: o(N) }), le({ default: w(() => [(p(!0), B(te, null, ne(_.value, (t) => (p(), se(je(t.renderNode), { key: t.dataIndex }))), 128))]), _: 2 }, [g.searchFormExtra ? { name: "extra", fn: w(() => [v(e.$slots, "searchFormExtra")]), key: "0" } : void 0]), 1040, ["submit-loading", "onSubmit", "onReset"])], 6)) : ae("", !0), E("div", { ref_key: "contentRef", ref: he, class: f([o(I)("table-wrapper"), e.card ? o(I)("table-wrapper-card") : null]), style: A(e.tableWrapperStyle) }, [E("div", { class: f(o(u)("header-wrapper")) }, [e.settings ? (p(), B("div", { key: 0, class: f(o(u)("header")) }, [E("div", { class: f(o(L)("header", "title")) }, [v(e.$slots, "title", k({ selectedRows: o(T), selectedRowKeys: o(C).selectedRowKeys, shownColumns: s.value }, F))], 2), g.title ? (p(), se(o(Ue), { key: 0, type: "vertical" })) : ae("", !0), c(yr, { config: e.settings === !0 ? {} : e.settings }, null, 8, ["config"])], 2)) : v(e.$slots, "title", k({ key: 1, selectedRows: o(T), selectedRowKeys: o(C).selectedRowKeys, shownColumns: s.value }, F))], 2), c(o(qe), k({ ref_key: "antdTableRef", ref: D, class: o(u)("table") }, J.value, { size: z.value, "table-layout": Ne.value, columns: s.value, onResizeColumn: a[0] || (a[0] = (t, d) => d.width = t) }), le({ summary: w(() => [v(e.$slots, "summary", { columns: s.value, records: J.value.dataSource, selectedRows: o(T) })]), _: 2 }, [o($) ? { name: "bottomPaginationTop", fn: w(() => [c(o(Sr), { ref_key: "scrollBarRef", ref: R, "scroll-container": D.value?.table?.scrollBodyRef, direction: "horizontal", "bar-color": "var(--ap-scrollbar-thumb-color-base)", "track-color": "var(--ap-table-header-bg, #f2f6f9)" }, null, 8, ["scroll-container"])]), key: "0" } : void 0, ne(o(ue)(g, ["title", "searchFormExtra", "headerCell", "summary"]), (t, d) => ({ name: d, fn: w((l) => [v(e.$slots, d, He(_e(l || {})))]) }))]), 1040, ["class", "size", "table-layout", "columns"])], 6)], 6)); } }); export { _r as default };