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