@anweb/nuxt-ancore 1.11.1 → 1.12.1
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 +1 -1
- package/dist/runtime/composables/useAnForm.d.ts +3 -2
- package/dist/runtime/composables/useAnForm.js +15 -4
- package/dist/runtime/composables/useAnList.d.ts +2 -0
- package/dist/runtime/composables/useAnList.js +23 -0
- package/dist/runtime/types/api.d.ts +2 -7
- package/dist/runtime/types/api.js +0 -0
- package/dist/runtime/types/argument.d.ts +1 -0
- package/dist/runtime/types/argument.js +0 -0
- package/dist/runtime/types/index.d.ts +2 -0
- package/dist/runtime/types/index.js +4 -2
- package/dist/runtime/types/infiniteScroll.d.ts +8 -0
- package/dist/runtime/types/infiniteScroll.js +0 -0
- package/dist/runtime/types/responseList.d.ts +4 -4
- package/dist/runtime/types/responseList.js +0 -0
- package/package.json +9 -10
package/dist/module.json
CHANGED
|
@@ -4,9 +4,10 @@ interface TStructureItem<TData> {
|
|
|
4
4
|
default: TData;
|
|
5
5
|
rules?: RuleItem[];
|
|
6
6
|
}
|
|
7
|
-
export declare const useAnForm: <TForm extends object>(params: Record<keyof TForm, TStructureItem<TForm[keyof TForm]>>, data?:
|
|
7
|
+
export declare const useAnForm: <TForm extends object, TData extends Partial<TForm> | null | (Record<string, any> & Partial<TForm>) = Partial<TForm> | null>(params: Record<keyof TForm, TStructureItem<TForm[keyof TForm]>>, data?: TData) => {
|
|
8
8
|
state: [TForm] extends [import("vue").Ref<any, any>] ? import("@vue/shared").IfAny<TForm, import("vue").Ref<TForm, TForm>, TForm> : import("vue").Ref<import("vue").UnwrapRef<TForm>, TForm | import("vue").UnwrapRef<TForm>>;
|
|
9
|
-
|
|
9
|
+
diff: import("vue").ComputedRef<Partial<TForm>>;
|
|
10
|
+
merge: (data: Partial<TForm>, commit?: true) => void;
|
|
10
11
|
validator: {
|
|
11
12
|
check: () => Promise<UseAsyncValidatorExecuteReturn>;
|
|
12
13
|
errors: [Partial<Record<keyof TForm, string>>] extends [import("vue").Ref<any, any>] ? import("@vue/shared").IfAny<import("vue").Ref<any, any> & Partial<Record<keyof TForm, string>>, import("vue").Ref<import("vue").Ref<any, any> & Partial<Record<keyof TForm, string>>, import("vue").Ref<any, any> & Partial<Record<keyof TForm, string>>>, import("vue").Ref<any, any> & Partial<Record<keyof TForm, string>>> : import("vue").Ref<import("vue").UnwrapRef<Partial<Record<keyof TForm, string>>>, Partial<Record<keyof TForm, string>> | import("vue").UnwrapRef<Partial<Record<keyof TForm, string>>>>;
|
|
@@ -21,10 +21,13 @@ export const useAnForm = (params, data) => {
|
|
|
21
21
|
initValidate();
|
|
22
22
|
void nextTick(History.clear);
|
|
23
23
|
};
|
|
24
|
-
const merge = (data2) => {
|
|
24
|
+
const merge = (data2, commit) => {
|
|
25
25
|
for (const key of keys) {
|
|
26
26
|
state.value[key] = data2[key];
|
|
27
27
|
}
|
|
28
|
+
if (commit) {
|
|
29
|
+
void nextTick(History.clear);
|
|
30
|
+
}
|
|
28
31
|
};
|
|
29
32
|
const initValidate = () => {
|
|
30
33
|
const rules = {};
|
|
@@ -57,15 +60,23 @@ export const useAnForm = (params, data) => {
|
|
|
57
60
|
const last = JSON.stringify(History.last.value.snapshot);
|
|
58
61
|
return firstOne !== last;
|
|
59
62
|
});
|
|
63
|
+
const diff = computed(() => {
|
|
64
|
+
const changed = {};
|
|
65
|
+
for (const key of keys) {
|
|
66
|
+
if (JSON.stringify(state.value[key]) !== JSON.stringify(first.value[key])) {
|
|
67
|
+
changed[key] = state.value[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return changed;
|
|
71
|
+
});
|
|
60
72
|
watch(state, () => {
|
|
61
73
|
errors.value = {};
|
|
62
74
|
}, { deep: true });
|
|
63
75
|
init();
|
|
64
76
|
return {
|
|
65
77
|
state,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
78
|
+
diff,
|
|
79
|
+
merge,
|
|
69
80
|
validator: {
|
|
70
81
|
check: () => {
|
|
71
82
|
return validatorExecute();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
|
|
2
|
+
import type { TInfiniteScroll } from '#ancore/types';
|
|
2
3
|
interface TConfig<TFilter> {
|
|
3
4
|
request: NitroFetchRequest;
|
|
4
5
|
apiConfig?: NitroFetchOptions<string>;
|
|
@@ -9,6 +10,7 @@ interface TConfig<TFilter> {
|
|
|
9
10
|
}
|
|
10
11
|
export declare const useAnList: <TData, TFilter extends object = {}>(initConfig: TConfig<TFilter>) => {
|
|
11
12
|
init: () => Promise<void>;
|
|
13
|
+
infiniteScroll: (scrollConfig?: TInfiniteScroll) => void;
|
|
12
14
|
filter: TFilter;
|
|
13
15
|
params: Record<string, unknown> | undefined;
|
|
14
16
|
items: TData[];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { ref, reactive, watch, computed } from "vue";
|
|
2
|
+
import { useInfiniteScroll } from "@vueuse/core";
|
|
2
3
|
import { useAnData } from "./useAnData.js";
|
|
3
4
|
export const useAnList = (initConfig) => {
|
|
4
5
|
const config = ref(initConfig);
|
|
5
6
|
const items = reactive([]);
|
|
6
7
|
const count = ref(null);
|
|
8
|
+
let resetInfiniteScroll;
|
|
7
9
|
const init = async () => {
|
|
8
10
|
await data.init();
|
|
9
11
|
refresh();
|
|
@@ -20,10 +22,30 @@ export const useAnList = (initConfig) => {
|
|
|
20
22
|
items.push(...data.data.value.items);
|
|
21
23
|
}
|
|
22
24
|
setCount(data.data.value.count);
|
|
25
|
+
resetInfiniteScroll?.();
|
|
23
26
|
};
|
|
24
27
|
const setCount = (value) => {
|
|
25
28
|
count.value = value;
|
|
26
29
|
};
|
|
30
|
+
const infiniteScroll = (scrollConfig) => {
|
|
31
|
+
const onLoadMore = scrollConfig?.onLoadMore || (() => {
|
|
32
|
+
if (!config.value.filter) config.value.filter = {};
|
|
33
|
+
config.value.filter[config.value.skipField || "skip"] = items.length;
|
|
34
|
+
});
|
|
35
|
+
const canLoadMore = scrollConfig?.options?.canLoadMore || (() => {
|
|
36
|
+
return (scrollConfig?.canLoadMore?.() ?? true) && inited.value && items.length < (count.value || 0) && // @ts-ignore
|
|
37
|
+
!!config.value.filter.limit;
|
|
38
|
+
});
|
|
39
|
+
const { reset } = useInfiniteScroll(
|
|
40
|
+
scrollConfig?.element || window,
|
|
41
|
+
onLoadMore,
|
|
42
|
+
{
|
|
43
|
+
...scrollConfig?.options,
|
|
44
|
+
canLoadMore
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
resetInfiniteScroll = reset;
|
|
48
|
+
};
|
|
27
49
|
const inited = computed(() => data.status.value !== "idle");
|
|
28
50
|
if (!config.value.apiConfig) {
|
|
29
51
|
config.value.apiConfig = {};
|
|
@@ -37,6 +59,7 @@ export const useAnList = (initConfig) => {
|
|
|
37
59
|
watch(data.data, refresh);
|
|
38
60
|
return {
|
|
39
61
|
init,
|
|
62
|
+
infiniteScroll,
|
|
40
63
|
filter: config.value.filter,
|
|
41
64
|
params: config.value.params,
|
|
42
65
|
items,
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
import type { NitroFetchRequest, NitroFetchOptions } from 'nitropack'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type TApi = <TData = unknown, TError = unknown>(
|
|
5
|
-
request: NitroFetchRequest,
|
|
6
|
-
opts: NitroFetchOptions<string>
|
|
7
|
-
) => Promise<TData>
|
|
1
|
+
import type { NitroFetchRequest, NitroFetchOptions } from 'nitropack';
|
|
2
|
+
export type TApi = <TData = unknown, TError = unknown>(request: NitroFetchRequest, opts: NitroFetchOptions<string>) => Promise<TData>;
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TArgument<TFn extends (...args: any[]) => any, Index extends number> = Index extends keyof Parameters<TFn> ? Parameters<TFn>[Index] : never;
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TArgument } from '#ancore/types';
|
|
2
|
+
import type { useInfiniteScroll } from '@vueuse/core';
|
|
3
|
+
export interface TInfiniteScroll {
|
|
4
|
+
element?: TArgument<typeof useInfiniteScroll, 0>;
|
|
5
|
+
onLoadMore?: TArgument<typeof useInfiniteScroll, 1>;
|
|
6
|
+
options?: TArgument<typeof useInfiniteScroll, 2>;
|
|
7
|
+
canLoadMore?: () => boolean;
|
|
8
|
+
}
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface TResponseList<TData> {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
1
|
+
export interface TResponseList<TData> {
|
|
2
|
+
items: TData[];
|
|
3
|
+
count: number;
|
|
4
|
+
}
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anweb/nuxt-ancore",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"description": "AnCore Nuxt module",
|
|
5
5
|
"repository": "https://github.com/ANLTD/ancore",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,20 +32,19 @@
|
|
|
32
32
|
"release:major": "npm run prepack && changelogen --major --release && npm publish --access public && git push --follow-tags"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@nuxt/kit": "^4.
|
|
36
|
-
"@vueuse/core": "^
|
|
37
|
-
"@vueuse/integrations": "^
|
|
35
|
+
"@nuxt/kit": "^4.2.0",
|
|
36
|
+
"@vueuse/core": "^14.0.0",
|
|
37
|
+
"@vueuse/integrations": "^14.0.0",
|
|
38
38
|
"async-validator": "^4.2.5",
|
|
39
|
-
"
|
|
40
|
-
"i18next": "^25.5.2"
|
|
39
|
+
"i18next": "^25.6.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@nuxt/devtools": "^
|
|
42
|
+
"@nuxt/devtools": "^3.0.0",
|
|
44
43
|
"@nuxt/module-builder": "^1.0.2",
|
|
45
|
-
"@nuxt/schema": "^4.
|
|
44
|
+
"@nuxt/schema": "^4.2.0",
|
|
46
45
|
"@types/node": "latest",
|
|
47
46
|
"changelogen": "^0.6.2",
|
|
48
|
-
"nuxt": "^4.
|
|
49
|
-
"typescript": "~5.9.
|
|
47
|
+
"nuxt": "^4.2.0",
|
|
48
|
+
"typescript": "~5.9.3"
|
|
50
49
|
}
|
|
51
50
|
}
|