@vuetkit/components 0.0.6 → 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/README.md +2 -1
- package/dist/index.d.ts +21 -3
- package/dist/index.js +37 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,4 +8,5 @@ Collection of business development components for Vue3 + ElementPlus projects.
|
|
|
8
8
|
|
|
9
9
|
### Feedback
|
|
10
10
|
|
|
11
|
-
- [useMessage](/components/src/feedback/
|
|
11
|
+
- [useMessage](/components/src/feedback/useMessage/)
|
|
12
|
+
- [useAsyncConfirm](/components/src/feedback/useAsyncConfirm/)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestService } from "@vuetkit/core";
|
|
2
|
+
import { MessageProps, MessageType } from "element-plus";
|
|
2
3
|
|
|
3
|
-
//#region src/feedback/
|
|
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
|
|
21
|
+
//#region src/feedback/useMessage/index.d.ts
|
|
4
22
|
declare function useMessage(options?: MessageProps): {
|
|
5
23
|
success: (message: string) => import("element-plus").MessageHandler;
|
|
6
24
|
error: (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,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { useRequest } from "@vuetkit/core";
|
|
2
|
+
import { ElMessage, ElMessageBox } from "element-plus";
|
|
3
|
+
//#region src/feedback/useMessage/index.ts
|
|
3
4
|
const DEFAULT_DURATION = 3e3;
|
|
4
5
|
const DEFAULT_SHOW_CLOSE = true;
|
|
5
6
|
const DEFAULT_PLAIN = 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 };
|