@aplus-frontend/ui
Version:
105 lines (104 loc) • 3.03 kB
JavaScript
import { clsx as k } from "clsx";
import { isArray as g, isFunction as w } from "lodash-unified";
import { unref as E, computed as F } from "vue";
import { getFinalEditableNode as v } from "../../ap-grid/utils/editable.mjs";
import { updateFormProps as y, getFieldProps as q } from "../../ap-table/utils.mjs";
import { getColumnIsRequired as A } from "../../editable-table/utils.mjs";
import "../../utils/index.mjs";
import { getRowKey as K } from "../editable/utils.mjs";
import { isDef as M } from "../../utils/is.mjs";
function b(t, n, i) {
t.__skipNextRefresh ? t.__skipNextRefresh[n] = i : t.__skipNextRefresh = { [n]: i };
}
function S(t, n, i) {
t.__prevEditable ? t.__prevEditable[n] = i : t.__prevEditable = { [n]: i };
}
const O = (t, n, i) => {
function I(e) {
const s = e.editable, o = i ? [i] : g(t.name) ? t.name : [t.name];
return !s || e.children?.length ? {
_path: [...o]
} : {
customRender({ value: d, originalNode: R, params: a, ...r }) {
const c = w(e.editable) ? e.editable(
r.text,
r.record,
r.rowIndex
) : !!e.editable;
let u = R;
const p = g(e.dataIndex) ? e.dataIndex : [e.dataIndex], _ = K(
r.record,
r.rowIndex,
t.rowKey
);
if (c) {
const x = y(
e,
q(e.fieldProps, {
value: d,
...r
})
), h = {};
t.onFieldChange && (h[`onUpdate:${x.valuePropName || "value"}`] = (N) => t.onFieldChange?.(
r.rowIndex,
e.dataIndex,
N
));
const C = {
name: [...o, String(_), ...p],
...x || {},
field: {
style: "width: 100%",
...x?.field || {},
...h,
class: k("is-editable", x.class)
}
};
u = v(
e,
C,
r.record,
E(n)
);
}
e.customRender && (u = e.customRender({
value: d,
...r,
editable: c,
originalNode: u,
index: r.rowIndex,
renderIndex: r.rowIndex,
path: [...o, String(_)]
}));
const l = a.node, f = a.column.getColId(), m = l.__prevEditable?.[f];
return !l.__skipNextRefresh?.[f] && M(m) && m !== c && (b(l, f, !0), setTimeout(() => {
a?.api.refreshCells({
rowNodes: [a.node],
columns: [a.column.getColId()],
force: !0
}), b(l, f, !1);
}, 0)), S(l, f, c), u;
},
_path: [...o]
};
}
return F(() => {
const e = t.columns;
if (!e)
return [];
function s(o) {
return o.map((d) => ({
...d,
_requireMark: A(d),
children: s(d.children || []),
// 处理可编辑/不可编辑下的单元格渲染
...I(d)
}));
}
return s(e);
});
};
export {
O as default,
O as useGetEditableColumns
};