123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- <template>
- <div class="wrapper">
- <img
- class="logo"
- src="./image/logo@2x.png" alt="">
- <ul class="form-wrap">
- <li>
- <label>
- <span
- v-for="(str, index) in '+86'"
- :key="index">{{ str }}</span>
- </label>
- <div class="value-wrap">
- <input
- type="tel"
- placeholder="请输入手机号码"
- v-myBlur
- v-model.trim="postData.phone"
- @input="funLimitLength">
- </div>
- </li>
- <li>
- <div class="value-wrap">
- <input
- type="tel"
- placeholder="请输入短信验证码"
- v-myBlur
- v-model.trim="postData.code"
- @input="funLimitLength">
- </div>
- <button
- class="get-code"
- @click="funGetCode">{{[0, 60].includes(numCount) ? '获取验证码' : numCount + '秒'}}
- </button>
- </li>
- </ul>
- <button
- class="submit"
- @click="funSubmit">登 录
- </button>
- <div class="footer">
- <van-checkbox
- v-model="checked"
- checked-color="#D32323"></van-checkbox>
- <p class="tip-text">
- <span
- class="label"
- v-for="(str, index) in '登录听邦即代表您已同意'"
- :key="'a' + index">{{ str }}</span>
- <span
- class="value"
- v-for="(str, index) in '《用户协议》'"
- :key="'b' + index">{{ str }}</span>
- <span
- class="label">与</span>
- <span
- class="value"
- v-for="(str, index) in '《隐私协议》'"
- :key="'c' + index">{{ str }}</span>
- </p>
- </div>
- </div>
- </template>
- <script>
- import { Toast, Checkbox } from 'vant'
- import { sendSMS } from '../api/common'
- import { login } from './api'
- import { isMobile, isSmscode } from '../utils/validate'
- import { clearLoginInfo } from '../utils'
- export default {
- name: 'login',
- components: {
- 'van-checkbox': Checkbox
- },
- data () {
- return {
- postData: {
- phone: '',
- code: ''
- },
- numCount: 60,
- timer: null,
- arrErrorList: [],
- checked: false
- }
- },
- async mounted () {
- await this.$nextTick()
- },
- methods: {
- funLimitLength () {
- const { phone, code } = this.postData
- this.postData.phone = phone.length > 11 ? phone.slice(0, 11) : phone
- this.postData.code = code.length > 6 ? code.slice(0, 6) : code
- },
- funCutDown () {
- clearInterval(this.timer)
- this.timer = setInterval(() => {
- if (this.numCount === 0) {
- clearInterval(this.timer)
- this.numCount = 0
- return
- }
- this.numCount--
- }, 1000)
- },
- // 获取验证码
- async funGetCode () {
- const numCount = this.numCount
- const { phone } = this.postData
- if (numCount < 60 && numCount > 0) {
- return
- }
- this.numCount = 60
- if (!isMobile(phone)) {
- Toast('请输入手机号码')
- return
- }
- this.funCutDown()
- try {
- const { status, msg } = await sendSMS(phone)
- if (status) {
- Toast('发送成功')
- } else {
- Toast(msg)
- clearInterval(this.timer)
- this.numCount = 60
- }
- } catch (err) {
- clearInterval(this.timer)
- this.numCount = 60
- }
- },
- verifyData () {
- const { phone, code } = this.postData
- this.arrErrorList = []
- if (!isMobile(phone)) {
- this.arrErrorList.push('请输入手机号码')
- }
- if (!isSmscode(code)) {
- this.arrErrorList.push('请输入验证码')
- }
- if (!this.checked) {
- this.arrErrorList.push('请勾选用户协议及隐私政策')
- }
- return this.arrErrorList.length <= 0
- },
- async funSubmit () {
- const { phone, code, msg } = this.postData
- if (!this.verifyData()) {
- Toast({
- message: this.arrErrorList[0],
- forbidClick: true
- })
- return
- }
- const myToast = Toast.loading({
- message: '提交中...',
- duration: 1000 * 100,
- forbidClick: true
- })
- try {
- const { status, data } = await login(phone, code)
- myToast.clear()
- if (status) {
- const { token } = data
- clearLoginInfo()
- this.$nextTick(() => {
- this.$store.commit('common/UPDATE_PHONE', phone)
- this.$store.commit('common/UPDATE_TOKEN', token)
- this.$cookie.set('afhousephone', phone, '30d')
- this.$cookie.set('afhousetoken', token, '30d')
- })
- Toast({
- type: 'success',
- message: '登录成功',
- forbidClick: true,
- onClose: () => {
- this.$router.go(-1)
- }
- })
- return
- }
- Toast(msg)
- } catch (err) {
- myToast.clear()
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .wrapper {
- position: relative;
- left: 0;
- top: 0;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- width: 100%;
- height: 100%;
- padding-bottom: 50px;
- background: linear-gradient(180deg, #000000 0%, #272727 100%);
- }
- .logo {
- width: 121px;
- height: 138px;
- }
- .form-wrap {
- li {
- position: relative;
- left: 0;
- top: 0;
- display: flex;
- align-items: flex-start;
- width: 327px;
- padding: 13px 0;
- margin-top: 12px;
- border-bottom: 1px solid #2A2929;
- border-radius: 4px;
- &:nth-of-type(1) {
- margin-top: 53px;
- }
- }
- label {
- display: flex;
- margin-right: 9px;
- span {
- line-height: 22px;
- font-size: 16px;
- font-weight: 500;
- color: #A6A2A2;
- &.label-code:nth-of-type(5), {
- visibility: hidden;
- }
- }
- }
- .value-wrap {
- flex: 1;
- display: flex;
- }
- input,
- textarea {
- width: 100%;
- min-height: 20px;
- padding-top: 2px;
- line-height: 20px;
- font-size: 15px;
- color: #fff;
- word-break: break-all;
- resize: none;
- outline: 0 none;
- overflow: hidden;
- background: transparent;
- -webkit-text-fill-color: #fff;
- opacity: 1;
- &::-webkit-input-placeholder {
- color: #A6A2A2;
- -webkit-text-fill-color: #A6A2A2;
- opacity: 1;
- }
- }
- .get-code {
- @include vertical-center;
- right: 0;
- z-index: 1;
- display: block;
- min-width: 87px;
- padding: 6px;
- line-height: 14px;
- font-size: 12px;
- font-weight: 500;
- color: #C9A585;
- background: #D32323;
- border-radius: 14px;
- }
- }
- .submit {
- width: 343px;
- height: 50px;
- margin-top: 39px;
- background: #D32323;
- border-radius: 25px;
- font-size: 18px;
- color: #FFFFFF;
- line-height: 50px;
- letter-spacing: 1px;
- }
- .footer {
- position: absolute;
- left: 0;
- bottom: 24px;
- z-index: 1;
- display: flex;
- align-items: center;
- width: 100%;
- justify-content: center;
- .tip-text {
- display: flex;
- align-items: center;
- margin-left: 6px;
- span {
- font-size: 12px;
- font-family: STSongti-SC-Bold, STSongti-SC;
- font-weight: bold;
- color: #848484;
- line-height: 17px;
- &.value {
- color: #D32323;
- }
- }
- }
- }
- </style>
|