|
|
|
@ -2,16 +2,14 @@
|
|
|
|
|
<view class="register absolute"> |
|
|
|
|
<view class="whiteBg" v-if="formItem === 1"> |
|
|
|
|
<view class="title acea-row"> |
|
|
|
|
<view class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList" |
|
|
|
|
@click="navTap(index)" :key="index">{{ item }}</view> |
|
|
|
|
<view class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList" @click="navTap(index)" :key="index">{{ item }}</view> |
|
|
|
|
</view> |
|
|
|
|
<!-- 手机号登录 --> |
|
|
|
|
<view class="list" :hidden="current !== 0"> |
|
|
|
|
<form @submit.prevent="submit"> |
|
|
|
|
<view class="item getPhoneCode"> |
|
|
|
|
<view class="phoneInput acea-row row-between-wrapper"> |
|
|
|
|
<input type="text" placeholder="输入手机号码" |
|
|
|
|
v-model="account" required/> |
|
|
|
|
<input type="text" placeholder="输入手机号码" v-model="account" required /> |
|
|
|
|
</view> |
|
|
|
|
<view class="phoneCode" @click="sendCode"> |
|
|
|
|
{{ clockText }} |
|
|
|
@ -72,8 +70,7 @@
|
|
|
|
|
<use xlink:href="#icon-code_1" /> |
|
|
|
|
</svg>--> |
|
|
|
|
<input name="verifyCode" type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" /> |
|
|
|
|
<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" |
|
|
|
|
@click="code">{{ text }}</button> |
|
|
|
|
<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">{{ text }}</button> |
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
<view class="item"> |
|
|
|
@ -94,7 +91,6 @@
|
|
|
|
|
</view> |
|
|
|
|
</view> |
|
|
|
|
<!-- #endif --> |
|
|
|
|
|
|
|
|
|
</view> |
|
|
|
|
<view class="logon" @click="register">注册</view> |
|
|
|
|
<view class="tip"> |
|
|
|
@ -105,90 +101,69 @@
|
|
|
|
|
</view> |
|
|
|
|
</template> |
|
|
|
|
<script> |
|
|
|
|
import sendVerifyCode from "@/mixins/SendVerifyCode"; |
|
|
|
|
import { |
|
|
|
|
login, |
|
|
|
|
loginMobile, |
|
|
|
|
registerVerify, |
|
|
|
|
register |
|
|
|
|
} from "@/api/user"; |
|
|
|
|
import attrs, { |
|
|
|
|
required, |
|
|
|
|
alpha_num, |
|
|
|
|
chs_phone |
|
|
|
|
} from "@/utils/validate"; |
|
|
|
|
import { |
|
|
|
|
validatorDefaultCatch |
|
|
|
|
} from "@/utils/dialog"; |
|
|
|
|
import dayjs from "dayjs"; |
|
|
|
|
import cookie from "@/utils/store/cookie"; |
|
|
|
|
import sendVerifyCode from '@/mixins/SendVerifyCode' |
|
|
|
|
import { login, loginMobile, registerVerify, register } from '@/api/user' |
|
|
|
|
import attrs, { required, alpha_num, chs_phone } from '@/utils/validate' |
|
|
|
|
import { validatorDefaultCatch } from '@/utils/dialog' |
|
|
|
|
import dayjs from 'dayjs' |
|
|
|
|
import cookie from '@/utils/store/cookie' |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
handleGetUserInfo |
|
|
|
|
} from "@/utils"; |
|
|
|
|
import { handleGetUserInfo } from '@/utils' |
|
|
|
|
|
|
|
|
|
const BACK_URL = "login_back_url"; |
|
|
|
|
const BACK_URL = 'login_back_url' |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
name: "Login", |
|
|
|
|
export default { |
|
|
|
|
name: 'Login', |
|
|
|
|
mixins: [sendVerifyCode], |
|
|
|
|
data: function () { |
|
|
|
|
data: function() { |
|
|
|
|
return { |
|
|
|
|
navList: ["手机号登录", "密码登录"], |
|
|
|
|
navList: ['手机号登录', '密码登录'], |
|
|
|
|
// navList: ["手机号登录",], |
|
|
|
|
current: 0, |
|
|
|
|
account: "", |
|
|
|
|
password: "", |
|
|
|
|
captcha: "", |
|
|
|
|
inviteCode: "", |
|
|
|
|
account: '', |
|
|
|
|
password: '', |
|
|
|
|
captcha: '', |
|
|
|
|
inviteCode: '', |
|
|
|
|
formItem: 1, |
|
|
|
|
type: "login", |
|
|
|
|
type: 'login', |
|
|
|
|
timer: null, |
|
|
|
|
clock: 60, |
|
|
|
|
clockText: '验证码' |
|
|
|
|
}; |
|
|
|
|
clockText: '验证码', |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
async loginMobile() { |
|
|
|
|
var that = this; |
|
|
|
|
const { |
|
|
|
|
account, |
|
|
|
|
captcha |
|
|
|
|
} = that; |
|
|
|
|
var that = this |
|
|
|
|
const { account, captcha } = that |
|
|
|
|
try { |
|
|
|
|
await that |
|
|
|
|
.$validator({ |
|
|
|
|
account: [ |
|
|
|
|
required(required.message("手机号码")), |
|
|
|
|
chs_phone(chs_phone.message()) |
|
|
|
|
], |
|
|
|
|
captcha: [ |
|
|
|
|
required(required.message("验证码")), |
|
|
|
|
alpha_num(alpha_num.message("验证码")) |
|
|
|
|
] |
|
|
|
|
account: [required(required.message('手机号码')), chs_phone(chs_phone.message())], |
|
|
|
|
captcha: [required(required.message('验证码')), alpha_num(alpha_num.message('验证码'))], |
|
|
|
|
}) |
|
|
|
|
.validate({ |
|
|
|
|
account, |
|
|
|
|
captcha |
|
|
|
|
}); |
|
|
|
|
captcha, |
|
|
|
|
}) |
|
|
|
|
} catch (e) { |
|
|
|
|
return validatorDefaultCatch(e); |
|
|
|
|
return validatorDefaultCatch(e) |
|
|
|
|
} |
|
|
|
|
const res = await loginMobile({ |
|
|
|
|
loginMobile({ |
|
|
|
|
account: that.account, |
|
|
|
|
captcha: that.captcha, |
|
|
|
|
spread: cookie.get("spread") |
|
|
|
|
spread: cookie.get('spread'), |
|
|
|
|
}) |
|
|
|
|
if (res.status === 200) { |
|
|
|
|
this.$store.commit("login", res.data.token, dayjs(res.data.expires_time)); |
|
|
|
|
handleGetUserInfo(); |
|
|
|
|
} else { |
|
|
|
|
.then(res => { |
|
|
|
|
this.$store.commit('login', res.data.token, dayjs(res.data.expires_time)) |
|
|
|
|
handleGetUserInfo() |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: res.msg || res.response.data.msg || err.response.data.message, |
|
|
|
|
icon: "none", |
|
|
|
|
duration: 2000 |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
icon: 'none', |
|
|
|
|
duration: 2000, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
// .then(res => { |
|
|
|
|
// that.$store.commit("login", res.data.token, dayjs(res.data.expires_time)); |
|
|
|
|
// handleGetUserInfo(); |
|
|
|
@ -203,100 +178,72 @@
|
|
|
|
|
// }); |
|
|
|
|
}, |
|
|
|
|
async register() { |
|
|
|
|
var that = this; |
|
|
|
|
const { |
|
|
|
|
account, |
|
|
|
|
captcha, |
|
|
|
|
password |
|
|
|
|
} = that; |
|
|
|
|
var that = this |
|
|
|
|
const { account, captcha, password } = that |
|
|
|
|
try { |
|
|
|
|
await that |
|
|
|
|
.$validator({ |
|
|
|
|
account: [ |
|
|
|
|
required(required.message("手机号码")), |
|
|
|
|
chs_phone(chs_phone.message()) |
|
|
|
|
], |
|
|
|
|
captcha: [ |
|
|
|
|
required(required.message("验证码")), |
|
|
|
|
alpha_num(alpha_num.message("验证码")) |
|
|
|
|
], |
|
|
|
|
password: [ |
|
|
|
|
required(required.message("密码")), |
|
|
|
|
attrs.range([6, 16], attrs.range.message("密码")), |
|
|
|
|
alpha_num(alpha_num.message("密码")) |
|
|
|
|
] |
|
|
|
|
account: [required(required.message('手机号码')), chs_phone(chs_phone.message())], |
|
|
|
|
captcha: [required(required.message('验证码')), alpha_num(alpha_num.message('验证码'))], |
|
|
|
|
password: [required(required.message('密码')), attrs.range([6, 16], attrs.range.message('密码')), alpha_num(alpha_num.message('密码'))], |
|
|
|
|
}) |
|
|
|
|
.validate({ |
|
|
|
|
account, |
|
|
|
|
captcha, |
|
|
|
|
password |
|
|
|
|
}); |
|
|
|
|
password, |
|
|
|
|
}) |
|
|
|
|
} catch (e) { |
|
|
|
|
return validatorDefaultCatch(e); |
|
|
|
|
return validatorDefaultCatch(e) |
|
|
|
|
} |
|
|
|
|
register({ |
|
|
|
|
account: that.account, |
|
|
|
|
captcha: that.captcha, |
|
|
|
|
password: that.password, |
|
|
|
|
inviteCode: that.inviteCode, |
|
|
|
|
spread: cookie.get("spread") |
|
|
|
|
spread: cookie.get('spread'), |
|
|
|
|
}) |
|
|
|
|
.then(res => { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: res.msg, |
|
|
|
|
icon: "success", |
|
|
|
|
duration: 2000 |
|
|
|
|
}); |
|
|
|
|
that.formItem = 1; |
|
|
|
|
icon: 'success', |
|
|
|
|
duration: 2000, |
|
|
|
|
}) |
|
|
|
|
that.formItem = 1 |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: err.msg || err.response.data.msg || err.response.data.message, |
|
|
|
|
icon: "none", |
|
|
|
|
duration: 2000 |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
icon: 'none', |
|
|
|
|
duration: 2000, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
// 获取验证码 |
|
|
|
|
async code() { |
|
|
|
|
const { |
|
|
|
|
account |
|
|
|
|
} = this; |
|
|
|
|
const { account } = this |
|
|
|
|
try { |
|
|
|
|
await this |
|
|
|
|
.$validator({ |
|
|
|
|
account: [ |
|
|
|
|
required(required.message("手机号码")), |
|
|
|
|
chs_phone(chs_phone.message()) |
|
|
|
|
] |
|
|
|
|
await this.$validator({ |
|
|
|
|
account: [required(required.message('手机号码')), chs_phone(chs_phone.message())], |
|
|
|
|
}).validate({ |
|
|
|
|
account, |
|
|
|
|
}) |
|
|
|
|
.validate({ |
|
|
|
|
account |
|
|
|
|
}); |
|
|
|
|
} catch (e) { |
|
|
|
|
return validatorDefaultCatch(e); |
|
|
|
|
return validatorDefaultCatch(e) |
|
|
|
|
} |
|
|
|
|
if (this.formItem == 2) this.type = "register"; |
|
|
|
|
if (this.formItem == 2) this.type = 'register' |
|
|
|
|
this.showCode() |
|
|
|
|
}, |
|
|
|
|
// 手机号登录获取验证码 |
|
|
|
|
async sendCode () { |
|
|
|
|
const { |
|
|
|
|
account |
|
|
|
|
} = this; |
|
|
|
|
async sendCode() { |
|
|
|
|
const { account } = this |
|
|
|
|
try { |
|
|
|
|
await this |
|
|
|
|
.$validator({ |
|
|
|
|
account: [ |
|
|
|
|
required(required.message("手机号码")), |
|
|
|
|
chs_phone(chs_phone.message()) |
|
|
|
|
] |
|
|
|
|
await this.$validator({ |
|
|
|
|
account: [required(required.message('手机号码')), chs_phone(chs_phone.message())], |
|
|
|
|
}).validate({ |
|
|
|
|
account, |
|
|
|
|
}) |
|
|
|
|
.validate({ |
|
|
|
|
account |
|
|
|
|
}); |
|
|
|
|
} catch (e) { |
|
|
|
|
return validatorDefaultCatch(e); |
|
|
|
|
return validatorDefaultCatch(e) |
|
|
|
|
} |
|
|
|
|
// 倒计时 |
|
|
|
|
if (this.clock !== 60) { |
|
|
|
@ -321,87 +268,79 @@
|
|
|
|
|
showCode() { |
|
|
|
|
return registerVerify({ |
|
|
|
|
phone: this.account, |
|
|
|
|
type: this.type |
|
|
|
|
type: this.type, |
|
|
|
|
}) |
|
|
|
|
.then(res => { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: res.msg, |
|
|
|
|
icon: "success", |
|
|
|
|
duration: 2000 |
|
|
|
|
}); |
|
|
|
|
this.sendCode(); |
|
|
|
|
icon: 'success', |
|
|
|
|
duration: 2000, |
|
|
|
|
}) |
|
|
|
|
this.sendCode() |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: err.msg || err.response.data.msg || err.response.data.message, |
|
|
|
|
icon: "none", |
|
|
|
|
duration: 2000 |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
icon: 'none', |
|
|
|
|
duration: 2000, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
navTap(index) { |
|
|
|
|
this.current = index |
|
|
|
|
}, |
|
|
|
|
navTap(index) { this.current = index; }, |
|
|
|
|
async submit() { |
|
|
|
|
const { |
|
|
|
|
account, |
|
|
|
|
password |
|
|
|
|
} = this; |
|
|
|
|
const { account, password } = this |
|
|
|
|
try { |
|
|
|
|
await this.$validator({ |
|
|
|
|
account: [ |
|
|
|
|
required(required.message("账号")), |
|
|
|
|
attrs.range([5, 16], attrs.range.message("账号")), |
|
|
|
|
alpha_num(alpha_num.message("账号")) |
|
|
|
|
], |
|
|
|
|
password: [ |
|
|
|
|
required(required.message("密码")), |
|
|
|
|
attrs.range([6, 16], attrs.range.message("密码")), |
|
|
|
|
alpha_num(alpha_num.message("密码")) |
|
|
|
|
] |
|
|
|
|
account: [required(required.message('账号')), attrs.range([5, 16], attrs.range.message('账号')), alpha_num(alpha_num.message('账号'))], |
|
|
|
|
password: [required(required.message('密码')), attrs.range([6, 16], attrs.range.message('密码')), alpha_num(alpha_num.message('密码'))], |
|
|
|
|
}).validate({ |
|
|
|
|
account, |
|
|
|
|
password |
|
|
|
|
}); |
|
|
|
|
password, |
|
|
|
|
}) |
|
|
|
|
} catch (e) { |
|
|
|
|
return validatorDefaultCatch(e); |
|
|
|
|
return validatorDefaultCatch(e) |
|
|
|
|
} |
|
|
|
|
// 账号密码登录 |
|
|
|
|
const res = await login({ |
|
|
|
|
|
|
|
|
|
login({ |
|
|
|
|
username: account, |
|
|
|
|
password, |
|
|
|
|
spread: cookie.get("spread") |
|
|
|
|
spread: cookie.get('spread'), |
|
|
|
|
}) |
|
|
|
|
if (res.status === 200) { |
|
|
|
|
this.$store.commit("login", res.data.token, dayjs(res.data.expires_time)); |
|
|
|
|
handleGetUserInfo(); |
|
|
|
|
} else { |
|
|
|
|
.then(res => { |
|
|
|
|
this.$store.commit('login', res.data.token, dayjs(res.data.expires_time)) |
|
|
|
|
handleGetUserInfo() |
|
|
|
|
}) |
|
|
|
|
.catch(err => { |
|
|
|
|
uni.showToast({ |
|
|
|
|
title: res.msg || res.response.data.msg || err.response.data.message, |
|
|
|
|
icon: "none", |
|
|
|
|
duration: 2000 |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
title: err.msg || err.response.data.msg || err.response.data.message, |
|
|
|
|
icon: 'none', |
|
|
|
|
duration: 2000, |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<style lang="scss"> |
|
|
|
|
.register .whiteBg .title .item{ |
|
|
|
|
.register .whiteBg .title .item { |
|
|
|
|
border-bottom: 2px solid; |
|
|
|
|
} |
|
|
|
|
.register .whiteBg .title .item.on{ |
|
|
|
|
.register .whiteBg .title .item.on { |
|
|
|
|
border-bottom-color: #f35749; |
|
|
|
|
} |
|
|
|
|
.getPhoneCode{ |
|
|
|
|
.getPhoneCode { |
|
|
|
|
display: flex; |
|
|
|
|
justify-content: space-between; |
|
|
|
|
.phoneInput{ |
|
|
|
|
.phoneInput { |
|
|
|
|
width: 70%; |
|
|
|
|
} |
|
|
|
|
.phoneCode{ |
|
|
|
|
.phoneCode { |
|
|
|
|
width: 30%; |
|
|
|
|
text-align: center; |
|
|
|
|
color: #FFFFFF; |
|
|
|
|
color: #ffffff; |
|
|
|
|
background-color: #f35749; |
|
|
|
|
padding: 12rpx; |
|
|
|
|
font-size: 28rpx; |
|
|
|
|