| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- export class Prompt {
- constructor() {}
- /**
- * 显示消息提示框。
- */
- showToast(
- options = {
- title: '', // String 是 提示的内容,长度与 icon 取值有关。
- icon: 'none', // String 否 图标,有效值详见下方说明。
- image: '', // String 否 自定义图标的本地路径 5+App、H5、微信小程序、百度小程序
- mask: true, // Boolean 否 是否显示透明蒙层,防止触摸穿透,默认:false 5+App、微信小程序
- duration: 1500, // Number 否 提示的延迟时间,单位毫秒,默认:1500
- position: '', // String 否 纯文本轻提示显示位置,填写有效值后只有 title 属性生效, 有效值详见下方说明。 5+App
- success: () => {}, // Function 否 接口调用成功的回调函数
- fail: () => {}, // Function 否 接口调用失败的回调函数
- complete: () => {} // Function 否 接口调用结束的回调函数(调用成功、失败都会执行)
- }
- ) {
- uni.showToast({
- title: options.title || '提示',
- icon: options.icon || 'none',
- image: options.image || '',
- mask: options.mask || true,
- duration: options.duration || 1500,
- position: options.position || '',
- success: options.success || (() => {}),
- fail: options.fail || (() => {}),
- complete: options.complete || (() => {})
- })
- }
- /**
- * 隐藏消息提示框。
- */
- hideToast() {
- uni.hideToast()
- }
- /**
- * 显示 loading 提示框, 需主动调用 hideLoading 才能关闭提示框。
- * @param {*} options
- */
- showLoading(
- options = {
- title: '', // String 是 提示的内容,长度与 icon 取值有关。
- mask: true, // Boolean 否 是否显示透明蒙层,防止触摸穿透,默认:false 5+App、微信小程序
- success: () => {}, // Function 否 接口调用成功的回调函数
- fail: () => {}, // Function 否 接口调用失败的回调函数
- complete: () => {} // Function 否 接口调用结束的回调函数(调用成功、失败都会执行)
- }
- ) {
- uni.showLoading({
- title: options.title || '',
- mask: options.mask || true,
- success: options.success || (() => {}),
- fail: options.fail || (() => {}),
- complete: options.complete || (() => {})
- })
- }
- /**
- * 隐藏 loading 提示框。
- */
- hideLoading() {
- uni.hideLoading()
- }
- /**
- * 显示操作菜单
- * @param {*} options
- */
- showActionSheet(
- options = {
- itemList: [], // Array<String>
- itemColor: '#000000',
- success: () => {}, // Function 否 接口调用成功的回调函数
- fail: () => {}, // Function 否 接口调用失败的回调函数
- complete: () => {} // Function 否 接口调用结束的回调函数(调用成功、失败都会执行)
- }
- ) {
- uni.showActionSheet({
- itemList: options.itemList || [],
- itemColor: options.itemColor || '#000000',
- success: options.success || (() => {}),
- fail: options.fail || (() => {}),
- complete: options.complete || (() => {})
- })
- }
- /**
- * 显示模态弹窗,类似于标准 html 的消息框:alert、confirm。
- * @param {*} options
- */
- showModal(
- options = {
- title: '', // String 是 提示的标题
- content: '', // String 是 提示的内容
- showCancel: true, // Boolean 否 是否显示取消按钮,默认为 true
- cancelText: '取消', // String 否 取消按钮的文字,默认为"取消",最多 4 个字符
- cancelColor: '#000000', // HexColor 否 取消按钮的文字颜色,默认为"#000000" H5、微信小程序、百度小程序
- confirmText: '确定', // String 否 确定按钮的文字,默认为"确定",最多 4 个字符
- confirmColor: '#007aff', // HexColor 否 确定按钮的文字颜色,H5平台默认为"#007aff",微信小程序平台默认为"#3CC51F",百度小程序平台默认为"#3c76ff" H5、微信小程序、百度小程序
- success: () => {}, // Function 否 接口调用成功的回调函数
- fail: () => {}, // Function 否 接口调用失败的回调函数
- complete: () => {} // Function 否 接口调用结束的回调函数(调用成功、失败都会执行)
- }
- ) {
- uni.showModal({
- title: options.title || '提示',
- content: options.content || '',
- showCancel: options.showCancel || true,
- cancelText: options.cancelText || '取消',
- cancelColor: options.cancelColor || '#000000',
- confirmText: options.confirmText || '确定',
- confirmColor: options.confirmColor || '#007aff',
- success: options.success || (() => {}),
- fail: options.fail || (() => {}),
- complete: options.complete || (() => {})
- })
- }
- }
|