Skip to content

Commit 3c1ba24

Browse files
committed
fix: login
1 parent e60479e commit 3c1ba24

File tree

1 file changed

+16
-27
lines changed

1 file changed

+16
-27
lines changed

src/views/Login.vue

+16-27
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
fieldDecoratorId="username"
1212
:fieldDecoratorOptions="{rules: [{ required: true, message: '请输入帐户名或邮箱地址' }, { validator: this.handleUsernameOrEmail }], validateTrigger: 'blur'}"
1313
>
14-
<a-input size="large" type="text" v-model="formLogin.username" placeholder="帐户名或邮箱地址 / admin">
14+
<a-input size="large" type="text" placeholder="帐户名或邮箱地址 / admin">
1515
<a-icon slot="prefix" type='user' :style="{ color: 'rgba(0,0,0,.25)' }"/>
1616
</a-input>
1717
</a-form-item>
1818

1919
<a-form-item
2020
fieldDecoratorId="password"
2121
:fieldDecoratorOptions="{rules: [{ required: true, message: '请输入密码' }], validateTrigger: 'blur'}">
22-
<a-input size="large" type="password" v-model="formLogin.password" placeholder="密码 / admin">
22+
<a-input size="large" type="password" placeholder="密码 / admin">
2323
<a-icon slot="prefix" type='lock' :style="{ color: 'rgba(0,0,0,.25)' }"/>
2424
</a-input>
2525
</a-form-item>
@@ -28,7 +28,7 @@
2828
<a-form-item
2929
fieldDecoratorId="mobile"
3030
:fieldDecoratorOptions="{rules: [{ required: true, pattern: /^1[34578]\d{9}$/, message: '请输入正确的手机号' }], validateTrigger: 'blur'}">
31-
<a-input size="large" type="text" v-model="formLogin.mobile" placeholder="手机号">
31+
<a-input size="large" type="text" placeholder="手机号">
3232
<a-icon slot="prefix" type='mobile' :style="{ color: 'rgba(0,0,0,.25)' }"/>
3333
</a-input>
3434
</a-form-item>
@@ -38,7 +38,7 @@
3838
<a-form-item
3939
fieldDecoratorId="captcha"
4040
:fieldDecoratorOptions="{rules: [{ required: true, message: '请输入验证码' }], validateTrigger: 'blur'}">
41-
<a-input size="large" type="text" v-model="formLogin.captcha" placeholder="验证码">
41+
<a-input size="large" type="text" placeholder="验证码">
4242
<a-icon slot="prefix" type='mail' :style="{ color: 'rgba(0,0,0,.25)' }"/>
4343
</a-input>
4444
</a-form-item>
@@ -48,7 +48,7 @@
4848
class="getCaptcha"
4949
:disabled="state.smsSendBtn"
5050
@click.stop.prevent="getCaptcha"
51-
v-text="!state.smsSendBtn&&'获取验证码'||(state.time+' s')"></a-button>
51+
v-text="!state.smsSendBtn && '获取验证码' || (state.time+' s')"></a-button>
5252
</a-col>
5353
</a-row>
5454
</a-tab-pane>
@@ -153,17 +153,25 @@
153153
let that = this
154154
let flag = false
155155
156+
let loginParams = {
157+
remember_me: that.formLogin.rememberMe
158+
};
159+
160+
// 使用账户密码登陆
156161
if (that.customActiveKey === 'tab1') {
157-
that.form.validateFields([ 'username', 'password' ], { force: true }, (err) => {
162+
that.form.validateFields([ 'username', 'password' ], { force: true }, (err, values) => {
158163
if (!err) {
159164
flag = true
165+
loginParams[!that.loginType ? 'email' : 'username'] = values.username
166+
loginParams.password = md5(values.password)
160167
}
161168
})
169+
// 使用手机号登陆
162170
} else {
163-
that.form.validateFields([ 'mobile', 'captcha' ], { force: true }, (err) => {
171+
that.form.validateFields([ 'mobile', 'captcha' ], { force: true }, (err, values) => {
164172
if (!err) {
165173
flag = true
166-
that.loginType = 2 // 登录类型修改为手机登录
174+
loginParams = Object.assign(loginParams, values)
167175
}
168176
})
169177
}
@@ -172,25 +180,6 @@
172180
173181
that.loginBtn = true
174182
175-
let loginParams = {
176-
password: md5(that.formLogin.password),
177-
remember_me: that.formLogin.rememberMe
178-
};
179-
180-
switch (that.loginType) {
181-
case 0:
182-
loginParams.email = that.formLogin.username
183-
break;
184-
case 1:
185-
loginParams.username = that.formLogin.username
186-
break;
187-
case 2:
188-
default:
189-
loginParams.mobile = that.formLogin.mobile
190-
loginParams.captcha = that.formLogin.captcha
191-
break;
192-
}
193-
194183
that.Login(loginParams).then(() => {
195184
if (that.requiredTwoStepCaptcha) {
196185
that.stepCaptchaVisible = true

0 commit comments

Comments
 (0)