jumpUtil.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * 跳转非tabbar页面
  3. * @param url 路径
  4. * @param param 参数对象
  5. * @param timeout 延时时间,默认0
  6. * @param type default普通跳转 redirect关闭当前页面跳转 reLaunch关闭所有页面跳转 默认default
  7. */
  8. export const jump = (url, param, timeout = 0, type = 'default') => {
  9. setTimeout(() => {
  10. if (param) {
  11. url = `${url}?detail=${encodeURIComponent(JSON.stringify(param)?.replace(/%/g, '%25'))}`
  12. }
  13. if (type === 'default') {
  14. uni.navigateTo({ url })
  15. } else if (type === 'redirect') {
  16. uni.redirectTo({ url })
  17. } else {
  18. uni.reLaunch({ url })
  19. }
  20. }, timeout)
  21. }
  22. /**
  23. * 跳转到tabbar页面
  24. * @param url 路径
  25. * @param timeout 延时时间,默认0
  26. */
  27. export const jumpToTabbar = (url, timeout = 0) => {
  28. setTimeout(() => {
  29. uni.switchTab({ url })
  30. }, timeout)
  31. }
  32. /**
  33. * 关闭当前页面,返回上一级或者多级页面
  34. * @param delta 级数,默认1
  35. */
  36. export const goBack = (delta = 1) => {
  37. uni.navigateBack({ delta })
  38. }
  39. /**
  40. * 获取跳转参数
  41. * @param loadParam
  42. * @return {{}|any}
  43. */
  44. export const getJumpParam = (loadParam) => {
  45. if (typeof loadParam === 'object' && loadParam?.detail) {
  46. return JSON.parse(decodeURIComponent(loadParam.detail))
  47. }
  48. return {}
  49. }