/** * 通用交互组合式函数,替代旧版全局 base mixin。 * 用法:const { toast, showLoading, navigateBack } = useApp() */ export function useApp() { const toast = (title, duration = 2500) => { if (!title) return uni.showToast({ icon: 'none', title: typeof title === 'string' ? title : '操作失败', duration }) } const showLoading = (title = '加载中...') => { uni.showLoading({ mask: true, title }) } const hideLoading = () => uni.hideLoading() /** 返回上一页,若已是首个页面则回到首页 tab */ const navigateBack = (options) => { const pages = getCurrentPages() if (pages.length <= 1) { uni.switchTab({ url: '/pages/toolbox/toolbox' }) } else { uni.navigateBack(options) } } return { toast, showLoading, hideLoading, navigateBack } }