index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="login-container"
  3. :class="backgroundClass"
  4. ref="login"
  5. @keyup.enter.native="handleLogin">
  6. <top-color v-show="false"></top-color>
  7. <div class="login-weaper animated bounceInDown">
  8. <div class="login-left" :class="backgroundClass">
  9. <div class="login-time">
  10. {{time}}
  11. </div>
  12. <!--<img class="img" src="/img/logoTubao.png" alt="">-->
  13. <p class="title">
  14. {{ special === 1 ? '多多易车配管理平台' :$t('login.info') }}
  15. </p>
  16. <!--$t 国际化vue-i18n中英文切换 -->
  17. </div>
  18. <div class="login-border">
  19. <div class="login-main">
  20. <h4 class="login-title">
  21. {{ $t('login.title') }}
  22. <top-lang></top-lang>
  23. </h4>
  24. <userLogin v-if="activeName==='user'"></userLogin>
  25. <codeLogin v-else-if="activeName==='code'"></codeLogin>
  26. <thirdLogin v-else-if="activeName==='third'"></thirdLogin>
  27. <div class="login-menu">
  28. <a href="#" @click.stop="activeName='user'">{{ $t('login.userLogin') }}</a>
  29. <!--<a href="#" @click.stop="activeName='code'">{{ $t('login.phoneLogin') }}</a>-->
  30. <a href="#" @click.stop="activeName='third'">{{ $t('login.thirdLogin') }}</a>
  31. </div>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script>
  38. import userLogin from "./userlogin"; // 账号密码登录按钮
  39. import codeLogin from "./codelogin"; // 手机号登录按钮
  40. import thirdLogin from "./thirdlogin"; // 第三方登录按钮
  41. import {mapGetters} from "vuex";
  42. import {dateFormat} from "@/util/date"; // 处理日期格式
  43. import {validatenull} from "@/util/validate"; // 判断是否是空null
  44. import topLang from "@/page/index/top/top-lang"; // 左侧背景颜色版
  45. import topColor from "@/page/index/top/top-color"; // 中英文翻译组建
  46. import {getQueryString, getTopUrl} from "@/util/util";
  47. export default {
  48. name: "login",
  49. components: {
  50. userLogin,
  51. codeLogin,
  52. thirdLogin,
  53. topLang,
  54. topColor
  55. },
  56. data() {
  57. return {
  58. time: "",
  59. activeName: "user",
  60. socialForm: {
  61. tenantId: "000000",
  62. source: "",
  63. code: "",
  64. state: "",
  65. },
  66. special: 0
  67. };
  68. },
  69. watch: {
  70. $route() {
  71. this.handleLogin();
  72. }
  73. },
  74. created() {
  75. this.handleLogin();
  76. this.getTime();
  77. },
  78. mounted() {
  79. },
  80. computed: {
  81. ...mapGetters(["website", "tagWel"]),
  82. backgroundClass() {
  83. const domain = window.location.hostname.split('.')[0];
  84. if ('duoduo' === domain) {
  85. this.special = 1
  86. return `bg-${domain}`;
  87. }
  88. return 'bg-default';
  89. }
  90. },
  91. props: [],
  92. methods: {
  93. getTime() {
  94. setInterval(() => {
  95. this.time = dateFormat(new Date());
  96. }, 1000);
  97. },
  98. handleLogin() {
  99. const topUrl = getTopUrl();
  100. const redirectUrl = "/oauth/redirect/";
  101. this.socialForm.source = getQueryString("source");
  102. this.socialForm.code = getQueryString("code");
  103. this.socialForm.state = getQueryString("state");
  104. console.log(this.socialForm,'socialForm')
  105. if (validatenull(this.socialForm.source) && topUrl.includes(redirectUrl)) {
  106. let source = topUrl.split("?")[0];
  107. source = source.split(redirectUrl)[1];
  108. this.socialForm.source = source;
  109. }
  110. if (!validatenull(this.socialForm.source) && !validatenull(this.socialForm.code) && !validatenull(this.socialForm.state)) {
  111. const loading = this.$loading({
  112. lock: true,
  113. text: '第三方系统登录中,请稍后。。。',
  114. spinner: "el-icon-loading"
  115. });
  116. this.$store.dispatch("LoginBySocial", this.socialForm).then(() => {
  117. window.location.href = topUrl.split(redirectUrl)[0];
  118. this.$router.push({path: this.tagWel.value});
  119. loading.close();
  120. }).catch(() => {
  121. loading.close();
  122. });
  123. }
  124. }
  125. }
  126. };
  127. </script>
  128. <style lang="scss">
  129. @import "@/styles/login.scss";
  130. </style>