cosey 0.4.28 → 0.4.29
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 +2 -2
- package/hooks/useUpsert.js +15 -11
- package/package.json +1 -1
package/hooks/useUpsert.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ export interface UseUpsertOptions<Model, Row = Model> {
|
|
|
21
21
|
onShownEdit?: (...args: any[]) => void;
|
|
22
22
|
detailsFetch?: (row: Row) => any;
|
|
23
23
|
beforeFill?: (row: Row) => any;
|
|
24
|
-
addFetch?: () => any;
|
|
25
|
-
editFetch?: (row: Row) => any;
|
|
24
|
+
addFetch?: (...args: any[]) => any;
|
|
25
|
+
editFetch?: (row: Row, ...args: any[]) => any;
|
|
26
26
|
success?: (res: any) => any;
|
|
27
27
|
addSuccessText?: string;
|
|
28
28
|
editSuccessText?: string;
|
package/hooks/useUpsert.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ElMessage } from 'element-plus';
|
|
2
2
|
import { cloneDeep, pick } from 'lodash-es';
|
|
3
|
-
import { ref, computed, unref, reactive,
|
|
3
|
+
import { ref, computed, unref, reactive, shallowRef, useTemplateRef, readonly, nextTick } from 'vue';
|
|
4
4
|
import { toRefs } from '@vueuse/core';
|
|
5
5
|
import { useLocale } from './useLocale.js';
|
|
6
6
|
import { uuid } from '../utils/string.js';
|
|
@@ -46,15 +46,19 @@ function useUpsert(options) {
|
|
|
46
46
|
},
|
|
47
47
|
title: mergedTitle
|
|
48
48
|
});
|
|
49
|
+
const data = shallowRef();
|
|
50
|
+
const row = shallowRef();
|
|
51
|
+
let addParams = [];
|
|
52
|
+
let editParams = [];
|
|
49
53
|
const formRefKey = uuid();
|
|
50
54
|
const formRef = useTemplateRef(formRefKey);
|
|
51
55
|
const onSubmit = async () => {
|
|
52
56
|
let res;
|
|
53
57
|
if (type.value === "add") {
|
|
54
|
-
res = await unref(addFetch)?.();
|
|
58
|
+
res = await unref(addFetch)?.(...addParams);
|
|
55
59
|
ElMessage.success(unref(addSuccessText) || t("co.common.operateSuccess"));
|
|
56
60
|
} else {
|
|
57
|
-
res = await unref(editFetch)?.(row.value);
|
|
61
|
+
res = await unref(editFetch)?.(row.value, ...editParams);
|
|
58
62
|
ElMessage.success(unref(editSuccessText) || t("co.common.operateSuccess"));
|
|
59
63
|
}
|
|
60
64
|
unref(success)?.(res);
|
|
@@ -65,20 +69,19 @@ function useUpsert(options) {
|
|
|
65
69
|
ref: formRefKey,
|
|
66
70
|
submit: onSubmit
|
|
67
71
|
});
|
|
68
|
-
const data = shallowRef();
|
|
69
|
-
const row = shallowRef();
|
|
70
72
|
let exposeOptions;
|
|
71
73
|
const expose = {
|
|
72
|
-
edit: async (...args) => {
|
|
74
|
+
edit: async (_row, ...args) => {
|
|
75
|
+
editParams = args;
|
|
73
76
|
type.value = "edit";
|
|
74
|
-
row.value =
|
|
77
|
+
row.value = _row;
|
|
75
78
|
deepAssign(unref(model), initialModel);
|
|
76
|
-
unref(onEdit)?.(...
|
|
79
|
+
unref(onEdit)?.(_row, ...editParams);
|
|
77
80
|
visible.value = true;
|
|
78
81
|
unref(onShow)?.();
|
|
79
82
|
nextTick(() => {
|
|
80
83
|
unref(onShown)?.();
|
|
81
|
-
unref(onShownEdit)?.(...
|
|
84
|
+
unref(onShownEdit)?.(...editParams);
|
|
82
85
|
});
|
|
83
86
|
let filledRow = row.value;
|
|
84
87
|
if (unref(detailsFetch)) {
|
|
@@ -89,15 +92,16 @@ function useUpsert(options) {
|
|
|
89
92
|
Object.assign(unref(model), pick(filledRow, modelKeys));
|
|
90
93
|
},
|
|
91
94
|
add: (...args) => {
|
|
95
|
+
addParams = args;
|
|
92
96
|
type.value = "add";
|
|
93
97
|
row.value = void 0;
|
|
94
98
|
deepAssign(unref(model), initialModel);
|
|
95
|
-
unref(onAdd)?.(...
|
|
99
|
+
unref(onAdd)?.(...addParams);
|
|
96
100
|
visible.value = true;
|
|
97
101
|
unref(onShow)?.();
|
|
98
102
|
nextTick(() => {
|
|
99
103
|
unref(onShown)?.();
|
|
100
|
-
unref(onShownAdd)?.(...
|
|
104
|
+
unref(onShownAdd)?.(...addParams);
|
|
101
105
|
});
|
|
102
106
|
},
|
|
103
107
|
setData: (_data) => {
|