|
@@ -22,9 +22,12 @@
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div class="container-login100-form-btn">
|
|
<div class="container-login100-form-btn">
|
|
- <div class="wrap-login100-form-btn" :class="{'login-loading': isLoging}" v-loading="isLoging" element-loading-background="rgb(0 0 0 / 0%);" element-loading-custom-class="login-loading-class">
|
|
|
|
|
|
+ <div class="wrap-login100-form-btn" :class="{'login-loading': isLoging}" v-loading="isLoging"
|
|
|
|
+ element-loading-background="rgb(0 0 0 / 0%);" element-loading-custom-class="login-loading-class">
|
|
<div class="login100-form-bgbtn"></div>
|
|
<div class="login100-form-bgbtn"></div>
|
|
- <button class="login100-form-btn" @click="login">登录</button>
|
|
|
|
|
|
+ <button class="login100-form-btn" @click="handleClick">
|
|
|
|
+ {{ isDefault ? "创建账户" : "登录" }}
|
|
|
|
+ </button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@@ -37,44 +40,66 @@
|
|
import crypto from 'crypto'
|
|
import crypto from 'crypto'
|
|
import api_user from "@/apiStore/api_user";
|
|
import api_user from "@/apiStore/api_user";
|
|
import userService from "./service/UserService";
|
|
import userService from "./service/UserService";
|
|
|
|
+import handle from "@/until/handle";
|
|
|
|
+import querystring from "querystring";
|
|
|
|
+
|
|
export default {
|
|
export default {
|
|
name: 'Login',
|
|
name: 'Login',
|
|
- data(){
|
|
|
|
- return {
|
|
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
isLoging: false,
|
|
isLoging: false,
|
|
showPassword: false,
|
|
showPassword: false,
|
|
loginLoading: false,
|
|
loginLoading: false,
|
|
- username: '',
|
|
|
|
- password: ''
|
|
|
|
- }
|
|
|
|
|
|
+ username: '',
|
|
|
|
+ password: '',
|
|
|
|
+ isDefault: false,
|
|
|
|
+ }
|
|
},
|
|
},
|
|
- created(){
|
|
|
|
|
|
+ created() {
|
|
var that = this;
|
|
var that = this;
|
|
- document.onkeydown = function(e) {
|
|
|
|
|
|
+ document.onkeydown = function (e) {
|
|
var key = window.event.keyCode;
|
|
var key = window.event.keyCode;
|
|
if (key == 13) {
|
|
if (key == 13) {
|
|
- that.login();
|
|
|
|
|
|
+ that.handleClick();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- methods:{
|
|
|
|
|
|
+ beforeMount() {
|
|
|
|
+ this.executeIsDefault()
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
|
|
- //登录逻辑
|
|
|
|
- login(){
|
|
|
|
- if(this.username!=='' && this.password!==''){
|
|
|
|
- this.toLogin();
|
|
|
|
- }else{
|
|
|
|
- this.$message.warning("请输入账号密码");
|
|
|
|
|
|
+ async executeIsDefault() {
|
|
|
|
+ let url = "/api/user/default"
|
|
|
|
+ let [err, res] = await handle(
|
|
|
|
+ this.$axios.get(url)
|
|
|
|
+ )
|
|
|
|
+ if (err) {
|
|
|
|
+ this.$message.error(`获取服务器信息失败`);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let response = res.data
|
|
|
|
+ if (response.code !== 0) {
|
|
|
|
+ this.$message.error(`获取服务器信息失败 ${response.msg}`);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (response.data) {
|
|
|
|
+ this.$message.success("没有管理员账户, 开始注册管理员账户")
|
|
|
|
+ this.$notify({
|
|
|
|
+ title: '提示',
|
|
|
|
+ message: '没有管理员账户, 请先注册账户',
|
|
|
|
+ duration: 0
|
|
|
|
+ });
|
|
|
|
+ this.isDefault = true;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ //登录请求
|
|
|
|
+ async toLogin() {
|
|
|
|
+ //需要想后端发送的登录参数
|
|
|
|
+ let loginParam = {
|
|
|
|
+ username: this.username,
|
|
|
|
+ password: crypto.createHash('md5').update(this.password, "utf8").digest('hex')
|
|
}
|
|
}
|
|
- },
|
|
|
|
-
|
|
|
|
- //登录请求
|
|
|
|
- async toLogin(){
|
|
|
|
- //需要想后端发送的登录参数
|
|
|
|
- let loginParam = {
|
|
|
|
- username: this.username,
|
|
|
|
- password: crypto.createHash('md5').update(this.password, "utf8").digest('hex')
|
|
|
|
- }
|
|
|
|
let that = this;
|
|
let that = this;
|
|
//设置在登录状态
|
|
//设置在登录状态
|
|
this.isLoging = true;
|
|
this.isLoging = true;
|
|
@@ -97,7 +122,7 @@ export default {
|
|
//登录成功后
|
|
//登录成功后
|
|
that.cancelEnterkeyDefaultAction();
|
|
that.cancelEnterkeyDefaultAction();
|
|
await that.$router.push('/');
|
|
await that.$router.push('/');
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
that.isLoging = false;
|
|
that.isLoging = false;
|
|
that.$message({
|
|
that.$message({
|
|
showClose: true,
|
|
showClose: true,
|
|
@@ -106,6 +131,39 @@ export default {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
+ async executeRegister() {
|
|
|
|
+ let url = "/api/user/register"
|
|
|
|
+ let loginParam = {
|
|
|
|
+ username: this.username,
|
|
|
|
+ password: crypto.createHash('md5').update(this.password, "utf8").digest('hex')
|
|
|
|
+ }
|
|
|
|
+ loginParam = querystring.stringify(loginParam)
|
|
|
|
+ let [err, res] = await handle(
|
|
|
|
+ this.$axios.post(url, loginParam))
|
|
|
|
+ if (err) {
|
|
|
|
+ this.$message.error(`注册账户失败`);
|
|
|
|
+ console.log(err);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ let response = res.data
|
|
|
|
+ if (response.code !== 0) {
|
|
|
|
+ this.$message.error(`注册账户失败 ${response.msg}`);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.$message.success("管理员账户注册成功")
|
|
|
|
+ this.isDefault = false;
|
|
|
|
+ },
|
|
|
|
+ handleClick() {
|
|
|
|
+ if (this.username == '' || this.password == '') {
|
|
|
|
+ this.$message.warning("请输入账号密码");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if (this.isDefault) {
|
|
|
|
+ this.executeRegister()
|
|
|
|
+ } else {
|
|
|
|
+ this.toLogin()
|
|
|
|
+ }
|
|
|
|
+ },
|
|
setCookie: function (cname, cvalue, exdays) {
|
|
setCookie: function (cname, cvalue, exdays) {
|
|
let d = new Date();
|
|
let d = new Date();
|
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
|
@@ -114,7 +172,7 @@ export default {
|
|
document.cookie = cname + "=" + cvalue + "; " + expires;
|
|
document.cookie = cname + "=" + cvalue + "; " + expires;
|
|
console.info(document.cookie);
|
|
console.info(document.cookie);
|
|
},
|
|
},
|
|
- cancelEnterkeyDefaultAction: function() {
|
|
|
|
|
|
+ cancelEnterkeyDefaultAction: function () {
|
|
document.onkeydown = function(e) {
|
|
document.onkeydown = function(e) {
|
|
let key = window.event.keyCode;
|
|
let key = window.event.keyCode;
|
|
if (key == 13) {
|
|
if (key == 13) {
|