@orchidui/core 1.8.1-115 → 1.8.1-116
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.
- package/dist/DataTable/useDataTable.js +54 -54
- package/package.json +1 -1
@@ -1,79 +1,79 @@
|
|
1
|
-
import { ref as
|
1
|
+
import { ref as n } from "vue";
|
2
2
|
function j(w) {
|
3
|
-
const { id: B, name: _, localDb: I, options:
|
3
|
+
const { id: B, name: _, localDb: I, options: y } = w, C = n(B), s = n(_), f = n(I), L = n([]), l = n([]), r = n({
|
4
4
|
page: 1,
|
5
5
|
per_page: 10
|
6
|
-
}),
|
6
|
+
}), b = n({
|
7
7
|
total: 0,
|
8
8
|
last_page: 0
|
9
|
-
}),
|
10
|
-
let
|
11
|
-
const
|
12
|
-
|
13
|
-
let
|
14
|
-
const
|
15
|
-
|
16
|
-
|
17
|
-
const
|
18
|
-
return o.some((
|
19
|
-
}) :
|
20
|
-
const
|
21
|
-
return typeof
|
22
|
-
}) :
|
23
|
-
}),
|
24
|
-
|
9
|
+
}), v = n(!1);
|
10
|
+
let D = null;
|
11
|
+
const g = async () => {
|
12
|
+
v.value = !0, D && clearTimeout(D), D = setTimeout(async () => {
|
13
|
+
let e = f.value.table(s.value);
|
14
|
+
const a = T();
|
15
|
+
console.log("filterOptions", a), a.filter && Object.entries(a.filter).forEach(([c, u]) => {
|
16
|
+
u && (Array.isArray(u) ? e = e.filter((d) => {
|
17
|
+
const o = d[c];
|
18
|
+
return o == null ? !1 : u.some((p) => p == null ? !1 : typeof p == "string" && typeof o == "string" ? o.toLowerCase().includes(p.toLowerCase()) : o === p);
|
19
|
+
}) : typeof u == "string" ? e = e.filter((d) => {
|
20
|
+
const o = d[c];
|
21
|
+
return typeof o != "string" ? !1 : o.toLowerCase().includes(u.toLowerCase());
|
22
|
+
}) : e = e.filter((d) => d[c] === u));
|
23
|
+
}), a.sortBy && a.sortBy.length > 0 && a.sortBy.forEach((c) => {
|
24
|
+
e = e.sortBy(c.column), c.direction === "desc" && (e = e.reverse());
|
25
25
|
});
|
26
|
-
const
|
27
|
-
|
28
|
-
const
|
29
|
-
|
30
|
-
total:
|
31
|
-
last_page: Math.ceil(
|
32
|
-
},
|
26
|
+
const t = (parseInt(r.value.page) - 1) * parseInt(r.value.per_page), i = await e.offset(t).limit(parseInt(r.value.per_page)).toArray();
|
27
|
+
L.value = i;
|
28
|
+
const m = await e.count();
|
29
|
+
console.log("totalField", m), b.value = {
|
30
|
+
total: m,
|
31
|
+
last_page: Math.ceil(parseInt(m) / parseInt(r.value.per_page))
|
32
|
+
}, v.value = !1;
|
33
33
|
}, 500);
|
34
34
|
}, T = () => {
|
35
|
-
const
|
36
|
-
return Object.entries(r.value).forEach(([
|
37
|
-
|
35
|
+
const e = {}, a = (y == null ? void 0 : y.filterable_fields) ?? [];
|
36
|
+
return Object.entries(r.value).forEach(([t, i]) => {
|
37
|
+
a.includes(t) && i !== void 0 && i !== null && i !== "" && (e[t] = i);
|
38
38
|
}), {
|
39
|
-
filter:
|
40
|
-
sortBy:
|
41
|
-
pagination:
|
39
|
+
filter: e,
|
40
|
+
sortBy: l.value,
|
41
|
+
pagination: b.value
|
42
42
|
};
|
43
43
|
};
|
44
44
|
return {
|
45
45
|
// State
|
46
|
-
sortBy:
|
47
|
-
localData:
|
46
|
+
sortBy: l,
|
47
|
+
localData: L,
|
48
48
|
dataTableId: C,
|
49
|
-
dbTablename:
|
50
|
-
paginationData:
|
51
|
-
isLoading:
|
49
|
+
dbTablename: s,
|
50
|
+
paginationData: b,
|
51
|
+
isLoading: v,
|
52
52
|
// Methods
|
53
|
-
toggleSort: (
|
54
|
-
const
|
55
|
-
|
56
|
-
(
|
57
|
-
) :
|
53
|
+
toggleSort: (e) => {
|
54
|
+
const a = l.value.find((t) => t.column === e);
|
55
|
+
a ? a.direction === "asc" ? l.value = l.value.map(
|
56
|
+
(t) => t.column === e ? { ...t, direction: "desc" } : t
|
57
|
+
) : l.value = l.value.filter((t) => t.column !== e) : l.value = [...l.value, { column: e, direction: "asc" }], g();
|
58
58
|
},
|
59
|
-
bulkPutLocalData: async (
|
60
|
-
await f.value.table(
|
59
|
+
bulkPutLocalData: async (e) => {
|
60
|
+
await f.value.table(s.value).bulkPut(e);
|
61
61
|
},
|
62
|
-
bulkDeleteLocalData: async (
|
63
|
-
await f.value.table(
|
62
|
+
bulkDeleteLocalData: async (e) => {
|
63
|
+
await f.value.table(s.value).bulkDelete(e);
|
64
64
|
},
|
65
65
|
getLocalDataUpdatedAt: async () => {
|
66
|
-
const
|
67
|
-
return
|
66
|
+
const e = await f.value.table(s.value).orderBy("updated_at").reverse().limit(1).first();
|
67
|
+
return e == null ? void 0 : e.updated_at;
|
68
68
|
},
|
69
|
-
getLocalDataIds: async () => await f.value.table(
|
70
|
-
syncLocalData:
|
69
|
+
getLocalDataIds: async () => await f.value.table(s.value).toCollection().primaryKeys(),
|
70
|
+
syncLocalData: g,
|
71
71
|
// Setters
|
72
|
-
setFilter: (
|
73
|
-
r.value = { ...
|
72
|
+
setFilter: (e) => {
|
73
|
+
r.value = { ...e }, g();
|
74
74
|
},
|
75
|
-
setSortBy: (
|
76
|
-
|
75
|
+
setSortBy: (e) => {
|
76
|
+
l.value = { ...e }, g();
|
77
77
|
}
|
78
78
|
};
|
79
79
|
}
|