Commit 5139117b138791d2850381822205d0b76462e394
1 parent
878445a2
更新登录模板
支持短信验证码登录
Showing
20 changed files
with
837 additions
and
140 deletions
sql/ruoyi-vue-pro.sql
No preview for this file type
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/enums/sms/SmsSceneEnum.java
| ... | ... | @@ -18,8 +18,8 @@ public enum SmsSceneEnum implements IntArrayValuable { |
| 18 | 18 | |
| 19 | 19 | MEMBER_LOGIN(1, "user-sms-login", "会员用户 - 手机号登陆"), |
| 20 | 20 | MEMBER_UPDATE_MOBILE(2, "user-sms-reset-password", "会员用户 - 修改手机"), |
| 21 | - MEMBER_FORGET_PASSWORD(3, "user-sms-update-mobile", "会员用户 - 忘记密码"); | |
| 22 | - | |
| 21 | + MEMBER_FORGET_PASSWORD(3, "user-sms-update-mobile", "会员用户 - 忘记密码"), | |
| 22 | + ADMIN_MEMBER_LOGIN(21, "admin-sms-login", "后台用户 - 手机号登录"); | |
| 23 | 23 | // 如果未来希望管理后台支持手机验证码登陆,可以通过添加 ADMIN_MEMBER_LOGIN 枚举 |
| 24 | 24 | |
| 25 | 25 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(SmsSceneEnum::getScene).toArray(); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/AuthController.java
| ... | ... | @@ -61,6 +61,26 @@ public class AuthController { |
| 61 | 61 | return success(AuthLoginRespVO.builder().token(token).build()); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | + @PostMapping("/sms-login") | |
| 65 | + @ApiOperation("使用短信验证码登录") | |
| 66 | + @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 | |
| 67 | + public CommonResult<AuthLoginRespVO> smsLogin(@RequestBody @Valid AuthSmsLoginReqVO reqVO) { | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + String token = authService.smsLogin(reqVO, getClientIP(), getUserAgent()); | |
| 72 | + // 返回结果 | |
| 73 | + return success(AuthLoginRespVO.builder().token(token).build()); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @PostMapping("/send-login-sms-code") | |
| 77 | + @ApiOperation(value = "发送手机验证码") | |
| 78 | + @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 | |
| 79 | + public CommonResult<Boolean> sendLoginSmsCode(@RequestBody @Valid AuthSmsSendReqVO reqVO) { | |
| 80 | + authService.sendSmsCode(getLoginUserId(), reqVO); | |
| 81 | + return success(true); | |
| 82 | + } | |
| 83 | + | |
| 64 | 84 | @GetMapping("/get-permission-info") |
| 65 | 85 | @ApiOperation("获取登录用户的权限信息") |
| 66 | 86 | public CommonResult<AuthPermissionInfoRespVO> getPermissionInfo() { | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSmsLoginReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.AllArgsConstructor; | |
| 6 | +import lombok.Builder; | |
| 7 | +import lombok.Data; | |
| 8 | +import lombok.NoArgsConstructor; | |
| 9 | +import org.hibernate.validator.constraints.Length; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.NotEmpty; | |
| 12 | +import javax.validation.constraints.Pattern; | |
| 13 | + | |
| 14 | +@ApiModel("管理后台 - 短信验证码的呢老姑 Request VO") | |
| 15 | +@Data | |
| 16 | +@NoArgsConstructor | |
| 17 | +@AllArgsConstructor | |
| 18 | +@Builder | |
| 19 | +public class AuthSmsLoginReqVO { | |
| 20 | + | |
| 21 | + @ApiModelProperty(value = "手机号", required = true, example = "yudaoyuanma") | |
| 22 | + @NotEmpty(message = "手机号不能为空") | |
| 23 | + @Length(min = 11, max = 11, message = "手机号格式错误,仅支持大陆手机号") | |
| 24 | + @Pattern(regexp = "^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$", message = "账号格式为数字以及字母") | |
| 25 | + private String mobile; | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + @ApiModelProperty(value = "短信验证码", required = true, example = "1024", notes = "验证码开启时,需要传递") | |
| 30 | + @NotEmpty(message = "验证码不能为空", groups = CodeEnableGroup.class) | |
| 31 | + private String code; | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * 开启验证码的 Group | |
| 35 | + */ | |
| 36 | + public interface CodeEnableGroup {} | |
| 37 | + | |
| 38 | +} | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSmsSendReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.AllArgsConstructor; | |
| 6 | +import lombok.Builder; | |
| 7 | +import lombok.Data; | |
| 8 | +import lombok.NoArgsConstructor; | |
| 9 | +import org.hibernate.validator.constraints.Length; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.NotEmpty; | |
| 12 | +import javax.validation.constraints.Pattern; | |
| 13 | + | |
| 14 | +@ApiModel("管理后台 - 短信验证码的呢老姑 Request VO") | |
| 15 | +@Data | |
| 16 | +@NoArgsConstructor | |
| 17 | +@AllArgsConstructor | |
| 18 | +@Builder | |
| 19 | +public class AuthSmsSendReqVO { | |
| 20 | + | |
| 21 | + @ApiModelProperty(value = "手机号", required = true, example = "yudaoyuanma") | |
| 22 | + @NotEmpty(message = "手机号不能为空") | |
| 23 | + @Length(min = 11, max = 11, message = "手机号格式错误,仅支持大陆手机号") | |
| 24 | + @Pattern(regexp = "^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,8,9]))[0-9]{8}$", message = "账号格式为数字以及字母") | |
| 25 | + private String mobile; | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + @ApiModelProperty(value = "短信验证码", required = true, example = "1024", notes = "验证码开启时,需要传递") | |
| 30 | + @NotEmpty(message = "验证码不能为空", groups = CodeEnableGroup.class) | |
| 31 | + private String code; | |
| 32 | + | |
| 33 | + @ApiModelProperty(value = "短信场景", required = true, example = "1") | |
| 34 | + @NotEmpty(message = "短信场景", groups = CodeEnableGroup.class) | |
| 35 | + private Integer scene; | |
| 36 | + | |
| 37 | + @ApiModelProperty(value = "验证码的唯一标识", required = true, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62", notes = "验证码开启时,需要传递") | |
| 38 | + @NotEmpty(message = "唯一标识不能为空", groups = AuthLoginReqVO.CodeEnableGroup.class) | |
| 39 | + private String uuid; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 开启验证码的 Group | |
| 43 | + */ | |
| 44 | + public interface CodeEnableGroup {} | |
| 45 | + | |
| 46 | +} | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/auth/AuthConvert.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.convert.auth; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 5 | 5 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 6 | +import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; | |
| 6 | 7 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| 7 | 8 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; |
| 8 | 9 | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; |
| ... | ... | @@ -76,5 +77,5 @@ public interface AuthConvert { |
| 76 | 77 | SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLogin2ReqVO reqVO); |
| 77 | 78 | SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialLoginReqVO reqVO); |
| 78 | 79 | SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO); |
| 79 | - | |
| 80 | + SmsCodeSendReqDTO convert(AuthSmsSendReqVO reqVO); | |
| 80 | 81 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java
| ... | ... | @@ -20,6 +20,10 @@ public class SecurityConfiguration { |
| 20 | 20 | public void customize(ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry registry) { |
| 21 | 21 | // 登录的接口,可匿名访问 |
| 22 | 22 | registry.antMatchers(buildAdminApi("/system/login")).anonymous(); |
| 23 | + //手机短信验证码登录 | |
| 24 | + registry.antMatchers(buildAdminApi("/system/sms-login")).anonymous(); | |
| 25 | + //短信登录验证码接口 | |
| 26 | + registry.antMatchers(buildAdminApi("/system/send-login-sms-code")).anonymous(); | |
| 23 | 27 | // 验证码的接口 |
| 24 | 28 | registry.antMatchers(buildAdminApi("/system/captcha/**")).anonymous(); |
| 25 | 29 | // 获得租户编号的接口 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthService.java
| ... | ... | @@ -25,6 +25,23 @@ public interface AdminAuthService extends SecurityAuthFrameworkService { |
| 25 | 25 | String login(@Valid AuthLoginReqVO reqVO, String userIp, String userAgent); |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | + * 短信验证码发送 | |
| 29 | + * @param userId | |
| 30 | + * @param reqVO | |
| 31 | + */ | |
| 32 | + public void sendSmsCode(Long userId, AuthSmsSendReqVO reqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 短信登录 | |
| 36 | + * | |
| 37 | + * @param reqVO 登录信息 | |
| 38 | + * @param userIp 用户 IP | |
| 39 | + * @param userAgent 用户 UA | |
| 40 | + * @return 身份令牌,使用 JWT 方式 | |
| 41 | + */ | |
| 42 | + String smsLogin(AuthSmsLoginReqVO reqVO, String userIp, String userAgent) ; | |
| 43 | + | |
| 44 | + /** | |
| 28 | 45 | * 社交登录,使用 code 授权码 |
| 29 | 46 | * |
| 30 | 47 | * @param reqVO 登录信息 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
| ... | ... | @@ -8,14 +8,14 @@ import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; |
| 8 | 8 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 9 | 9 | import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePasswordAuthenticationToken; |
| 10 | 10 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; |
| 11 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO; | |
| 12 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; | |
| 13 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLogin2ReqVO; | |
| 14 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialLoginReqVO; | |
| 11 | +import cn.iocoder.yudao.module.system.api.sms.SmsCodeApi; | |
| 12 | +import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; | |
| 13 | +import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.*; | |
| 15 | 14 | import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; |
| 16 | 15 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 17 | 16 | import cn.iocoder.yudao.module.system.enums.logger.LoginLogTypeEnum; |
| 18 | 17 | import cn.iocoder.yudao.module.system.enums.logger.LoginResultEnum; |
| 18 | +import cn.iocoder.yudao.module.system.enums.sms.SmsSceneEnum; | |
| 19 | 19 | import cn.iocoder.yudao.module.system.service.common.CaptchaService; |
| 20 | 20 | import cn.iocoder.yudao.module.system.service.logger.LoginLogService; |
| 21 | 21 | import cn.iocoder.yudao.module.system.service.permission.PermissionService; |
| ... | ... | @@ -41,6 +41,7 @@ import java.util.Objects; |
| 41 | 41 | import java.util.Set; |
| 42 | 42 | |
| 43 | 43 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 44 | +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; | |
| 44 | 45 | import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*; |
| 45 | 46 | import static java.util.Collections.singleton; |
| 46 | 47 | |
| ... | ... | @@ -74,6 +75,10 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 74 | 75 | @Resource |
| 75 | 76 | private Validator validator; |
| 76 | 77 | |
| 78 | + @Resource | |
| 79 | + private SmsCodeApi smsCodeApi; | |
| 80 | + | |
| 81 | + | |
| 77 | 82 | @Override |
| 78 | 83 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { |
| 79 | 84 | // 获取 username 对应的 AdminUserDO |
| ... | ... | @@ -110,6 +115,58 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 110 | 115 | return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_USERNAME, userIp, userAgent); |
| 111 | 116 | } |
| 112 | 117 | |
| 118 | + @Override | |
| 119 | + public void sendSmsCode(Long userId, AuthSmsSendReqVO reqVO) { | |
| 120 | + | |
| 121 | + this.verifyCaptchaSmsSend(reqVO); | |
| 122 | + //登录场景,验证是否存在 | |
| 123 | + if(reqVO.getScene().compareTo(SmsSceneEnum.ADMIN_MEMBER_LOGIN.getScene())==0) { | |
| 124 | + if (userService.getUserByMobile(reqVO.getMobile()) == null) { | |
| 125 | + throw exception(USER_NOT_EXISTS); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + // TODO 要根据不同的场景,校验是否有用户 | |
| 129 | + smsCodeApi.sendSmsCode(AuthConvert.INSTANCE.convert(reqVO).setCreateIp(getClientIP())); | |
| 130 | + } | |
| 131 | + | |
| 132 | + | |
| 133 | + /** | |
| 134 | + * 短信登录 | |
| 135 | + */ | |
| 136 | + @Override | |
| 137 | + public String smsLogin(AuthSmsLoginReqVO reqVO, String userIp, String userAgent) { | |
| 138 | + | |
| 139 | + /* 从 Member的AuhtConvert中拷贝出来的,没单独写类 */ | |
| 140 | + if ( reqVO == null) { | |
| 141 | + return null; | |
| 142 | + } | |
| 143 | + | |
| 144 | + SmsCodeUseReqDTO smsCodeUseReqDTO = new SmsCodeUseReqDTO(); | |
| 145 | + smsCodeUseReqDTO.setMobile( reqVO.getMobile() ); | |
| 146 | + smsCodeUseReqDTO.setCode( reqVO.getCode() ); | |
| 147 | + smsCodeUseReqDTO.setScene( SmsSceneEnum.ADMIN_MEMBER_LOGIN.getScene() ); | |
| 148 | + smsCodeUseReqDTO.setUsedIp(userIp); | |
| 149 | + smsCodeApi.useSmsCode(smsCodeUseReqDTO); | |
| 150 | + | |
| 151 | + // 获得用户信息 | |
| 152 | + AdminUserDO user = userService.getUserByMobile(reqVO.getMobile()); | |
| 153 | + | |
| 154 | + | |
| 155 | + if(user==null) | |
| 156 | + { | |
| 157 | + throw exception(USER_NOT_EXISTS); | |
| 158 | + } | |
| 159 | + | |
| 160 | + cn.hutool.core.lang.Assert.notNull(user, "获取用户失败,结果为空"); | |
| 161 | + | |
| 162 | + // 执行登陆 | |
| 163 | + this.createLoginLog(user.getMobile(),LoginLogTypeEnum.LOGIN_MOBILE, LoginResultEnum.SUCCESS); | |
| 164 | + LoginUser loginUser = buildLoginUser(user); | |
| 165 | + | |
| 166 | + // 缓存登陆用户到 Redis 中,返回 sessionId 编号 | |
| 167 | + return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_MOBILE, userIp, userAgent); | |
| 168 | + } | |
| 169 | + | |
| 113 | 170 | private void verifyCaptcha(AuthLoginReqVO reqVO) { |
| 114 | 171 | // 如果验证码关闭,则不进行校验 |
| 115 | 172 | if (!captchaService.isCaptchaEnable()) { |
| ... | ... | @@ -159,6 +216,33 @@ public class AdminAuthServiceImpl implements AdminAuthService { |
| 159 | 216 | return (LoginUser) authentication.getPrincipal(); |
| 160 | 217 | } |
| 161 | 218 | |
| 219 | + /** | |
| 220 | + * 验证验证码并发送短信 | |
| 221 | + * @param reqVO | |
| 222 | + */ | |
| 223 | + private void verifyCaptchaSmsSend(AuthSmsSendReqVO reqVO) { | |
| 224 | + // 如果验证码关闭,则不进行校验 | |
| 225 | + if (!captchaService.isCaptchaEnable()) { | |
| 226 | + return; | |
| 227 | + } | |
| 228 | + // 校验验证码 | |
| 229 | + ValidationUtils.validate(validator, reqVO, AuthLoginReqVO.CodeEnableGroup.class); | |
| 230 | + // 验证码不存在 | |
| 231 | + final LoginLogTypeEnum logTypeEnum = LoginLogTypeEnum.LOGIN_USERNAME; | |
| 232 | + String code = captchaService.getCaptchaCode(reqVO.getUuid()); | |
| 233 | + if (code == null) { | |
| 234 | + throw exception(AUTH_LOGIN_CAPTCHA_NOT_FOUND); | |
| 235 | + } | |
| 236 | + // 验证码不正确 | |
| 237 | + if (!code.equals(reqVO.getCode())) { | |
| 238 | + // 创建登录失败日志(验证码不正确) | |
| 239 | + throw exception(AUTH_LOGIN_CAPTCHA_CODE_ERROR); | |
| 240 | + } | |
| 241 | + // 正确,所以要删除下验证码 | |
| 242 | + captchaService.deleteCaptchaCode(reqVO.getUuid()); | |
| 243 | + } | |
| 244 | + | |
| 245 | + | |
| 162 | 246 | private void createLoginLog(String username, LoginLogTypeEnum logTypeEnum, LoginResultEnum loginResult) { |
| 163 | 247 | // 获得用户 |
| 164 | 248 | AdminUserDO user = userService.getUserByUsername(username); | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
| ... | ... | @@ -98,6 +98,15 @@ public interface AdminUserService { |
| 98 | 98 | AdminUserDO getUserByUsername(String username); |
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | + * 通过手机号获取用户 | |
| 102 | + * | |
| 103 | + * @param mobile 手机号 | |
| 104 | + * @return 用户对象信息 | |
| 105 | + */ | |
| 106 | + AdminUserDO getUserByMobile(String mobile); | |
| 107 | + | |
| 108 | + | |
| 109 | + /** | |
| 101 | 110 | * 获得用户分页列表 |
| 102 | 111 | * |
| 103 | 112 | * @param reqVO 分页条件 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
| ... | ... | @@ -168,6 +168,16 @@ public class AdminUserServiceImpl implements AdminUserService { |
| 168 | 168 | return userMapper.selectByUsername(username); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | + /** | |
| 172 | + * 通过手机号获取用户 | |
| 173 | + * @param mobile | |
| 174 | + * @return | |
| 175 | + */ | |
| 176 | + @Override | |
| 177 | + public AdminUserDO getUserByMobile(String mobile) { | |
| 178 | + return userMapper.selectByMobile(mobile); | |
| 179 | + } | |
| 180 | + | |
| 171 | 181 | @Override |
| 172 | 182 | public PageResult<AdminUserDO> getUserPage(UserPageReqVO reqVO) { |
| 173 | 183 | return userMapper.selectPage(reqVO, this.getDeptCondition(reqVO.getDeptId())); | ... | ... |
yudao-ui-admin/.env.dev
yudao-ui-admin/src/api/login.js
| ... | ... | @@ -100,3 +100,30 @@ export function socialUnbind(type, unionId) { |
| 100 | 100 | } |
| 101 | 101 | }) |
| 102 | 102 | } |
| 103 | + | |
| 104 | +// 获取登录验证码 | |
| 105 | +export function sendLoginSmsCode(mobile,scene,uuid,code) { | |
| 106 | + var datas = { | |
| 107 | + mobile | |
| 108 | + ,scene | |
| 109 | + ,uuid, | |
| 110 | + code | |
| 111 | + }; | |
| 112 | + return request({ | |
| 113 | + url: '/system/send-login-sms-code', | |
| 114 | + method: 'post', | |
| 115 | + data: datas | |
| 116 | + }) | |
| 117 | +} | |
| 118 | + | |
| 119 | +// 短信验证码登录 | |
| 120 | +export function smsLogin(mobile, code) { | |
| 121 | + return request({ | |
| 122 | + url: '/system/sms-login', | |
| 123 | + method: 'post', | |
| 124 | + data: { | |
| 125 | + mobile, | |
| 126 | + code | |
| 127 | + } | |
| 128 | + }) | |
| 129 | +} | |
| 103 | 130 | \ No newline at end of file | ... | ... |
yudao-ui-admin/src/assets/images/bg-mobile.png
0 → 100644
12.1 KB
yudao-ui-admin/src/assets/images/bg.png
0 → 100644
67.8 KB
yudao-ui-admin/src/assets/images/icon.png
0 → 100644
308 Bytes
yudao-ui-admin/src/assets/images/pic.png
0 → 100644
30.1 KB
yudao-ui-admin/src/assets/styles/login.scss
0 → 100644
| 1 | +/* ===== PC DESIGN ===== */ | |
| 2 | +$W: 1000; | |
| 3 | +$H: 1920; | |
| 4 | +$picW: 438; | |
| 5 | +$picH: 560; | |
| 6 | +$formW: 320; | |
| 7 | +$tabW: $formW / 2; | |
| 8 | +$rowH: 56; | |
| 9 | +$buttonH: 50; | |
| 10 | + | |
| 11 | +// container | |
| 12 | +$containerBgColor: #e6ebf2; | |
| 13 | +$containerBgImage: '../assets/images/bg.png'; | |
| 14 | +// container-logo | |
| 15 | +$logoWidth: 417px; | |
| 16 | +$logoHeight: 64px; | |
| 17 | +$logoImage: '../assets/logo/login-logo.png'; | |
| 18 | +// container-content | |
| 19 | +$contentWidth: round($W / $H * 100) * 1vw; | |
| 20 | +$contentHeight: round($picH / $W * 100) / 100 * $contentWidth; | |
| 21 | +$contentBgColor: #ffffff; | |
| 22 | +// container-content-pic | |
| 23 | +$picWidth: round($picW / $H * 100) * 1vw; | |
| 24 | +$picHeight: inherit; | |
| 25 | +$picImage: '../assets/images/pic.png'; | |
| 26 | +// container-content-field | |
| 27 | +$fieldWidth: $contentWidth - $picWidth; | |
| 28 | +$fieldHeight: inherit; | |
| 29 | +// container-content-field-form | |
| 30 | +$formWidth: $formW * 1px; | |
| 31 | +$tabWidth: $tabW * 1px; | |
| 32 | +$rowHeight: $rowH * 1px; | |
| 33 | +$buttonHeight: $buttonH * 1px; | |
| 34 | + | |
| 35 | +// - - - - - 页面基础设置 | |
| 36 | +.container { | |
| 37 | + .login-code { | |
| 38 | + width: 33%; | |
| 39 | + height: 38px; | |
| 40 | + float: right; | |
| 41 | + img { | |
| 42 | + cursor: pointer; | |
| 43 | + width:100%;max-width:100px; height:auto; | |
| 44 | + vertical-align: middle; | |
| 45 | + } | |
| 46 | + } | |
| 47 | + // 元素 | |
| 48 | + width: inherit; | |
| 49 | + height: inherit; | |
| 50 | + min-width: 1080px; | |
| 51 | + min-height: 620px; | |
| 52 | + background-color: $containerBgColor; | |
| 53 | + background-image: url($containerBgImage); | |
| 54 | + background-size: cover; | |
| 55 | + // 定位 | |
| 56 | + position: relative; | |
| 57 | + display: flex; | |
| 58 | + justify-content: center; | |
| 59 | + align-items: center; | |
| 60 | + // 文字 | |
| 61 | + font-size: 14px; | |
| 62 | + font-family: Microsoft YaHei; | |
| 63 | + font-weight: 400; | |
| 64 | + .logo { | |
| 65 | + // 元素 | |
| 66 | + width: $logoWidth; | |
| 67 | + height: $logoHeight; | |
| 68 | + background-image: url($logoImage); | |
| 69 | + background-size: contain; | |
| 70 | + // 定位 | |
| 71 | + position: absolute; | |
| 72 | + top: 50px; | |
| 73 | + left: 50%; | |
| 74 | + margin-left: -$logoWidth/2; | |
| 75 | + } | |
| 76 | + .content { | |
| 77 | + // 元素 | |
| 78 | + width: $contentWidth; | |
| 79 | + height: $contentHeight; | |
| 80 | + background-color: #ffffff; | |
| 81 | + box-shadow: 0px 16px 40px rgba(0, 0, 0, 0.07); | |
| 82 | + border-radius: 20px; | |
| 83 | + // 定位 | |
| 84 | + position: relative; | |
| 85 | + .pic { | |
| 86 | + // 元素 | |
| 87 | + width: $picWidth; | |
| 88 | + height: $picHeight; | |
| 89 | + background-image: url($picImage); | |
| 90 | + background-repeat: no-repeat; | |
| 91 | + background-size: cover; | |
| 92 | + border-radius: 20px 0 0 20px; | |
| 93 | + // 定位 | |
| 94 | + position: absolute; | |
| 95 | + top: 0; | |
| 96 | + left: 0; | |
| 97 | + } | |
| 98 | + .field { | |
| 99 | + width: $fieldWidth; | |
| 100 | + height: $fieldHeight; | |
| 101 | + // 定位 | |
| 102 | + position: absolute; | |
| 103 | + top: 0; | |
| 104 | + left: $picWidth; | |
| 105 | + display:flex; | |
| 106 | + justify-content: center; | |
| 107 | + align-items: center; | |
| 108 | + .pc-title{ width: 100%; clear: both;} | |
| 109 | + .mobile-title, | |
| 110 | + .mobile-switch { | |
| 111 | + display: none; | |
| 112 | + } | |
| 113 | + .form { | |
| 114 | + box-sizing: border-box; | |
| 115 | + width: $formWidth; | |
| 116 | + // - - - tab | |
| 117 | + :deep(.el-tabs__content) { | |
| 118 | + padding: 20px 0 0; | |
| 119 | + } | |
| 120 | + :deep(.el-tabs__item) { | |
| 121 | + // 元素 | |
| 122 | + width: $tabWidth; | |
| 123 | + height: $rowHeight; | |
| 124 | + padding: 0; | |
| 125 | + // 文字 | |
| 126 | + line-height: $rowHeight; | |
| 127 | + color: #666666; | |
| 128 | + } | |
| 129 | + :deep(.el-tabs__item.is-active) { | |
| 130 | + font-weight: bold; | |
| 131 | + color: #2F53EB; | |
| 132 | + } | |
| 133 | + :deep(.el-tabs__active-bar) { | |
| 134 | + height: 3px; | |
| 135 | + border-radius: 2px; | |
| 136 | + } | |
| 137 | + // - - - input | |
| 138 | + :deep(.el-input__inner) { | |
| 139 | + // 元素 | |
| 140 | + width: 100%; | |
| 141 | + height: $rowHeight; | |
| 142 | + background: #f5f5f5; | |
| 143 | + border: 0; | |
| 144 | + border-radius: 28px; | |
| 145 | + // 文字 | |
| 146 | + text-align: center; | |
| 147 | + line-height: 19px; | |
| 148 | + color: #262626; | |
| 149 | + } | |
| 150 | + .code:deep(.el-input__inner) { | |
| 151 | + padding: 0 24px; | |
| 152 | + // 文字 | |
| 153 | + text-align: left; | |
| 154 | + } | |
| 155 | + :deep(.el-input__inner::-webkit-input-placeholder) { /* WebKit browsers */ | |
| 156 | + font-weight: 400; | |
| 157 | + color: #8C8C8C; | |
| 158 | + } | |
| 159 | + :deep(.el-input__inner:-moz-placeholder) { /* Mozilla Firefox 4 to 18 */ | |
| 160 | + font-weight: 400; | |
| 161 | + color: #8C8C8C; | |
| 162 | + } | |
| 163 | + :deep(.el-input__inner::-moz-placeholder) { /* Mozilla Firefox 19+ */ | |
| 164 | + font-weight: 400; | |
| 165 | + color: #8C8C8C; | |
| 166 | + opacity:1; | |
| 167 | + } | |
| 168 | + :deep(.el-input__inner:-ms-input-placeholder) { /* Internet Explorer 10+ */ | |
| 169 | + font-weight: 400; | |
| 170 | + color: #8C8C8C !important; | |
| 171 | + } | |
| 172 | + :deep(.el-form-item) { | |
| 173 | + position: relative; | |
| 174 | + .button-code { | |
| 175 | + // 元素 | |
| 176 | + height: $rowHeight; | |
| 177 | + box-sizing: border-box; | |
| 178 | + // 定位 | |
| 179 | + position: absolute; | |
| 180 | + top: 0; | |
| 181 | + right: 20px; | |
| 182 | + z-index: 1; | |
| 183 | + // 文字 | |
| 184 | + line-height: 20px; | |
| 185 | + font-size: 14px; | |
| 186 | + font-family: PingFang SC; | |
| 187 | + font-weight: 400; | |
| 188 | + color: #2F53EB; | |
| 189 | + span { | |
| 190 | + padding-left: 15px; | |
| 191 | + border-left: 2px solid #D9D9D9; | |
| 192 | + } | |
| 193 | + } | |
| 194 | + } | |
| 195 | + :deep(.el-form-item__error) { | |
| 196 | + padding-left: 24px; | |
| 197 | + } | |
| 198 | + .button { | |
| 199 | + width: 100%; | |
| 200 | + height: $buttonHeight; | |
| 201 | + background: rgba(24, 144, 255, 0.2); | |
| 202 | + border: 0; | |
| 203 | + border-radius: 24px; | |
| 204 | + margin-bottom: 20px; | |
| 205 | + // 文字 | |
| 206 | + line-height: 26px; | |
| 207 | + font-size: 20px; | |
| 208 | + color: #FFFFFF; | |
| 209 | + } | |
| 210 | + .button-active { | |
| 211 | + background: #2F53EB; | |
| 212 | + box-shadow: 0px 2px 8px rgba(0, 80, 184, 0.2); | |
| 213 | + } | |
| 214 | + } | |
| 215 | + } | |
| 216 | + } | |
| 217 | + .footer { | |
| 218 | + // 元素 | |
| 219 | + height: 16px; | |
| 220 | + line-height: 16px; | |
| 221 | + font-size: 12px; | |
| 222 | + color: #8c8c8c; | |
| 223 | + // 定位 | |
| 224 | + position: absolute; | |
| 225 | + bottom: 30px; | |
| 226 | + a, | |
| 227 | + a:hover, | |
| 228 | + a:active { | |
| 229 | + color: inherit; | |
| 230 | + text-decoration: none; | |
| 231 | + } | |
| 232 | + } | |
| 233 | +} | |
| 234 | + | |
| 235 | +// - - - - - PC 最小尺寸设置 | |
| 236 | +@media screen and (min-width: 599px) and (max-width: 1366px) { | |
| 237 | + .container { | |
| 238 | + .content { | |
| 239 | + width: 710px; | |
| 240 | + height: 397px; | |
| 241 | + .pic { | |
| 242 | + width: 314px; | |
| 243 | + } | |
| 244 | + .field { | |
| 245 | + width: calc(710px - 314px); | |
| 246 | + left: 314px; | |
| 247 | + .form { | |
| 248 | + width: 320px; | |
| 249 | + :deep(.el-input__inner) { | |
| 250 | + width: 320px; | |
| 251 | + height: 56px; | |
| 252 | + } | |
| 253 | + .button { | |
| 254 | + height: 50px; | |
| 255 | + } | |
| 256 | + } | |
| 257 | + } | |
| 258 | + } | |
| 259 | + } | |
| 260 | +} | |
| 261 | + | |
| 262 | + | |
| 263 | +/* ===== MOBILE DESIGN ===== */ | |
| 264 | +$mobileW: 375; | |
| 265 | +$mobileH: 812; | |
| 266 | +$mobileContentW: 327; | |
| 267 | +$mobileContentH: 376; | |
| 268 | +$mobileFormW: 280; | |
| 269 | +$mobileRowH: 48; | |
| 270 | +$mobileButtonH: 48; | |
| 271 | + | |
| 272 | +// container | |
| 273 | +$mobileContainerBgImage: '../assets/images/bg-mobile.png'; | |
| 274 | +// container-content | |
| 275 | +$mobileContentWidth: round($mobileContentW / $mobileW * 100) * 1vw; | |
| 276 | +$mobileContentHeight: round($mobileContentH / $mobileW * 100) / 100 * $mobileContentWidth; | |
| 277 | +// container-content-field-form | |
| 278 | +$mobileFormWidth: round($mobileFormW / $mobileW *100) * 1vw; | |
| 279 | +$mobileRowHeight: $mobileRowH * 1px; | |
| 280 | +$mobileButtonHeight: $mobileButtonH * 1px; | |
| 281 | +$iconBgImage: '../assets/images/icon.png'; | |
| 282 | + | |
| 283 | +// - - - - - 移动端设置 | |
| 284 | +@media screen and (max-width: 599px) { | |
| 285 | + .container { | |
| 286 | + // 元素 | |
| 287 | + background-image: url($mobileContainerBgImage); | |
| 288 | + min-width: 280px; | |
| 289 | + min-height: 568px; | |
| 290 | + // 文字 | |
| 291 | + font-size: 17px; | |
| 292 | + font-family: PingFang SC; | |
| 293 | + font-weight: bold; | |
| 294 | + .logo { | |
| 295 | + display: none; | |
| 296 | + } | |
| 297 | + | |
| 298 | + .content { | |
| 299 | + // 元素 | |
| 300 | + width: $mobileContentWidth; | |
| 301 | + height: $mobileContentHeight; | |
| 302 | + min-width: 250px; | |
| 303 | + min-height: 340px; | |
| 304 | + // 定位 | |
| 305 | + display: flex; | |
| 306 | + justify-content: center; | |
| 307 | + align-items: center; | |
| 308 | + .pic { | |
| 309 | + display: none; | |
| 310 | + } | |
| 311 | + .field { | |
| 312 | + // 元素 | |
| 313 | + width: inherit; | |
| 314 | + min-height: inherit; | |
| 315 | + // 定位 | |
| 316 | + left: 0; | |
| 317 | + display: flex; | |
| 318 | + flex-direction: column; | |
| 319 | + .mobile-title { | |
| 320 | + // 元素 | |
| 321 | + margin: 0 0 20px; | |
| 322 | + display: block; | |
| 323 | + } | |
| 324 | + .form { | |
| 325 | + width: $mobileFormWidth; | |
| 326 | + // - - - tab | |
| 327 | + :deep(.el-tabs__header) { | |
| 328 | + display: none; | |
| 329 | + } | |
| 330 | + :deep(.el-tabs__content) { | |
| 331 | + padding: 0; | |
| 332 | + } | |
| 333 | + // - - - input | |
| 334 | + :deep(.el-input__inner) { | |
| 335 | + height: $mobileRowHeight; | |
| 336 | + line-height: 24px; | |
| 337 | + // 文字 | |
| 338 | + text-align: center; | |
| 339 | + color: #262626; | |
| 340 | + } | |
| 341 | + :deep(.el-form-item) { | |
| 342 | + .button-code { | |
| 343 | + // 元素 | |
| 344 | + height: $mobileRowHeight; | |
| 345 | + } | |
| 346 | + } | |
| 347 | + .button { | |
| 348 | + height: $mobileButtonHeight; | |
| 349 | + line-height: 24px; | |
| 350 | + color: #FFFFFF; | |
| 351 | + } | |
| 352 | + } | |
| 353 | + .mobile-switch { | |
| 354 | + display: block; | |
| 355 | + line-height: 20px; | |
| 356 | + font-size: 14px; | |
| 357 | + font-weight: 400; | |
| 358 | + color: #595959; | |
| 359 | + margin: 0; | |
| 360 | + .icon { | |
| 361 | + width: 14px; | |
| 362 | + height: 14px; | |
| 363 | + display: inline-block; | |
| 364 | + background-image: url($iconBgImage); | |
| 365 | + background-size: cover; | |
| 366 | + } | |
| 367 | + } | |
| 368 | + .mobile-switch:hover { | |
| 369 | + cursor: pointer; | |
| 370 | + } | |
| 371 | + } | |
| 372 | + } | |
| 373 | + .footer { | |
| 374 | + // 元素 | |
| 375 | + font-size: 12px; | |
| 376 | + font-family: PingFang SC; | |
| 377 | + font-weight: 400; | |
| 378 | + line-height: 17px; | |
| 379 | + color: #333333; | |
| 380 | + opacity: 0.6; | |
| 381 | + // 定位 | |
| 382 | + position: absolute; | |
| 383 | + bottom: 20px; | |
| 384 | + } | |
| 385 | + } | |
| 386 | + | |
| 387 | +} | ... | ... |
yudao-ui-admin/src/store/modules/user.js
| 1 | -import {login, logout, getInfo, socialLogin, socialLogin2} from '@/api/login' | |
| 1 | +import {login, logout, getInfo, socialLogin, socialLogin2,smsLogin} from '@/api/login' | |
| 2 | 2 | import { getToken, setToken, removeToken } from '@/utils/auth' |
| 3 | 3 | |
| 4 | 4 | const user = { |
| ... | ... | @@ -86,7 +86,21 @@ const user = { |
| 86 | 86 | }) |
| 87 | 87 | }) |
| 88 | 88 | }, |
| 89 | - | |
| 89 | + // 登录 | |
| 90 | + SmsLogin({ commit }, userInfo) { | |
| 91 | + const mobile = userInfo.mobile.trim() | |
| 92 | + const mobileCode = userInfo.mobileCode | |
| 93 | + return new Promise((resolve, reject) => { | |
| 94 | + smsLogin(mobile,mobileCode).then(res => { | |
| 95 | + res = res.data; | |
| 96 | + setToken(res.token) | |
| 97 | + commit('SET_TOKEN', res.token) | |
| 98 | + resolve() | |
| 99 | + }).catch(error => { | |
| 100 | + reject(error) | |
| 101 | + }) | |
| 102 | + }) | |
| 103 | +}, | |
| 90 | 104 | // 获取用户信息 |
| 91 | 105 | GetInfo({ commit, state }) { |
| 92 | 106 | return new Promise((resolve, reject) => { | ... | ... |
yudao-ui-admin/src/views/login.vue
| 1 | + | |
| 1 | 2 | <template> |
| 2 | - <div class="login"> | |
| 3 | - <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> | |
| 4 | - <h3 class="title">芋道后台管理系统</h3> | |
| 5 | - <el-form-item prop="tenantName" v-if="tenantEnable"> | |
| 6 | - <el-input v-model="loginForm.tenantName" type="text" auto-complete="off" placeholder='租户'> | |
| 7 | - <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" /> | |
| 8 | - </el-input> | |
| 9 | - </el-form-item> | |
| 10 | - <el-form-item prop="username"> | |
| 11 | - <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号"> | |
| 12 | - <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> | |
| 13 | - </el-input> | |
| 14 | - </el-form-item> | |
| 15 | - <el-form-item prop="password"> | |
| 16 | - <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码" @keyup.enter.native="handleLogin"> | |
| 17 | - <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> | |
| 18 | - </el-input> | |
| 19 | - </el-form-item> | |
| 20 | - <el-form-item prop="code" v-if="captchaEnable"> | |
| 21 | - <el-input v-model="loginForm.code" auto-complete="off" placeholder="验证码" style="width: 63%" @keyup.enter.native="handleLogin"> | |
| 22 | - <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> | |
| 23 | - </el-input> | |
| 24 | - <div class="login-code"> | |
| 25 | - <img :src="codeUrl" @click="getCode" class="login-code-img"/> | |
| 26 | - </div> | |
| 27 | - </el-form-item> | |
| 28 | - <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> | |
| 29 | - <el-form-item style="width:100%;"> | |
| 30 | - <el-button :loading="loading" size="medium" type="primary" style="width:100%;" @click.native.prevent="handleLogin"> | |
| 31 | - <span v-if="!loading">登 录</span> | |
| 32 | - <span v-else>登 录 中...</span> | |
| 33 | - </el-button> | |
| 34 | - </el-form-item> | |
| 3 | + <div class="container"> | |
| 4 | + <div class="logo"></div> | |
| 5 | + <!-- 登录区域 --> | |
| 6 | + <div class="content"> | |
| 7 | + <!-- 配图 --> | |
| 8 | + <div class="pic"></div> | |
| 9 | + <!-- 表单 --> | |
| 10 | + <div class="field"> | |
| 11 | + <!-- [移动端]标题 --> | |
| 12 | + <h2 class="mobile-title"> | |
| 13 | + <h3 class="title">芋道后台管理系统</h3> | |
| 14 | + </h2> | |
| 15 | + | |
| 16 | + <!-- 表单 --> | |
| 17 | + <!-- 表单 --> | |
| 18 | + <div class="form-cont"> | |
| 19 | + <el-tabs class="form" v-model="loginForm.loginType" style=" float:none;"> | |
| 20 | + <el-tab-pane label="账号密码登录" name="uname"> | |
| 21 | + </el-tab-pane> | |
| 22 | + <el-tab-pane label="短信验证码登录" name="sms"> | |
| 23 | + </el-tab-pane> | |
| 24 | + </el-tabs> | |
| 25 | + <div> | |
| 26 | + <el-form ref="loginForm" :model="loginForm" :rules="LoginRules" class="login-form"> | |
| 27 | + <el-form-item prop="tenantName" v-if="tenantEnable"> | |
| 28 | + <el-input v-model="loginForm.tenantName" type="text" auto-complete="off" placeholder='租户'> | |
| 29 | + <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" /> | |
| 30 | + </el-input> | |
| 31 | + </el-form-item> | |
| 32 | + <el-form-item prop="username" v-if="loginForm.loginType=='uname'"> | |
| 33 | + <el-input | |
| 34 | + v-model="loginForm.username" | |
| 35 | + type="text" | |
| 36 | + auto-complete="off" | |
| 37 | + placeholder="账号" | |
| 38 | + > | |
| 39 | + <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> | |
| 40 | + </el-input> | |
| 41 | + </el-form-item> | |
| 42 | + <el-form-item prop="password" v-if="loginForm.loginType=='uname'"> | |
| 43 | + <el-input | |
| 44 | + v-model="loginForm.password" | |
| 45 | + type="password" | |
| 46 | + auto-complete="off" | |
| 47 | + placeholder="密码" | |
| 48 | + @keyup.enter.native="handleLogin" | |
| 49 | + > | |
| 50 | + <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> | |
| 51 | + </el-input> | |
| 52 | + </el-form-item> | |
| 53 | + | |
| 54 | + | |
| 55 | + <el-form-item prop="mobile" v-if="loginForm.loginType=='sms'"> | |
| 56 | + <el-input v-model="loginForm.mobile" type="text" auto-complete="off" placeholder="请输入手机号"> | |
| 57 | + <svg-icon slot="prefix" icon-class="phone" class="el-input__icon input-icon" /> | |
| 58 | + </el-input> | |
| 59 | + </el-form-item> | |
| 60 | + <el-form-item prop="mobileCode" v-if="loginForm.loginType=='sms'"> | |
| 61 | + <el-input v-model="loginForm.mobileCode" type="text" auto-complete="off" @keyup.enter.native="handleLogin" placeholder="短信验证码"> | |
| 62 | + <template slot="icon"> | |
| 63 | + <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" /> | |
| 64 | + </template> | |
| 65 | + <template slot="append"> | |
| 66 | + <span v-if="mobileCodeTimer<=0" class="getMobileCode" @click="getSmsCode" style="cursor: pointer;">获取验证码</span> | |
| 67 | + <span v-if="mobileCodeTimer>0" class="getMobileCode">{{mobileCodeTimer}}秒后可重新获取</span> | |
| 68 | + </template> | |
| 69 | + </el-input> | |
| 70 | + </el-form-item> | |
| 35 | 71 | |
| 36 | - <el-form-item style="width:100%;"> | |
| 37 | - <div class="oauth-login" style="display:flex"> | |
| 38 | - <div class="oauth-login-item" v-for="item in SysUserSocialTypeEnum" :key="item.type" @click="doSocialLogin(item)"> | |
| 39 | - <img :src="item.img" height="25px" width="25px" alt="登录" > | |
| 40 | - <span>{{item.title}}</span> | |
| 41 | - </div> | |
| 42 | - </div> | |
| 43 | - </el-form-item> | |
| 44 | - </el-form> | |
| 45 | - <!-- 底部 --> | |
| 46 | - <div class="el-login-footer"> | |
| 47 | - <span>Copyright © 2020-2021 iocoder.cn All Rights Reserved.</span> | |
| 72 | + <el-form-item prop="code" v-if="captchaEnable"> | |
| 73 | + <el-input | |
| 74 | + v-model="loginForm.code" | |
| 75 | + auto-complete="off" | |
| 76 | + placeholder="验证码" | |
| 77 | + style="width: 63%" | |
| 78 | + @keyup.enter.native="handleLogin" | |
| 79 | + > | |
| 80 | + <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" /> | |
| 81 | + </el-input> | |
| 82 | + <div class="login-code"> | |
| 83 | + <img :src="codeUrl" @click="getCode" class="login-code-img"/> | |
| 84 | + </div> | |
| 85 | + </el-form-item> | |
| 86 | + <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox> | |
| 87 | + <el-form-item style="width:100%;"> | |
| 88 | + <el-button | |
| 89 | + :loading="loading" | |
| 90 | + size="medium" | |
| 91 | + type="primary" | |
| 92 | + style="width:100%;" | |
| 93 | + @click.native.prevent="handleLogin" | |
| 94 | + > | |
| 95 | + <span v-if="!loading">登 录</span> | |
| 96 | + <span v-else>登 录 中...</span> | |
| 97 | + </el-button> | |
| 98 | + | |
| 99 | + </el-form-item> | |
| 100 | + </el-form> | |
| 101 | + </div> | |
| 102 | + </div> | |
| 103 | + | |
| 104 | + </div> | |
| 105 | + </div> | |
| 106 | + <!-- footer --> | |
| 107 | + <div class="footer"> | |
| 108 | + Copyright © 2020-2021 iocoder.cn All Rights Reserved. | |
| 48 | 109 | </div> |
| 49 | 110 | </div> |
| 50 | 111 | </template> |
| 51 | 112 | |
| 52 | 113 | <script> |
| 53 | -import { getCodeImg,socialAuthRedirect } from "@/api/login"; | |
| 114 | +import { getCodeImg,socialAuthRedirect ,sendLoginSmsCode} from "@/api/login"; | |
| 54 | 115 | import { getTenantIdByName } from "@/api/system/tenant"; |
| 55 | 116 | import Cookies from "js-cookie"; |
| 56 | 117 | import { encrypt, decrypt } from '@/utils/jsencrypt' |
| ... | ... | @@ -61,29 +122,50 @@ export default { |
| 61 | 122 | name: "Login", |
| 62 | 123 | data() { |
| 63 | 124 | return { |
| 125 | + | |
| 64 | 126 | codeUrl: "", |
| 65 | 127 | captchaEnable: true, |
| 66 | 128 | tenantEnable: true, |
| 129 | + mobileCodeTimer:0, | |
| 67 | 130 | loginForm: { |
| 131 | + loginType:"sms", | |
| 68 | 132 | username: "admin", |
| 69 | 133 | password: "admin123", |
| 134 | + mobile:"", | |
| 135 | + mobileCode:"", | |
| 70 | 136 | rememberMe: false, |
| 71 | 137 | code: "", |
| 72 | 138 | uuid: "", |
| 73 | 139 | tenantName: "芋道源码", |
| 74 | 140 | }, |
| 75 | - loginRules: { | |
| 141 | + scene:21, | |
| 142 | + | |
| 143 | + LoginRules:{ | |
| 76 | 144 | username: [ |
| 145 | + | |
| 77 | 146 | { required: true, trigger: "blur", message: "用户名不能为空" } |
| 78 | 147 | ], |
| 79 | 148 | password: [ |
| 80 | 149 | { required: true, trigger: "blur", message: "密码不能为空" } |
| 81 | 150 | ], |
| 82 | 151 | code: [{ required: true, trigger: "change", message: "验证码不能为空" }], |
| 83 | - tenantName: [ | |
| 152 | + mobile: [ | |
| 153 | + | |
| 154 | + { required: true, trigger: "blur", message: "手机号不能为空" }, | |
| 155 | + {validator: function(rule, value, callback) { | |
| 156 | + if (/^1[34578]\d{9}$/.test(value) == false) { | |
| 157 | + callback(new Error("手机号格式错误")); | |
| 158 | + } else { | |
| 159 | + callback(); | |
| 160 | + } | |
| 161 | + }, trigger: "blur" | |
| 162 | + } | |
| 163 | + ], | |
| 164 | + tenantName:[ | |
| 84 | 165 | { required: true, trigger: "blur", message: "租户不能为空" }, |
| 85 | 166 | { |
| 86 | 167 | validator: (rule, value, callback) => { |
| 168 | + // debugger | |
| 87 | 169 | getTenantIdByName(value).then(res => { |
| 88 | 170 | const tenantId = res.data; |
| 89 | 171 | if (tenantId && tenantId >= 0) { |
| ... | ... | @@ -97,9 +179,11 @@ export default { |
| 97 | 179 | }, |
| 98 | 180 | trigger: 'blur' |
| 99 | 181 | } |
| 100 | - ], | |
| 182 | + ] | |
| 101 | 183 | }, |
| 102 | - loading: false, | |
| 184 | + | |
| 185 | + | |
| 186 | + loading: false, | |
| 103 | 187 | redirect: undefined, |
| 104 | 188 | // 枚举 |
| 105 | 189 | SysUserSocialTypeEnum: SystemUserSocialTypeEnum, |
| ... | ... | @@ -142,15 +226,23 @@ export default { |
| 142 | 226 | const password = Cookies.get("password"); |
| 143 | 227 | const rememberMe = Cookies.get('rememberMe') |
| 144 | 228 | const tenantName = Cookies.get('tenantName'); |
| 229 | + const mobile = Cookies.get('mobile'); | |
| 230 | + const mobileCode = Cookies.get('mobileCode'); | |
| 231 | + const loginType = Cookies.get('loginType'); | |
| 145 | 232 | this.loginForm = { |
| 146 | 233 | username: username === undefined ? this.loginForm.username : username, |
| 147 | 234 | password: password === undefined ? this.loginForm.password : decrypt(password), |
| 148 | 235 | rememberMe: rememberMe === undefined ? false : Boolean(rememberMe), |
| 149 | 236 | tenantName: tenantName === undefined ? this.loginForm.tenantName : tenantName, |
| 237 | + mobile:mobile === undefined ? this.loginForm.mobile : mobile, | |
| 238 | + mobileCode:mobileCode === undefined ? this.loginForm.mobileCode : mobileCode, | |
| 239 | + loginType:loginType === undefined ? this.loginForm.loginType : loginType, | |
| 150 | 240 | }; |
| 151 | 241 | }, |
| 152 | 242 | handleLogin() { |
| 243 | + | |
| 153 | 244 | this.$refs.loginForm.validate(valid => { |
| 245 | + | |
| 154 | 246 | if (valid) { |
| 155 | 247 | this.loading = true; |
| 156 | 248 | // 设置 Cookie |
| ... | ... | @@ -166,7 +258,8 @@ export default { |
| 166 | 258 | Cookies.remove('tenantName'); |
| 167 | 259 | } |
| 168 | 260 | // 发起登陆 |
| 169 | - this.$store.dispatch("Login", this.loginForm).then(() => { | |
| 261 | + console.log("发起登录",this.loginForm); | |
| 262 | + this.$store.dispatch(this.loginForm.loginType=="sms"?"SmsLogin":"Login", this.loginForm).then(() => { | |
| 170 | 263 | this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); |
| 171 | 264 | }).catch(() => { |
| 172 | 265 | this.loading = false; |
| ... | ... | @@ -188,87 +281,33 @@ export default { |
| 188 | 281 | // console.log(res.url); |
| 189 | 282 | window.location.href = res.data; |
| 190 | 283 | }); |
| 284 | + }, | |
| 285 | + /**以下为升级短信登录 */ | |
| 286 | + | |
| 287 | + changeLoginType(){ | |
| 288 | + | |
| 289 | + }, | |
| 290 | + getSmsCode(){ | |
| 291 | + if(this.mobileCodeTimer>0) return; | |
| 292 | + this.$refs.loginForm.validate(valid => { | |
| 293 | + if(!valid) return; | |
| 294 | + var _this=this; | |
| 295 | + sendLoginSmsCode(this.loginForm.mobile,this.scene,this.loginForm.uuid,this.loginForm.code).then(res => { | |
| 296 | + this.$modal.msgSuccess("获取验证码成功") | |
| 297 | + this.mobileCodeTimer=60; | |
| 298 | + var msgTimer = setInterval(function(){ | |
| 299 | + _this.mobileCodeTimer=_this.mobileCodeTimer-1; | |
| 300 | + if(_this.mobileCodeTimer<=0){ | |
| 301 | + clearInterval(msgTimer); | |
| 302 | + } | |
| 303 | + | |
| 304 | + },1000); | |
| 305 | + }); | |
| 306 | + }); | |
| 191 | 307 | } |
| 192 | 308 | } |
| 193 | 309 | }; |
| 194 | 310 | </script> |
| 195 | - | |
| 196 | -<style rel="stylesheet/scss" lang="scss"> | |
| 197 | -.login { | |
| 198 | - display: flex; | |
| 199 | - justify-content: center; | |
| 200 | - align-items: center; | |
| 201 | - height: 100%; | |
| 202 | - background-image: url("http://static.yudao.iocoder.cn/login-background.jpg"); | |
| 203 | - background-size: cover; | |
| 204 | -} | |
| 205 | -.title { | |
| 206 | - margin: 0px auto 30px auto; | |
| 207 | - text-align: center; | |
| 208 | - color: #707070; | |
| 209 | -} | |
| 210 | - | |
| 211 | -.login-form { | |
| 212 | - border-radius: 6px; | |
| 213 | - background: #ffffff; | |
| 214 | - width: 500px; | |
| 215 | - padding: 25px 25px 5px 25px; | |
| 216 | - .el-input { | |
| 217 | - height: 38px; | |
| 218 | - input { | |
| 219 | - height: 38px; | |
| 220 | - } | |
| 221 | - } | |
| 222 | - .input-icon { | |
| 223 | - height: 39px; | |
| 224 | - width: 14px; | |
| 225 | - margin-left: 2px; | |
| 226 | - } | |
| 227 | -} | |
| 228 | -.login-tip { | |
| 229 | - font-size: 13px; | |
| 230 | - text-align: center; | |
| 231 | - color: #bfbfbf; | |
| 232 | -} | |
| 233 | -.login-code { | |
| 234 | - width: 33%; | |
| 235 | - height: 38px; | |
| 236 | - float: right; | |
| 237 | - img { | |
| 238 | - cursor: pointer; | |
| 239 | - vertical-align: middle; | |
| 240 | - } | |
| 241 | -} | |
| 242 | -.el-login-footer { | |
| 243 | - height: 40px; | |
| 244 | - line-height: 40px; | |
| 245 | - position: fixed; | |
| 246 | - bottom: 0; | |
| 247 | - width: 100%; | |
| 248 | - text-align: center; | |
| 249 | - color: #fff; | |
| 250 | - font-family: Arial; | |
| 251 | - font-size: 12px; | |
| 252 | - letter-spacing: 1px; | |
| 253 | -} | |
| 254 | -.login-code-img { | |
| 255 | - height: 38px; | |
| 256 | -} | |
| 257 | -.oauth-login { | |
| 258 | - display: flex; | |
| 259 | - cursor:pointer; | |
| 260 | -} | |
| 261 | -.oauth-login-item { | |
| 262 | - display: flex; | |
| 263 | - align-items: center; | |
| 264 | - margin-right: 10px; | |
| 265 | -} | |
| 266 | -.oauth-login-item img { | |
| 267 | - height: 25px; | |
| 268 | - width: 25px; | |
| 269 | -} | |
| 270 | -.oauth-login-item span:hover { | |
| 271 | - text-decoration: underline red; | |
| 272 | - color: red; | |
| 273 | -} | |
| 311 | +<style lang="scss" scoped> | |
| 312 | + @import "~@/assets/styles/login.scss"; | |
| 274 | 313 | </style> | ... | ... |