Commit 1a48301cee27a9e81b3086ea6bd69c7b61aa9e0b

Authored by YunaiV
1 parent 926c75d2

vue2 验证码,增加开关、修复对社交登录的支持

yudao-ui-admin/.env.demo1024
@@ -17,6 +17,9 @@ VUE_APP_APP_NAME ='/admin-ui/' @@ -17,6 +17,9 @@ VUE_APP_APP_NAME ='/admin-ui/'
17 # 多租户的开关 17 # 多租户的开关
18 VUE_APP_TENANT_ENABLE = true 18 VUE_APP_TENANT_ENABLE = true
19 19
  20 +# 验证码的开关
  21 +VUE_APP_CAPTCHA_ENABLE = true
  22 +
20 # 文档的开关 23 # 文档的开关
21 VUE_APP_DOC_ENABLE = true 24 VUE_APP_DOC_ENABLE = true
22 25
yudao-ui-admin/.env.dev
@@ -13,6 +13,9 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true @@ -13,6 +13,9 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true
13 # 多租户的开关 13 # 多租户的开关
14 VUE_APP_TENANT_ENABLE = true 14 VUE_APP_TENANT_ENABLE = true
15 15
  16 +# 验证码的开关
  17 +VUE_APP_CAPTCHA_ENABLE = true
  18 +
16 # 文档的开关 19 # 文档的开关
17 VUE_APP_DOC_ENABLE = true 20 VUE_APP_DOC_ENABLE = true
18 21
yudao-ui-admin/.env.local
@@ -14,6 +14,9 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true @@ -14,6 +14,9 @@ VUE_CLI_BABEL_TRANSPILE_MODULES = true
14 # 多租户的开关 14 # 多租户的开关
15 VUE_APP_TENANT_ENABLE = true 15 VUE_APP_TENANT_ENABLE = true
16 16
  17 +# 验证码的开关
  18 +VUE_APP_CAPTCHA_ENABLE = true
  19 +
17 # 文档的开关 20 # 文档的开关
18 VUE_APP_DOC_ENABLE = true 21 VUE_APP_DOC_ENABLE = true
19 22
yudao-ui-admin/.env.prod
@@ -15,6 +15,9 @@ VUE_APP_APP_NAME ='yudao-admin' @@ -15,6 +15,9 @@ VUE_APP_APP_NAME ='yudao-admin'
15 # 多租户的开关 15 # 多租户的开关
16 VUE_APP_TENANT_ENABLE = true 16 VUE_APP_TENANT_ENABLE = true
17 17
  18 +# 验证码的开关
  19 +VUE_APP_CAPTCHA_ENABLE = true
  20 +
18 # 文档的开关 21 # 文档的开关
19 VUE_APP_DOC_ENABLE = false 22 VUE_APP_DOC_ENABLE = false
20 23
yudao-ui-admin/.env.stage
@@ -15,6 +15,9 @@ PUBLIC_PATH = 'http://static.yudao.iocoder.cn/' @@ -15,6 +15,9 @@ PUBLIC_PATH = 'http://static.yudao.iocoder.cn/'
15 # 多租户的开关 15 # 多租户的开关
16 VUE_APP_TENANT_ENABLE = true 16 VUE_APP_TENANT_ENABLE = true
17 17
  18 +# 验证码的开关
  19 +VUE_APP_CAPTCHA_ENABLE = true
  20 +
18 # 文档的开关 21 # 文档的开关
19 VUE_APP_DOC_ENABLE = false 22 VUE_APP_DOC_ENABLE = false
20 23
yudao-ui-admin/src/utils/ruoyi.js
@@ -186,6 +186,19 @@ export function getTenantEnable() { @@ -186,6 +186,19 @@ export function getTenantEnable() {
186 } 186 }
187 187
188 /** 188 /**
  189 + * 获得验证码功能是否开启
  190 + */
  191 +export function getCaptchaEnable() {
  192 + if (process.env.VUE_APP_CAPTCHA_ENABLE === "true") {
  193 + return true;
  194 + }
  195 + if (process.env.VUE_APP_CAPTCHA_ENABLE === "false") {
  196 + return false;
  197 + }
  198 + return process.env.VUE_APP_CAPTCHA_ENABLE || true;
  199 +}
  200 +
  201 +/**
189 * 获得文档是否开启 202 * 获得文档是否开启
190 */ 203 */
191 export function getDocEnable() { 204 export function getDocEnable() {
yudao-ui-admin/src/views/login.vue
@@ -87,12 +87,11 @@ @@ -87,12 +87,11 @@
87 </div> 87 </div>
88 </div> 88 </div>
89 </div> 89 </div>
90 - <Verify  
91 - ref="verify"  
92 - :captcha-type="'blockPuzzle'"  
93 - :img-size="{width:'400px',height:'200px'}"  
94 - @success="handleLogin"  
95 - /> 90 +
  91 + <!-- 图形验证码 -->
  92 + <Verify ref="verify" :captcha-type="'blockPuzzle'" :img-size="{width:'400px',height:'200px'}"
  93 + @success="handleLogin" />
  94 +
96 <!-- footer --> 95 <!-- footer -->
97 <div class="footer"> 96 <div class="footer">
98 Copyright © 2020-2022 iocoder.cn All Rights Reserved. 97 Copyright © 2020-2022 iocoder.cn All Rights Reserved.
@@ -104,7 +103,7 @@ @@ -104,7 +103,7 @@
104 import {sendSmsCode, socialAuthRedirect} from "@/api/login"; 103 import {sendSmsCode, socialAuthRedirect} from "@/api/login";
105 import {getTenantIdByName} from "@/api/system/tenant"; 104 import {getTenantIdByName} from "@/api/system/tenant";
106 import {SystemUserSocialTypeEnum} from "@/utils/constants"; 105 import {SystemUserSocialTypeEnum} from "@/utils/constants";
107 -import {getTenantEnable} from "@/utils/ruoyi"; 106 +import {getCaptchaEnable, getTenantEnable} from "@/utils/ruoyi";
108 import { 107 import {
109 getPassword, 108 getPassword,
110 getRememberMe, getTenantName, 109 getRememberMe, getTenantName,
@@ -188,16 +187,21 @@ export default { @@ -188,16 +187,21 @@ export default {
188 created() { 187 created() {
189 // 租户开关 188 // 租户开关
190 this.tenantEnable = getTenantEnable(); 189 this.tenantEnable = getTenantEnable();
  190 + // 验证码开关
  191 + this.captchaEnable = getCaptchaEnable();
191 // 重定向地址 192 // 重定向地址
192 this.redirect = this.$route.query.redirect; 193 this.redirect = this.$route.query.redirect;
193 this.getCookie(); 194 this.getCookie();
194 }, 195 },
195 methods: { 196 methods: {
196 getCode() { 197 getCode() {
197 - // 只有开启的状态,才加载验证码。默认开启 198 + // 情况一,未开启:则直接登录
198 if (!this.captchaEnable) { 199 if (!this.captchaEnable) {
  200 + this.handleLogin({})
199 return; 201 return;
200 } 202 }
  203 +
  204 + // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
201 // 弹出验证码 205 // 弹出验证码
202 this.$refs.verify.show() 206 this.$refs.verify.show()
203 }, 207 },
@@ -214,7 +218,7 @@ export default { @@ -214,7 +218,7 @@ export default {
214 tenantName: tenantName ? tenantName : this.loginForm.tenantName, 218 tenantName: tenantName ? tenantName : this.loginForm.tenantName,
215 }; 219 };
216 }, 220 },
217 - handleLogin(params) { 221 + handleLogin(captchaParams) {
218 this.$refs.loginForm.validate(valid => { 222 this.$refs.loginForm.validate(valid => {
219 if (valid) { 223 if (valid) {
220 this.loading = true; 224 this.loading = true;
@@ -230,7 +234,7 @@ export default { @@ -230,7 +234,7 @@ export default {
230 removeRememberMe() 234 removeRememberMe()
231 removeTenantName() 235 removeTenantName()
232 } 236 }
233 - this.loginForm.captchaVerification = params.captchaVerification 237 + this.loginForm.captchaVerification = captchaParams.captchaVerification
234 // 发起登陆 238 // 发起登陆
235 // console.log("发起登录", this.loginForm); 239 // console.log("发起登录", this.loginForm);
236 this.$store.dispatch(this.loginForm.loginType === "sms" ? "SmsLogin" : "Login", this.loginForm).then(() => { 240 this.$store.dispatch(this.loginForm.loginType === "sms" ? "SmsLogin" : "Login", this.loginForm).then(() => {
yudao-ui-admin/src/views/socialLogin.vue
@@ -32,20 +32,11 @@ @@ -32,20 +32,11 @@
32 <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/> 32 <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
33 </el-input> 33 </el-input>
34 </el-form-item> 34 </el-form-item>
35 - <el-form-item prop="code" v-if="captchaEnable">  
36 - <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%"  
37 - @keyup.enter.native="handleLogin">  
38 - <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon"/>  
39 - </el-input>  
40 - <div class="login-code">  
41 - <img :src="codeUrl" @click="getCode" class="login-code-img"/>  
42 - </div>  
43 - </el-form-item>  
44 <el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">记住密码</el-checkbox> 35 <el-checkbox v-model="loginForm.rememberMe" style="margin:0 0 25px 0;">记住密码</el-checkbox>
45 <!-- 下方的登录按钮 --> 36 <!-- 下方的登录按钮 -->
46 <el-form-item style="width:100%;"> 37 <el-form-item style="width:100%;">
47 <el-button :loading="loading" size="medium" type="primary" style="width:100%;" 38 <el-button :loading="loading" size="medium" type="primary" style="width:100%;"
48 - @click.native.prevent="handleLogin"> 39 + @click.native.prevent="getCode">
49 <span v-if="!loading">登 录</span> 40 <span v-if="!loading">登 录</span>
50 <span v-else>登 录 中...</span> 41 <span v-else>登 录 中...</span>
51 </el-button> 42 </el-button>
@@ -55,6 +46,11 @@ @@ -55,6 +46,11 @@
55 </div> 46 </div>
56 </div> 47 </div>
57 </div> 48 </div>
  49 +
  50 + <!-- 图形验证码 -->
  51 + <Verify ref="verify" :captcha-type="'blockPuzzle'" :img-size="{width:'400px',height:'200px'}"
  52 + @success="handleLogin" />
  53 +
58 <!-- footer --> 54 <!-- footer -->
59 <div class="footer"> 55 <div class="footer">
60 Copyright © 2020-2022 iocoder.cn All Rights Reserved. 56 Copyright © 2020-2022 iocoder.cn All Rights Reserved.
@@ -72,10 +68,15 @@ import { @@ -72,10 +68,15 @@ import {
72 setRememberMe, 68 setRememberMe,
73 setUsername 69 setUsername
74 } from "@/utils/auth"; 70 } from "@/utils/auth";
75 -import {getCodeImg} from "@/api/login"; 71 +
  72 +import Verify from '@/components/Verifition/Verify';
  73 +import {getCaptchaEnable} from "@/utils/ruoyi";
76 74
77 export default { 75 export default {
78 name: "ThirdLogin", 76 name: "ThirdLogin",
  77 + components: {
  78 + Verify
  79 + },
79 data() { 80 data() {
80 return { 81 return {
81 codeUrl: "", 82 codeUrl: "",
@@ -85,8 +86,7 @@ export default { @@ -85,8 +86,7 @@ export default {
85 username: "admin", 86 username: "admin",
86 password: "admin123", 87 password: "admin123",
87 rememberMe: false, 88 rememberMe: false,
88 - code: "",  
89 - uuid: "", 89 + captchaVerification: "",
90 }, 90 },
91 loginRules: { 91 loginRules: {
92 username: [ 92 username: [
@@ -114,9 +114,10 @@ export default { @@ -114,9 +114,10 @@ export default {
114 // }, 114 // },
115 created() { 115 created() {
116 this.getCookie(); 116 this.getCookie();
  117 + // 验证码开关
  118 + this.captchaEnable = getCaptchaEnable();
117 // 重定向地址 119 // 重定向地址
118 this.redirect = this.$route.query.redirect; 120 this.redirect = this.$route.query.redirect;
119 - this.getCode();  
120 // 社交登录相关 121 // 社交登录相关
121 this.type = this.$route.query.type; 122 this.type = this.$route.query.type;
122 this.code = this.$route.query.code; 123 this.code = this.$route.query.code;
@@ -133,19 +134,15 @@ export default { @@ -133,19 +134,15 @@ export default {
133 }, 134 },
134 methods: { 135 methods: {
135 getCode() { 136 getCode() {
136 - // 只有开启的状态,才加载验证码。默认开启 137 + // 情况一,未开启:则直接登录
137 if (!this.captchaEnable) { 138 if (!this.captchaEnable) {
  139 + this.handleLogin({})
138 return; 140 return;
139 } 141 }
140 - // 请求远程,获得验证码  
141 - getCodeImg().then(res => {  
142 - res = res.data;  
143 - this.captchaEnable = res.enable;  
144 - if (this.captchaEnable) {  
145 - this.codeUrl = "data:image/gif;base64," + res.img;  
146 - this.loginForm.uuid = res.uuid;  
147 - }  
148 - }); 142 +
  143 + // 情况二,已开启:则展示验证码;只有完成验证码的情况,才进行登录
  144 + // 弹出验证码
  145 + this.$refs.verify.show()
149 }, 146 },
150 getCookie() { 147 getCookie() {
151 const username = getUsername(); 148 const username = getUsername();
@@ -158,7 +155,7 @@ export default { @@ -158,7 +155,7 @@ export default {
158 loginType: this.loginForm.loginType, 155 loginType: this.loginForm.loginType,
159 }; 156 };
160 }, 157 },
161 - handleLogin() { 158 + handleLogin(captchaParams) {
162 this.$refs.loginForm.validate(valid => { 159 this.$refs.loginForm.validate(valid => {
163 if (valid) { 160 if (valid) {
164 this.loading = true; 161 this.loading = true;
@@ -177,8 +174,7 @@ export default { @@ -177,8 +174,7 @@ export default {
177 // 账号密码登录 174 // 账号密码登录
178 username: this.loginForm.username, 175 username: this.loginForm.username,
179 password: this.loginForm.password, 176 password: this.loginForm.password,
180 - code: this.loginForm.code,  
181 - uuid: this.loginForm.uuid, 177 + captchaVerification: captchaParams.captchaVerification
182 }).then(() => { 178 }).then(() => {
183 this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); 179 this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
184 }).catch(() => { 180 }).catch(() => {