UNPKG

@aplus-frontend/ui

Version:

232 lines (231 loc) 6.24 kB
import { defineComponent as z, ref as A, unref as s, useSlots as K, toRef as O, watch as G, nextTick as W, shallowRef as H, createBlock as U, openBlock as $, mergeProps as p, withCtx as c, createVNode as q, createSlots as J, renderList as Q, renderSlot as X, normalizeProps as Y, guardReactiveProps as Z } from "vue"; import { Table as M } from "@aplus-frontend/antdv"; import { ApForm as h } from "../ap-form/index.mjs"; import { isUndefined as ee, isNumber as d, cloneDeep as te, isArray as ae, omit as b } from "lodash-unified"; import "../config-provider/index.mjs"; import { useInjectForm as oe } from "../ap-form/context.mjs"; import "../utils/index.mjs"; import ne from "./hooks/use-get-columns.mjs"; import { scrollToRowIndex as le } from "./utils.mjs"; import { getModelValue as se } from "../ap-form/utils/get.mjs"; import { useDevWarning as re } from "../utils/warning.mjs"; import ie from "./style/index.mjs"; import { useNamespace as ue } from "../config-provider/hooks/use-namespace.mjs"; import { useGlobalConfig as fe } from "../config-provider/hooks/use-global-config.mjs"; import { isDef as g } from "../utils/is.mjs"; const ve = /* @__PURE__ */ z({ name: "EditableTableFormItem", __name: "form-item", props: { dropdownPrefixCls: {}, pagination: { type: [Boolean, Object], default: !1 }, loading: { type: [Boolean, Object], default: void 0 }, size: { default: "small" }, bordered: { type: Boolean, default: !1 }, locale: {}, onResizeColumn: {}, rowSelection: {}, getPopupContainer: {}, scroll: {}, sortDirections: { default: () => ["ascend", "descend"] }, showSorterTooltip: { type: [Boolean, Object], default: !0 }, prefixCls: {}, rowKey: { type: [String, Function], default: "key" }, tableLayout: { default: "fixed" }, 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: {}, value: {}, defaultValue: {}, "onUpdate:value": {}, onChange: {}, maxLength: {}, onFieldChange: {}, label: {}, name: {}, formItem: { default: () => ({}) } }, setup(w, { expose: x }) { const o = w; re("EditableTableFormItem")(!1, "breaking", "EditableTableFormItem has been EOL, Please use EditableAgGridFormItem(https://aplus.aplnk.com/aplus-ui/components/ag-grid/editable/) instead."); const { internalInstance: i, model: y } = oe(), u = A(se(s(y), o.name) || []), C = K(), R = O(o, "name"), F = h.useWatch(R); G(() => F.value, async (e) => { await W(), u.value = e, o.onChange?.(e); }, { deep: !0 }); const { b: B } = ue("editable-table"), I = ie("editable-table"), m = H(), T = fe("valueTypeMap"), v = ne(o, T); function D(e, n) { const l = s(u)?.length || 0; if (g(o.maxLength) && l >= o.maxLength) return; const t = { ...e || {} }; i?.setFieldValue(o.name, t, !0, (a, r) => { if (!a[r]) { a[r] = [t]; return; } ee(n) ? a[r].push(t) : a[r].splice(n, 0, t); }); } function E(e, n = "suffix") { const l = s(u)?.length || 0, t = d(e) ? e : e.length; if (g(o.maxLength) && l + t > o.maxLength) return; const a = d(e) ? new Array(e).fill(0).map(() => ({})) : te(e); i?.setFieldValue(o.name, a, !0, (r, f) => { if (!r[f]) { r[f] = [...a]; return; } n === "suffix" ? r[f].push(...a) : r[f].unshift(...a); }); } function S(e) { const n = new Set(d(e) ? [e] : e); i?.setFieldValue(o.name, void 0, !0, (l, t) => { l[t] = l[t].filter((a, r) => !n.has(r)); }); } function L(e) { const n = new Set(ae(e) ? e : [e]); n.size !== 0 && i?.setFieldValue?.(o.name, void 0, !0, (l, t) => { l[t] = l[t].filter((a) => !n.has(a[o.rowKey])); }); } function V() { return s(u); } function k(e) { return s(u)?.[e]; } function N(e, n, l = !0) { i?.setFieldValue(o.name, void 0, !0, (t, a) => { !t[a] || !t[a][e] || (t[a][e] = { ...l ? t[a][e] : {}, ...n }); }); } function _(e) { i?.setFieldValue(o.name, e); } function P(e, n) { const l = e === "end" ? u.value.length - 1 : e; le(l, m.value?.$el, n); } function j() { i?.setFieldValue?.(o.name, []); } return x({ add: D, remove: S, getRowData: k, getRowsData: V, setRowData: N, addMultiple: E, scrollTo: P, setTableData: _, clear: j, removeByKey: L }), (e, n) => ($(), U(s(h).FormItem, p(e.formItem, { name: e.name, label: e.label }), { default: c(() => [q(s(M), p(s(b)(o, ["name", "maxLength", "onChange"]), { ref_key: "tableRef", ref: m, class: [s(B)(), s(I)], columns: s(v), "data-source": u.value }), J({ _: 2 }, [Q(s(b)(C, ["headerCell"]), (l, t) => ({ name: t, fn: c((a) => [X(e.$slots, t, Y(Z(a || {})))]) }))]), 1040, ["class", "columns", "data-source"])]), _: 3 }, 16, ["name", "label"])); } }); export { ve as default };