UNPKG

@layui/layui-vue

Version:

a component library for Vue 3 base on layui-vue

37 lines (36 loc) 1.66 kB
import { ref as o, watch as r, reactive as p, computed as S, toRaw as h } from "vue"; import { isValueArray as f, loopForEach as v } from "../../utils/arrayUtil.js"; function K(t, u) { const s = o(t.selectedKey); r(() => t.selectedKey, (e) => { s.value = e; }); const i = o(!1), m = o(!1), c = p([]), n = S(() => { const e = [], l = (a) => { a.forEach((d) => { e.push(d[t.id]), f(d[t.childrenColumnName]) && l(d[t.childrenColumnName]); }); }; return l(t.dataSource), e; }); return r(() => t.selectedKeys, (e) => { c.splice(0, c.length, ...h(e || [])); }, { immediate: !0, deep: !0 }), r(() => [c, n.value], ([e, l]) => { var a; i.value = l.every((d) => e.includes(d)), m.value = l.some((d) => e.includes(d)), e.length !== ((a = t.selectedKeys) == null ? void 0 : a.length) && u("update:selectedKeys", [...e]); }, { immediate: !0, deep: !0 }), { tableSelectedKey: s, toggleSelected: function(e) { s.value = e, u("update:selectedKey", e); }, allMSelected: i, setMAllSelected: function(e) { e ? c.push(...n.value.filter((l) => !c.includes(l))) : c.splice(0, c.length, ...c.filter((l) => !n.value.includes(l))), u("checkbox-all", e ? n.value : []); }, someMSelected: m, tableMSelectedKeys: c, toggleMSelected: function(e, l) { l ? c.push(e[t.id]) : c.splice(c.indexOf(e[t.id]), 1), u("checkbox", l, h(e)); }, getAllSelectedDataSource: function() { const e = [.../* @__PURE__ */ new Set([s.value, ...c])], l = []; return v(t.dataSource, t.childrenColumnName, (a) => { e.includes(a[t.id]) && l.push({ ...a }); }), l; } }; } export { K as useTableSelected };