loginUtils.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. console.log(url);
  19. if (pageUrl != url) {
  20. uni.navigateTo({
  21. url
  22. })
  23. }
  24. }
  25. // 保存页面
  26. export function saveUrl() {
  27. let path = getPageUrl(true)
  28. uni.setStorageSync('present', path);
  29. }
  30. // 处理分享链接地址
  31. export function getPageUrl(showSpeard=false) {
  32. let page = getActionPage();
  33. let path = '/' + page.route;
  34. let url = '';
  35. // 获取对象可枚举键值列表
  36. let objKeys = Object.keys(page.options);
  37. // 判断有无传值
  38. if (objKeys.length > 0) {
  39. // 循环赋值对象数据
  40. for (let a in page.options) {
  41. // 判断有无邀请人
  42. if (a != 'speard') {
  43. url += a + "=" + page.options[a] + "&"
  44. }else{
  45. // 判断是否需要存储邀请人
  46. if(showSpeard){
  47. url += a + "=" + page.options[a] + "&"
  48. }
  49. }
  50. }
  51. path += '?' + url.substr(0, url.length - 1);
  52. }
  53. // 返回处理邀请人后的邀请地址
  54. return path
  55. }