| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- type Icon = 'success' | 'error' | 'loading' | 'none'
- const duration = 3000
- /**
- * 轻提示
- * @param text 提示文本
- * @param icon 提示图标
- */
- export function showToast(text = '网络异常,请稍后再试', icon: Icon = 'none'): void {
- wx.showToast({
- title: text,
- icon: icon,
- duration: duration
- })
- }
- /**
- * 显示 loading 提示框
- * @param fn 回调函数
- * @param text 提示文本
- */
- export function showLoading(fn?: () => void, text = '正在加载...'): void {
- wx.showLoading({
- title: text,
- mask: true,
- success: () => {
- if (fn) fn()
- }
- })
- }
- /**
- * 隐藏 loading 提示框
- * @param fn 回调函数
- * @param text 提示文本
- */
- export function hideLoading(fn?: () => void, text?: string, icon: Icon = 'none'): void {
- wx.hideLoading({
- success: () => {},
- complete:() => {
- if (text) showToast(text, icon)
- if (fn) fn()
- }
- })
- }
- /**
- * 隐藏 model 提示框
- * @param fn 回调函数
- * @param title 提示文本
- * @param content 提示内容
- */
- export function showModel(fn?: () => void, title = '提示', content?: string, showCancel = true): void {
- wx.showModal({
- title: title,
- content: content,
- showCancel: showCancel,
- success: (res) => {
- if (res.confirm) {
- if (fn) fn()
- }
- }
- })
- }
|