@aplus-frontend/ui
Version:
244 lines (243 loc) • 6.4 kB
JavaScript
import { defineComponent as A, useSlots as L, ref as g, onMounted as P, watch as G, createElementBlock as W, openBlock as U, Fragment as $, createVNode as p, unref as l, withCtx as h, mergeProps as q, createSlots as J, renderList as Q, renderSlot as X, normalizeProps as Y, guardReactiveProps as Z } from "vue";
import { cloneDeep as u, isEqual as ee, omit as oe } from "lodash-unified";
import { ApForm as y } from "../../ap-form/index.mjs";
import { useInjectForm as te } from "../../ap-form/context.mjs";
import { useWatch as ae } from "../../ap-form/hooks/use-watch.mjs";
import { getModelValue as ne } from "../../ap-form/utils/get.mjs";
import { transformValues as le } from "../../ap-form/utils/transform.mjs";
import "../../config-provider/index.mjs";
import { useGetEditableColumns as re } from "../hooks/use-editable-columns.mjs";
import { useEditableFormItemApi as se } from "../hooks/use-editable-form-item-api.mjs";
import "../index.vue2.mjs";
import ie from "../style/editable.mjs";
import { getShadowName as me } from "../utils.mjs";
import { getColumnTransformOptions as ue, arrayToObject as C } from "./utils.mjs";
import { useNamespace as de } from "../../config-provider/hooks/use-namespace.mjs";
import { useGlobalConfig as pe } from "../../config-provider/hooks/use-global-config.mjs";
import fe from "../index.vue.mjs";
const _e = /* @__PURE__ */ A({
name: "EditableGrid",
__name: "form-item",
props: {
dropdownPrefixCls: {},
bordered: {
type: Boolean
},
locale: {},
onResizeColumn: {},
getPopupContainer: {},
scroll: {},
sortDirections: {},
showSorterTooltip: {
type: [Boolean, Object]
},
prefixCls: {},
rowKey: {
type: [String, Function],
default: "key"
},
tableLayout: {},
title: {},
id: {},
showHeader: {
type: Boolean
},
components: {},
customHeaderRow: {},
direction: {},
expandFixed: {
type: [String, Boolean]
},
expandColumnWidth: {},
expandedRowKeys: {},
defaultExpandedRowKeys: {},
expandedRowRender: {},
expandRowByClick: {
type: Boolean
},
expandIcon: {},
onExpand: {},
onExpandedRowsChange: {},
defaultExpandAllRows: {
type: Boolean
},
indentSize: {},
expandIconColumnIndex: {},
showExpandColumn: {
type: Boolean
},
expandedRowClassName: {},
childrenColumnName: {},
rowExpandable: {},
transformCellText: {},
rowHoverable: {
type: Boolean
},
rowSelection: {
type: [Boolean, Object]
},
onLoadingChange: {},
onShownColumnsChange: {},
pagination: {
type: [Boolean, Object],
default: !1
},
searchFormWrapperStyle: {},
tableWrapperStyle: {},
wrapperStyle: {},
tableStyle: {},
adaptive: {
type: Boolean
},
columnResizable: {
type: Boolean,
default: !1
},
loading: {
type: Boolean,
default: void 0
},
summary: {},
rowHeight: {
default: 66
},
getRowHeight: {},
advanceRenderer: {
type: Boolean
},
browserTooltips: {
type: Boolean
},
virtual: {
type: [Boolean, Object],
default: void 0
},
onRowClicked: {},
onScrollEnd: {},
rowClassName: {},
rowClassRules: {},
autoHeight: {
type: Boolean
},
onUpdate: {},
customRow: {},
theme: {},
emptyComponent: {},
columns: {},
defaultValue: {},
onChange: {},
maxLength: {},
onFieldChange: {},
label: {},
name: {},
formItem: {}
},
setup(b, {
expose: R
}) {
const B = L(), o = b, {
b: v
} = de("editable-aggrid"), x = ie("editable-aggrid"), r = g(), {
internalInstance: s
} = te();
function I(e) {
const t = ue(o.columns || []);
if (!Object.keys(t).length || !e?.length)
return e;
let a = [];
for (const m of e)
a.push(le(m, t));
return a;
}
const i = me(o.name);
let f = [];
P(() => {
const e = o.formItem?.initialValue ?? ne(s?.getInitialValues() ?? {}, o.name);
e && (s?.updateInitialModel(i, C(u(e), o.rowKey)), f = u(e), n.value || _(u(e), "suffix", !0));
});
const n = g([]), S = ae(o.name);
G(() => S.value, (e) => {
ee(e, n.value) || c(e ?? u(f));
}, {
deep: !0,
flush: "post",
immediate: !0
});
const T = pe("valueTypeMap"), E = re(o, T, i), {
add: F,
addMultiple: V,
__addMultiple: _,
remove: N,
removeByKey: j,
getRowData: k,
getRowsData: D,
setRowData: O,
clear: H,
refreshRowIds: d
} = se(o, s, n, i);
function K() {
const e = r.value?._internalGridApi;
if (!d.value?.length || !e)
return;
const t = d.value.map((a) => e.getRowNode(a)).filter((a) => !!a);
e.refreshCells({
rowNodes: t,
force: !0
}), d.value = [];
}
function c(e) {
n.value = [...e];
const t = C(e, o.rowKey);
s?.setFieldValue(o.name, [...e]), s?.setFieldValue(i, t);
}
function w(e, t) {
const a = e === "end" ? n.value.length - 1 : e;
r.value?.scrollToRow(a, t);
}
function M(e, t) {
r.value?.scrollToColumn(e, t);
}
return R({
add: F,
addMultiple: V,
remove: N,
removeByKey: j,
getRowData: k,
getRowsData: D,
setRowData: O,
clear: H,
setTableData: c,
scrollTo: w,
scrollToRow: w,
scrollToColumn: M,
table: r
}), (e, t) => (U(), W($, null, [p(l(y).FormItem, {
hidden: "",
name: e.name,
"initial-value": e.formItem?.initialValue,
transform: I
}, null, 8, ["name", "initial-value"]), p(l(y).FormItem, {
label: e.label
}, {
default: h(() => [p(fe, q(l(oe)(o, ["name", "maxLength", "onChange", "defaultValue", "formItem"]), {
ref_key: "tableRef",
ref: r,
class: [l(v)(), l(x)],
size: "mini",
columns: l(E),
"data-source": n.value,
"search-form": !1,
onUpdate: K
}), J({
_: 2
}, [Q(B, (a, m) => ({
name: m,
fn: h((z) => [X(e.$slots, m, Y(Z(z || {})))])
}))]), 1040, ["class", "columns", "data-source"])]),
_: 3
}, 8, ["label"])], 64));
}
});
export {
_e as default
};