loginSuccess.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import pagesJson from '@/pages.json'
  2. export default function(e = {}) {
  3. const {
  4. showToast = true, toastText = '登录成功', autoBack = true, uniIdRedirectUrl = ''
  5. } = e
  6. console.log({
  7. toastText,
  8. autoBack
  9. });
  10. if (showToast) {
  11. uni.showToast({
  12. title: toastText,
  13. icon: 'none'
  14. });
  15. }
  16. if (autoBack) {
  17. let delta = 0; //判断需要返回几层
  18. let pages = getCurrentPages();
  19. uni.$emit('uni-id-pages-login-success',pages)
  20. console.log(pages);
  21. pages.forEach((page, index) => {
  22. if (pages[pages.length - index - 1].route.split('/')[3] == 'login') {
  23. delta++
  24. }
  25. })
  26. console.log('判断需要返回几层:',pages, delta);
  27. if (uniIdRedirectUrl) {
  28. return uni.reLaunch({
  29. url: uniIdRedirectUrl
  30. })
  31. }
  32. // #ifdef H5
  33. if(e.loginType == 'weixin'){
  34. console.log('window.history',window.history);
  35. return window.history.go(-3)
  36. }
  37. // #endif
  38. if (delta) {
  39. const page = pagesJson.pages[0]
  40. return uni.reLaunch({
  41. url: `/${page.path}`
  42. })
  43. }
  44. uni.navigateBack({
  45. delta
  46. })
  47. }
  48. }