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