1
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
* @功能描述:
* @作者: Xuweihao
* @Date: 2021-12-30 14:39:16
*/
import { Dialog, Toast } from "vant";
/**
* 用Vue封装的plus.nativeUI功能,目的是统一样式,统一判断
* @author zhangpeng
* @date 2020-07-01 10:07:54
*/
const NativeUI = {
/**
* 显示系统等待对话框
* @param {String} title
*/
showWaiting(title = "正在查询...", duration = 30000) {
Toast.loading({
message: title,
loadingType: "spinner",
forbidClick: true, //是否禁止背景点
duration: duration, //默认时长30000ms
});
},
/**
* 关闭系统等待对话框
*/
closeWaiting() {
Toast.clear();
},
/**
* 吐司提示
* @author zhangpeng
* @param {String} message 文本内容,支持通过\n换行
* @param {String} durationtype 可选值为"long"、"short",值为"long"时显示时间约为3.5s,值为"short"时显示时间约为2s,未设置时默认值为"short"。
* @date 2020-07-01 11:29:49
* @update
*/
// toast( message?: any, duration?: any) {
toast(message?: any, duration?: any,durationtype = "short",) {
if (!window.plus) {
if (durationtype === "long") {
duration = 3500;
} else if (durationtype === "short") {
duration = 2000;
} else {
duration = 3500;
}
Toast({
duration: duration, // 持续展示 toast
forbidClick: true,
message: message,
});
} else {
window.plus.nativeUI.toast(message, { verticalAlign: "center", durationtype: "long" });
}
},
/**
* 展示消息确认弹窗
* @author zhangpeng
* @param {String} title 标题
* @param {String} message? 文本内容,支持通过\n换行
* @param {String} confirmButtonText 确认按钮文案
* @param {String} cancelButtonText 取消按钮文案
* @date 2020-07-01 10:30:42
* @update
*/
confirm(title: string = "温馨提示", message?: any, confirmButtonText = "确认", cancelButtonText = "取消") {
let confirm;
if (!window.plus) {
confirm = Dialog.confirm({
title: title,
message: message,
confirmButtonText: confirmButtonText,
cancelButtonText: cancelButtonText
});
} else {
confirm = new Promise((resolve: any, reject) => {
window.plus.nativeUI.confirm(
message,
(e: any) => {
if (e.index === 0) {
resolve();
} else {
reject();
}
},
title,
[confirmButtonText, cancelButtonText]
);
});
}
return confirm;
}
};
export { NativeUI };