| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- /**
- * 全局 Toast 工具方法
- * 通过 uni 全局事件与 ay-toast 组件通信
- *
- * 使用方式(在非组件模块中,如 HTTP 请求):
- * import toast from '@/utils/toast.js'
- * toast.success('操作成功')
- * toast.error('操作失败')
- * toast.loading('加载中...')
- * toast.hide()
- */
- const toast = {
- /**
- * 显示成功提示
- * @param {String} title - 提示文字
- * @param {Object} options - 额外配置
- */
- success(title = '操作成功', options = {}) {
- uni.$emit('ayToast:show', {
- type: 'success',
- title,
- duration: 2000,
- ...options
- })
- },
- /**
- * 显示错误提示
- * @param {String} title - 提示文字
- * @param {Object} options - 额外配置
- */
- error(title = '操作失败', options = {}) {
- uni.$emit('ayToast:show', {
- type: 'error',
- title,
- duration: 2500,
- ...options
- })
- },
- /**
- * 显示加载提示
- * @param {String} title - 提示文字
- * @param {Object} options - 额外配置
- */
- loading(title = '加载中...', options = {}) {
- uni.$emit('ayToast:show', {
- type: 'loading',
- title,
- duration: 0,
- mask: true,
- ...options
- })
- },
- /**
- * 显示纯文字提示
- * @param {String} title - 提示文字
- * @param {Object} options - 额外配置
- */
- text(title, options = {}) {
- uni.$emit('ayToast:show', {
- type: 'text',
- title,
- duration: 2000,
- ...options
- })
- },
- /**
- * 隐藏 Toast
- */
- hide() {
- uni.$emit('ayToast:hide')
- }
- }
- export default toast
|