@finema/core 2.7.5 → 2.7.7
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/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { reactive, toRef } from "vue";
|
|
2
2
|
import { ObjectHelper } from "../utils/ObjectHelper.js";
|
|
3
3
|
import {
|
|
4
4
|
apiObjectHelper
|
|
5
5
|
} from "../helpers/apiObjectHelper.js";
|
|
6
6
|
export const useObjectLoader = (loaderOptions) => {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const state = reactive({
|
|
8
|
+
data: null,
|
|
9
|
+
status: ObjectHelper.createStatus(),
|
|
10
|
+
options: {}
|
|
11
|
+
});
|
|
10
12
|
const clear = () => {
|
|
11
|
-
status
|
|
12
|
-
data
|
|
13
|
+
state.status = ObjectHelper.createStatus();
|
|
14
|
+
state.data = null;
|
|
13
15
|
};
|
|
14
16
|
const run = async (payload = {}) => {
|
|
15
17
|
await apiObjectHelper(
|
|
16
18
|
() => ({
|
|
17
|
-
data: data
|
|
18
|
-
status: status
|
|
19
|
-
options: options
|
|
19
|
+
data: state.data,
|
|
20
|
+
status: state.status,
|
|
21
|
+
options: state.options
|
|
20
22
|
}),
|
|
21
|
-
(
|
|
22
|
-
status
|
|
23
|
+
(_status) => {
|
|
24
|
+
state.status = _status;
|
|
23
25
|
},
|
|
24
|
-
(
|
|
25
|
-
options
|
|
26
|
+
(_options) => {
|
|
27
|
+
state.options = _options;
|
|
26
28
|
},
|
|
27
29
|
(_data) => {
|
|
28
|
-
data
|
|
30
|
+
state.data = _data ?? null;
|
|
29
31
|
},
|
|
30
32
|
payload.data,
|
|
31
33
|
{
|
|
@@ -35,15 +37,15 @@ export const useObjectLoader = (loaderOptions) => {
|
|
|
35
37
|
);
|
|
36
38
|
};
|
|
37
39
|
const setLoading = () => {
|
|
38
|
-
status
|
|
40
|
+
state.status = ObjectHelper.toLoadingStatus(state.status);
|
|
39
41
|
};
|
|
40
42
|
const setData = (_data) => {
|
|
41
|
-
data
|
|
43
|
+
state.data = _data;
|
|
42
44
|
};
|
|
43
45
|
return {
|
|
44
|
-
data,
|
|
45
|
-
status,
|
|
46
|
-
options,
|
|
46
|
+
data: toRef(state, "data"),
|
|
47
|
+
status: toRef(state, "status"),
|
|
48
|
+
options: toRef(state, "options"),
|
|
47
49
|
run,
|
|
48
50
|
clear,
|
|
49
51
|
setLoading,
|
|
@@ -76,7 +76,7 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
76
76
|
find.status = ObjectHelper.toLoadingStatus(find.status);
|
|
77
77
|
};
|
|
78
78
|
const fetchPage = async (page = 1, query = "", opts) => {
|
|
79
|
-
|
|
79
|
+
await apiFetchHelper(
|
|
80
80
|
() => ({
|
|
81
81
|
status: fetch.status,
|
|
82
82
|
items: fetch.items,
|
|
@@ -100,7 +100,7 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
100
100
|
);
|
|
101
101
|
};
|
|
102
102
|
const findRun = async (id, opts) => {
|
|
103
|
-
|
|
103
|
+
await apiFindHelper(
|
|
104
104
|
() => ({
|
|
105
105
|
status: find.status,
|
|
106
106
|
data: find.item,
|
|
@@ -123,7 +123,7 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
123
123
|
);
|
|
124
124
|
};
|
|
125
125
|
const addRun = async (payload) => {
|
|
126
|
-
|
|
126
|
+
await apiAddHelper(
|
|
127
127
|
() => ({
|
|
128
128
|
items: fetch.items,
|
|
129
129
|
status: add.status,
|
|
@@ -150,7 +150,7 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
150
150
|
);
|
|
151
151
|
};
|
|
152
152
|
const updateRun = async (id, payload) => {
|
|
153
|
-
|
|
153
|
+
await updateHelper(
|
|
154
154
|
() => ({
|
|
155
155
|
items: fetch.items,
|
|
156
156
|
status: update.status,
|
|
@@ -182,20 +182,20 @@ export const usePageLoader = (loaderOptions) => {
|
|
|
182
182
|
);
|
|
183
183
|
};
|
|
184
184
|
const fetchSearch = async (query = "", opts) => {
|
|
185
|
-
|
|
185
|
+
await fetchPage(1, query, opts);
|
|
186
186
|
};
|
|
187
187
|
const fetchPageChange = async (page, opts) => {
|
|
188
188
|
const {
|
|
189
189
|
page: _page,
|
|
190
190
|
...params
|
|
191
191
|
} = fetch.options?.request?.params || {};
|
|
192
|
-
|
|
192
|
+
await fetchPage(page, "", {
|
|
193
193
|
params,
|
|
194
194
|
...opts
|
|
195
195
|
});
|
|
196
196
|
};
|
|
197
197
|
const deleteRun = async (id, opts) => {
|
|
198
|
-
|
|
198
|
+
await apiDeleteHelper(
|
|
199
199
|
() => ({
|
|
200
200
|
status: del.status,
|
|
201
201
|
data: del.item,
|