登陆界面,优化成输入租户名

This commit is contained in:
YunaiV 2021-12-05 00:12:54 +08:00
parent 0cb4823b5b
commit 535d3c9c01
4 changed files with 71 additions and 11 deletions

View File

@ -22,9 +22,11 @@ public class SecurityConfiguration {
@Bean @Bean
public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() { public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() {
return registry -> { return registry -> {
// 通用的接口可匿名访问 TODO 芋艿需要抽象出去 // 验证码的接口
registry.antMatchers(api("/system/captcha/**")).anonymous(); registry.antMatchers(api("/system/captcha/**")).anonymous();
// Spring Boot Admin Server 的安全配置 TODO 芋艿需要抽象出去 // 获得租户编号的接口
registry.antMatchers(api("/system/tenant/get-id-by-name")).anonymous();
// Spring Boot Admin Server 的安全配置
registry.antMatchers(adminSeverContextPath).anonymous() registry.antMatchers(adminSeverContextPath).anonymous()
.antMatchers(adminSeverContextPath + "/**").anonymous(); .antMatchers(adminSeverContextPath + "/**").anonymous();
// 短信回调 API // 短信回调 API

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.adminserver.modules.system.controller.tenant;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Objects;
@Api(tags = "租户")
@RestController
@RequestMapping("/system/tenant")
public class SysTenantController {
@GetMapping("/get-id-by-name")
@ApiOperation(value = "使用租户名,获得租户编号", notes = "登录界面,根据用户的租户名,获得租户编号")
@ApiImplicitParam(name = "name", value = "租户名", required = true, example = "芋道源码", dataTypeClass = Long.class)
public CommonResult<Long> getTenantIdByName(@RequestParam("name") String name) {
if (Objects.equals("芋道源码", name)) {
return CommonResult.success(0L);
}
return CommonResult.success(null);
}
}

View File

@ -0,0 +1,12 @@
import request from '@/utils/request'
// 使用租户名,获得租户编号
export function getTenantIdByName(name) {
return request({
url: '/system/tenant/get-id-by-name',
method: 'get',
params: {
name
}
})
}

View File

@ -2,8 +2,8 @@
<div class="login"> <div class="login">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
<h3 class="title">芋道后台管理系统</h3> <h3 class="title">芋道后台管理系统</h3>
<el-form-item prop="username"> <el-form-item prop="tenantName">
<el-input v-model="loginForm.tenantId" type="text" auto-complete="off" placeholder="租户"> <el-input v-model="loginForm.tenantName" type="text" auto-complete="off" placeholder='租户'>
<svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" /> <svg-icon slot="prefix" icon-class="tree" class="el-input__icon input-icon" />
</el-input> </el-input>
</el-form-item> </el-form-item>
@ -51,6 +51,7 @@
<script> <script>
import { getCodeImg,socialAuthRedirect } from "@/api/login"; import { getCodeImg,socialAuthRedirect } from "@/api/login";
import { getTenantIdByName } from "@/api/system/tenant";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt' import { encrypt, decrypt } from '@/utils/jsencrypt'
import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants"; import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants";
@ -61,16 +62,32 @@ export default {
return { return {
codeUrl: "", codeUrl: "",
loginForm: { loginForm: {
tenantId: "",
username: "admin", username: "admin",
password: "admin123", password: "admin123",
rememberMe: false, rememberMe: false,
code: "", code: "",
uuid: "" uuid: "",
tenantName: "芋道源码",
}, },
loginRules: { loginRules: {
tenantId: [ tenantName: [
{ required: true, trigger: "blur", message: "租户不能为空" }, { required: true, trigger: "blur", message: "租户不能为空" },
{
validator: (rule, value, callback) => {
// debugger
getTenantIdByName(value).then(res => {
const tenantId = res.data;
if (tenantId >= 0) {
//
Cookies.set("tenantId", tenantId);
callback();
} else {
callback('租户不存在');
}
});
},
trigger: 'blur'
}
], ],
username: [ username: [
{ required: true, trigger: "blur", message: "用户名不能为空" } { required: true, trigger: "blur", message: "用户名不能为空" }
@ -112,12 +129,12 @@ export default {
const username = Cookies.get("username"); const username = Cookies.get("username");
const password = Cookies.get("password"); const password = Cookies.get("password");
const rememberMe = Cookies.get('rememberMe') const rememberMe = Cookies.get('rememberMe')
const tenantId = Cookies.get('tenantId'); const tenantName = Cookies.get('tenantName');
this.loginForm = { this.loginForm = {
username: username === undefined ? this.loginForm.username : username, username: username === undefined ? this.loginForm.username : username,
password: password === undefined ? this.loginForm.password : decrypt(password), password: password === undefined ? this.loginForm.password : decrypt(password),
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe), rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
tenantId: tenantId === undefined ? 0 : tenantId, // TODO magic number tenantName: tenantName === undefined ? this.loginForm.tenantName : tenantName,
}; };
}, },
handleLogin() { handleLogin() {
@ -129,13 +146,13 @@ export default {
Cookies.set("username", this.loginForm.username, { expires: 30 }); Cookies.set("username", this.loginForm.username, { expires: 30 });
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 }); Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
Cookies.set('tenantName', this.loginForm.tenantName, { expires: 30 });
} else { } else {
Cookies.remove("username"); Cookies.remove("username");
Cookies.remove("password"); Cookies.remove("password");
Cookies.remove('rememberMe'); Cookies.remove('rememberMe');
Cookies.remove('tenantName');
} }
//
Cookies.set("tenantId", this.loginForm.tenantId);
// //
this.$store.dispatch("Login", this.loginForm).then(() => { this.$store.dispatch("Login", this.loginForm).then(() => {
this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); this.$router.push({ path: this.redirect || "/" }).catch(()=>{});