index.vue
3.5 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script>
export default {
name: "Login",
data: function () {
return {
loginForm: {
account: "",
password: "",
hospitalname:"",
},
loginRules: {
account: [
{
required: true,
trigger: "blur",
message: this.$t("login.accountTip"),
},
],
password: [
{
required: true,
trigger: "blur",
message: this.$t("login.passwordTip"),
},
],
},
capsTooltip: false,
loading: false,
showDialog: false,
redirect: undefined,
otherQuery: {},
};
},
computed: {
loginLoading() {
return this.$store.state.user.loginLoading;
},
},
watch: {
loginLoading(val) {
if (!val) this.loading = false;
},
$route: {
handler: function (route) {
const query = route.query;
if (query) {
this.redirect = query.redirect;
// this.otherQuery = this.getOtherQuery(query)
}
},
immediate: true,
},
},
created() {
const _this = this;
// const _this = this;
// document.onkeydown = function (e) {
// const { keyCode } = e;
// if (keyCode === 13) {
// _this.handleLogin();
// }
// };
},
mounted() {
this.handlemyLogin();
// if (this.loginForm.account == "") {
// this.$refs.account.focus();
// } else if (this.loginForm.password == "") {
// this.$refs.password.focus();
// }
// this.$store.commit("user/SET_LOGIN_LOADING", false);
},
destroyed() {
document.onkeydown = function (e) {
const { keyCode } = e;
if (keyCode === 13) {
}
};
},
methods: {
checkCapslock(e) {
const { key } = e;
this.capsTooltip = key && key.length === 1 && key >= "A" && key <= "Z";
},
handleLogin() {
if (this.loading) return;
this.$refs.loginForm.validate((valid) => {
if (valid) {
this.loading = true;
this.$store.commit("user/SET_LOGIN_LOADING", true);
this.$store
.dispatch("user/login", this.loginForm)
.then(() => {
this.$router.push({
path: this.redirect || "/home",
query: this.otherQuery,
});
})
.catch(() => {
this.$store.commit("user/SET_LOGIN_LOADING", false);
});
} else {
return false;
}
});
},
handlemyLogin() {
//this.$store.dispatch('user/logout')
console.log("开始执行单点登录!");
if (this.loading) return;
let username = this.$route.query.username;
let hospitalname=this.$route.query.hospitalname;
console.log("username:"+username);
if (username != null && username != "") {
this.loginForm.account = username;
this.loginForm.hospitalname =hospitalname;
this.loading = true;
this.$store.commit("user/SET_LOGIN_LOADING", true);
this.$store
.dispatch("user/pislogin", this.loginForm)
.then(() => {
this.$router.push({
path: this.redirect || "/home",
query: this.otherQuery,
});
})
.catch(() => {
this.$store.commit("user/SET_LOGIN_LOADING", false);
});
}
},
},
getOtherQuery(query) {
return Object.keys(query).reduce((acc, cur) => {
if (cur !== "redirect") {
acc[cur] = query[cur];
}
return acc;
}, {});
},
};
</script>