|
1 | 1 | <template>
|
2 |
| - <a-form class="user-layout-login" ref="formLogin" :autoFormCreate="(form)=>{this.form = form}" id="formLogin"> |
3 |
| - <a-tabs |
4 |
| - :activeKey="customActiveKey" |
5 |
| - :tabBarStyle="{ textAlign: 'center', borderBottom: 'unset' }" |
6 |
| - @change="handleTabClick"> |
7 |
| - <a-tab-pane key="tab1" tab="账号密码登陆"> |
| 2 | + <div> |
| 3 | + <a-form class="user-layout-login" ref="formLogin" :autoFormCreate="(form)=>{this.form = form}" id="formLogin"> |
| 4 | + <a-tabs |
| 5 | + :activeKey="customActiveKey" |
| 6 | + :tabBarStyle="{ textAlign: 'center', borderBottom: 'unset' }" |
| 7 | + @change="handleTabClick"> |
| 8 | + <a-tab-pane key="tab1" tab="账号密码登陆"> |
8 | 9 |
|
9 |
| - <a-form-item |
10 |
| - fieldDecoratorId="username" |
11 |
| - :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入帐户名或邮箱地址' }, { validator: this.handleUsernameOrEmail }], validateTrigger: 'blur'}" |
12 |
| - > |
13 |
| - <a-input size="large" type="text" v-model="formLogin.username" placeholder="帐户名或邮箱地址 / admin"> |
14 |
| - <a-icon slot="prefix" type='user' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
15 |
| - </a-input> |
16 |
| - </a-form-item> |
| 10 | + <a-form-item |
| 11 | + fieldDecoratorId="username" |
| 12 | + :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入帐户名或邮箱地址' }, { validator: this.handleUsernameOrEmail }], validateTrigger: 'blur'}" |
| 13 | + > |
| 14 | + <a-input size="large" type="text" v-model="formLogin.username" placeholder="帐户名或邮箱地址 / admin"> |
| 15 | + <a-icon slot="prefix" type='user' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
| 16 | + </a-input> |
| 17 | + </a-form-item> |
17 | 18 |
|
18 |
| - <a-form-item |
19 |
| - fieldDecoratorId="password" |
20 |
| - :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入密码' }], validateTrigger: 'blur'}"> |
21 |
| - <a-input size="large" type="password" v-model="formLogin.password" placeholder="密码 / admin"> |
22 |
| - <a-icon slot="prefix" type='lock' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
23 |
| - </a-input> |
24 |
| - </a-form-item> |
25 |
| - </a-tab-pane> |
26 |
| - <a-tab-pane key="tab2" tab="手机号登陆"> |
27 |
| - <a-form-item |
28 |
| - fieldDecoratorId="mobile" |
29 |
| - :fieldDecoratorOptions="{rules: [{ required: true, pattern: /^1[34578]\d{9}$/, message: '请输入正确的手机号' }], validateTrigger: 'blur'}"> |
30 |
| - <a-input size="large" type="text" v-model="formLogin.mobile" placeholder="手机号"> |
31 |
| - <a-icon slot="prefix" type='mobile' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
32 |
| - </a-input> |
33 |
| - </a-form-item> |
| 19 | + <a-form-item |
| 20 | + fieldDecoratorId="password" |
| 21 | + :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入密码' }], validateTrigger: 'blur'}"> |
| 22 | + <a-input size="large" type="password" v-model="formLogin.password" placeholder="密码 / admin"> |
| 23 | + <a-icon slot="prefix" type='lock' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
| 24 | + </a-input> |
| 25 | + </a-form-item> |
| 26 | + </a-tab-pane> |
| 27 | + <a-tab-pane key="tab2" tab="手机号登陆"> |
| 28 | + <a-form-item |
| 29 | + fieldDecoratorId="mobile" |
| 30 | + :fieldDecoratorOptions="{rules: [{ required: true, pattern: /^1[34578]\d{9}$/, message: '请输入正确的手机号' }], validateTrigger: 'blur'}"> |
| 31 | + <a-input size="large" type="text" v-model="formLogin.mobile" placeholder="手机号"> |
| 32 | + <a-icon slot="prefix" type='mobile' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
| 33 | + </a-input> |
| 34 | + </a-form-item> |
34 | 35 |
|
35 |
| - <a-row :gutter="16"> |
36 |
| - <a-col class="gutter-row" :span="16"> |
37 |
| - <a-form-item |
38 |
| - fieldDecoratorId="captcha" |
39 |
| - :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入验证码' }], validateTrigger: 'blur'}"> |
40 |
| - <a-input size="large" type="text" v-model="formLogin.captcha" placeholder="验证码"> |
41 |
| - <a-icon slot="prefix" type='mail' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
42 |
| - </a-input> |
43 |
| - </a-form-item> |
44 |
| - </a-col> |
45 |
| - <a-col class="gutter-row" :span="8"> |
46 |
| - <a-button |
47 |
| - class="getCaptcha" |
48 |
| - :disabled="state.smsSendBtn" |
49 |
| - @click.stop.prevent="getCaptcha" |
50 |
| - v-text="!state.smsSendBtn&&'获取验证码'||(state.time+' s')"></a-button> |
51 |
| - </a-col> |
52 |
| - </a-row> |
53 |
| - </a-tab-pane> |
54 |
| - </a-tabs> |
| 36 | + <a-row :gutter="16"> |
| 37 | + <a-col class="gutter-row" :span="16"> |
| 38 | + <a-form-item |
| 39 | + fieldDecoratorId="captcha" |
| 40 | + :fieldDecoratorOptions="{rules: [{ required: true, message: '请输入验证码' }], validateTrigger: 'blur'}"> |
| 41 | + <a-input size="large" type="text" v-model="formLogin.captcha" placeholder="验证码"> |
| 42 | + <a-icon slot="prefix" type='mail' :style="{ color: 'rgba(0,0,0,.25)' }"/> |
| 43 | + </a-input> |
| 44 | + </a-form-item> |
| 45 | + </a-col> |
| 46 | + <a-col class="gutter-row" :span="8"> |
| 47 | + <a-button |
| 48 | + class="getCaptcha" |
| 49 | + :disabled="state.smsSendBtn" |
| 50 | + @click.stop.prevent="getCaptcha" |
| 51 | + v-text="!state.smsSendBtn&&'获取验证码'||(state.time+' s')"></a-button> |
| 52 | + </a-col> |
| 53 | + </a-row> |
| 54 | + </a-tab-pane> |
| 55 | + </a-tabs> |
55 | 56 |
|
56 |
| - <a-form-item> |
57 |
| - <a-checkbox v-model="formLogin.rememberMe">自动登陆</a-checkbox> |
58 |
| - <router-link :to="{ name: 'recover', params: { user: 'aaa'} }" class="forge-password" style="float: right;"> |
59 |
| - 忘记密码 |
60 |
| - </router-link> |
61 |
| - </a-form-item> |
| 57 | + <a-form-item> |
| 58 | + <a-checkbox v-model="formLogin.rememberMe">自动登陆</a-checkbox> |
| 59 | + <router-link :to="{ name: 'recover', params: { user: 'aaa'} }" class="forge-password" style="float: right;"> |
| 60 | + 忘记密码 |
| 61 | + </router-link> |
| 62 | + </a-form-item> |
62 | 63 |
|
63 |
| - <a-form-item style="margin-top:24px"> |
64 |
| - <a-button |
65 |
| - size="large" |
66 |
| - type="primary" |
67 |
| - htmlType="submit" |
68 |
| - class="login-button" |
69 |
| - :loading="loginBtn" |
70 |
| - @click.stop.prevent="handleSubmit" |
71 |
| - :disabled="loginBtn">确定 |
72 |
| - </a-button> |
73 |
| - </a-form-item> |
| 64 | + <a-form-item style="margin-top:24px"> |
| 65 | + <a-button |
| 66 | + size="large" |
| 67 | + type="primary" |
| 68 | + htmlType="submit" |
| 69 | + class="login-button" |
| 70 | + :loading="loginBtn" |
| 71 | + @click.stop.prevent="handleSubmit" |
| 72 | + :disabled="loginBtn">确定 |
| 73 | + </a-button> |
| 74 | + </a-form-item> |
74 | 75 |
|
75 |
| - <div class="user-login-other"> |
76 |
| - <span>其他登陆方式</span> |
77 |
| - <a><a-icon class="item-icon" type="alipay-circle"></a-icon></a> |
78 |
| - <a><a-icon class="item-icon" type="taobao-circle"></a-icon></a> |
79 |
| - <a><a-icon class="item-icon" type="weibo-circle"></a-icon></a> |
80 |
| - <router-link class="register" :to="{ name: 'register' }"> |
81 |
| - 注册账户 |
82 |
| - </router-link> |
83 |
| - </div> |
| 76 | + <div class="user-login-other"> |
| 77 | + <span>其他登陆方式</span> |
| 78 | + <a><a-icon class="item-icon" type="alipay-circle"></a-icon></a> |
| 79 | + <a><a-icon class="item-icon" type="taobao-circle"></a-icon></a> |
| 80 | + <a><a-icon class="item-icon" type="weibo-circle"></a-icon></a> |
| 81 | + <router-link class="register" :to="{ name: 'register' }"> |
| 82 | + 注册账户 |
| 83 | + </router-link> |
| 84 | + </div> |
| 85 | + </a-form> |
84 | 86 |
|
85 |
| - </a-form> |
| 87 | + <two-step-captcha v-if="requiredTwoStepCaptcha" :visible="stepCaptchaVisible" @success="stepCaptchaSuccess"></two-step-captcha> |
| 88 | + </div> |
86 | 89 | </template>
|
87 | 90 |
|
88 | 91 | <script>
|
89 | 92 | import md5 from "md5"
|
90 | 93 | import api from '@/api/'
|
| 94 | + import TwoStepCaptcha from '@/components/tools/TwoStepCaptcha' |
91 | 95 | import { mapActions } from "vuex"
|
92 | 96 | import { timeFix } from "@/utils/util"
|
93 | 97 |
|
94 | 98 | export default {
|
| 99 | + components: { |
| 100 | + TwoStepCaptcha |
| 101 | + }, |
95 | 102 | data () {
|
96 | 103 | return {
|
97 | 104 | customActiveKey: "tab1",
|
98 | 105 | loginBtn: false,
|
99 | 106 | // login type: 0 email, 1 username, 2 telephone
|
100 | 107 | loginType: 0,
|
| 108 | + requiredTwoStepCaptcha: true, |
| 109 | + stepCaptchaVisible: false, |
101 | 110 | form: null,
|
102 | 111 | state: {
|
103 | 112 | time: 60,
|
|
112 | 121 | },
|
113 | 122 | }
|
114 | 123 | },
|
| 124 | + created () { |
| 125 | + /* |
| 126 | + this.$http.get('/auth/2step-code') |
| 127 | + .then(res => { |
| 128 | + this.requiredTwoStepCaptcha = res.result |
| 129 | + }).catch(err => { |
| 130 | + console.log('2step-code:', err) |
| 131 | + }) |
| 132 | + */ |
| 133 | + this.requiredTwoStepCaptcha = true |
| 134 | + |
| 135 | + }, |
115 | 136 | methods: {
|
116 | 137 | ...mapActions([ "Login" ]),
|
117 | 138 | // handler
|
|
171 | 192 | }
|
172 | 193 |
|
173 | 194 | that.Login(loginParams).then(() => {
|
174 |
| - that.loginBtn = false |
175 |
| - that.$router.push({ name: "dashboard" }) |
176 |
| - that.$message.success(timeFix() + ',欢迎回来', 3) |
| 195 | + if (that.requiredTwoStepCaptcha) { |
| 196 | + that.stepCaptchaVisible = true |
| 197 | + } else { |
| 198 | + that.loginSuccess() |
| 199 | + } |
177 | 200 | }).catch((err) => {
|
178 | 201 | that.requestFailed(err);
|
179 | 202 | })
|
|
217 | 240 | }
|
218 | 241 | );
|
219 | 242 | },
|
| 243 | + stepCaptchaSuccess () { |
| 244 | + this.loginSuccess() |
| 245 | + }, |
| 246 | + loginSuccess () { |
| 247 | + this.loginBtn = false |
| 248 | + this.$router.push({ name: "dashboard" }) |
| 249 | + this.$message.success(timeFix() + ',欢迎回来', 3) |
| 250 | + }, |
220 | 251 | requestFailed (err) {
|
221 | 252 | this.$notification[ 'error' ]({
|
222 | 253 | message: '错误',
|
|
0 commit comments