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