cosey 0.4.12 → 0.4.13
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/hooks/useUpsert.d.ts +8 -7
- package/hooks/useUpsert.js +18 -16
- package/package.json +1 -1
package/hooks/useUpsert.d.ts
CHANGED
|
@@ -9,16 +9,17 @@ export interface UseUpsertExpose<Row extends Record<string, any>, Data = any> {
|
|
|
9
9
|
setOptions: (options: UseUpsertExposeOptions) => any;
|
|
10
10
|
}
|
|
11
11
|
export type UpsertType = 'edit' | 'add';
|
|
12
|
-
export interface UseUpsertOptions<Model, Row = Model
|
|
12
|
+
export interface UseUpsertOptions<Model, Row = Model> {
|
|
13
13
|
title?: string;
|
|
14
14
|
stuffTitle?: string;
|
|
15
15
|
model: Model;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
onAdd?: (...args: any[]) => void;
|
|
17
|
+
onEdit?: (row: Row, ...args: any[]) => void;
|
|
18
|
+
onShow?: () => void;
|
|
19
|
+
detailsFetch?: (row: Row) => any;
|
|
18
20
|
beforeFill?: (row: Row) => any;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
edit?: (data: Data) => any;
|
|
21
|
+
addFetch?: () => any;
|
|
22
|
+
editFetch?: () => any;
|
|
22
23
|
success?: (res: any) => any;
|
|
23
24
|
addSuccessText?: string;
|
|
24
25
|
editSuccessText?: string;
|
|
@@ -42,7 +43,7 @@ export interface UseUpsertReturn<Model extends Record<string, any>, Row extends
|
|
|
42
43
|
isEdit: ComputedRef<boolean>;
|
|
43
44
|
isAdd: ComputedRef<boolean>;
|
|
44
45
|
}
|
|
45
|
-
export declare function useUpsert<Model extends Record<string, any>, Row extends Record<string, any> = Model, Data = any>(options: MaybeRef<UseUpsertOptions<Model, Row
|
|
46
|
+
export declare function useUpsert<Model extends Record<string, any>, Row extends Record<string, any> = Model, Data = any>(options: MaybeRef<UseUpsertOptions<Model, Row>>): UseUpsertReturn<Model, Row, Data>;
|
|
46
47
|
export interface UseExternalUpsertOptions {
|
|
47
48
|
success?: () => any;
|
|
48
49
|
}
|
package/hooks/useUpsert.js
CHANGED
|
@@ -17,12 +17,13 @@ function useUpsert(options) {
|
|
|
17
17
|
title,
|
|
18
18
|
addSuccessText,
|
|
19
19
|
editSuccessText,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
onAdd,
|
|
21
|
+
onEdit,
|
|
22
|
+
onShow,
|
|
23
|
+
detailsFetch,
|
|
22
24
|
beforeFill,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
edit,
|
|
25
|
+
addFetch,
|
|
26
|
+
editFetch,
|
|
26
27
|
success
|
|
27
28
|
} = toRefs(computed(() => unref(options)));
|
|
28
29
|
const { t, lang } = useLocale();
|
|
@@ -45,13 +46,12 @@ function useUpsert(options) {
|
|
|
45
46
|
const formRefKey = uuid();
|
|
46
47
|
const formRef = useTemplateRef(formRefKey);
|
|
47
48
|
const onSubmit = async () => {
|
|
48
|
-
const data2 = await unref(beforeSubmit)?.(unref(model)) || unref(model);
|
|
49
49
|
let res;
|
|
50
50
|
if (type.value === "add") {
|
|
51
|
-
res = await unref(
|
|
51
|
+
res = await unref(addFetch)?.();
|
|
52
52
|
ElMessage.success(unref(addSuccessText) || t("co.common.addSuccess"));
|
|
53
53
|
} else {
|
|
54
|
-
res = await unref(
|
|
54
|
+
res = await unref(editFetch)?.();
|
|
55
55
|
ElMessage.success(unref(editSuccessText) || t("co.common.editSuccess"));
|
|
56
56
|
}
|
|
57
57
|
unref(success)?.(res);
|
|
@@ -66,26 +66,28 @@ function useUpsert(options) {
|
|
|
66
66
|
const row = shallowRef();
|
|
67
67
|
let exposeOptions;
|
|
68
68
|
const expose = {
|
|
69
|
-
edit: async (
|
|
69
|
+
edit: async (...args) => {
|
|
70
70
|
type.value = "edit";
|
|
71
|
-
row.value =
|
|
71
|
+
row.value = args[0];
|
|
72
72
|
deepAssign(unref(model), initialModel);
|
|
73
|
+
unref(onEdit)?.(...args);
|
|
73
74
|
visible.value = true;
|
|
74
|
-
unref(
|
|
75
|
-
let filledRow =
|
|
76
|
-
if (unref(
|
|
77
|
-
filledRow = await unref(
|
|
75
|
+
unref(onShow)?.();
|
|
76
|
+
let filledRow = row.value;
|
|
77
|
+
if (unref(detailsFetch)) {
|
|
78
|
+
filledRow = await unref(detailsFetch)(row.value);
|
|
78
79
|
}
|
|
79
80
|
filledRow = { ...filledRow };
|
|
80
81
|
filledRow = unref(beforeFill)?.(filledRow) || filledRow;
|
|
81
82
|
Object.assign(unref(model), pick(filledRow, modelKeys));
|
|
82
83
|
},
|
|
83
|
-
add: () => {
|
|
84
|
+
add: (...args) => {
|
|
84
85
|
type.value = "add";
|
|
85
86
|
row.value = void 0;
|
|
86
87
|
deepAssign(unref(model), initialModel);
|
|
88
|
+
unref(onAdd)?.(...args);
|
|
87
89
|
visible.value = true;
|
|
88
|
-
unref(
|
|
90
|
+
unref(onShow)?.();
|
|
89
91
|
},
|
|
90
92
|
setData: (_data) => {
|
|
91
93
|
data.value = _data;
|