login.vue
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<template>
<div id="login_box">
<el-row type="flex" justify="center" align="middle" style="height:80%">
<el-card class="box-card" shadow="hover" style="width:25%">
<div slot="header" style="text-align:center" class="clearfix">
<span style="font-size:24px">合同管理系统</span>
</div>
<el-form ref="login_form" :model="form" :rules="rules" label-width="60px" label-position="top">
<el-form-item prop="username">
<el-input v-model="form.username">
<template slot="prepend">姓名</template>
</el-input>
</el-form-item>
<el-form-item prop="password">
<el-input type="password" v-model="form.password" auto-complete="off" @keydown.enter="submitForm('login_form')">
<template slot="prepend">密码</template>
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('login_form')">提交</el-button>
<el-button @click="resetForm('login_form')">重置</el-button>
</el-form-item>
</el-form>
</el-card>
</el-row>
</div>
</template>
<script>
export default {
name: "login",
data() {
return {
auth_base_url: disparch_data.auth_base_url,
form: {
username: "",
password: ""
},
rules: {
username: [{ required: true, message: "请输入用户名", trigger: "blur" }]
// password: [
// { required: true, message: "请输入登录密码", trigger: "blur" }
// ]
}
};
},
methods: {
submitForm(form) {
this.$refs[form].validate(valid => {
if (valid) {
window.localStorage.setItem("username", this.form.username);
window.sessionStorage.setItem("loginCheck", true);
this.$Axios({
method: "post",
url: this.auth_base_url + "users/login",
headers: { "Content-Type": "application/json" },
data: {
user_type: "user",
username: this.form.username,
password: this.form.password
}
})
.then(res => {
if (res.data.ecode) {
this.$message({
message: res.data.enote,
type: "error"
});
} else {
window.sessionStorage.setItem("username", this.form.username);
window.sessionStorage.setItem("user_unid", res.data.user_unid);
window.sessionStorage.setItem('user_roles',JSON.stringify(res.data.roles));
this.$router.push({ path: "/nav/search" });
}
})
.catch(err => {
this.$message({
message: "登录错误",
type: "error"
});
});
}
});
},
resetForm(form) {
this.$refs[form].resetFields();
},
is_login() {}
},
mounted() {
this.form.username = localStorage.getItem("username");
}
};
</script>
<style scoped>
#login_box {
height: 100%;
}
</style>