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