```java
<!--<html xmlns:th="http://www.thymeleaf.org">-->
<div th:fragment="html">
<script>
Vue.config.productionTip = true;
$(function () {
var data4Vue = {
uri: 'api/iam/user/v1.2/userlogin',
user: {name: '', password: ''},
result: [],
headers: [],
checkVCode: '',
};
var vue = new Vue({
el: '#workingArea',
data: data4Vue,
mounted: function () {
localStorage.getItem("Authorization");
linkDefaultActions();
},
methods: {
interceptor: function () {
console.log("拦截器检查" + config);
axios.interceptors.request.use((config) => {
console.log('请求拦截器:');
console.log(config);
if (localStorage.getItem('Authorization') != null) {
config.headers['Authorization'] = localStorage.getItem('Authorization');
}
return config;
},
error => {
console.log(error);
return Promise.reject(error);
});
axios.interceptors.response.use((response) => {
console.log('响应拦截器:');
console.log(response);
if (response.headers.authorization) {
localStorage.setItem('Authorization', response.headers.authorization);
}
return response;
},
error => {
console.log('err' + error)
Message({
message: error.message,
type: 'error',
duration: 5 * 1000
})
return Promise.reject(error)
});
},
login: function () {
if (0 == this.user.name.length) {
$("span.errorMessage").html("请输入用户名");
$("div.loginErrorMessageDiv").css("visibility", "visible");
return;
}
if (0 == this.user.password.length) {
$("span.errorMessage").html("请输入密码");
$("div.loginErrorMessageDiv").css("visibility", "visible");
return;
}
if (document.getElementById("vCodeResultIcon").className.localeCompare("bi bi-check-circle-fill")) {
$("span.errorMessage").html("验证码检查未通过");
$("div.loginErrorMessageDiv").css("visibility", "visible");
getCaptcha();
return;
}
axios.post(this.uri, this.user)
.then(function (response) {
if (response.data.code == 0) {
console.log("打印返回的token:" + response.headers.authorization);
localStorage.setItem("Authorization", response.headers.authorization);
} else {
$("span.errorMessage").html(response.data.message);
$("div.loginErrorMessageDiv").css("visibility", "visible");
}
})
.catch(function (error) {
alert("login error:" + error);
}).then(function () {
getCaptcha();
});
},
refreshCaptcha: function () {
getCaptcha();
},
},
watch: {
checkVCode: function () {
if (document.getElementById("vcodeStr").value.length == 4) {
axios.post("captcha/v1/checkCaptcha?vCode=" + document.getElementById("vcodeStr").value)
.then(function (response) {
if (response.data.code == 0) {
document.getElementById("vCodeResultIcon").className = "bi bi-check-circle-fill";
} else {
getCaptcha();
}
})
.catch(function (error) {
alert("checkVCode error:" + error);
});
;
} else {
document.getElementById("vCodeResultIcon").className = "bi bi-x-circle-fill";
}
document.getElementById("vCodeResultIcon").style.visibility = "visible";
}
},
});
$("div.loginSmallDiv").css("padding", 50, 25, 0, 25);
$("div.loginSmallDiv").css("width", 350);
$("div.loginSmallDiv").css("height", 450);
});
function getCaptcha() {
axios.get("captcha/v1/getCaptcha")
.then(function (response) {
document.getElementById("randImg").src = "captcha/v1/getCaptcha";
}).catch(function (error) {
alert("getCaptcha error:" + error);
});
document.getElementById("vCodeResultIcon").style.visibility = "hidden";
document.getElementById("vCodeResultIcon").className = "bi bi-x-circle-fill";
document.getElementById("vcodeStr").value = "";
}
</script>
<a href="/dreamfuture/fore/home.html">home</a>
<div id="loginDiv" style="position: relative;" align="center">
<!--<img id="loginBackgroundImg" class="loginBackgroundImg" src="img/site/loginBackground.png" height="500">-->
<div id="loginSmallDiv" class="loginSmallDiv" style="background-color: aliceblue">
<div class="loginErrorMessageDiv" style="visibility: hidden">
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
<span class="errorMessage"></span>
</div>
</div>
<!--<div>
<p th:text="${result.message}" th:if="${not #strings.isEmpty(result.message)}"></p>
</div>-->
<div class="h4 mb-3 fw-normal">账户登录</div>
<div class="input-group">
<span class=" input-group-addon"><i class="bi bi-person"></i></span>
<input v-model="user.name" class="form-control" placeholder="手机/会员名/邮箱" type="text" required v-focus>
</div>
<br>
<div class="input-group">
<span class=" input-group-addon"><i class="bi bi-key"></i></span>
<input v-model="user.password" type="password" class="form-control" placeholder="密码" required>
</div>
<br>
<div class="input-group">
<span class=" input-group-addon">
<i class="bi bi-input-cursor-text"></i></span>
<input v-model="checkVCode" id="vcodeStr" type="text" name="vcodeStr" class="form-control"
placeholder="请输入验证码"
maxlength="4"
>
<span class=" input-group-addon"><i class="bi bi-"></i></span>
<span class=" input-group-addon">
<i class="bi bi-x-circle-fill" style="visibility: hidden" id="vCodeResultIcon"></i></span>
<img src="captcha/v1/getCaptcha" id="randImg" @click="refreshCaptcha">
</div>
<br>
<div class="checkbox mb-3">
<label>
<input type="checkbox" value="remember-me" class="right-button"> 记住我
</label>
<label>
<input type="checkbox" value="remember-me"> 忘记密码
</label>
</div>
<div style="margin-top:20px">
<button class="w-50 btn btn-primary" type="button" @click="login">登录</button>
</div>
<br>
<div>
<a class="pull-left" href="#nowhere">忘记登录密码</a>
<a href="register" class="pull-right">免费注册</a>
</div>
</div>
</div>
</div>