@ecolovo/uniapp-components 2.0.3 → 2.0.5
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/components/badge/badge.vue +22 -11
- package/components/badge/types.d.ts +6 -0
- package/components/badge/types.js +4 -0
- package/components/badge/types.ts +10 -0
- package/components/button/button.vue +77 -48
- package/components/button/types.d.ts +20 -0
- package/components/button/types.js +4 -0
- package/components/button/types.ts +24 -0
- package/components/checkbox/checkbox.scss +1 -1
- package/components/checkbox/checkbox.vue +2 -0
- package/components/checkbox/types.d.ts +10 -0
- package/components/checkbox/types.js +4 -0
- package/components/checkbox/types.ts +16 -0
- package/components/checkbox-group/checkbox-group.vue +2 -0
- package/components/checkbox-group/types.d.ts +10 -0
- package/components/checkbox-group/types.js +8 -0
- package/components/checkbox-group/types.ts +20 -0
- package/components/checkbox-group2/checkbox-group2.vue +2 -0
- package/components/data-list/data-list.vue +13 -7
- package/components/date-picker/date-picker.vue +2 -0
- package/components/date-picker/types.d.ts +12 -0
- package/components/date-picker/types.js +4 -0
- package/components/date-picker/types.ts +18 -0
- package/components/dialog/dialog-content.vue +61 -46
- package/components/dialog/dialog.vue +55 -29
- package/components/dialog/types.d.ts +20 -0
- package/components/dialog/types.js +4 -0
- package/components/dialog/types.ts +24 -0
- package/components/dropdown/dropdown.vue +2 -0
- package/components/dropdown/types.d.ts +10 -0
- package/components/dropdown/types.js +4 -0
- package/components/dropdown/types.ts +16 -0
- package/components/empty/empty.vue +37 -20
- package/components/empty/types.d.ts +12 -0
- package/components/empty/types.js +9 -0
- package/components/empty/types.ts +21 -0
- package/components/flex/flex.vue +2 -0
- package/components/flex/types.d.ts +12 -0
- package/components/flex/types.js +4 -0
- package/components/flex/types.ts +22 -0
- package/components/form/form.vue +2 -0
- package/components/form/types.d.ts +6 -0
- package/components/form/types.js +4 -0
- package/components/form/types.ts +10 -0
- package/components/form-item/form-item.scss +6 -0
- package/components/form-item/form-item.vue +9 -3
- package/components/form-item/types.d.ts +6 -0
- package/components/form-item/types.js +4 -0
- package/components/form-item/types.ts +12 -0
- package/components/image/image.vue +28 -21
- package/components/image/types.d.ts +18 -0
- package/components/image/types.js +4 -0
- package/components/image/types.ts +23 -0
- package/components/index.d.ts +2 -1
- package/components/index.js +2 -1
- package/components/index.ts +2 -1
- package/components/input/input.scss +9 -0
- package/components/input/input.vue +11 -4
- package/components/input/password-input.vue +3 -1
- package/components/input/types.d.ts +20 -0
- package/components/input/types.js +8 -0
- package/components/input/types.ts +31 -0
- package/components/list-page/list-page.vue +21 -24
- package/components/list-page/types.d.ts +6 -0
- package/components/list-page/types.js +4 -0
- package/components/list-page/types.ts +12 -0
- package/components/load-more/load-more.scss +1 -0
- package/components/load-more/load-more.vue +66 -6
- package/components/load-more/types.d.ts +6 -0
- package/components/load-more/types.js +4 -0
- package/components/load-more/types.ts +12 -0
- package/components/loading/loading.vue +2 -0
- package/components/loading/types.d.ts +6 -0
- package/components/loading/types.js +4 -0
- package/components/loading/types.ts +12 -0
- package/components/message-box/message-box.d.ts +14 -16
- package/components/message-box/message-box.ts +0 -2
- package/components/message-box/message-box.vue +18 -43
- package/components/message-box/types.d.ts +16 -0
- package/components/message-box/types.js +4 -0
- package/components/message-box/types.ts +22 -0
- package/components/number-dialog/number-dialog.vue +5 -3
- package/components/number-dialog/types.d.ts +18 -0
- package/components/number-dialog/types.js +4 -0
- package/components/number-dialog/types.ts +24 -0
- package/components/number-input/number-input.scss +1 -1
- package/components/number-input/number-input.vue +5 -3
- package/components/number-input/types.d.ts +20 -0
- package/components/number-input/types.js +4 -0
- package/components/number-input/types.ts +26 -0
- package/components/numpad/numpad.vue +2 -0
- package/components/numpad/types.d.ts +10 -0
- package/components/numpad/types.js +4 -0
- package/components/numpad/types.ts +14 -0
- package/components/page/page-body.scss +1 -1
- package/components/page/page-footer.vue +2 -3
- package/components/page/page-header.vue +19 -9
- package/components/page/page.vue +45 -14
- package/components/page/types.d.ts +16 -0
- package/components/page/types.js +8 -0
- package/components/page/types.ts +27 -0
- package/components/picker/picker-popup.vue +10 -6
- package/components/picker/picker.vue +8 -0
- package/components/picker/types.d.ts +14 -0
- package/components/picker/types.js +4 -0
- package/components/picker/types.ts +18 -0
- package/components/popover/popover-content.vue +10 -1
- package/components/popover/popover-mask.vue +5 -5
- package/components/popover/popover.vue +34 -29
- package/components/popover/types.d.ts +10 -0
- package/components/popover/types.js +4 -0
- package/components/popover/types.ts +16 -0
- package/components/popup/popup-content.vue +61 -43
- package/components/popup/popup.vue +34 -28
- package/components/popup/types.d.ts +20 -0
- package/components/popup/types.js +4 -0
- package/components/popup/types.ts +24 -0
- package/components/price/price.scss +7 -3
- package/components/price/price.vue +6 -0
- package/components/price/types.d.ts +10 -0
- package/components/price/types.js +4 -0
- package/components/price/types.ts +14 -0
- package/components/search/search.vue +2 -0
- package/components/search/types.d.ts +14 -0
- package/components/search/types.js +4 -0
- package/components/search/types.ts +18 -0
- package/components/searching/searching.scss +9 -9
- package/components/searching/searching.vue +2 -0
- package/components/searching/types.d.ts +8 -0
- package/components/searching/types.js +4 -0
- package/components/searching/types.ts +14 -0
- package/components/switch/switch.vue +5 -8
- package/components/switch/types.d.ts +8 -0
- package/components/switch/types.js +4 -0
- package/components/switch/types.ts +12 -0
- package/components/tab/tab.vue +2 -0
- package/components/tab/types.d.ts +8 -0
- package/components/tab/types.js +4 -0
- package/components/tab/types.ts +12 -0
- package/components/textarea/textarea.scss +10 -0
- package/components/textarea/textarea.vue +17 -9
- package/components/textarea/types.d.ts +12 -0
- package/components/textarea/types.js +4 -0
- package/components/textarea/types.ts +18 -0
- package/components/upload/composable.d.ts +24 -0
- package/components/upload/composable.js +173 -0
- package/components/upload/composable.ts +228 -0
- package/components/upload/media-upload.scss +12 -0
- package/components/upload/media-upload.vue +250 -0
- package/components/upload/types.d.ts +29 -0
- package/components/upload/types.js +4 -0
- package/components/upload/types.ts +38 -0
- package/composable/component-name.d.ts +8 -0
- package/composable/component-name.js +11 -4
- package/composable/component-name.ts +8 -0
- package/composable/dialog.d.ts +40 -0
- package/composable/dialog.js +96 -0
- package/composable/dialog.ts +113 -0
- package/composable/index.d.ts +5 -0
- package/composable/index.js +5 -0
- package/composable/index.ts +5 -0
- package/composable/message-box.d.ts +45 -28
- package/composable/message-box.js +68 -53
- package/composable/message-box.ts +101 -36
- package/composable/model.d.ts +8 -0
- package/composable/model.js +23 -0
- package/composable/model.ts +27 -0
- package/composable/page.d.ts +41 -0
- package/composable/page.js +25 -0
- package/composable/page.ts +34 -0
- package/configs/index.d.ts +24 -19
- package/configs/index.js +38 -35
- package/configs/index.ts +19 -0
- package/easyCom.d.ts +6 -6
- package/easyCom.js +19 -31
- package/easyCom.ts +4 -4
- package/globals.d.ts +93 -33
- package/globals.js +1 -0
- package/globals.ts +118 -0
- package/index.d.ts +3 -3
- package/index.js +2 -3
- package/index.ts +3 -2
- package/init.d.ts +11 -6
- package/init.js +84 -14
- package/init.ts +86 -1
- package/package.json +9 -9
- package/styles/var/component.scss +1 -0
- package/utils/date.d.ts +14 -19
- package/utils/date.js +77 -87
- package/utils/freezeDeep.js +7 -7
- package/utils/price.d.ts +15 -18
- package/utils/price.js +36 -37
- package/utils/upload.d.ts +1 -0
- package/utils/upload.js +8 -0
- package/utils/upload.ts +12 -0
- package/utils/windowInfo.d.ts +1 -9
- package/utils/windowInfo.js +10 -17
- package/utils/round.d.ts +0 -2
- package/utils/round.js +0 -13
- package/utils/round.ts +0 -14
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface CommonProps {
|
|
2
|
+
/** 绑定值,文件列表 */
|
|
3
|
+
modelValue?: string[] | UniApp.UploadMediaFile[];
|
|
4
|
+
/** 是否只读 */
|
|
5
|
+
readonly?: boolean;
|
|
6
|
+
/** 最大上传文件数 */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** 最大上传文件大小 */
|
|
9
|
+
maxSize?: number;
|
|
10
|
+
/** 自动上传文件 */
|
|
11
|
+
autoUpload?: boolean;
|
|
12
|
+
/** 上传文件方法
|
|
13
|
+
*
|
|
14
|
+
* 函数签名:
|
|
15
|
+
*
|
|
16
|
+
* @param file 待上传文件
|
|
17
|
+
*/
|
|
18
|
+
uploadHandler?: (file: UniApp.UploadMediaFile) => Promise<UniApp.UploadResponse>;
|
|
19
|
+
}
|
|
20
|
+
export type ConfigurableMediaUploadProps = {
|
|
21
|
+
/** 最大上传文件数 */
|
|
22
|
+
max?: number;
|
|
23
|
+
/** 最大上传文件大小 */
|
|
24
|
+
maxSize?: number;
|
|
25
|
+
/** 自动上传文件 */
|
|
26
|
+
autoUpload?: boolean;
|
|
27
|
+
};
|
|
28
|
+
export declare let mediaUploadProps: ConfigurableMediaUploadProps;
|
|
29
|
+
export declare const setDefaultMediaUploadProps: (props?: ConfigurableMediaUploadProps) => void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface CommonProps {
|
|
2
|
+
/** 绑定值,文件列表 */
|
|
3
|
+
modelValue?: string[] | UniApp.UploadMediaFile[];
|
|
4
|
+
/** 是否只读 */
|
|
5
|
+
readonly?: boolean;
|
|
6
|
+
/** 最大上传文件数 */
|
|
7
|
+
max?: number;
|
|
8
|
+
/** 最大上传文件大小 */
|
|
9
|
+
maxSize?: number;
|
|
10
|
+
/** 自动上传文件 */
|
|
11
|
+
autoUpload?: boolean;
|
|
12
|
+
/** 上传文件方法
|
|
13
|
+
*
|
|
14
|
+
* 函数签名:
|
|
15
|
+
*
|
|
16
|
+
* @param file 待上传文件
|
|
17
|
+
*/
|
|
18
|
+
uploadHandler?: (
|
|
19
|
+
file: UniApp.UploadMediaFile
|
|
20
|
+
) => Promise<UniApp.UploadResponse>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ConfigurableMediaUploadProps = {
|
|
24
|
+
/** 最大上传文件数 */
|
|
25
|
+
max?: number;
|
|
26
|
+
/** 最大上传文件大小 */
|
|
27
|
+
maxSize?: number;
|
|
28
|
+
/** 自动上传文件 */
|
|
29
|
+
autoUpload?: boolean;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export let mediaUploadProps: ConfigurableMediaUploadProps = {};
|
|
33
|
+
|
|
34
|
+
export const setDefaultMediaUploadProps = (
|
|
35
|
+
props: ConfigurableMediaUploadProps = {}
|
|
36
|
+
) => {
|
|
37
|
+
mediaUploadProps = props;
|
|
38
|
+
};
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { kebabCase, pascalCase } from 'case-anything';
|
|
2
2
|
import { componentPrefix } from '../configs';
|
|
3
|
+
/**
|
|
4
|
+
* 给组件添加基本类名
|
|
5
|
+
*
|
|
6
|
+
* 如组件名称为 foo-bar ,则返回 ['PreFooBar', 'pre-foo-bar'],
|
|
7
|
+
* 其中 pre 为组件自定义前缀
|
|
8
|
+
*
|
|
9
|
+
* @param componentName 组件名称
|
|
10
|
+
*/
|
|
3
11
|
const useClassNames = (componentName) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return [pascalCaseClass, kebabCaseClass];
|
|
12
|
+
const pascalCaseClass = pascalCase(componentPrefix) + pascalCase(componentName);
|
|
13
|
+
const kebabCaseClass = kebabCase(pascalCaseClass);
|
|
14
|
+
return [pascalCaseClass, kebabCaseClass];
|
|
8
15
|
};
|
|
9
16
|
export default useClassNames;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { kebabCase, pascalCase } from 'case-anything';
|
|
2
2
|
import { componentPrefix } from '../configs';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* 给组件添加基本类名
|
|
6
|
+
*
|
|
7
|
+
* 如组件名称为 foo-bar ,则返回 ['PreFooBar', 'pre-foo-bar'],
|
|
8
|
+
* 其中 pre 为组件自定义前缀
|
|
9
|
+
*
|
|
10
|
+
* @param componentName 组件名称
|
|
11
|
+
*/
|
|
4
12
|
const useClassNames = (componentName: string): [string, string] => {
|
|
5
13
|
const pascalCaseClass =
|
|
6
14
|
pascalCase(componentPrefix) + pascalCase(componentName);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* 可等待的弹窗
|
|
4
|
+
*/
|
|
5
|
+
declare const useAwaitableDialog: (isShow: Ref<boolean | undefined>) => {
|
|
6
|
+
/**
|
|
7
|
+
* 显示弹出框
|
|
8
|
+
*
|
|
9
|
+
* @returns 返回一个 Promise 对象,可用于异步操作
|
|
10
|
+
*/
|
|
11
|
+
show: <T = void>() => Promise<T | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* 确认操作
|
|
14
|
+
*
|
|
15
|
+
* @param value Promise 成功的值
|
|
16
|
+
*/
|
|
17
|
+
onConfirm: (value?: any) => void;
|
|
18
|
+
/**
|
|
19
|
+
* 取消操作
|
|
20
|
+
*
|
|
21
|
+
* @param err Promise 失败的错误值
|
|
22
|
+
*/
|
|
23
|
+
onCancel: (err?: any) => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 弹窗
|
|
27
|
+
*/
|
|
28
|
+
declare const useDialog: () => {
|
|
29
|
+
/** 弹窗组件实例引用 */
|
|
30
|
+
dialogRef: Ref<any>;
|
|
31
|
+
/**
|
|
32
|
+
* 显示弹出框
|
|
33
|
+
*/
|
|
34
|
+
show: <T = void>() => Promise<T | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* 关闭弹出框
|
|
37
|
+
*/
|
|
38
|
+
close: () => any;
|
|
39
|
+
};
|
|
40
|
+
export { useAwaitableDialog, useDialog };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* 可等待的弹窗
|
|
4
|
+
*/
|
|
5
|
+
const useAwaitableDialog = (isShow) => {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
let resolvePromise;
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
let rejectPromise;
|
|
10
|
+
/**
|
|
11
|
+
* 显示弹出框
|
|
12
|
+
*
|
|
13
|
+
* @returns 返回一个 Promise 对象,可用于异步操作
|
|
14
|
+
*/
|
|
15
|
+
const show = () => {
|
|
16
|
+
isShow.value = true;
|
|
17
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
18
|
+
[resolvePromise, rejectPromise] = [resolve, reject];
|
|
19
|
+
return promise;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 确认操作
|
|
23
|
+
*
|
|
24
|
+
* @param value Promise 成功的值
|
|
25
|
+
*/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
+
const onConfirm = (value) => {
|
|
28
|
+
resolvePromise?.(value);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* 取消操作
|
|
32
|
+
*
|
|
33
|
+
* @param err Promise 失败的错误值
|
|
34
|
+
*/
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
const onCancel = (err) => {
|
|
37
|
+
rejectPromise?.(err);
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
/**
|
|
41
|
+
* 显示弹出框
|
|
42
|
+
*
|
|
43
|
+
* @returns 返回一个 Promise 对象,可用于异步操作
|
|
44
|
+
*/
|
|
45
|
+
show,
|
|
46
|
+
/**
|
|
47
|
+
* 确认操作
|
|
48
|
+
*
|
|
49
|
+
* @param value Promise 成功的值
|
|
50
|
+
*/
|
|
51
|
+
onConfirm,
|
|
52
|
+
/**
|
|
53
|
+
* 取消操作
|
|
54
|
+
*
|
|
55
|
+
* @param err Promise 失败的错误值
|
|
56
|
+
*/
|
|
57
|
+
onCancel,
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* 弹窗
|
|
62
|
+
*/
|
|
63
|
+
const useDialog = () => {
|
|
64
|
+
const dialogRef = ref();
|
|
65
|
+
/**
|
|
66
|
+
* 显示弹出框
|
|
67
|
+
*/
|
|
68
|
+
const show = () => {
|
|
69
|
+
if (!dialogRef.value?.show) {
|
|
70
|
+
throw new Error('dialogRef 为空或该组件没有导出 show 方法');
|
|
71
|
+
}
|
|
72
|
+
return (dialogRef.value?.show)();
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* 关闭弹出框
|
|
76
|
+
*/
|
|
77
|
+
const close = () => {
|
|
78
|
+
if (!dialogRef.value?.close) {
|
|
79
|
+
throw new Error('dialogRef 为空或该组件没有导出 close 方法');
|
|
80
|
+
}
|
|
81
|
+
return dialogRef.value?.close();
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
/** 弹窗组件实例引用 */
|
|
85
|
+
dialogRef,
|
|
86
|
+
/**
|
|
87
|
+
* 显示弹出框
|
|
88
|
+
*/
|
|
89
|
+
show,
|
|
90
|
+
/**
|
|
91
|
+
* 关闭弹出框
|
|
92
|
+
*/
|
|
93
|
+
close,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export { useAwaitableDialog, useDialog };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ref, type Ref } from 'vue';
|
|
2
|
+
import { Dialog } from '../components';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 可等待的弹窗
|
|
6
|
+
*/
|
|
7
|
+
const useAwaitableDialog = (isShow: Ref<boolean | undefined>) => {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
let resolvePromise: PromiseWithResolvers<any>['resolve'] | undefined;
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
let rejectPromise: PromiseWithResolvers<any>['reject'] | undefined;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 显示弹出框
|
|
15
|
+
*
|
|
16
|
+
* @returns 返回一个 Promise 对象,可用于异步操作
|
|
17
|
+
*/
|
|
18
|
+
const show = <T = void>() => {
|
|
19
|
+
isShow.value = true;
|
|
20
|
+
|
|
21
|
+
const { promise, resolve, reject } = Promise.withResolvers<
|
|
22
|
+
T | undefined
|
|
23
|
+
>();
|
|
24
|
+
[resolvePromise, rejectPromise] = [resolve, reject];
|
|
25
|
+
|
|
26
|
+
return promise;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 确认操作
|
|
31
|
+
*
|
|
32
|
+
* @param value Promise 成功的值
|
|
33
|
+
*/
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
+
const onConfirm = (value?: any) => {
|
|
36
|
+
resolvePromise?.(value);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 取消操作
|
|
41
|
+
*
|
|
42
|
+
* @param err Promise 失败的错误值
|
|
43
|
+
*/
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
const onCancel = (err?: any) => {
|
|
46
|
+
rejectPromise?.(err);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
/**
|
|
51
|
+
* 显示弹出框
|
|
52
|
+
*
|
|
53
|
+
* @returns 返回一个 Promise 对象,可用于异步操作
|
|
54
|
+
*/
|
|
55
|
+
show,
|
|
56
|
+
/**
|
|
57
|
+
* 确认操作
|
|
58
|
+
*
|
|
59
|
+
* @param value Promise 成功的值
|
|
60
|
+
*/
|
|
61
|
+
onConfirm,
|
|
62
|
+
/**
|
|
63
|
+
* 取消操作
|
|
64
|
+
*
|
|
65
|
+
* @param err Promise 失败的错误值
|
|
66
|
+
*/
|
|
67
|
+
onCancel,
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 弹窗
|
|
73
|
+
*/
|
|
74
|
+
const useDialog = () => {
|
|
75
|
+
const dialogRef = ref<InstanceType<typeof Dialog>>();
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 显示弹出框
|
|
79
|
+
*/
|
|
80
|
+
const show = <T = void>() => {
|
|
81
|
+
if (!dialogRef.value?.show) {
|
|
82
|
+
throw new Error('dialogRef 为空或该组件没有导出 show 方法');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (dialogRef.value?.show as () => Promise<T | undefined>)();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* 关闭弹出框
|
|
90
|
+
*/
|
|
91
|
+
const close = () => {
|
|
92
|
+
if (!dialogRef.value?.close) {
|
|
93
|
+
throw new Error('dialogRef 为空或该组件没有导出 close 方法');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return dialogRef.value?.close();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
/** 弹窗组件实例引用 */
|
|
101
|
+
dialogRef,
|
|
102
|
+
/**
|
|
103
|
+
* 显示弹出框
|
|
104
|
+
*/
|
|
105
|
+
show,
|
|
106
|
+
/**
|
|
107
|
+
* 关闭弹出框
|
|
108
|
+
*/
|
|
109
|
+
close,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export { useAwaitableDialog, useDialog };
|
|
@@ -2,34 +2,51 @@ import type { Ref } from 'vue';
|
|
|
2
2
|
import type { default as MessageBox } from '../components/message-box/message-box.vue';
|
|
3
3
|
import type { default as Page } from '../components/page/page.vue';
|
|
4
4
|
import type { MessageBoxOptions } from '../components/message-box/message-box';
|
|
5
|
-
type MessageBoxShowCustomFunc = (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
type MessageBoxShowCustomFunc = (options: MessageBoxOptions) => Promise<void>;
|
|
6
|
+
type MessageBoxShowConfirmFunc = (options: string | Pick<MessageBoxOptions & {
|
|
7
|
+
content: string;
|
|
8
|
+
confirm?: string;
|
|
9
|
+
cancel?: string;
|
|
10
|
+
}, 'modal' | 'title' | 'content' | 'confirm' | 'cancel'>) => Promise<void>;
|
|
11
|
+
type MessageBoxShowMessageBoxFunc = (options: string | Pick<MessageBoxOptions & {
|
|
12
|
+
content: string;
|
|
13
|
+
confirm?: string;
|
|
14
|
+
cancel?: string;
|
|
15
|
+
}, 'modal' | 'title' | 'content' | 'confirm' | 'cancel'>) => Promise<void>;
|
|
16
|
+
type UseMessageBoxReturn = {
|
|
17
|
+
/**
|
|
18
|
+
* 显示消息框,选项自定义
|
|
19
|
+
*
|
|
20
|
+
* @param options 消息框选项
|
|
21
|
+
*/
|
|
22
|
+
show: MessageBoxShowCustomFunc;
|
|
23
|
+
/**
|
|
24
|
+
* 显示确认框,仅部分选项自定义
|
|
25
|
+
*
|
|
26
|
+
* @param options 确认框选项
|
|
27
|
+
*/
|
|
28
|
+
showConfirm: MessageBoxShowConfirmFunc;
|
|
29
|
+
/**
|
|
30
|
+
* 显示消息框,仅部分选项自定义
|
|
31
|
+
*
|
|
32
|
+
* @param options 消息框选项
|
|
33
|
+
*/
|
|
34
|
+
showMessageBox: MessageBoxShowMessageBoxFunc;
|
|
23
35
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
declare const useMessageBoxComponent: (messageBoxRef?: Ref<InstanceType<typeof MessageBox> | undefined>) => {
|
|
37
|
+
messageBoxRef: Ref<any>;
|
|
38
|
+
show: MessageBoxShowCustomFunc;
|
|
39
|
+
showConfirm: MessageBoxShowConfirmFunc;
|
|
40
|
+
showMessageBox: MessageBoxShowMessageBoxFunc;
|
|
29
41
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
/**
|
|
43
|
+
* 页面公用消息框,仅单一个实例,使用时需注意
|
|
44
|
+
*
|
|
45
|
+
* @param isInPage 是否在 Page 中使用,当为 `true` 时,须将返回的 `pageRef` 绑定到 `Page` 组件上
|
|
46
|
+
*/
|
|
47
|
+
declare function useMessageBox(isInPage: true): UseMessageBoxReturn & {
|
|
48
|
+
/** page 组件实例 */
|
|
49
|
+
pageRef: Ref<InstanceType<typeof Page>>;
|
|
34
50
|
};
|
|
35
|
-
|
|
51
|
+
declare function useMessageBox(isInPage?: false): UseMessageBoxReturn;
|
|
52
|
+
export { useMessageBox, useMessageBoxComponent };
|
|
@@ -1,56 +1,71 @@
|
|
|
1
1
|
import { inject, ref } from 'vue';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
const useMessageBoxComponent = (messageBoxRef) => {
|
|
3
|
+
const _messageBoxRef = ref(messageBoxRef);
|
|
4
|
+
const show = async (options) => {
|
|
5
|
+
await _messageBoxRef.value?.show(options);
|
|
6
|
+
};
|
|
7
|
+
const showConfirm = (options) => {
|
|
8
|
+
if (typeof options === 'string') {
|
|
9
|
+
options = { content: options };
|
|
10
|
+
}
|
|
11
|
+
const { title = '提示', content, modal = true, confirm = '确认', cancel = '取消', } = options;
|
|
12
|
+
return show({
|
|
13
|
+
title,
|
|
14
|
+
content,
|
|
15
|
+
modal,
|
|
16
|
+
confirm,
|
|
17
|
+
cancel,
|
|
18
|
+
showClose: false,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const showMessageBox = (options) => {
|
|
22
|
+
if (typeof options === 'string') {
|
|
23
|
+
options = { content: options };
|
|
24
|
+
}
|
|
25
|
+
const { title = '提示', content, modal = false, confirm: _confirm, cancel: _cancel, } = options;
|
|
26
|
+
// 仅显示一个按钮,要么是确认按钮,要么是取消按钮
|
|
27
|
+
const isCancel = _confirm === undefined && _cancel !== undefined;
|
|
28
|
+
const confirm = isCancel ? false : _confirm || '我知道了';
|
|
29
|
+
const cancel = !isCancel ? false : _cancel || '我知道了';
|
|
30
|
+
return show({
|
|
31
|
+
title,
|
|
32
|
+
content,
|
|
33
|
+
modal,
|
|
34
|
+
confirm,
|
|
35
|
+
cancel,
|
|
36
|
+
showClose: false,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
messageBoxRef: _messageBoxRef,
|
|
41
|
+
show,
|
|
42
|
+
showConfirm,
|
|
43
|
+
showMessageBox,
|
|
44
|
+
};
|
|
31
45
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
function useMessageBox(isInPage = false) {
|
|
47
|
+
if (!isInPage) {
|
|
48
|
+
const pageMessageBoxRef = inject('ecolovo/page/messageBoxRef');
|
|
49
|
+
if (!pageMessageBoxRef) {
|
|
50
|
+
throw new Error('该组件必须在 Page 中使用');
|
|
51
|
+
}
|
|
52
|
+
return useMessageBoxComponent(pageMessageBoxRef);
|
|
53
|
+
}
|
|
54
|
+
const pageRef = ref();
|
|
55
|
+
const show = async (options) => {
|
|
56
|
+
await pageRef.value?.show(options);
|
|
57
|
+
};
|
|
58
|
+
const showConfirm = async (options) => {
|
|
59
|
+
await pageRef.value?.showConfirm(options);
|
|
60
|
+
};
|
|
61
|
+
const showMessageBox = async (options) => {
|
|
62
|
+
await pageRef.value?.showMessageBox(options);
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
pageRef,
|
|
66
|
+
show,
|
|
67
|
+
showConfirm,
|
|
68
|
+
showMessageBox,
|
|
69
|
+
};
|
|
56
70
|
}
|
|
71
|
+
export { useMessageBox, useMessageBoxComponent };
|