@anweb/nuxt-ancore 1.4.5 → 1.4.6
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
|
@@ -4,22 +4,27 @@ import { userApi } from "../utils/index.js";
|
|
|
4
4
|
export const useAnData = (config) => {
|
|
5
5
|
const request = ref(config.request);
|
|
6
6
|
const loading = computed(() => {
|
|
7
|
-
return
|
|
7
|
+
return status.value === "pending";
|
|
8
8
|
});
|
|
9
9
|
const key = computed(() => {
|
|
10
10
|
return request.value.toString();
|
|
11
11
|
});
|
|
12
|
-
const
|
|
12
|
+
const {
|
|
13
|
+
data,
|
|
14
|
+
error,
|
|
15
|
+
execute,
|
|
16
|
+
status
|
|
17
|
+
} = useAsyncData(
|
|
13
18
|
key,
|
|
14
19
|
() => userApi(request.value, { method: "GET" }),
|
|
15
20
|
{ immediate: false }
|
|
16
21
|
);
|
|
17
22
|
return {
|
|
18
|
-
init:
|
|
23
|
+
init: execute,
|
|
19
24
|
loading,
|
|
20
25
|
request,
|
|
21
|
-
data
|
|
22
|
-
error
|
|
23
|
-
status
|
|
26
|
+
data,
|
|
27
|
+
error,
|
|
28
|
+
status
|
|
24
29
|
};
|
|
25
30
|
};
|
|
@@ -14,12 +14,12 @@ export default (config) => {
|
|
|
14
14
|
} else if (config.filter) {
|
|
15
15
|
filter.value = { ...config.filter };
|
|
16
16
|
}
|
|
17
|
-
await
|
|
17
|
+
await execute();
|
|
18
18
|
refresh();
|
|
19
19
|
if (config.events) {
|
|
20
20
|
for (const event of config.events) {
|
|
21
|
-
event.bus.on((
|
|
22
|
-
const newCount = event.callback(items, count.value || 0,
|
|
21
|
+
event.bus.on((data2) => {
|
|
22
|
+
const newCount = event.callback(items, count.value || 0, data2);
|
|
23
23
|
if (newCount || newCount === 0) {
|
|
24
24
|
count.value = newCount;
|
|
25
25
|
}
|
|
@@ -27,10 +27,10 @@ export default (config) => {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
if (config.ws) {
|
|
30
|
-
busWS.on((
|
|
31
|
-
const event = config.ws?.find((item) => item.type ===
|
|
30
|
+
busWS.on((data2) => {
|
|
31
|
+
const event = config.ws?.find((item) => item.type === data2.type);
|
|
32
32
|
if (event) {
|
|
33
|
-
const newCount = event.callback(items, count.value || 0,
|
|
33
|
+
const newCount = event.callback(items, count.value || 0, data2.data);
|
|
34
34
|
if (newCount || newCount === 0) {
|
|
35
35
|
count.value = newCount;
|
|
36
36
|
}
|
|
@@ -40,30 +40,35 @@ export default (config) => {
|
|
|
40
40
|
inited.value = true;
|
|
41
41
|
};
|
|
42
42
|
const refresh = () => {
|
|
43
|
-
if (!
|
|
43
|
+
if (!data.value) return;
|
|
44
44
|
if (!filter.value.skip) {
|
|
45
45
|
count.value = null;
|
|
46
46
|
items.length = 0;
|
|
47
47
|
}
|
|
48
48
|
if (config.reverse) {
|
|
49
|
-
items.unshift(...
|
|
49
|
+
items.unshift(...data.value.items);
|
|
50
50
|
} else {
|
|
51
|
-
items.push(...
|
|
51
|
+
items.push(...data.value.items);
|
|
52
52
|
}
|
|
53
|
-
count.value =
|
|
53
|
+
count.value = data.value.count;
|
|
54
54
|
};
|
|
55
55
|
const key = computed(() => {
|
|
56
56
|
return config.request + "?" + toQuery(filter.value);
|
|
57
57
|
});
|
|
58
58
|
const loading = computed(() => {
|
|
59
|
-
return
|
|
59
|
+
return status.value === "pending";
|
|
60
60
|
});
|
|
61
|
-
const
|
|
61
|
+
const {
|
|
62
|
+
data,
|
|
63
|
+
error,
|
|
64
|
+
execute,
|
|
65
|
+
status
|
|
66
|
+
} = useAsyncData(
|
|
62
67
|
key,
|
|
63
68
|
() => userApi(config.request, { method: "GET", query: filter.value }),
|
|
64
69
|
{ immediate: false }
|
|
65
70
|
);
|
|
66
|
-
watch(
|
|
71
|
+
watch(data, refresh);
|
|
67
72
|
return {
|
|
68
73
|
init,
|
|
69
74
|
inited,
|
|
@@ -71,7 +76,7 @@ export default (config) => {
|
|
|
71
76
|
loading,
|
|
72
77
|
items,
|
|
73
78
|
count,
|
|
74
|
-
error
|
|
75
|
-
status
|
|
79
|
+
error,
|
|
80
|
+
status
|
|
76
81
|
};
|
|
77
82
|
};
|