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