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