5
5
使用 Codeforces 账号登录
6
6
</h1 >
7
7
<p >
8
- <el-input placeholder =" 请输入邮箱" v-model =" email" style =" width : 300px " ></el-input >
8
+ <el-input placeholder =" 请输入邮箱" v-model =" email" :disabled = " loading " style =" width : 300px " ></el-input >
9
9
</p >
10
10
<p >
11
- <el-input placeholder =" 请输入密码" v-model =" password" style =" width : 300px " show-password ></el-input >
11
+ <el-input placeholder =" 请输入密码" v-model =" password" :disabled =" loading" style =" width : 300px "
12
+ show-password ></el-input >
12
13
</p >
13
14
<el-button type =" primary" v-on:click =" login()" style =" width : 250px " :loading =" loading" round >登录</el-button >
14
15
</div >
23
24
</template >
24
25
25
26
<script >
27
+ let common = require (' ../static/crawler/common' )
26
28
27
- let common = require (' ../static/crawler/common' )
29
+ export default {
30
+ name: " Login" ,
28
31
29
- export default {
30
- name: " Login" ,
31
-
32
- created () {
33
- if (this .user === ' ' ) {
34
- if (window .localStorage .email )
35
- this .email = window .localStorage .email ;
36
- if (window .localStorage .password )
37
- this .password = window .localStorage .password ;
38
- }
39
- },
32
+ created () {
33
+ if (this .user === ' ' ) {
34
+ if (window .localStorage .email )
35
+ this .email = window .localStorage .email ;
36
+ if (window .localStorage .password )
37
+ this .password = window .localStorage .password ;
38
+ }
39
+ },
40
40
41
- props: {
42
- user: String ,
43
- logout: String
44
- },
41
+ props: {
42
+ user: String ,
43
+ logout: String
44
+ },
45
45
46
- data () {
47
- return {
48
- loading: false ,
49
- email: ' ' ,
50
- password: ' '
51
- }
52
- },
46
+ data () {
47
+ return {
48
+ loading: false ,
49
+ email: ' ' ,
50
+ password: ' '
51
+ }
52
+ },
53
53
54
- methods: {
55
- login () {
56
- this .loading = true
57
- // let loading = this.$loading({
58
- // lock: true,
59
- // text: '正在登录',
60
- // background: 'rgba(0, 0, 0, 0.7)'
61
- // })
54
+ methods: {
55
+ login () {
56
+ // let loading = this.$loading({
57
+ // lock: true,
58
+ // text: '正在登录',
59
+ // background: 'rgba(0, 0, 0, 0.7)'
60
+ // })
61
+ this .loading = true
62
+ common .getXCsrfToken ((e , x ) => {
63
+ common .getLoginCookie (x, this .email , this .password , (e , u ) => {
64
+ // loading.close()
65
+ this .loading = false
66
+ if (e) {
67
+ this .$message .error (' 登录出错,请重试' )
68
+ } else {
69
+ if (u[0 ].match (/ \/ enter/ ) == null ) {
70
+ this .user = u[1 ]
71
+ this .logout = u[2 ]
72
+ this .$message .success (' 登录成功' )
73
+ this .$emit (' login' , {user: this .user , logout: this .logout })
74
+ } else {
75
+ this .$message .error (' 登录出错,请重试,也可能是账号密码出错' )
76
+ }
77
+ window .localStorage .email = this .email
78
+ window .localStorage .password = this .password
79
+ }
80
+ })
81
+ })
82
+ },
62
83
63
- common .getXCsrfToken ((e , x ) => {
64
- common .getLoginCookie (x, this .email , this .password , (e , u ) => {
84
+ toLogout () {
85
+ // let loading = this.$loading({
86
+ // lock: true,
87
+ // text: '正在退出登录',
88
+ // background: 'rgba(0, 0, 0, 0.7)'
89
+ // })
90
+ this .loading = true
91
+ common .logout (this .logout , (e ) => {
65
92
// loading.close()
66
93
this .loading = false
67
94
if (e) {
68
- this .$message .error (' 登录出错 ,请重试' )
95
+ this .$message .error (' 退出登录出错 ,请重试' )
69
96
} else {
70
- if (u[0 ] !== ' /enter?back=%2F' ) {
71
- this .user = u[1 ]
72
- this .logout = u[2 ]
73
- } else {
74
- this .$message .error (' 登录出错,请重试' )
75
- }
76
- window .localStorage .email = this .email
77
- window .localStorage .password = this .password
78
- this .$message .success (' 登录成功' )
97
+ this .$message .success (' 退出登录成功' )
98
+ this .user = ' '
99
+ this .logout = ' '
79
100
this .$emit (' login' , {user: this .user , logout: this .logout })
80
101
}
81
102
})
82
- })
83
- },
84
-
85
- toLogout () {
86
- // let loading = this.$loading({
87
- // lock: true,
88
- // text: '正在退出登录',
89
- // background: 'rgba(0, 0, 0, 0.7)'
90
- // })
91
- common .logout (this .logout , (e ) => {
92
- // loading.close()
93
- this .loading = false
94
- if (e) {
95
- this .$message .error (' 退出登录出错,请重试' )
96
- } else {
97
- this .$message .success (' 退出登录成功' )
98
- this .user = ' '
99
- this .logout = ' '
100
- this .$emit (' login' , {user: this .user , logout: this .logout })
101
- }
102
- })
103
+ }
103
104
}
104
105
}
105
- }
106
106
107
107
</script >
108
108
109
109
<style scoped>
110
- .inline-div {
111
- margin-top : 100px ;
112
- }
110
+ .inline-div {
111
+ margin-top : 100px ;
112
+ }
113
113
</style >
0 commit comments