transform.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. */
  11. /**
  12. * 动态加载js脚本文件
  13. * @param {*} scriptSrc
  14. */
  15. function appendScriptSrc(scriptSrc){
  16. var script = document.createElement('script');
  17. script.src = scriptSrc; // 加载JS文件路径
  18. document.body.appendChild(script);
  19. }
  20. /**
  21. * /passport/login--->/#/passport/login
  22. * /passport/callback/---->/#/passport/callback/
  23. * @param {*} transPath
  24. */
  25. function locationTransform(transPath){
  26. var topHref = top.location.href;
  27. if(topHref.indexOf('#') <= 0){
  28. var loginIndex = topHref.indexOf(transPath);
  29. if(loginIndex >- 1){
  30. topHref = topHref.substring(0,loginIndex) + '/#' + topHref.substring(loginIndex);
  31. top.location.href = topHref;
  32. }
  33. }
  34. }
  35. var transPaths = [
  36. '/passport/login',
  37. '/passport/callback/'
  38. ];
  39. for (i = 0; i < transPaths.length; i++) {
  40. locationTransform(transPaths[i]);
  41. }