uview-pro 0.5.7 → 0.5.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/changelog.md +34 -6
- package/components/u-button/types.ts +2 -0
- package/components/u-button/u-button.vue +1 -1
- package/components/u-modal/service.ts +22 -3
- package/components/u-modal/types.ts +1 -1
- package/components/u-modal/u-modal.vue +53 -9
- package/components/u-toast/service.ts +21 -2
- package/components/u-toast/types.ts +1 -1
- package/components/u-toast/u-toast.vue +45 -7
- package/components/u-upload/u-upload.vue +2 -0
- package/libs/hooks/useModal.ts +35 -9
- package/libs/hooks/useRouter.ts +173 -0
- package/libs/hooks/useToast.ts +29 -7
- package/locale/lang/en-US.ts +2 -0
- package/locale/lang/zh-CN.ts +2 -0
- package/package.json +1 -1
- package/readme.md +1 -0
package/changelog.md
CHANGED
|
@@ -1,20 +1,48 @@
|
|
|
1
|
-
## 0.5.
|
|
1
|
+
## 0.5.8(2026-02-10)
|
|
2
|
+
|
|
3
|
+
### 🚀 Chore | 构建/工程依赖/工具
|
|
4
|
+
|
|
5
|
+
- **deps:** 更新 uni-app 相关依赖包版本到 4.87,修复更新包后运行到 h5 报错问题 ([b00751b](https://github.com/anyup/uView-Pro/commit/b00751b2643bd582f2d1b9472e245d856352d4ed))
|
|
6
|
+
|
|
7
|
+
### 📝 Documentation | 文档
|
|
8
|
+
|
|
9
|
+
- 添加npm下载量统计徽章 ([63971ee](https://github.com/anyup/uView-Pro/commit/63971eead3365d5efe29166b2252e58904c0306c))
|
|
2
10
|
|
|
3
11
|
### 🐛 Bug Fixes | Bug 修复
|
|
4
12
|
|
|
5
|
-
- **
|
|
6
|
-
- **
|
|
7
|
-
- **u-
|
|
13
|
+
- **useToast:** 修复使用useToast全局提示会触发多次监听的问题(#130) ([ae56413](https://github.com/anyup/uView-Pro/commit/ae564132604d27c3d92de2f6ece5eaae75980aaa))
|
|
14
|
+
- **useModal:** 修复使用useModal全局弹窗会触发多次监听的问题(#130) ([50da10c](https://github.com/anyup/uView-Pro/commit/50da10c7c19d65885244df5c99634775be088824))
|
|
15
|
+
- **u-upload:** 修复u-upload组件中删除确认弹窗的“取消”和“确认”按钮国际化问题(#128) ([e48ab1d](https://github.com/anyup/uView-Pro/commit/e48ab1d23f50c850b1fd85c9b48860bd1d5105b0))
|
|
8
16
|
|
|
9
17
|
### ✨ Features | 新功能
|
|
10
18
|
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
19
|
+
- **useToast:** 支持使用useToast页面级弹出时,toast可指定页面ID(#130) ([7d09ffe](https://github.com/anyup/uView-Pro/commit/7d09ffe5f8bbee5a3872dfc716dc7ba013f7e1bc))
|
|
20
|
+
- **useModal:** 支持使用useModal页面级弹出时,modal可指定页面ID(#130) ([63af409](https://github.com/anyup/uView-Pro/commit/63af409370f775bac7ceabe98db8b5225491baa8))
|
|
21
|
+
- **u-button:** 添加按钮文本属性支持 ([72fda47](https://github.com/anyup/uView-Pro/commit/72fda47673f1b099f12dcd88ca20570d20d3d5bc))
|
|
22
|
+
- **router:** 添加路由跳转hooks功能 ([cb5a687](https://github.com/anyup/uView-Pro/commit/cb5a687bd7ec8c863d237f69b5cb486e86016398))
|
|
23
|
+
- **demo:** 添加useModal和useToast示例页面 ([f42ca51](https://github.com/anyup/uView-Pro/commit/f42ca51839b1ebd3f02106da0310f4bbbfbb96cf))
|
|
13
24
|
|
|
14
25
|
### 👥 Contributors
|
|
15
26
|
|
|
16
27
|
<a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a>
|
|
17
28
|
|
|
29
|
+
## 0.5.7(2026-02-06)
|
|
30
|
+
|
|
31
|
+
### 🐛 Bug Fixes | Bug 修复
|
|
32
|
+
|
|
33
|
+
- **u-tabs:** 修复u-tabs的scroll-view在不同平台会显示滚动条的问题,统一各平台的滚动条隐藏逻辑 ([6ba904b](https://github.com/anyup/uView-Pro/commit/6ba904b85fdc5be69ab8b430878e16fa74674c64))
|
|
34
|
+
- **demo:** 修复演示项目在钉钉小程序调用uni.setTabBarItem报错问题(#125) ([fd4ea39](https://github.com/anyup/uView-Pro/commit/fd4ea3987928039e9dcc3a53dc8bea42fce2b685))
|
|
35
|
+
- **u-input,u-field:** 修复输入框绑定值为undefined和null时的显示异常问题 ([4af659f](https://github.com/anyup/uView-Pro/commit/4af659fb365179e3ed7db26a1d8571c327497f7a))
|
|
36
|
+
|
|
37
|
+
### ✨ Features | 新功能
|
|
38
|
+
|
|
39
|
+
- **demo-page:** 所有页面支持小程序分享功能 ([a055904](https://github.com/anyup/uView-Pro/commit/a05590443e898ed076d47a04cb8bfc74c2e73da8))
|
|
40
|
+
- **u-card:** u-card添加圆角配置功能并调整默认边框样式 ([e43c939](https://github.com/anyup/uView-Pro/commit/e43c9396a17fe485305e63895a7ea8d6edf1906b))
|
|
41
|
+
|
|
42
|
+
### 👥 Contributors
|
|
43
|
+
|
|
44
|
+
<a href="https://github.com/anyup"><img src="https://github.com/anyup.png?size=40" width="40" height="40" alt="anyup" title="anyup"/></a>
|
|
45
|
+
|
|
18
46
|
## 0.5.6(2026-02-04)
|
|
19
47
|
|
|
20
48
|
### 🐛 Bug Fixes | Bug 修复
|
|
@@ -9,6 +9,8 @@ import { baseProps } from '../common/props';
|
|
|
9
9
|
|
|
10
10
|
export const ButtonProps = {
|
|
11
11
|
...baseProps,
|
|
12
|
+
/** 按钮文本 */
|
|
13
|
+
text: { type: String, default: '' },
|
|
12
14
|
/** 是否细边框 */
|
|
13
15
|
hairLine: { type: Boolean, default: true },
|
|
14
16
|
/** 按钮的预置样式,default,primary,error,warning,success */
|
|
@@ -8,15 +8,34 @@
|
|
|
8
8
|
import type { ModalProps } from './types';
|
|
9
9
|
|
|
10
10
|
// 普通(页面级)modal 事件
|
|
11
|
-
export const U_MODAL_EVENT_SHOW = 'uview-pro:u-modal:show';
|
|
12
|
-
export const U_MODAL_EVENT_HIDE = 'uview-pro:u-modal:hide';
|
|
13
|
-
export const U_MODAL_EVENT_CLEAR_LOADING = 'uview-pro:u-modal:clear-loading';
|
|
11
|
+
export const U_MODAL_EVENT_SHOW = 'uview-pro:u-modal:show:';
|
|
12
|
+
export const U_MODAL_EVENT_HIDE = 'uview-pro:u-modal:hide:';
|
|
13
|
+
export const U_MODAL_EVENT_CLEAR_LOADING = 'uview-pro:u-modal:clear-loading:';
|
|
14
14
|
|
|
15
15
|
// 全局(App 根部)modal 事件,供 useModal() 使用
|
|
16
16
|
export const U_MODAL_GLOBAL_EVENT_SHOW = 'uview-pro:u-modal:global:show';
|
|
17
17
|
export const U_MODAL_GLOBAL_EVENT_HIDE = 'uview-pro:u-modal:global:hide';
|
|
18
18
|
export const U_MODAL_GLOBAL_EVENT_CLEAR_LOADING = 'uview-pro:u-modal:global:clear-loading';
|
|
19
19
|
|
|
20
|
+
// 根据当前页面获取事件名
|
|
21
|
+
export function getEventWithCurrentPage(event: string, page?: string | boolean) {
|
|
22
|
+
if (page && typeof page === 'string' && page !== '') {
|
|
23
|
+
return event + page;
|
|
24
|
+
}
|
|
25
|
+
return event + getCurrentPage();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 获取当前页面路由
|
|
29
|
+
function getCurrentPage() {
|
|
30
|
+
try {
|
|
31
|
+
const pages = getCurrentPages();
|
|
32
|
+
const currentPage = pages[pages.length - 1].route as string;
|
|
33
|
+
return currentPage || '';
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
20
39
|
/**
|
|
21
40
|
* u-modal 函数式调用载荷类型
|
|
22
41
|
* @description 完整覆盖 u-modal 的所有 props(除 modelValue 外)
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<slot />
|
|
27
27
|
</view>
|
|
28
28
|
<view v-else class="u-model__content__message" :style="$u.toStyle(effectiveConfig.contentStyle)">
|
|
29
|
-
{{ effectiveConfig.content }}
|
|
29
|
+
<text>{{ effectiveConfig.content }}</text>
|
|
30
30
|
</view>
|
|
31
31
|
</view>
|
|
32
32
|
<view
|
|
@@ -89,6 +89,7 @@ import {
|
|
|
89
89
|
U_MODAL_GLOBAL_EVENT_CLEAR_LOADING,
|
|
90
90
|
U_MODAL_GLOBAL_EVENT_HIDE,
|
|
91
91
|
U_MODAL_GLOBAL_EVENT_SHOW,
|
|
92
|
+
getEventWithCurrentPage,
|
|
92
93
|
type ModalPayload
|
|
93
94
|
} from './service';
|
|
94
95
|
|
|
@@ -128,12 +129,28 @@ const slots = useSlots();
|
|
|
128
129
|
|
|
129
130
|
// 确认按钮是否正在加载中
|
|
130
131
|
const loading = ref(false);
|
|
131
|
-
const isGlobal = computed(() => props.global);
|
|
132
|
-
const isPage = computed(() => props.page);
|
|
133
|
-
const showEvent = computed(() =>
|
|
134
|
-
|
|
132
|
+
const isGlobal = computed(() => !!props.global);
|
|
133
|
+
const isPage = computed(() => !!props.page);
|
|
134
|
+
const showEvent = computed(() =>
|
|
135
|
+
isGlobal.value
|
|
136
|
+
? U_MODAL_GLOBAL_EVENT_SHOW
|
|
137
|
+
: isPage.value
|
|
138
|
+
? getEventWithCurrentPage(U_MODAL_EVENT_SHOW, props.page)
|
|
139
|
+
: ''
|
|
140
|
+
);
|
|
141
|
+
const hideEvent = computed(() =>
|
|
142
|
+
isGlobal.value
|
|
143
|
+
? U_MODAL_GLOBAL_EVENT_HIDE
|
|
144
|
+
: isPage.value
|
|
145
|
+
? getEventWithCurrentPage(U_MODAL_EVENT_HIDE, props.page)
|
|
146
|
+
: ''
|
|
147
|
+
);
|
|
135
148
|
const clearLoadingEvent = computed(() =>
|
|
136
|
-
isGlobal.value
|
|
149
|
+
isGlobal.value
|
|
150
|
+
? U_MODAL_GLOBAL_EVENT_CLEAR_LOADING
|
|
151
|
+
: isPage.value
|
|
152
|
+
? getEventWithCurrentPage(U_MODAL_EVENT_CLEAR_LOADING, props.page)
|
|
153
|
+
: ''
|
|
137
154
|
);
|
|
138
155
|
|
|
139
156
|
// 存储用户传入的回调函数
|
|
@@ -312,7 +329,12 @@ function resetTempConfig() {
|
|
|
312
329
|
userOnCancel = null;
|
|
313
330
|
}
|
|
314
331
|
|
|
315
|
-
|
|
332
|
+
// 开始监听事件
|
|
333
|
+
function startListeners() {
|
|
334
|
+
// 如果为全局 toast,则先移除所有事件监听,再重新监听
|
|
335
|
+
if (isGlobal.value) {
|
|
336
|
+
removeAllListeners();
|
|
337
|
+
}
|
|
316
338
|
if (showEvent.value) {
|
|
317
339
|
uni?.$on && uni.$on(showEvent.value, onServiceShow);
|
|
318
340
|
}
|
|
@@ -322,9 +344,10 @@ onMounted(() => {
|
|
|
322
344
|
if (clearLoadingEvent.value) {
|
|
323
345
|
uni?.$on && uni.$on(clearLoadingEvent.value, clearLoading);
|
|
324
346
|
}
|
|
325
|
-
}
|
|
347
|
+
}
|
|
326
348
|
|
|
327
|
-
|
|
349
|
+
// 停止监听事件
|
|
350
|
+
function stopListeners() {
|
|
328
351
|
if (showEvent.value) {
|
|
329
352
|
uni?.$off && uni.$off(showEvent.value, onServiceShow);
|
|
330
353
|
}
|
|
@@ -334,6 +357,27 @@ onBeforeUnmount(() => {
|
|
|
334
357
|
if (clearLoadingEvent.value) {
|
|
335
358
|
uni?.$off && uni.$off(clearLoadingEvent.value, clearLoading);
|
|
336
359
|
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// 移除所有事件监听
|
|
363
|
+
function removeAllListeners() {
|
|
364
|
+
if (showEvent.value) {
|
|
365
|
+
uni?.$off && uni.$off(showEvent.value);
|
|
366
|
+
}
|
|
367
|
+
if (hideEvent.value) {
|
|
368
|
+
uni?.$off && uni.$off(hideEvent.value);
|
|
369
|
+
}
|
|
370
|
+
if (clearLoadingEvent.value) {
|
|
371
|
+
uni?.$off && uni.$off(clearLoadingEvent.value);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
onMounted(() => {
|
|
376
|
+
startListeners();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
onBeforeUnmount(() => {
|
|
380
|
+
stopListeners();
|
|
337
381
|
});
|
|
338
382
|
|
|
339
383
|
defineExpose({
|
|
@@ -8,13 +8,32 @@
|
|
|
8
8
|
import type { ToastProps } from './types';
|
|
9
9
|
|
|
10
10
|
// 普通(页面级)toast 事件
|
|
11
|
-
export const U_TOAST_EVENT_SHOW = 'uview-pro:u-toast:show';
|
|
12
|
-
export const U_TOAST_EVENT_HIDE = 'uview-pro:u-toast:hide';
|
|
11
|
+
export const U_TOAST_EVENT_SHOW = 'uview-pro:u-toast:show:';
|
|
12
|
+
export const U_TOAST_EVENT_HIDE = 'uview-pro:u-toast:hide:';
|
|
13
13
|
|
|
14
14
|
// 全局(App 根部)toast 事件,供 useToast() 使用
|
|
15
15
|
export const U_TOAST_GLOBAL_EVENT_SHOW = 'uview-pro:u-toast:global:show';
|
|
16
16
|
export const U_TOAST_GLOBAL_EVENT_HIDE = 'uview-pro:u-toast:global:hide';
|
|
17
17
|
|
|
18
|
+
// 根据当前页面获取事件名
|
|
19
|
+
export function getEventWithCurrentPage(event: string, page?: string | boolean) {
|
|
20
|
+
if (page && typeof page === 'string' && page !== '') {
|
|
21
|
+
return event + page;
|
|
22
|
+
}
|
|
23
|
+
return event + getCurrentPage();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 获取当前页面路由
|
|
27
|
+
function getCurrentPage() {
|
|
28
|
+
try {
|
|
29
|
+
const pages = getCurrentPages();
|
|
30
|
+
const currentPage = pages[pages.length - 1].route as string;
|
|
31
|
+
return currentPage || '';
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
18
37
|
export type ToastPayload = Partial<ToastProps> & {
|
|
19
38
|
/** 文案(兼容 toast.show('xxx')) */
|
|
20
39
|
title?: string;
|
|
@@ -32,7 +32,7 @@ export const ToastProps = {
|
|
|
32
32
|
/** 是否作为全局根部 toast(通常放在 App.vue 中,给 useToast() 使用) */
|
|
33
33
|
global: { type: Boolean, default: false },
|
|
34
34
|
/** 是否作为页面级 toast(通常放在页面中,给 useToast({ page: true }) 使用) */
|
|
35
|
-
page: { type: Boolean, default: false },
|
|
35
|
+
page: { type: [Boolean, String] as PropType<boolean | string>, default: false },
|
|
36
36
|
/** 是否为loading “常驻” */
|
|
37
37
|
loading: { type: Boolean, default: false }
|
|
38
38
|
};
|
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
U_TOAST_EVENT_SHOW,
|
|
57
57
|
U_TOAST_GLOBAL_EVENT_HIDE,
|
|
58
58
|
U_TOAST_GLOBAL_EVENT_SHOW,
|
|
59
|
+
getEventWithCurrentPage,
|
|
59
60
|
type ToastPayload
|
|
60
61
|
} from './service';
|
|
61
62
|
|
|
@@ -197,31 +198,68 @@ function onServiceHide() {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
// 是否为 App 根部的“全局 toast”
|
|
200
|
-
const isGlobal = computed(() => props.global);
|
|
201
|
+
const isGlobal = computed(() => !!props.global);
|
|
201
202
|
// 是否为页面级 toast
|
|
202
|
-
const isPage = computed(() => props.page);
|
|
203
|
+
const isPage = computed(() => !!props.page);
|
|
203
204
|
|
|
204
205
|
// 显示事件
|
|
205
|
-
const showEvent = computed(() =>
|
|
206
|
+
const showEvent = computed(() =>
|
|
207
|
+
isGlobal.value
|
|
208
|
+
? U_TOAST_GLOBAL_EVENT_SHOW
|
|
209
|
+
: isPage.value
|
|
210
|
+
? getEventWithCurrentPage(U_TOAST_EVENT_SHOW, props.page)
|
|
211
|
+
: ''
|
|
212
|
+
);
|
|
213
|
+
|
|
206
214
|
// 隐藏事件
|
|
207
|
-
const hideEvent = computed(() =>
|
|
215
|
+
const hideEvent = computed(() =>
|
|
216
|
+
isGlobal.value
|
|
217
|
+
? U_TOAST_GLOBAL_EVENT_HIDE
|
|
218
|
+
: isPage.value
|
|
219
|
+
? getEventWithCurrentPage(U_TOAST_EVENT_HIDE, props.page)
|
|
220
|
+
: ''
|
|
221
|
+
);
|
|
208
222
|
|
|
209
|
-
|
|
223
|
+
// 开始监听事件
|
|
224
|
+
function startListeners() {
|
|
225
|
+
// 如果为全局 toast,则先移除所有事件监听,再重新监听
|
|
226
|
+
if (isGlobal.value) {
|
|
227
|
+
removeAllListeners();
|
|
228
|
+
}
|
|
210
229
|
if (showEvent.value) {
|
|
211
230
|
uni?.$on && uni.$on(showEvent.value, onServiceShow);
|
|
212
231
|
}
|
|
213
232
|
if (hideEvent.value) {
|
|
214
233
|
uni?.$on && uni.$on(hideEvent.value, onServiceHide);
|
|
215
234
|
}
|
|
216
|
-
}
|
|
235
|
+
}
|
|
217
236
|
|
|
218
|
-
|
|
237
|
+
// 停止监听事件
|
|
238
|
+
function stopListeners() {
|
|
219
239
|
if (showEvent.value) {
|
|
220
240
|
uni?.$off && uni.$off(showEvent.value, onServiceShow);
|
|
221
241
|
}
|
|
222
242
|
if (hideEvent.value) {
|
|
223
243
|
uni?.$off && uni.$off(hideEvent.value, onServiceHide);
|
|
224
244
|
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// 移除所有事件监听
|
|
248
|
+
function removeAllListeners() {
|
|
249
|
+
if (showEvent.value) {
|
|
250
|
+
uni?.$off && uni.$off(showEvent.value);
|
|
251
|
+
}
|
|
252
|
+
if (hideEvent.value) {
|
|
253
|
+
uni?.$off && uni.$off(hideEvent.value);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
onMounted(() => {
|
|
258
|
+
startListeners();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
onBeforeUnmount(() => {
|
|
262
|
+
stopListeners();
|
|
225
263
|
});
|
|
226
264
|
|
|
227
265
|
defineExpose<ToastExpose>({
|
|
@@ -365,6 +365,8 @@ function deleteItem(index: number) {
|
|
|
365
365
|
uni.showModal({
|
|
366
366
|
title: t('uUpload.modalTitle'),
|
|
367
367
|
content: t('uUpload.deleteConfirm'),
|
|
368
|
+
cancelText: t('uUpload.modalCancelText'),
|
|
369
|
+
confirmText: t('uUpload.modalConfirmText'),
|
|
368
370
|
success: async (res: any) => {
|
|
369
371
|
if (res.confirm) {
|
|
370
372
|
// 先检查是否有定义before-remove移除前钩子
|
package/libs/hooks/useModal.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
U_MODAL_GLOBAL_EVENT_SHOW,
|
|
6
6
|
U_MODAL_GLOBAL_EVENT_HIDE,
|
|
7
7
|
U_MODAL_GLOBAL_EVENT_CLEAR_LOADING,
|
|
8
|
+
getEventWithCurrentPage,
|
|
8
9
|
type ModalPayload
|
|
9
10
|
} from '../../components/u-modal/service';
|
|
10
11
|
|
|
@@ -32,8 +33,8 @@ export type UseModal = {
|
|
|
32
33
|
export type UseModalOptions = {
|
|
33
34
|
/** 是否使用全局根部 <u-modal global /> */
|
|
34
35
|
global?: boolean;
|
|
35
|
-
/** 是否使用页面级 <u-modal page /> */
|
|
36
|
-
page?: boolean;
|
|
36
|
+
/** 是否使用页面级 <u-modal page /> 或某个页面的 <u-modal page="pageId" /> */
|
|
37
|
+
page?: boolean | string;
|
|
37
38
|
};
|
|
38
39
|
|
|
39
40
|
function normalize(contentOrOptions: string | UseModalShowOptions): UseModalShowOptions {
|
|
@@ -44,18 +45,43 @@ function normalize(contentOrOptions: string | UseModalShowOptions): UseModalShow
|
|
|
44
45
|
return contentOrOptions || {};
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
function getPage(optionsOrGlobal: UseModalOptions | boolean): string {
|
|
49
|
+
if (typeof optionsOrGlobal === 'boolean') {
|
|
50
|
+
return '';
|
|
51
|
+
}
|
|
52
|
+
if (optionsOrGlobal.page && typeof optionsOrGlobal.page === 'string' && optionsOrGlobal.page !== '') {
|
|
53
|
+
return optionsOrGlobal.page;
|
|
54
|
+
}
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
/**
|
|
48
59
|
* Modal 函数式调用
|
|
49
|
-
* @description 需要页面/应用中至少存在一个 <u-modal global /> 或 <u-modal page />
|
|
50
|
-
*
|
|
60
|
+
* @description 需要页面/应用中至少存在一个 <u-modal global /> 或 <u-modal page /> 实例用于承接事件;不影响原 ref 调用方式。
|
|
61
|
+
*
|
|
62
|
+
* 支持两种调用方式:
|
|
63
|
+
* - 应用级 useModal() / useModal(true) / useModal({ global: true })
|
|
64
|
+
* - 页面级 useModal(false) / useModal({ page: true }) / useModal({ page: 'pageId' }) (pageId 应和页面中 <u-modal page="pageId" /> 的 page 属性一致)
|
|
51
65
|
*/
|
|
52
66
|
export function useModal(optionsOrGlobal: UseModalOptions | boolean = true): UseModal {
|
|
53
|
-
const isGlobal = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal
|
|
54
|
-
const isPage = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal === false : optionsOrGlobal.page
|
|
67
|
+
const isGlobal = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal === true : !!optionsOrGlobal.global;
|
|
68
|
+
const isPage = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal === false : !!optionsOrGlobal.page;
|
|
55
69
|
|
|
56
|
-
const showEvent = isGlobal
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
const showEvent = isGlobal
|
|
71
|
+
? U_MODAL_GLOBAL_EVENT_SHOW
|
|
72
|
+
: isPage
|
|
73
|
+
? getEventWithCurrentPage(U_MODAL_EVENT_SHOW, getPage(optionsOrGlobal))
|
|
74
|
+
: '';
|
|
75
|
+
const hideEvent = isGlobal
|
|
76
|
+
? U_MODAL_GLOBAL_EVENT_HIDE
|
|
77
|
+
: isPage
|
|
78
|
+
? getEventWithCurrentPage(U_MODAL_EVENT_HIDE, getPage(optionsOrGlobal))
|
|
79
|
+
: '';
|
|
80
|
+
const clearLoadingEvent = isGlobal
|
|
81
|
+
? U_MODAL_GLOBAL_EVENT_CLEAR_LOADING
|
|
82
|
+
: isPage
|
|
83
|
+
? getEventWithCurrentPage(U_MODAL_EVENT_CLEAR_LOADING, getPage(optionsOrGlobal))
|
|
84
|
+
: '';
|
|
59
85
|
|
|
60
86
|
function emitShow(payload: UseModalShowOptions) {
|
|
61
87
|
if (showEvent) {
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由跳转 hooks,基于 route.ts 的 Router 类实现
|
|
3
|
+
* 提供 Vue Composition API 风格的路由跳转方法
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ref } from 'vue';
|
|
7
|
+
|
|
8
|
+
interface RouterConfig {
|
|
9
|
+
type?: string;
|
|
10
|
+
url?: string;
|
|
11
|
+
delta?: number;
|
|
12
|
+
params?: Record<string, any>;
|
|
13
|
+
animationType?: string;
|
|
14
|
+
animationDuration?: number;
|
|
15
|
+
intercept?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare const uni: any;
|
|
19
|
+
|
|
20
|
+
const config: RouterConfig = {
|
|
21
|
+
type: 'navigateTo',
|
|
22
|
+
url: '',
|
|
23
|
+
delta: 1,
|
|
24
|
+
params: {},
|
|
25
|
+
animationType: 'pop-in',
|
|
26
|
+
animationDuration: 300,
|
|
27
|
+
intercept: false
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// 响应式配置,支持动态修改
|
|
31
|
+
const configRef = ref({ ...config });
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 判断 url 前面是否有 "/",如果没有则加上
|
|
35
|
+
*/
|
|
36
|
+
const addRootPath = (url: string): string => {
|
|
37
|
+
return url[0] === '/' ? url : `/${url}`;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 整合路由参数
|
|
42
|
+
*/
|
|
43
|
+
const mixinParam = (url: string, params: Record<string, any>): string => {
|
|
44
|
+
url = url && addRootPath(url);
|
|
45
|
+
let query = '';
|
|
46
|
+
if (/.*\/.*\?.*=.*/.test(url)) {
|
|
47
|
+
query = uni.$u.queryParams(params, false);
|
|
48
|
+
return url + '&' + query;
|
|
49
|
+
} else {
|
|
50
|
+
query = uni.$u.queryParams(params);
|
|
51
|
+
return url + query;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 执行路由跳转
|
|
57
|
+
*/
|
|
58
|
+
const openPage = (cfg: RouterConfig): void => {
|
|
59
|
+
const { url = '', type = '', delta = 1, animationDuration = 300 } = cfg;
|
|
60
|
+
if (type === 'navigateTo' || type === 'to') {
|
|
61
|
+
uni.navigateTo({ url, animationDuration });
|
|
62
|
+
}
|
|
63
|
+
if (type === 'redirectTo' || type === 'redirect') {
|
|
64
|
+
uni.redirectTo({ url });
|
|
65
|
+
}
|
|
66
|
+
if (type === 'switchTab' || type === 'tab') {
|
|
67
|
+
uni.switchTab({ url });
|
|
68
|
+
}
|
|
69
|
+
if (type === 'reLaunch' || type === 'launch') {
|
|
70
|
+
uni.reLaunch({ url });
|
|
71
|
+
}
|
|
72
|
+
if (type === 'navigateBack' || type === 'back') {
|
|
73
|
+
uni.navigateBack({ delta });
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 路由跳转主方法
|
|
79
|
+
*/
|
|
80
|
+
const route = async (options: string | RouterConfig = {}, params: Record<string, any> = {}): Promise<void> => {
|
|
81
|
+
let mergeConfig: RouterConfig = {};
|
|
82
|
+
|
|
83
|
+
if (typeof options === 'string') {
|
|
84
|
+
mergeConfig.url = mixinParam(options, params);
|
|
85
|
+
mergeConfig.type = 'navigateTo';
|
|
86
|
+
} else {
|
|
87
|
+
mergeConfig = uni.$u.deepMerge(configRef.value, options);
|
|
88
|
+
mergeConfig.url = mixinParam(options.url || '', options.params || {});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (params.intercept !== undefined) {
|
|
92
|
+
configRef.value.intercept = params.intercept;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
mergeConfig.params = params;
|
|
96
|
+
mergeConfig = uni.$u.deepMerge(configRef.value, mergeConfig);
|
|
97
|
+
|
|
98
|
+
if (uni.$u.routeIntercept && typeof uni.$u.routeIntercept === 'function') {
|
|
99
|
+
const isNext = await new Promise<boolean>(resolve => {
|
|
100
|
+
uni.$u.routeIntercept(mergeConfig, resolve);
|
|
101
|
+
});
|
|
102
|
+
isNext && openPage(mergeConfig);
|
|
103
|
+
} else {
|
|
104
|
+
openPage(mergeConfig);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 跳转到指定页面
|
|
110
|
+
*/
|
|
111
|
+
const to = (url: string, params?: Record<string, any>): Promise<void> => {
|
|
112
|
+
return route({ url, type: 'navigateTo' }, params || {});
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* 关闭当前页面,跳转到指定页面
|
|
117
|
+
*/
|
|
118
|
+
const redirect = (url: string, params?: Record<string, any>): Promise<void> => {
|
|
119
|
+
return route({ url, type: 'redirectTo' }, params || {});
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 跳转到 tabBar 页面
|
|
124
|
+
*/
|
|
125
|
+
const tab = (url: string, params?: Record<string, any>): Promise<void> => {
|
|
126
|
+
return route({ url, type: 'switchTab' }, params || {});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 关闭所有页面,跳转到指定页面
|
|
131
|
+
*/
|
|
132
|
+
const reLaunch = (url: string, params?: Record<string, any>): Promise<void> => {
|
|
133
|
+
return route({ url, type: 'reLaunch' }, params || {});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* 返回上一页
|
|
138
|
+
*/
|
|
139
|
+
const back = (delta: number = 1): Promise<void> => {
|
|
140
|
+
return route({ type: 'navigateBack', delta });
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* 设置默认路由配置
|
|
145
|
+
*/
|
|
146
|
+
const setConfig = (newConfig: Partial<RouterConfig>): void => {
|
|
147
|
+
configRef.value = uni.$u.deepMerge(configRef.value, newConfig);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 获取当前路由配置
|
|
152
|
+
*/
|
|
153
|
+
const getConfig = (): RouterConfig => {
|
|
154
|
+
return { ...configRef.value };
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export function useRouter() {
|
|
158
|
+
return {
|
|
159
|
+
// 核心跳转方法
|
|
160
|
+
route,
|
|
161
|
+
// 便捷方法
|
|
162
|
+
to,
|
|
163
|
+
redirect,
|
|
164
|
+
tab,
|
|
165
|
+
reLaunch,
|
|
166
|
+
back,
|
|
167
|
+
// 配置方法
|
|
168
|
+
setConfig,
|
|
169
|
+
getConfig
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export default useRouter;
|
package/libs/hooks/useToast.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
U_TOAST_EVENT_SHOW,
|
|
4
4
|
U_TOAST_GLOBAL_EVENT_HIDE,
|
|
5
5
|
U_TOAST_GLOBAL_EVENT_SHOW,
|
|
6
|
+
getEventWithCurrentPage,
|
|
6
7
|
type ToastPayload
|
|
7
8
|
} from '../../components/u-toast/service';
|
|
8
9
|
import type { ThemeType } from '../../types/global';
|
|
@@ -33,8 +34,8 @@ export type UseToast = {
|
|
|
33
34
|
export type UseToastOptions = {
|
|
34
35
|
/** 是否使用全局根部 <u-toast global />,默认 true;为 false 时走页面级 <u-toast /> */
|
|
35
36
|
global?: boolean;
|
|
36
|
-
/** 是否使用页面级 <u-toast page /> */
|
|
37
|
-
page?: boolean;
|
|
37
|
+
/** 是否使用页面级 <u-toast page /> 或某个页面的 <u-toast page="pageId" /> */
|
|
38
|
+
page?: boolean | string;
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
function normalize(titleOrOptions: string | UseToastShowOptions): UseToastShowOptions {
|
|
@@ -42,16 +43,37 @@ function normalize(titleOrOptions: string | UseToastShowOptions): UseToastShowOp
|
|
|
42
43
|
return titleOrOptions || {};
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
function getPage(optionsOrGlobal: UseToastOptions | boolean): string {
|
|
47
|
+
if (typeof optionsOrGlobal === 'boolean') {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
if (optionsOrGlobal.page && typeof optionsOrGlobal.page === 'string' && optionsOrGlobal.page !== '') {
|
|
51
|
+
return optionsOrGlobal.page;
|
|
52
|
+
}
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
/**
|
|
46
57
|
* Toast 函数式调用
|
|
47
58
|
* @description 需要页面/应用中至少存在一个 <u-toast global /> 或 <u-toast page /> 实例用于承接事件;不影响原 ref 调用方式。
|
|
48
|
-
*
|
|
59
|
+
*
|
|
60
|
+
* 支持两种调用方式:
|
|
61
|
+
* - 应用级 useToast() / useToast(true) / useToast({ global: true })
|
|
62
|
+
* - 页面级 useToast(false) / useToast({ page: true }) / useToast({ page: 'pageId' }) (pageId 应和页面中 <u-toast page="pageId" /> 的 page 属性一致)
|
|
49
63
|
*/
|
|
50
64
|
export function useToast(optionsOrGlobal: UseToastOptions | boolean = true): UseToast {
|
|
51
|
-
const isGlobal = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal
|
|
52
|
-
const isPage = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal === false : optionsOrGlobal.page
|
|
53
|
-
const showEvent = isGlobal
|
|
54
|
-
|
|
65
|
+
const isGlobal = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal === true : !!optionsOrGlobal.global;
|
|
66
|
+
const isPage = typeof optionsOrGlobal === 'boolean' ? optionsOrGlobal === false : !!optionsOrGlobal.page;
|
|
67
|
+
const showEvent = isGlobal
|
|
68
|
+
? U_TOAST_GLOBAL_EVENT_SHOW
|
|
69
|
+
: isPage
|
|
70
|
+
? getEventWithCurrentPage(U_TOAST_EVENT_SHOW, getPage(optionsOrGlobal))
|
|
71
|
+
: '';
|
|
72
|
+
const hideEvent = isGlobal
|
|
73
|
+
? U_TOAST_GLOBAL_EVENT_HIDE
|
|
74
|
+
: isPage
|
|
75
|
+
? getEventWithCurrentPage(U_TOAST_EVENT_HIDE, getPage(optionsOrGlobal))
|
|
76
|
+
: '';
|
|
55
77
|
|
|
56
78
|
function emitShow(payload: UseToastShowOptions) {
|
|
57
79
|
if (showEvent) {
|
package/locale/lang/en-US.ts
CHANGED
|
@@ -13,6 +13,8 @@ export default {
|
|
|
13
13
|
reUpload: 'Re-upload',
|
|
14
14
|
uploadFailed: 'Upload failed, please try again',
|
|
15
15
|
modalTitle: 'Notice',
|
|
16
|
+
modalCancelText: 'Cancel',
|
|
17
|
+
modalConfirmText: 'Confirm',
|
|
16
18
|
deleteConfirm: 'Are you sure you want to delete this item?',
|
|
17
19
|
terminatedRemove: 'Removal cancelled',
|
|
18
20
|
removeSuccess: 'Removed successfully',
|
package/locale/lang/zh-CN.ts
CHANGED
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.8",
|
|
6
6
|
"description": "uView Pro是基于Vue3+TS的多平台UI框架,提供80+高质量组件、便捷工具和常用模板,支持多主题、暗黑模式、多语言,支持H5/APP/鸿蒙/小程序多端开发。已在鸿蒙应用商店上架,欢迎体验!",
|
|
7
7
|
"main": "index.ts",
|
|
8
8
|
"module": "index.ts",
|
package/readme.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
[](https://github.com/anyup/uView-Pro)
|
|
10
10
|
[](https://github.com/anyup/uView-Pro)
|
|
11
11
|
[](https://github.com/anyup/uView-Pro/issues)
|
|
12
|
+
[](https://www.npmjs.com/package/uview-pro)
|
|
12
13
|
[](https://www.npmjs.com/package/uview-pro)
|
|
13
14
|
[](https://uviewpro.cn)
|
|
14
15
|
[](https://nodejs.org/)
|