UNPKG

@wetspace/pro-components

Version:
275 lines (274 loc) 9.92 kB
import { defineComponent as X, shallowRef as f, useSlots as Y, computed as s, watch as k, createVNode as o, mergeProps as K, Fragment as w, createTextVNode as A } from "vue"; import { useNamespace as Z, ElTable as p, ElTableColumn as y, ElCheckbox as F, ElRadio as ee, ElCheckboxGroup as ne } from "element-plus"; import { wetSchemaTableProps as te, wetBaseColumnProps as le } from "./types.mjs"; import { useElementBounding as ae } from "../../node_modules/.pnpm/@vueuse_core@10.11.1_vue@3.5.12_typescript@5.4.2_/node_modules/@vueuse/core/index.mjs"; import ue from "./components/selection.vue.mjs"; import re from "./components/enum.vue.mjs"; import i from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/get.mjs"; import oe from "../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/difference.mjs"; import { useDebounceFn as ie } from "../../node_modules/.pnpm/@vueuse_shared@10.11.1_vue@3.5.12_typescript@5.4.2_/node_modules/@vueuse/shared/index.mjs"; const O = (e) => Array.isArray(e) ? e.join("") : e, de = /* @__PURE__ */ X({ name: "WetSchemaTable", props: te, emits: ["update:selections"], setup(e, { emit: b, expose: j }) { const E = f(), { height: _ } = ae(E), v = Z("schema-table"), x = Y(), T = f(), h = f([]), z = s(() => { const n = { ...e }; return delete n.columns, n; }), S = f(!0), N = ie(() => { S.value = !0; }, 200); k(() => e.size, () => { e.fill && (S.value = !1, N()); }); const B = s(() => Array.isArray(e.rowKey) ? e.rowKey.join(".") : e.rowKey), W = s(() => e.rowKey ? e.selections.map((n) => i(n, e.rowKey, void 0)) : []), $ = (n, t) => { var a; let l = e.selections; !e.rowKey || !t || (n ? l.push(t) : l = l.filter((u) => { const r = i(t, e.rowKey, void 0), d = i(u, e.rowKey, void 0); return r !== d; }), (a = e.rowSelection) != null && a.onChange && e.rowSelection.onChange(l), b("update:selections", l)); }, G = (n) => { let t = [...e.selections]; const l = e.rowKey || ""; if (n) { let a = t.map((u) => i(u, l, void 0)); a = a.filter((u) => u !== void 0), e.data.forEach((u) => { const r = i(u, l, void 0); a.includes(r) || t.push(u); }), h.value = ["1"]; } else { h.value = []; let a = e.data.map((u) => i(u, l, void 0)); a = a.filter((u) => u !== void 0), t = t.filter((u) => { const r = i(u, l, void 0); return !a.includes(r); }); } b("update:selections", t); }, C = s(() => { const n = e.rowKey || [], t = [...e.selections]; let l = (e.data || []).map((r) => i(r, n, void 0)); l = l.filter((r) => r !== void 0); let a = t.map((r) => i(r, n, void 0)); return a = a.filter((r) => r !== void 0), oe(l, a).length === 0; }), H = s(() => C.value ? !C.value : e.selections.length !== 0); k(C, (n) => { n && e.selections.length !== 0 ? h.value = ["1"] : h.value = []; }); const q = (n) => { var t, l; !e.rowKey || n === void 0 || (((t = e.rowSelection) == null ? void 0 : t.type) === "line" || ((l = e.rowSelection) == null ? void 0 : l.type) === "radio") && (e.rowSelection.onChange && e.rowSelection.onChange([n]), b("update:selections", [n])); }, J = s(() => { var n, t, l; return ((n = e.rowSelection) == null ? void 0 : n.type) === "line" || ((t = e.rowSelection) == null ? void 0 : t.type) === "radio" ? !0 : !!((l = e.columns) == null ? void 0 : l.find((u) => u.isScrollMark === !0)) || e.highlightCurrentRow; }), M = (n, t) => { const l = Array.isArray(t) ? t : [t]; return i(n, l, e.emptyFormat || void 0); }, I = s(() => { var t; let n = !1; return (t = e.columns) == null || t.forEach((l) => { l.fixed && (n = !0); }), n; }), V = f({}), R = (n) => { const t = Array.isArray(n.dataIndex) ? n.dataIndex.join("") : n.dataIndex, l = {}; return Object.keys(le).forEach((a) => { n[a] !== void 0 && (l[a] = n[a]); }), l.prop = t, n.columns && n.columns.length !== 0 ? o(y, K(l, { showOverflowTooltip: n.ellipsis ? e.ellipsisProps : !1, key: t }), { default() { return n.columns.map((a) => R(a)); } }) : o(y, K(l, { label: l.label || n.title, key: t }), { default({ row: a, $index: u }) { return o(w, null, [n.isScrollMark && o("span", { ref: (r) => V.value[u] = r }, null), n.isRender ? x[t] && x[t]({ row: a, $index: u }) : n.render ? n.render({ row: a, $index: u }) : n.valueEnum ? o(re, { valueEnum: n.valueEnum, value: M(a, n.dataIndex) }, null) : M(a, n.dataIndex)]); } }); }, P = f({}), L = (n, t) => { const l = [...n, {}], a = []; let u = "", r = [], d = 0; return l.forEach((c, g) => { if (!u) u = c[t], r.push(c); else if (u === c[t]) r.push(c); else { u = c[t]; const m = d; d = g, a.push({ start: m, lg: r.length }), r = [], r.push(c); } }), a; }; e.mergeDataIndexs && k(() => e.data, (n) => { var t; n && ((t = e.mergeDataIndexs) == null || t.forEach((l) => { const a = O(l); P.value[a] = L(n, a); })); }, { immediate: !0, deep: !0 }); const Q = s(() => { if (e.mergeDataIndexs || e.spanMethod) return (n) => { const { column: t, rowIndex: l } = n; if (e.spanMethod) return e.spanMethod(n); if ((e.mergeDataIndexs || []).map((u) => O(u)).includes(t.property)) { const u = P.value[t.property].find((r) => r.start === l); return u ? [u.lg, 1] : [0, 0]; } else return [1, 1]; }; }); return j({ scrollToIndex: (n) => { var l; V.value[n] && V.value[n].scrollIntoView({ behavior: "smooth", block: "center" }); const t = e.data[n]; t && ((l = T.value) == null || l.setCurrentRow(t)); } }), () => { var n; return o("div", { ref: E, class: [v.b(), v.is("fill", e.fill)] }, [o(ue, { type: (n = e.rowSelection) == null ? void 0 : n.type, modelValue: W.value }, { default: () => [o(p, K(z.value, { rowKey: B.value, highlightCurrentRow: J.value, height: e.height ? e.height : e.fill ? _.value : void 0, "onCurrent-change": q, ref: T, style: { display: S.value ? "block" : "none" }, spanMethod: Q.value }), { default: () => [e.expandable && o(y, { fixed: I.value, type: "expand" }, { default({ row: t, $index: l }) { var a, u, r, d, c, g; if (typeof e.expandable == "boolean") return x.expandable && x.expandable({ row: t, $index: l }); { let m; const D = (a = e.expandable) == null ? void 0 : a.dataIndex; return (u = e.expandable) != null && u.dataOutput ? m = e.expandable.dataOutput : m = (U) => D ? i(U, D, []) : [], o(de, { size: ((r = e.expandable) == null ? void 0 : r.size) || "small", class: [v.e("expandable")], expandable: (d = e.expandable) == null ? void 0 : d.expandable, showIndex: (c = e.expandable) == null ? void 0 : c.showIndex, columns: (g = e.expandable) == null ? void 0 : g.columns, ellipsisProps: e.ellipsisProps, data: m(t, l) }, null); } } }), e.rowSelection && e.rowKey && o(y, { width: 50, fixed: e.rowSelection.fixed || I.value, align: "center" }, { default({ row: t }) { var a, u; if (!e.rowKey) return o(w, null, null); const l = i(t, e.rowKey, void 0); return ((a = e.rowSelection) == null ? void 0 : a.type) === "checkbox" ? o(F, { label: l, value: l, onChange: (r) => $(r, t) }, { default: () => [A(" ")] }) : ((u = e.rowSelection) == null ? void 0 : u.type) === "radio" ? o(ee, { label: l, value: l }, { default: () => [A(" ")] }) : o(w, null, null); }, header() { var t; return o(w, null, [((t = e.rowSelection) == null ? void 0 : t.type) === "checkbox" && o(ne, { modelValue: h.value }, { default: () => [o(F, { indeterminate: H.value, label: "1", value: "1", onChange: G }, { default: () => [A(" ")] })] })]); } }), e.showIndex && o(y, { fixed: I.value, label: "序号", showOverflowTooltip: e.ellipsisProps, width: 60 }, { default({ $index: t }) { return o(w, null, [t + 1]); } }), (e.columns || []).map((t) => R(t))] })] })]); }; } }); export { de as default };