@wetspace/pro-components
Version:
::: tip 基本介绍
68 lines (67 loc) • 1.92 kB
JavaScript
import { watch as g } from "vue";
import "element-plus";
const b = (y, m, c) => {
const { columns: u, data: l } = y, f = { ...{ summaryLabel: "合计", summaryEmpty: "-" }, ...c }, r = [];
return u.forEach((s, t) => {
if (t === 0)
r[t] = f.summaryLabel;
else if (m.includes(s.property)) {
let e = 0;
l.forEach((a) => {
const n = a[s.property];
isNaN(Number(n)) || (e += Number(n));
}), r[t] = `${e}`;
} else
r[t] = f.summaryEmpty;
}), r;
}, v = (y, m, c) => {
let u = {}, l = {};
const i = (r) => {
u = {}, l = {}, r.forEach((s, t) => {
if (m.forEach((e) => {
if (!u[e])
u[e] = [{ start: 0, step: 1, value: s[e] }];
else {
const a = u[e][u[e].length - 1];
a.value === s[e] ? a.step++ : u[e].push({
start: t,
step: 1,
value: s[e]
});
}
}), c) {
const { rowIndex: e, adjoinProp: a } = c;
(typeof e == "function" ? e(t) : e.includes(t)) && a.forEach((o) => {
if (!l[t])
l[t] = [{ start: o, step: 1, value: s[o] }];
else {
const p = l[t][l[t].length - 1];
p.value === s[o] ? p.step++ : l[t].push({ start: o, step: 1, value: s[o] });
}
});
}
});
}, f = (r) => {
const s = (c == null ? void 0 : c.adjoinProp) || [], { column: t, rowIndex: e } = r;
let a = 1, n = 1;
if (m.includes(t.property)) {
const o = u[t.property].find((p) => p.start === e);
n = o ? o.step : 0;
}
if (l[`${e}`] && s.includes(t.property)) {
const o = l[`${e}`].find((p) => p.start === t.property);
a = o ? o.step : 0;
}
return { colspan: a, rowspan: n };
};
return g(y, (r) => {
r && i(r);
}, {
immediate: !0,
deep: !0
}), f;
};
export {
b as tableColumnSummary,
v as useMergeTableCell
};