@vuetkit/components 0.0.7 → 0.0.8
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/index.d.ts +20 -2
- package/dist/index.js +36 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestService } from "@vuetkit/core";
|
|
2
|
+
import { MessageProps, MessageType } from "element-plus";
|
|
2
3
|
|
|
4
|
+
//#region src/feedback/useAsyncConfirm/index.d.ts
|
|
5
|
+
interface AsyncConfirmOptions {
|
|
6
|
+
title?: string;
|
|
7
|
+
message?: string;
|
|
8
|
+
type?: MessageType;
|
|
9
|
+
confirmButtonText?: string;
|
|
10
|
+
cancelButtonText?: string;
|
|
11
|
+
successMessage?: string;
|
|
12
|
+
errorMessage?: string;
|
|
13
|
+
confirmSuccess?: () => void;
|
|
14
|
+
confirmError?: (error: unknown) => void;
|
|
15
|
+
}
|
|
16
|
+
declare function useAsyncConfirm(confirmService: RequestService, options: AsyncConfirmOptions): {
|
|
17
|
+
loading: import("vue").Ref<boolean, boolean>;
|
|
18
|
+
confirm: (params?: unknown) => void;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
3
21
|
//#region src/feedback/useMessage/index.d.ts
|
|
4
22
|
declare function useMessage(options?: MessageProps): {
|
|
5
23
|
success: (message: string) => import("element-plus").MessageHandler;
|
|
@@ -9,4 +27,4 @@ declare function useMessage(options?: MessageProps): {
|
|
|
9
27
|
closeAll: () => void;
|
|
10
28
|
};
|
|
11
29
|
//#endregion
|
|
12
|
-
export { useMessage };
|
|
30
|
+
export { AsyncConfirmOptions, useAsyncConfirm, useMessage };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useRequest } from "@vuetkit/core";
|
|
2
|
+
import { ElMessage, ElMessageBox } from "element-plus";
|
|
2
3
|
//#region src/feedback/useMessage/index.ts
|
|
3
4
|
const DEFAULT_DURATION = 3e3;
|
|
4
5
|
const DEFAULT_SHOW_CLOSE = true;
|
|
@@ -44,4 +45,37 @@ function useMessage(options = {}) {
|
|
|
44
45
|
};
|
|
45
46
|
}
|
|
46
47
|
//#endregion
|
|
47
|
-
|
|
48
|
+
//#region src/feedback/useAsyncConfirm/index.ts
|
|
49
|
+
function useAsyncConfirm(confirmService, options) {
|
|
50
|
+
const { title = "Confirm", message = "Sure Confirm?", type = "error", confirmButtonText = "Sure", cancelButtonText = "Cancel", confirmSuccess, confirmError, successMessage, errorMessage } = options || {};
|
|
51
|
+
const { loading, execute: executeConfirm, error } = useRequest(confirmService, { manual: true });
|
|
52
|
+
const { success, error: showError } = useMessage();
|
|
53
|
+
function confirm(params) {
|
|
54
|
+
ElMessageBox.confirm(message, title, {
|
|
55
|
+
confirmButtonText,
|
|
56
|
+
cancelButtonText,
|
|
57
|
+
type,
|
|
58
|
+
beforeClose: async (action, instance, done) => {
|
|
59
|
+
if (action === "confirm") {
|
|
60
|
+
instance.confirmButtonLoading = true;
|
|
61
|
+
await executeConfirm(params);
|
|
62
|
+
instance.confirmButtonLoading = false;
|
|
63
|
+
if (error.value) {
|
|
64
|
+
if (errorMessage) showError(errorMessage);
|
|
65
|
+
confirmError === null || confirmError === void 0 || confirmError(error.value);
|
|
66
|
+
} else {
|
|
67
|
+
if (successMessage) success(successMessage);
|
|
68
|
+
confirmSuccess === null || confirmSuccess === void 0 || confirmSuccess();
|
|
69
|
+
}
|
|
70
|
+
done();
|
|
71
|
+
} else done();
|
|
72
|
+
}
|
|
73
|
+
}).catch(() => {});
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
loading,
|
|
77
|
+
confirm
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { useAsyncConfirm, useMessage };
|