Commit 0cb4823b5b0ad5668a801da0def2b7d9296f9cbd

Authored by YunaiV
1 parent 7c8fe2fc

1. 前端登陆界面,接入租户

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