authorize.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div class="container">
  3. <div class="logo"></div>
  4. <!-- 登录区域 -->
  5. <div class="content">
  6. <!-- 配图 -->
  7. <div class="pic"></div>
  8. <!-- 表单 -->
  9. <div class="field">
  10. <!-- [移动端]标题 -->
  11. <h2 class="mobile-title">
  12. <h3 class="title">芋道后台管理系统</h3>
  13. </h2>
  14. <!-- 表单 -->
  15. <div class="form-cont">
  16. <el-tabs class="form" style=" float:none;">
  17. <el-tab-pane label="三方授权" name="uname">
  18. </el-tab-pane>
  19. </el-tabs>
  20. <div>
  21. <el-form ref="loginForm" :model="loginForm" :rules="LoginRules" class="login-form">
  22. <el-form-item prop="tenantName" v-if="tenantEnable">
  23. <el-input v-model="loginForm.tenantName" type="text" auto-complete="off" placeholder='租户'>
  24. <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon"/>
  25. </el-input>
  26. </el-form-item>
  27. <!-- 账号密码登录 -->
  28. <div v-if="loginForm.loginType === 'uname'">
  29. <el-form-item prop="username">
  30. <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号">
  31. <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
  32. </el-input>
  33. </el-form-item>
  34. <el-form-item prop="password">
  35. <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
  36. @keyup.enter.native="handleLogin">
  37. <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
  38. </el-input>
  39. </el-form-item>
  40. <el-form-item prop="code" v-if="captchaEnable">
  41. <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%"
  42. @keyup.enter.native="handleLogin">
  43. <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>
  44. </el-input>
  45. </el-form-item>
  46. </div>
  47. <!-- 下方的登录按钮 -->
  48. <el-form-item style="width:100%;">
  49. <el-button :loading="loading" size="medium" type="primary" style="width:60%;"
  50. @click.native.prevent="handleLogin">
  51. <span v-if="!loading">同意授权</span>
  52. <span v-else>登 录 中...</span>
  53. </el-button>
  54. <el-button size="medium" style="width:37%">拒绝</el-button>
  55. </el-form-item>
  56. </el-form>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <!-- footer -->
  62. <div class="footer">
  63. Copyright © 2020-2022 iocoder.cn All Rights Reserved.
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import {getTenantIdByName} from "@/api/system/tenant";
  69. import Cookies from "js-cookie";
  70. import {SystemUserSocialTypeEnum} from "@/utils/constants";
  71. import {getTenantEnable} from "@/utils/ruoyi";
  72. import {authorize} from "@/api/login";
  73. export default {
  74. name: "Login",
  75. data() {
  76. return {
  77. tenantEnable: true,
  78. loginForm: {
  79. tenantName: "芋道源码",
  80. },
  81. LoginRules: {
  82. tenantName: [
  83. {required: true, trigger: "blur", message: "租户不能为空"},
  84. {
  85. validator: (rule, value, callback) => {
  86. // debugger
  87. getTenantIdByName(value).then(res => {
  88. const tenantId = res.data;
  89. if (tenantId && tenantId >= 0) {
  90. // 设置租户
  91. Cookies.set("tenantId", tenantId);
  92. callback();
  93. } else {
  94. callback('租户不存在');
  95. }
  96. });
  97. },
  98. trigger: 'blur'
  99. }
  100. ]
  101. },
  102. loading: false,
  103. redirect: undefined,
  104. // 枚举
  105. SysUserSocialTypeEnum: SystemUserSocialTypeEnum,
  106. };
  107. },
  108. created() {
  109. // 租户开关
  110. this.tenantEnable = getTenantEnable();
  111. // 重定向地址
  112. this.redirect = this.$route.query.redirect;
  113. this.getCookie();
  114. },
  115. methods: {
  116. getCookie() {
  117. const tenantName = Cookies.get('tenantName');
  118. this.loginForm = {
  119. tenantName: tenantName === undefined ? this.loginForm.tenantName : tenantName
  120. };
  121. },
  122. handleLogin() {
  123. if (true) {
  124. authorize()
  125. return;
  126. }
  127. this.$refs.loginForm.validate(valid => {
  128. if (valid) {
  129. this.loading = true;
  130. // 发起登陆
  131. console.log("发起登录", this.loginForm);
  132. this.$store.dispatch(this.loginForm.loginType === "sms" ? "SmsLogin" : "Login", this.loginForm).then(() => {
  133. this.$router.push({path: this.redirect || "/"}).catch(() => {
  134. });
  135. }).catch(() => {
  136. this.loading = false;
  137. this.getCode();
  138. });
  139. }
  140. });
  141. }
  142. }
  143. };
  144. </script>
  145. <style lang="scss" scoped>
  146. @import "~@/assets/styles/login.scss";
  147. .oauth-login {
  148. display: flex;
  149. align-items: cen;
  150. cursor:pointer;
  151. }
  152. .oauth-login-item {
  153. display: flex;
  154. align-items: center;
  155. margin-right: 10px;
  156. }
  157. .oauth-login-item img {
  158. height: 25px;
  159. width: 25px;
  160. }
  161. .oauth-login-item span:hover {
  162. text-decoration: underline red;
  163. color: red;
  164. }
  165. </style>