loginSuccess.js 863 B

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