修改
This commit is contained in:
parent
d07c6f64f0
commit
34cfa5e34c
@ -12,7 +12,7 @@ let downloadLoadingInstance;
|
|||||||
export let isRelogin = { show: false };
|
export let isRelogin = { show: false };
|
||||||
|
|
||||||
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
|
||||||
// 创建axios实例
|
// 创建axios实例
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
// axios中请求配置有baseURL选项,表示请求URL公共部分
|
||||||
baseURL: process.env.VUE_APP_BASE_API,
|
baseURL: process.env.VUE_APP_BASE_API,
|
||||||
@ -72,7 +72,7 @@ service.interceptors.response.use(res => {
|
|||||||
// 获取错误信息
|
// 获取错误信息
|
||||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||||
// 二进制数据则直接返回
|
// 二进制数据则直接返回
|
||||||
if(res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer'){
|
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
if (code === 401) {
|
if (code === 401) {
|
||||||
@ -82,8 +82,7 @@ service.interceptors.response.use(res => {
|
|||||||
confirmButtonText: '重新登录',
|
confirmButtonText: '重新登录',
|
||||||
cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}
|
}).then(() => {
|
||||||
).then(() => {
|
|
||||||
isRelogin.show = false;
|
isRelogin.show = false;
|
||||||
store.dispatch('LogOut').then(() => {
|
store.dispatch('LogOut').then(() => {
|
||||||
location.href = '/index';
|
location.href = '/index';
|
||||||
@ -99,6 +98,8 @@ service.interceptors.response.use(res => {
|
|||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
|
} else if (code === 600) {
|
||||||
|
return Promise.reject(new Error(msg))
|
||||||
} else if (code !== 200) {
|
} else if (code !== 200) {
|
||||||
Notification.error({
|
Notification.error({
|
||||||
title: msg
|
title: msg
|
||||||
@ -113,11 +114,9 @@ service.interceptors.response.use(res => {
|
|||||||
let { message } = error;
|
let { message } = error;
|
||||||
if (message == "Network Error") {
|
if (message == "Network Error") {
|
||||||
message = "后端接口连接异常";
|
message = "后端接口连接异常";
|
||||||
}
|
} else if (message.includes("timeout")) {
|
||||||
else if (message.includes("timeout")) {
|
|
||||||
message = "系统接口请求超时";
|
message = "系统接口请求超时";
|
||||||
}
|
} else if (message.includes("Request failed with status code")) {
|
||||||
else if (message.includes("Request failed with status code")) {
|
|
||||||
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
||||||
}
|
}
|
||||||
Message({
|
Message({
|
||||||
@ -136,7 +135,7 @@ export function download(url, params, filename) {
|
|||||||
transformRequest: [(params) => { return tansParams(params) }],
|
transformRequest: [(params) => { return tansParams(params) }],
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
responseType: 'blob'
|
responseType: 'blob'
|
||||||
}).then(async (data) => {
|
}).then(async(data) => {
|
||||||
const isLogin = await blobValidate(data);
|
const isLogin = await blobValidate(data);
|
||||||
if (isLogin) {
|
if (isLogin) {
|
||||||
const blob = new Blob([data])
|
const blob = new Blob([data])
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
type="text"
|
type="text"
|
||||||
auto-complete="off"
|
auto-complete="off"
|
||||||
placeholder="账号"
|
placeholder="账号"
|
||||||
style="width: 310px;"
|
style="width: 310px"
|
||||||
>
|
>
|
||||||
<svg-icon
|
<svg-icon
|
||||||
slot="prefix"
|
slot="prefix"
|
||||||
@ -68,7 +68,7 @@
|
|||||||
style="
|
style="
|
||||||
width: 300px;
|
width: 300px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
background-image: linear-gradient(to right, #01A4FF, #1259EE );
|
background-image: linear-gradient(to right, #01a4ff, #1259ee);
|
||||||
border-radius: -33px;
|
border-radius: -33px;
|
||||||
border: none;
|
border: none;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
@ -90,7 +90,7 @@
|
|||||||
<img
|
<img
|
||||||
src="../assets/images/bg3.png"
|
src="../assets/images/bg3.png"
|
||||||
alt=""
|
alt=""
|
||||||
style="width: 1400px; height: 700px; border-radius: 0 6px 6px 0;"
|
style="width: 1400px; height: 700px; border-radius: 0 6px 6px 0"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<!-- 底部 -->
|
<!-- 底部 -->
|
||||||
@ -103,7 +103,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { getCodeImg } from "@/api/login";
|
import { getCodeImg } from "@/api/login";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
import { encrypt, decrypt } from "@/utils/jsencrypt";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: "Login",
|
||||||
@ -115,23 +115,23 @@ export default {
|
|||||||
password: "admin123",
|
password: "admin123",
|
||||||
rememberMe: false,
|
rememberMe: false,
|
||||||
code: "",
|
code: "",
|
||||||
uuid: ""
|
uuid: "",
|
||||||
},
|
},
|
||||||
loginRules: {
|
loginRules: {
|
||||||
username: [
|
username: [
|
||||||
{ required: true, trigger: "blur", message: "请输入您的账号" }
|
{ required: true, trigger: "blur", message: "请输入您的账号" },
|
||||||
],
|
],
|
||||||
password: [
|
password: [
|
||||||
{ required: true, trigger: "blur", message: "请输入您的密码" }
|
{ required: true, trigger: "blur", message: "请输入您的密码" },
|
||||||
],
|
],
|
||||||
code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
code: [{ required: true, trigger: "change", message: "请输入验证码" }],
|
||||||
},
|
},
|
||||||
loading: false,
|
loading: false,
|
||||||
// 验证码开关
|
// 验证码开关
|
||||||
captchaOnOff: true,
|
captchaOnOff: true,
|
||||||
// 注册开关
|
// 注册开关
|
||||||
register: false,
|
register: false,
|
||||||
redirect: undefined
|
redirect: undefined,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -139,8 +139,8 @@ export default {
|
|||||||
handler: function (route) {
|
handler: function (route) {
|
||||||
this.redirect = route.query && route.query.redirect;
|
this.redirect = route.query && route.query.redirect;
|
||||||
},
|
},
|
||||||
immediate: true
|
immediate: true,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.getCode();
|
this.getCode();
|
||||||
@ -148,8 +148,9 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getCode() {
|
getCode() {
|
||||||
getCodeImg().then(res => {
|
getCodeImg().then((res) => {
|
||||||
this.captchaOnOff = res.captchaOnOff === undefined ? true : res.captchaOnOff;
|
this.captchaOnOff =
|
||||||
|
res.captchaOnOff === undefined ? true : res.captchaOnOff;
|
||||||
if (this.captchaOnOff) {
|
if (this.captchaOnOff) {
|
||||||
this.codeUrl = "data:image/gif;base64," + res.img;
|
this.codeUrl = "data:image/gif;base64," + res.img;
|
||||||
this.loginForm.uuid = res.uuid;
|
this.loginForm.uuid = res.uuid;
|
||||||
@ -159,29 +160,40 @@ export default {
|
|||||||
getCookie() {
|
getCookie() {
|
||||||
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");
|
||||||
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:
|
||||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
password === undefined ? this.loginForm.password : decrypt(password),
|
||||||
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleLogin() {
|
handleLogin() {
|
||||||
this.$refs.loginForm.validate(valid => {
|
this.$refs.loginForm.validate((valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
if (this.loginForm.rememberMe) {
|
if (this.loginForm.rememberMe) {
|
||||||
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), {
|
||||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
expires: 30,
|
||||||
|
});
|
||||||
|
Cookies.set("rememberMe", this.loginForm.rememberMe, {
|
||||||
|
expires: 30,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove("username");
|
Cookies.remove("username");
|
||||||
Cookies.remove("password");
|
Cookies.remove("password");
|
||||||
Cookies.remove('rememberMe');
|
Cookies.remove("rememberMe");
|
||||||
}
|
}
|
||||||
this.$store.dispatch("Login", this.loginForm).then(() => {
|
this.$store
|
||||||
this.$router.push({ path: this.redirect || "/" }).catch(() => { });
|
.dispatch("Login", this.loginForm)
|
||||||
}).catch(() => {
|
.then(() => {
|
||||||
|
this.$router.push({ path: this.redirect || "/" }).catch(() => {});
|
||||||
|
setTimeout(() => {
|
||||||
|
this.loading = false;
|
||||||
|
}, 1500);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
if (this.captchaOnOff) {
|
if (this.captchaOnOff) {
|
||||||
this.getCode();
|
this.getCode();
|
||||||
@ -189,14 +201,14 @@ export default {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style rel="stylesheet/scss" lang="scss" scoped>
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
||||||
.bg{
|
.bg {
|
||||||
position:absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
// .el-input el-input--medium el-input--prefix{
|
// .el-input el-input--medium el-input--prefix{
|
||||||
// height: 50px;
|
// height: 50px;
|
||||||
@ -205,12 +217,12 @@ export default {
|
|||||||
// border: none;
|
// border: none;
|
||||||
// border-radius: 10px;
|
// border-radius: 10px;
|
||||||
// }
|
// }
|
||||||
.el-input--medium ::v-deep .el-input__inner{
|
.el-input--medium ::v-deep .el-input__inner {
|
||||||
height: 50px;
|
height: 50px;
|
||||||
line-height: 36px;
|
line-height: 36px;
|
||||||
// background-color: red;
|
// background-color: red;
|
||||||
border: none;
|
border: none;
|
||||||
border: 1px solid #E5E5E5;
|
border: 1px solid #e5e5e5;
|
||||||
border-radius: 36px;
|
border-radius: 36px;
|
||||||
}
|
}
|
||||||
.login {
|
.login {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user