page.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { CUSTOM_TABBAR_NO_CACHE } from '@/layouts/fg-tabbar/tabbarList'
  2. import { stringifyQuery } from './queryString'
  3. // uniapp 返回 入参为堆栈
  4. export function goBack(delta = 1) {
  5. console.log(delta)
  6. uni.navigateBack({ delta })
  7. }
  8. // uniapp 跳转页面 可携带参数
  9. export function toPage({ url, params, isRedirect = false, isReLaunch = false }: any) {
  10. let targetUrl = url + (isReLaunch ? '?isReLaunch=1' : '')
  11. const tabBarPages = ['/pages/index/index', '/pages/income/income', '/pages/mine/mine']
  12. if (params && Object.keys(params).length > 0) {
  13. const strParams = stringifyQuery(params)
  14. targetUrl = `${url}?${strParams + (isReLaunch ? '&isReLaunch=1' : '')}`
  15. }
  16. console.log(targetUrl)
  17. if (tabBarPages.includes(url)) {
  18. if (CUSTOM_TABBAR_NO_CACHE) {
  19. uni.navigateTo({ url: targetUrl })
  20. }
  21. else {
  22. uni.switchTab({
  23. url: targetUrl,
  24. })
  25. }
  26. }
  27. else {
  28. if (isRedirect) {
  29. uni.redirectTo({
  30. url: targetUrl,
  31. })
  32. }
  33. else if (isReLaunch) {
  34. uni.reLaunch({
  35. url: targetUrl,
  36. })
  37. }
  38. else {
  39. uni.navigateTo({
  40. url: targetUrl,
  41. })
  42. }
  43. }
  44. }