loginUtils.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. export function getActionPage() {
  2. let pages = getCurrentPages();
  3. return pages[pages.length - 1]
  4. }
  5. //登录拦截
  6. export function interceptor() {
  7. let pages = getActionPage();
  8. // 获取当前页面
  9. let pageUrl = '/' + pages.route;
  10. let url = '/pages/public/login'
  11. // #ifdef H5
  12. // 判断是否为公众号调用微信授权登录
  13. let weichatBrowser = uni.getStorageSync('weichatBrowser');
  14. if (weichatBrowser) {
  15. url = '/pages/public/wxLogin';
  16. }
  17. // #endif
  18. // #ifdef MP-WEIXIN
  19. url = '/pages/public/wxLogin';
  20. // #endif
  21. if (pageUrl != url) {
  22. uni.navigateTo({
  23. url
  24. })
  25. }
  26. }
  27. // 保存页面
  28. export function saveUrl() {
  29. let path = getPageUrl(true)
  30. uni.setStorageSync('present', path);
  31. }
  32. // 处理分享链接地址
  33. export function getPageUrl(showSpeard=false) {
  34. let page = getActionPage();
  35. let path = '/' + page.route;
  36. let url = '';
  37. // 获取对象可枚举键值列表
  38. let objKeys = Object.keys(page.options);
  39. // 判断有无传值
  40. if (objKeys.length > 0) {
  41. // 循环赋值对象数据
  42. for (let a in page.options) {
  43. // 判断有无邀请人
  44. if (a != 'speard') {
  45. url += a + "=" + page.options[a] + "&"
  46. }else{
  47. // 判断是否需要存储邀请人
  48. if(showSpeard){
  49. url += a + "=" + page.options[a] + "&"
  50. }
  51. }
  52. }
  53. path += '?' + url.substr(0, url.length - 1);
  54. }
  55. // 返回处理邀请人后的邀请地址
  56. return path
  57. }