init
This commit is contained in:
commit
2b8870a40e
51 changed files with 5845 additions and 0 deletions
76
utils/ui.js
Normal file
76
utils/ui.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* 显示加载提示
|
||||
* @param {string} [title='加载中'] - 提示文本
|
||||
* @param {boolean} [mask=true] - 是否显示透明蒙层
|
||||
*/
|
||||
export const showLoading = (title = '加载中', mask = true) => {
|
||||
wx.showLoading({
|
||||
title,
|
||||
mask
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 隐藏加载提示
|
||||
*/
|
||||
export const hideLoading = () => {
|
||||
wx.hideLoading();
|
||||
};
|
||||
|
||||
/**
|
||||
* 显示Toast提示
|
||||
* @param {string} title - 提示内容
|
||||
* @param {string} [icon='none'] - 图标类型
|
||||
* @param {number} [duration=1500] - 显示时长(毫秒)
|
||||
*/
|
||||
export const showToast = (title, icon = 'none', duration = 1500) => {
|
||||
return new Promise((resolve) => {
|
||||
wx.showToast({
|
||||
title,
|
||||
icon,
|
||||
duration,
|
||||
success: resolve
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 显示确认对话框
|
||||
* @param {string} content - 对话框内容
|
||||
* @param {Object} [options] - 配置选项
|
||||
* @param {string} [options.title='提示'] - 对话框标题
|
||||
* @param {string} [options.confirmText='确定'] - 确认按钮文本
|
||||
* @param {string} [options.cancelText='取消'] - 取消按钮文本
|
||||
* @param {boolean} [options.showCancel=true] - 是否显示取消按钮
|
||||
* @returns {Promise<boolean>} 用户是否点击了确认
|
||||
*/
|
||||
export const showConfirmModal = (content, options = {}) => {
|
||||
return new Promise((resolve) => {
|
||||
wx.showModal({
|
||||
title: options.title || '提示',
|
||||
content,
|
||||
confirmText: options.confirmText || '确定',
|
||||
cancelText: options.cancelText || '取消',
|
||||
showCancel: options.showCancel !== false,
|
||||
success: (res) => resolve(res.confirm),
|
||||
fail: () => resolve(false)
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 显示操作菜单
|
||||
* @param {Array<string>} itemList - 菜单项列表
|
||||
* @param {string} [itemColor='#000000'] - 菜单项颜色
|
||||
* @returns {Promise<number>} 用户选择的索引,取消时为-1
|
||||
*/
|
||||
export const showActionSheet = (itemList, itemColor = '#000000') => {
|
||||
return new Promise((resolve) => {
|
||||
wx.showActionSheet({
|
||||
itemList,
|
||||
itemColor,
|
||||
success: (res) => resolve(res.tapIndex),
|
||||
fail: () => resolve(-1)
|
||||
});
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue