@aplus-frontend/ui 0.6.0-beta.14 → 0.6.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,100 @@
1
+ import { TableRowSelection } from '@aplus-frontend/antdv/lib/table/interface';
2
+ import { ComputedRef, Ref } from 'vue';
3
+ import { ApTableProps, ApTableRowSelection } from '../../ap-table';
4
+ import { Recordable } from '../../type';
5
+ export interface RowSelectionReturnType<RecordType = any> {
6
+ rowSelection: ComputedRef<TableRowSelection<RecordType>>;
7
+ selectedRows: Ref<Partial<RecordType>[]>;
8
+ /**
9
+ * 选中某行
10
+ * @param item
11
+ * @returns
12
+ */
13
+ select: (item: RecordType) => void;
14
+ /**
15
+ * 取消选中某行
16
+ * @param item
17
+ * @returns
18
+ */
19
+ unSelect: (item: RecordType) => void;
20
+ /**
21
+ * 某行是否被选中
22
+ * @param item
23
+ * @returns
24
+ */
25
+ isSelected: (item: RecordType) => boolean;
26
+ /**
27
+ * 选中当前所有数据
28
+ * @returns
29
+ */
30
+ selectAll: () => void;
31
+ /**
32
+ * 取消选中当前所有数据
33
+ * @returns
34
+ */
35
+ unSelectAll: () => void;
36
+ /**
37
+ * 清空所有选中
38
+ * @returns
39
+ */
40
+ clearAll: () => void;
41
+ /**
42
+ * 切换某行的选中状态
43
+ * @param item
44
+ * @returns
45
+ */
46
+ toggleSelect: (item: RecordType) => void;
47
+ /**
48
+ * 多项选中
49
+ * @param items
50
+ * @returns
51
+ */
52
+ selectMulti: (items: RecordType[]) => void;
53
+ /**
54
+ * 多项反选
55
+ * @param items
56
+ * @returns
57
+ */
58
+ unSelectMulti: (items: RecordType[]) => void;
59
+ /**
60
+ * VxeTable 表格checkbox-change事件
61
+ * @param item
62
+ * @param select
63
+ * @param partRowData
64
+ * @returns
65
+ */
66
+ selectChange: (item: RecordType, select: boolean, partRowData: RecordType[]) => void;
67
+ /**
68
+ * VxeTable 表格checkbox-all事件
69
+ * @param item
70
+ * @param select
71
+ * @param partRowData
72
+ * @returns
73
+ */
74
+ selectAllChange: (select: boolean, partRowData: RecordType[]) => void;
75
+ /**
76
+ * VxeTable 表格checkbox-range-change事件
77
+ * @param selected
78
+ * @param partRowData
79
+ * @returns
80
+ */
81
+ selectRangeChange: (selected: RecordType[], partRowData: RecordType[]) => void;
82
+ /**
83
+ * 通过key勾选多条数据
84
+ * @param keys
85
+ * @returns
86
+ */
87
+ selectMultiByKeys: (keys: (string | number)[]) => void;
88
+ }
89
+ type RowSelectionParams<T> = Omit<ApTableRowSelection<T>, 'mode'> & {
90
+ /**
91
+ * 数据源(如果是后端分页,则表示当页数据,否则是全量数据)
92
+ */
93
+ dataSource: Ref<T[]>;
94
+ /**
95
+ * 同Table的rowkey
96
+ */
97
+ rowKey: ApTableProps['rowKey'];
98
+ };
99
+ declare const useTableRowSelection: <RecordType = Recordable>(props: RowSelectionParams<RecordType>) => RowSelectionReturnType<RecordType>;
100
+ export default useTableRowSelection;
@@ -0,0 +1,122 @@
1
+ import { ref as k, computed as v, unref as a } from "vue";
2
+ import { isFunction as i, cloneDeep as M } from "lodash-unified";
3
+ function m(u, c) {
4
+ return !(c != null && c.length) || i(u) ? [] : c.map((f) => ({ [u]: f }));
5
+ }
6
+ const T = (u) => {
7
+ u.defaultSelectedRowKeys;
8
+ const c = k(
9
+ m(u.rowKey, u.defaultSelectedRowKeys)
10
+ );
11
+ function f(e, t) {
12
+ c.value = t;
13
+ }
14
+ const l = (e) => i(u.rowKey) ? u.rowKey(e) : e[u.rowKey], s = v(() => {
15
+ const e = /* @__PURE__ */ new Map();
16
+ return a(c).forEach((t) => {
17
+ e.set(l(t), t);
18
+ }), e;
19
+ });
20
+ function g(e) {
21
+ return a(s).has(l(e));
22
+ }
23
+ function h(e) {
24
+ const t = a(s);
25
+ t.set(l(e), e), c.value = [...t.values()];
26
+ }
27
+ function x(e) {
28
+ const t = a(s);
29
+ for (const n of e)
30
+ t.set(l(n), n);
31
+ c.value = [...t.values()];
32
+ }
33
+ function w(e) {
34
+ if (i(u.rowKey))
35
+ return;
36
+ const t = a(s);
37
+ for (const n of e) {
38
+ const o = a(u.dataSource).find(
39
+ (d) => l(d) === n
40
+ ), S = { [u.rowKey]: n };
41
+ t.set(String(n), o || S);
42
+ }
43
+ c.value = [...t.values()];
44
+ }
45
+ function y(e) {
46
+ const t = a(s);
47
+ t.delete(l(e)), c.value = [...t.values()];
48
+ }
49
+ function E(e) {
50
+ const t = a(s);
51
+ for (const n of e)
52
+ t.delete(l(n));
53
+ c.value = [...t.values()];
54
+ }
55
+ function r(e, t) {
56
+ const n = e;
57
+ for (const o of t)
58
+ n.set(l(o), o);
59
+ return n;
60
+ }
61
+ function K(e, t, n) {
62
+ const o = a(s);
63
+ t ? o.set(l(e), e) : o.delete(l(e)), r(o, n), c.value = [...o.values()];
64
+ }
65
+ function A(e, t) {
66
+ const n = M(a(s));
67
+ e ? a(u.dataSource).forEach((o) => {
68
+ n.set(l(o), o);
69
+ }) : a(u.dataSource).forEach((o) => {
70
+ n.delete(l(o));
71
+ }), r(n, t), c.value = [...n.values()];
72
+ }
73
+ function C(e, t) {
74
+ const n = M(a(s));
75
+ a(u.dataSource).forEach((o) => {
76
+ e.find((d) => l(d) === l(o)) ? n.set(l(o), o) : n.delete(l(o));
77
+ }), r(n, t), c.value = [...n.values()];
78
+ }
79
+ function R() {
80
+ const e = a(s);
81
+ a(u.dataSource).forEach((t) => {
82
+ e.set(l(t), t);
83
+ }), c.value = [...e.values()];
84
+ }
85
+ function D(e) {
86
+ const t = a(s), n = l(e);
87
+ t.has(n) ? t.delete(n) : t.set(n, e), c.value = [...t.values()];
88
+ }
89
+ function I() {
90
+ const e = a(s);
91
+ a(u.dataSource).forEach((t) => {
92
+ e.delete(l(t));
93
+ }), c.value = [...e.values()];
94
+ }
95
+ function b() {
96
+ c.value = [];
97
+ }
98
+ return {
99
+ select: h,
100
+ unSelect: y,
101
+ isSelected: g,
102
+ selectAll: R,
103
+ unSelectAll: I,
104
+ clearAll: b,
105
+ toggleSelect: D,
106
+ selectedRows: c,
107
+ selectMulti: x,
108
+ unSelectMulti: E,
109
+ rowSelection: v(() => ({
110
+ ...u,
111
+ onChange: f,
112
+ selectedRowKeys: a(c).map((e) => l(e))
113
+ })),
114
+ selectChange: K,
115
+ selectAllChange: A,
116
+ selectRangeChange: C,
117
+ selectMultiByKeys: w
118
+ };
119
+ };
120
+ export {
121
+ T as default
122
+ };