Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

33 rindas
858 B

  1. /**
  2. * 通用交互组合式函数,替代旧版全局 base mixin。
  3. * 用法:const { toast, showLoading, navigateBack } = useApp()
  4. */
  5. export function useApp() {
  6. const toast = (title, duration = 2500) => {
  7. if (!title) return
  8. uni.showToast({
  9. icon: 'none',
  10. title: typeof title === 'string' ? title : '操作失败',
  11. duration
  12. })
  13. }
  14. const showLoading = (title = '加载中...') => {
  15. uni.showLoading({ mask: true, title })
  16. }
  17. const hideLoading = () => uni.hideLoading()
  18. /** 返回上一页,若已是首个页面则回到首页 tab */
  19. const navigateBack = (options) => {
  20. const pages = getCurrentPages()
  21. if (pages.length <= 1) {
  22. uni.switchTab({ url: '/pages/toolbox/toolbox' })
  23. } else {
  24. uni.navigateBack(options)
  25. }
  26. }
  27. return { toast, showLoading, hideLoading, navigateBack }
  28. }