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