mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 09:11:52 +08:00
登陆界面,优化成输入租户名
This commit is contained in:
parent
0cb4823b5b
commit
535d3c9c01
@ -22,9 +22,11 @@ public class SecurityConfiguration {
|
||||
@Bean
|
||||
public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() {
|
||||
return registry -> {
|
||||
// 通用的接口,可匿名访问 TODO 芋艿:需要抽象出去
|
||||
// 验证码的接口
|
||||
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()
|
||||
.antMatchers(adminSeverContextPath + "/**").anonymous();
|
||||
// 短信回调 API
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
12
yudao-admin-ui/src/api/system/tenant.js
Normal file
12
yudao-admin-ui/src/api/system/tenant.js
Normal 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
|
||||
}
|
||||
})
|
||||
}
|
@ -2,8 +2,8 @@
|
||||
<div class="login">
|
||||
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
||||
<h3 class="title">芋道后台管理系统</h3>
|
||||
<el-form-item prop="username">
|
||||
<el-input v-model="loginForm.tenantId" type="text" auto-complete="off" placeholder="租户">
|
||||
<el-form-item prop="tenantName">
|
||||
<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" />
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
@ -51,6 +51,7 @@
|
||||
|
||||
<script>
|
||||
import { getCodeImg,socialAuthRedirect } from "@/api/login";
|
||||
import { getTenantIdByName } from "@/api/system/tenant";
|
||||
import Cookies from "js-cookie";
|
||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||
import {InfApiErrorLogProcessStatusEnum, SysUserSocialTypeEnum} from "@/utils/constants";
|
||||
@ -61,16 +62,32 @@ export default {
|
||||
return {
|
||||
codeUrl: "",
|
||||
loginForm: {
|
||||
tenantId: "",
|
||||
username: "admin",
|
||||
password: "admin123",
|
||||
rememberMe: false,
|
||||
code: "",
|
||||
uuid: ""
|
||||
uuid: "",
|
||||
tenantName: "芋道源码",
|
||||
},
|
||||
loginRules: {
|
||||
tenantId: [
|
||||
tenantName: [
|
||||
{ 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: [
|
||||
{ required: true, trigger: "blur", message: "用户名不能为空" }
|
||||
@ -112,12 +129,12 @@ export default {
|
||||
const username = Cookies.get("username");
|
||||
const password = Cookies.get("password");
|
||||
const rememberMe = Cookies.get('rememberMe')
|
||||
const tenantId = Cookies.get('tenantId');
|
||||
const tenantName = Cookies.get('tenantName');
|
||||
this.loginForm = {
|
||||
username: username === undefined ? this.loginForm.username : username,
|
||||
password: password === undefined ? this.loginForm.password : decrypt(password),
|
||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
||||
tenantId: tenantId === undefined ? 0 : tenantId, // TODO 芋艿:优化下,magic number
|
||||
tenantName: tenantName === undefined ? this.loginForm.tenantName : tenantName,
|
||||
};
|
||||
},
|
||||
handleLogin() {
|
||||
@ -129,13 +146,13 @@ export default {
|
||||
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
||||
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
||||
Cookies.set('tenantName', this.loginForm.tenantName, { expires: 30 });
|
||||
} else {
|
||||
Cookies.remove("username");
|
||||
Cookies.remove("password");
|
||||
Cookies.remove('rememberMe');
|
||||
Cookies.remove('tenantName');
|
||||
}
|
||||
// 设置租户
|
||||
Cookies.set("tenantId", this.loginForm.tenantId);
|
||||
// 发起登陆
|
||||
this.$store.dispatch("Login", this.loginForm).then(() => {
|
||||
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
||||
|
Loading…
Reference in New Issue
Block a user