uview-pro 0.5.3 → 0.5.4
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/changelog.md +29 -8
- package/components/u-action-sheet/types.ts +1 -1
- package/components/u-action-sheet/u-action-sheet.vue +5 -5
- package/components/u-action-sheet-item/types.ts +1 -1
- package/components/u-alert-tips/types.ts +1 -1
- package/components/u-alert-tips/u-alert-tips.vue +1 -1
- package/components/u-avatar/types.ts +1 -1
- package/components/u-avatar-cropper/types.ts +1 -1
- package/components/u-back-top/types.ts +1 -1
- package/components/u-badge/types.ts +1 -1
- package/components/u-button/u-button.vue +4 -3
- package/components/u-calendar/types.ts +1 -1
- package/components/u-calendar/u-calendar.vue +1 -1
- package/components/u-car-keyboard/types.ts +1 -1
- package/components/u-card/types.ts +1 -1
- package/components/u-cell-group/types.ts +1 -1
- package/components/u-cell-item/types.ts +1 -1
- package/components/u-checkbox/types.ts +1 -1
- package/components/u-checkbox-group/types.ts +1 -1
- package/components/u-circle-progress/types.ts +1 -1
- package/components/u-circle-progress/u-circle-progress.vue +1 -1
- package/components/u-dropdown-item/u-dropdown-item.vue +1 -1
- package/components/u-empty/u-empty.vue +1 -1
- package/components/u-fab/u-fab.vue +1 -1
- package/components/u-field/types.ts +9 -9
- package/components/u-field/u-field.vue +8 -7
- package/components/u-form-item/u-form-item.vue +1 -1
- package/components/u-image/types.ts +1 -1
- package/components/u-index-anchor/u-index-anchor.vue +5 -5
- package/components/u-input/u-input.vue +8 -7
- package/components/u-loading/types.ts +2 -0
- package/components/u-loading/u-loading.vue +3 -2
- package/components/u-loadmore/types.ts +2 -0
- package/components/u-loadmore/u-loadmore.vue +11 -8
- package/components/u-message-input/u-message-input.vue +4 -3
- package/components/u-navbar/u-navbar.vue +4 -4
- package/components/u-notice-bar/u-notice-bar.vue +1 -1
- package/components/u-pagination/u-pagination.vue +1 -1
- package/components/u-popup/u-popup.vue +2 -2
- package/components/u-rate/u-rate.vue +4 -4
- package/components/u-safe-bottom/u-safe-bottom.vue +4 -1
- package/components/u-search/u-search.vue +1 -1
- package/components/u-section/types.ts +1 -1
- package/components/u-switch/u-switch.vue +1 -1
- package/components/u-tabbar/types.ts +4 -1
- package/components/u-tabbar/u-tabbar.vue +4 -4
- package/components/u-text/u-text.vue +17 -16
- package/components/u-textarea/types.ts +1 -1
- package/components/u-textarea/u-textarea.vue +5 -4
- package/components/u-toast/service.ts +21 -0
- package/components/u-toast/types.ts +7 -2
- package/components/u-toast/u-toast.vue +82 -19
- package/components/u-upload/types.ts +2 -2
- package/components/u-upload/u-upload.vue +1 -1
- package/index.ts +1 -1
- package/libs/function/clipboard.ts +5 -5
- package/libs/function/color.ts +3 -1
- package/libs/function/styleUtils.ts +5 -5
- package/libs/function/test.ts +6 -6
- package/libs/function/type2icon.ts +3 -4
- package/libs/hooks/index.ts +1 -0
- package/libs/hooks/useCompRelation.ts +4 -4
- package/libs/hooks/useRect.ts +9 -4
- package/libs/hooks/useToast.ts +90 -0
- package/libs/index.ts +1 -1
- package/libs/request/index.ts +4 -4
- package/package.json +1 -1
- package/types/global.d.ts +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
U_TOAST_EVENT_HIDE,
|
|
3
|
+
U_TOAST_EVENT_SHOW,
|
|
4
|
+
U_TOAST_GLOBAL_EVENT_HIDE,
|
|
5
|
+
U_TOAST_GLOBAL_EVENT_SHOW,
|
|
6
|
+
type ToastPayload
|
|
7
|
+
} from '../../components/u-toast/service';
|
|
8
|
+
import type { ThemeType } from '../../types/global';
|
|
9
|
+
|
|
10
|
+
export type UseToastShowOptions = ToastPayload;
|
|
11
|
+
|
|
12
|
+
export type UseToast = {
|
|
13
|
+
/**
|
|
14
|
+
* 显示 toast
|
|
15
|
+
* - show('文本')
|
|
16
|
+
* - show({ title, type, duration, ... })
|
|
17
|
+
*/
|
|
18
|
+
show: (titleOrOptions: string | UseToastShowOptions) => void;
|
|
19
|
+
/** 关闭 toast */
|
|
20
|
+
close: () => void;
|
|
21
|
+
/** 成功 */
|
|
22
|
+
success: (titleOrOptions: string | UseToastShowOptions) => void;
|
|
23
|
+
/** 错误 */
|
|
24
|
+
error: (titleOrOptions: string | UseToastShowOptions) => void;
|
|
25
|
+
/** 警告 */
|
|
26
|
+
warning: (titleOrOptions: string | UseToastShowOptions) => void;
|
|
27
|
+
/** 信息 */
|
|
28
|
+
info: (titleOrOptions: string | UseToastShowOptions) => void;
|
|
29
|
+
/** 加载中(默认常驻,需 close 关闭) */
|
|
30
|
+
loading: (titleOrOptions: string | UseToastShowOptions) => void;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type UseToastOptions = {
|
|
34
|
+
/** 是否使用全局根部 <u-toast global />,默认 true;为 false 时走页面级 <u-toast /> */
|
|
35
|
+
global?: boolean;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function normalize(titleOrOptions: string | UseToastShowOptions): UseToastShowOptions {
|
|
39
|
+
if (typeof titleOrOptions === 'string') return { title: titleOrOptions };
|
|
40
|
+
return titleOrOptions || {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Toast 函数式调用
|
|
45
|
+
* @description 需要页面/应用中至少存在一个 <u-toast /> 实例用于承接事件;不影响原 ref 调用方式。
|
|
46
|
+
* 支持两种调用方式:useToast() / useToast({ global: false }) / useToast(false)
|
|
47
|
+
*/
|
|
48
|
+
export function useToast(): UseToast;
|
|
49
|
+
export function useToast(options: UseToastOptions): UseToast;
|
|
50
|
+
export function useToast(global: boolean): UseToast;
|
|
51
|
+
export function useToast(optionsOrGlobal: UseToastOptions | boolean = {}): UseToast {
|
|
52
|
+
const isGlobal =
|
|
53
|
+
typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal !== false : optionsOrGlobal.global !== false;
|
|
54
|
+
const showEvent = isGlobal ? U_TOAST_GLOBAL_EVENT_SHOW : U_TOAST_EVENT_SHOW;
|
|
55
|
+
const hideEvent = isGlobal ? U_TOAST_GLOBAL_EVENT_HIDE : U_TOAST_EVENT_HIDE;
|
|
56
|
+
|
|
57
|
+
function emitShow(payload: UseToastShowOptions) {
|
|
58
|
+
uni?.$emit && uni.$emit(showEvent, payload);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function emitHide() {
|
|
62
|
+
uni?.$emit && uni.$emit(hideEvent);
|
|
63
|
+
}
|
|
64
|
+
function show(titleOrOptions: string | UseToastShowOptions) {
|
|
65
|
+
emitShow(normalize(titleOrOptions));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function close() {
|
|
69
|
+
emitHide();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function withType(type: ThemeType, titleOrOptions: string | UseToastShowOptions) {
|
|
73
|
+
const options = normalize(titleOrOptions);
|
|
74
|
+
emitShow({ ...options, type });
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
show,
|
|
79
|
+
close,
|
|
80
|
+
success: (v: any) => withType('success', v),
|
|
81
|
+
error: (v: any) => withType('error', v),
|
|
82
|
+
warning: (v: any) => withType('warning', v),
|
|
83
|
+
info: (v: any) => withType('info', v),
|
|
84
|
+
loading: (v: any) => {
|
|
85
|
+
const options = normalize(v);
|
|
86
|
+
// loading 通常需要常驻,除非用户显式传 duration
|
|
87
|
+
emitShow({ ...options, loading: true, duration: options.duration ?? 1e9 });
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
package/libs/index.ts
CHANGED
|
@@ -248,7 +248,7 @@ export function kebabCase(word: string): string {
|
|
|
248
248
|
* @param {number} value 堵塞时间 单位ms 毫秒
|
|
249
249
|
* @returns {Promise} 返回promise
|
|
250
250
|
*/
|
|
251
|
-
export function sleep(value: number = 30) {
|
|
251
|
+
export function sleep(value: number = 30): Promise<boolean> {
|
|
252
252
|
return new Promise(resolve => {
|
|
253
253
|
setTimeout(() => {
|
|
254
254
|
resolve(true);
|
package/libs/request/index.ts
CHANGED
|
@@ -223,7 +223,7 @@ export class Request {
|
|
|
223
223
|
method: 'GET',
|
|
224
224
|
url,
|
|
225
225
|
data,
|
|
226
|
-
header: options.header,
|
|
226
|
+
header: options.header || {},
|
|
227
227
|
meta: options.meta
|
|
228
228
|
});
|
|
229
229
|
}
|
|
@@ -237,7 +237,7 @@ export class Request {
|
|
|
237
237
|
url,
|
|
238
238
|
method: 'POST',
|
|
239
239
|
data,
|
|
240
|
-
header: options.header,
|
|
240
|
+
header: options.header || {},
|
|
241
241
|
meta: options.meta
|
|
242
242
|
});
|
|
243
243
|
}
|
|
@@ -251,7 +251,7 @@ export class Request {
|
|
|
251
251
|
url,
|
|
252
252
|
method: 'PUT',
|
|
253
253
|
data,
|
|
254
|
-
header: options.header,
|
|
254
|
+
header: options.header || {},
|
|
255
255
|
meta: options.meta
|
|
256
256
|
});
|
|
257
257
|
}
|
|
@@ -265,7 +265,7 @@ export class Request {
|
|
|
265
265
|
url,
|
|
266
266
|
method: 'DELETE',
|
|
267
267
|
data,
|
|
268
|
-
header: options.header,
|
|
268
|
+
header: options.header || {},
|
|
269
269
|
meta: options.meta
|
|
270
270
|
});
|
|
271
271
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"id": "uview-pro",
|
|
3
3
|
"name": "uview-pro",
|
|
4
4
|
"displayName": "【支持鸿蒙】uView Pro|基于Vue3+TS的高质量UI组件库,支持多主题、暗黑模式、多语言",
|
|
5
|
-
"version": "0.5.
|
|
5
|
+
"version": "0.5.4",
|
|
6
6
|
"description": "uView Pro是基于Vue3+TS的多平台UI框架,提供80+高质量组件、便捷工具和常用模板,支持多主题、暗黑模式、多语言,支持H5/APP/鸿蒙/小程序多端开发。已在鸿蒙应用商店上架,欢迎体验!",
|
|
7
7
|
"main": "index.ts",
|
|
8
8
|
"module": "index.ts",
|
package/types/global.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ThemeType = 'primary' | 'info' | 'error' | 'warning' | 'success';
|
|
1
|
+
export type ThemeType = 'primary' | 'info' | 'error' | 'warning' | 'success' | 'default';
|
|
2
2
|
|
|
3
3
|
export type ImgMode = 'aspectFit' | 'aspectFill' | 'widthFix' | 'top' | 'bottom' | 'center' | 'scaleToFill';
|
|
4
4
|
|