AutoLogin.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="divClass">认证中...</div>
  3. </template>
  4. <script>
  5. import AuthSettingResource from '../api/commom/AuthSettingResource.js';
  6. export default {
  7. components: {
  8. },
  9. data: function () {
  10. return {
  11. appName: null,
  12. corpId: null,
  13. code: null,
  14. clientId: null, // 临时设置公司id,必须设置
  15. authSettingDto: undefined, //authSetting服务器配置信息
  16. isUniqueLoginModel: false, //唯一认证方式
  17. }
  18. },
  19. mounted: function () {
  20. this.getIsUniqueLoginModel();
  21. this.initData();
  22. },
  23. methods: {
  24. /**
  25. * 获取认证服务器数据
  26. * @author GuoZhiBo 20211026
  27. */
  28. getAuthSettingDto: function () {
  29. var _self = this;
  30. var redirect_uri = window.location.href;
  31. redirect_uri = redirect_uri.replace('#', '%23');
  32. var code = _self.getQueryVariable(redirect_uri);
  33. if (code == undefined) {
  34. AuthSettingResource.getAuthSettingDto().then(
  35. successData => {
  36. if (
  37. successData != null &&
  38. successData.defaultAccountLogin != true
  39. ) {
  40. _self.authSettingDto = successData;
  41. var url =
  42. _self.authSettingDto.authorizedWebsite +
  43. _self.authSettingDto.jaccountClientId +
  44. '&redirect_uri=' +
  45. redirect_uri;
  46. _self.authSettingDto.redirect_uri = redirect_uri;
  47. var authSettingDto = JSON.stringify(_self.authSettingDto);
  48. localStorage.setItem('#authSettingDto', authSettingDto);
  49. window.location.href = url;
  50. }
  51. },
  52. errorData => {
  53. Common.processException(errorData);
  54. },
  55. );
  56. } else {
  57. var authSettingDto_str = localStorage.getItem('#authSettingDto');
  58. if (authSettingDto_str != undefined) {
  59. var authSettingDto = JSON.parse(authSettingDto_str);
  60. _self.profileLogin(
  61. code,
  62. authSettingDto.redirect_uri,
  63. authSettingDto.jaccountClientId,
  64. authSettingDto.id,
  65. );
  66. }
  67. }
  68. },
  69. /**
  70. * 获取登录方式
  71. * @author GuoZhiBo 20211110
  72. */
  73. getIsUniqueLoginModel: function () {
  74. var _self = this;
  75. AuthSettingResource.getAuthSettingDto().then(
  76. successData => {
  77. if (successData != null) {
  78. console.log(successData);
  79. _self.isUniqueLoginModel = successData.isUniqueLoginModel;
  80. } else {
  81. _self.isUniqueLoginModel = undefined;
  82. }
  83. _self.loading=false;
  84. },
  85. errorData => {
  86. Common.processException(errorData);
  87. _self.loading=false;
  88. },
  89. );
  90. },
  91. /**
  92. * 获取url参数
  93. * @param {Object} name
  94. */
  95. getQueryVariable: function (obj) {
  96. var index = obj.indexOf('code=');
  97. if (index == -1) {
  98. return undefined;
  99. } else {
  100. return obj.substring(index + 5, obj.length);
  101. }
  102. },
  103. }
  104. }
  105. </script>
  106. <style scoped>
  107. .divClass {
  108. text-align: center;
  109. font-size: 30px;
  110. color: red;
  111. }
  112. </style>