Commit 0cb4823b5b0ad5668a801da0def2b7d9296f9cbd
1 parent
7c8fe2fc
1. 前端登陆界面,接入租户
Showing
2 changed files
with
23 additions
and
2 deletions
yudao-admin-ui/src/utils/request.js
| @@ -3,6 +3,7 @@ import { Notification, MessageBox, Message } from 'element-ui' | @@ -3,6 +3,7 @@ import { Notification, MessageBox, Message } from 'element-ui' | ||
| 3 | import store from '@/store' | 3 | import store from '@/store' |
| 4 | import { getToken } from '@/utils/auth' | 4 | import { getToken } from '@/utils/auth' |
| 5 | import errorCode from '@/utils/errorCode' | 5 | import errorCode from '@/utils/errorCode' |
| 6 | +import Cookies from "js-cookie"; | ||
| 6 | 7 | ||
| 7 | axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' | 8 | axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8' |
| 8 | // 创建axios实例 | 9 | // 创建axios实例 |
| @@ -19,6 +20,11 @@ service.interceptors.request.use(config => { | @@ -19,6 +20,11 @@ service.interceptors.request.use(config => { | ||
| 19 | if (getToken() && !isToken) { | 20 | if (getToken() && !isToken) { |
| 20 | config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 | 21 | config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改 |
| 21 | } | 22 | } |
| 23 | + // 设置租户 | ||
| 24 | + const tenantId = Cookies.get('tenantId'); | ||
| 25 | + if (tenantId) { | ||
| 26 | + config.headers['tenant-id'] = tenantId; | ||
| 27 | + } | ||
| 22 | // get请求映射params参数 | 28 | // get请求映射params参数 |
| 23 | if (config.method === 'get' && config.params) { | 29 | if (config.method === 'get' && config.params) { |
| 24 | let url = config.url + '?'; | 30 | let url = config.url + '?'; |
yudao-admin-ui/src/views/login.vue
| @@ -3,6 +3,11 @@ | @@ -3,6 +3,11 @@ | ||
| 3 | <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> | 3 | <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form"> |
| 4 | <h3 class="title">芋道后台管理系统</h3> | 4 | <h3 class="title">芋道后台管理系统</h3> |
| 5 | <el-form-item prop="username"> | 5 | <el-form-item prop="username"> |
| 6 | + <el-input v-model="loginForm.tenantId" 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"> | ||
| 6 | <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号"> | 11 | <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号"> |
| 7 | <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> | 12 | <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" /> |
| 8 | </el-input> | 13 | </el-input> |
| @@ -56,6 +61,7 @@ export default { | @@ -56,6 +61,7 @@ export default { | ||
| 56 | return { | 61 | return { |
| 57 | codeUrl: "", | 62 | codeUrl: "", |
| 58 | loginForm: { | 63 | loginForm: { |
| 64 | + tenantId: "", | ||
| 59 | username: "admin", | 65 | username: "admin", |
| 60 | password: "admin123", | 66 | password: "admin123", |
| 61 | rememberMe: false, | 67 | rememberMe: false, |
| @@ -63,6 +69,9 @@ export default { | @@ -63,6 +69,9 @@ export default { | ||
| 63 | uuid: "" | 69 | uuid: "" |
| 64 | }, | 70 | }, |
| 65 | loginRules: { | 71 | loginRules: { |
| 72 | + tenantId: [ | ||
| 73 | + { required: true, trigger: "blur", message: "租户不能为空" }, | ||
| 74 | + ], | ||
| 66 | username: [ | 75 | username: [ |
| 67 | { required: true, trigger: "blur", message: "用户名不能为空" } | 76 | { required: true, trigger: "blur", message: "用户名不能为空" } |
| 68 | ], | 77 | ], |
| @@ -103,16 +112,19 @@ export default { | @@ -103,16 +112,19 @@ export default { | ||
| 103 | const username = Cookies.get("username"); | 112 | const username = Cookies.get("username"); |
| 104 | const password = Cookies.get("password"); | 113 | const password = Cookies.get("password"); |
| 105 | const rememberMe = Cookies.get('rememberMe') | 114 | const rememberMe = Cookies.get('rememberMe') |
| 115 | + const tenantId = Cookies.get('tenantId'); | ||
| 106 | this.loginForm = { | 116 | this.loginForm = { |
| 107 | username: username === undefined ? this.loginForm.username : username, | 117 | username: username === undefined ? this.loginForm.username : username, |
| 108 | password: password === undefined ? this.loginForm.password : decrypt(password), | 118 | password: password === undefined ? this.loginForm.password : decrypt(password), |
| 109 | - rememberMe: rememberMe === undefined ? false : Boolean(rememberMe) | 119 | + rememberMe: rememberMe === undefined ? false : Boolean(rememberMe), |
| 120 | + tenantId: tenantId === undefined ? 0 : tenantId, // TODO 芋艿:优化下,magic number | ||
| 110 | }; | 121 | }; |
| 111 | }, | 122 | }, |
| 112 | handleLogin() { | 123 | handleLogin() { |
| 113 | this.$refs.loginForm.validate(valid => { | 124 | this.$refs.loginForm.validate(valid => { |
| 114 | if (valid) { | 125 | if (valid) { |
| 115 | this.loading = true; | 126 | this.loading = true; |
| 127 | + // 设置 Cookie | ||
| 116 | if (this.loginForm.rememberMe) { | 128 | if (this.loginForm.rememberMe) { |
| 117 | Cookies.set("username", this.loginForm.username, { expires: 30 }); | 129 | Cookies.set("username", this.loginForm.username, { expires: 30 }); |
| 118 | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); | 130 | Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 }); |
| @@ -122,6 +134,9 @@ export default { | @@ -122,6 +134,9 @@ export default { | ||
| 122 | Cookies.remove("password"); | 134 | Cookies.remove("password"); |
| 123 | Cookies.remove('rememberMe'); | 135 | Cookies.remove('rememberMe'); |
| 124 | } | 136 | } |
| 137 | + // 设置租户 | ||
| 138 | + Cookies.set("tenantId", this.loginForm.tenantId); | ||
| 139 | + // 发起登陆 | ||
| 125 | this.$store.dispatch("Login", this.loginForm).then(() => { | 140 | this.$store.dispatch("Login", this.loginForm).then(() => { |
| 126 | this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); | 141 | this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); |
| 127 | }).catch(() => { | 142 | }).catch(() => { |
| @@ -167,7 +182,7 @@ export default { | @@ -167,7 +182,7 @@ export default { | ||
| 167 | .login-form { | 182 | .login-form { |
| 168 | border-radius: 6px; | 183 | border-radius: 6px; |
| 169 | background: #ffffff; | 184 | background: #ffffff; |
| 170 | - width: 400px; | 185 | + width: 500px; |
| 171 | padding: 25px 25px 5px 25px; | 186 | padding: 25px 25px 5px 25px; |
| 172 | .el-input { | 187 | .el-input { |
| 173 | height: 38px; | 188 | height: 38px; |