mall-app-t/pages/index/login.vue

195 lines
5.6 KiB
Vue
Raw Normal View History

2024-05-22 18:05:56 +08:00
<template>
2024-05-29 17:07:37 +08:00
<pb-layout :leftIcon="''" navbar="inner" :bgStyle="{ backgroundColor: '#fff' }">
<view class="login-module ss-p-x-30">
<view class="login-title ss-font-56 ss-m-b-72">
{{ title }}
</view>
<uni-forms ref="smsLoginRef" v-model="state.model" :rules="state.rules" validateTrigger="bind">
<uni-forms-item name="mobile">
<uni-easyinput
:styles="state.inputStyle"
trim="all"
placeholder="请输入手机号"
v-model="state.model.mobile"
:inputBorder="false"
type="number"
/>
</uni-forms-item>
<uni-forms-item name="code">
<uni-easyinput
:styles="state.inputStyle"
trim="all"
placeholder="验证码"
v-model="state.model.code"
:inputBorder="false"
type="number"
maxlength="4"
>
<template #right>
<button
:disabled="state.isMobileEnd"
:class="{ 'code-btn-end': state.isMobileEnd }"
class="ss-reset-button code-btn code-btn-start"
@tap="getSmsCode('smsLogin', state.model.mobile)"
>
{{ getSmsTimer('smsLogin') }}
</button>
</template>
</uni-easyinput>
</uni-forms-item>
</uni-forms>
<button class="ss-reset-button login-btn-start" @tap="smsLoginSubmit">登录</button>
<view class="agreement-box ss-flex ss-row-center" :class="{ shake: state.isShaking }">
<label class="radio ss-flex" @tap="onChange">
<radio
:checked="state.agreeStatus"
color="var(--ui-BG-Main)"
style="transform: scale(0.8)"
@tap.stop="onChange"
/>
<view class="agreement-text ss-flex ss-m-l-8">
我已阅读并遵守
<view class="tcp-text" @tap.stop="onProtocol('商家入驻协议')"> 商家入驻协议 </view>
</view>
</label>
</view>
</view>
</pb-layout>
2024-05-22 18:05:56 +08:00
</template>
<script setup>
import { ref } from 'vue'
2024-05-29 17:07:37 +08:00
import { code, mobile } from '@/peach/validate/form'
import AuthUtil from '@/peach/api/member/auth'
2024-05-23 01:44:16 +08:00
import peach from '@/peach'
2024-05-29 17:07:37 +08:00
import { showAuthModal, closeAuthModal, getSmsCode, getSmsTimer } from '@/peach/hooks/useModal'
2024-05-22 18:05:56 +08:00
const title = ref('欢迎登录')
2024-05-23 01:38:19 +08:00
const smsLoginRef = ref(null)
2024-05-22 18:05:56 +08:00
const state = ref({
2024-05-29 17:07:37 +08:00
isMobileEnd: false,
agreeStatus: false,
isShaking: false,
model: {
mobile: '15036370128',
code: '9999',
},
rules: {
mobile,
code,
},
inputStyle: {
backgroundColor: '#ECECEC',
},
2024-05-22 18:05:56 +08:00
})
2024-05-23 01:38:19 +08:00
function onChange() {
2024-05-29 17:07:37 +08:00
state.value.agreeStatus = !state.value.agreeStatus
2024-05-23 01:38:19 +08:00
}
async function smsLoginSubmit() {
2024-05-29 17:07:37 +08:00
const validate = await smsLoginRef.value.validate().catch((err) => {
console.log('err', err)
})
if (!validate) return
if (!state.value.agreeStatus) {
state.value.isShaking = true
setTimeout(() => {
state.value.isShaking = false
}, 1000)
peach.$helper.toast('请勾选同意')
return
}
2024-05-23 01:38:19 +08:00
2024-05-29 17:07:37 +08:00
const { code } = await AuthUtil.smsLogin(state.value.model)
2024-05-23 01:38:19 +08:00
}
2024-05-22 18:05:56 +08:00
</script>
2024-05-23 01:38:19 +08:00
<style lang="scss">
.login-module {
2024-05-29 17:07:37 +08:00
.uni-easyinput {
::v-deep .uni-easyinput__content {
border-radius: 41rpx;
padding: 0 10rpx;
}
2024-05-23 01:38:19 +08:00
2024-05-29 17:07:37 +08:00
.is-focused {
::v-deep .content-clear-icon {
.uniui-clear {
color: red !important;
}
}
2024-05-29 01:29:31 +08:00
}
}
2024-05-23 01:38:19 +08:00
}
</style>
2024-05-22 18:05:56 +08:00
<style lang="scss" scoped>
.login-module {
2024-05-29 17:07:37 +08:00
margin-top: 50%;
overflow: hidden;
.login-title {
color: '#1818d';
font-weight: 600;
2024-05-22 18:05:56 +08:00
}
2024-05-23 01:38:19 +08:00
2024-05-29 17:07:37 +08:00
.login-btn-start {
height: 82rpx;
line-height: normal;
background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
border-radius: 28rpx;
font-size: 26rpx;
font-weight: 500;
color: #fff;
}
2024-05-23 01:38:19 +08:00
2024-05-29 17:07:37 +08:00
.code-btn-start {
width: 160rpx;
height: 56rpx;
line-height: normal;
border-radius: 28rpx;
font-size: 26rpx;
font-weight: 400;
2024-05-22 18:05:56 +08:00
color: var(--ui-BG-Main);
2024-05-29 17:07:37 +08:00
opacity: 1;
2024-05-23 01:38:19 +08:00
}
2024-05-29 17:07:37 +08:00
.agreement-box {
margin: -10px auto 10px;
position: absolute;
bottom: 30rpx;
width: 100%;
2024-05-23 01:38:19 +08:00
2024-05-29 17:07:37 +08:00
.protocol-check {
transform: scale(0.7);
}
.agreement-text {
font-size: 26rpx;
font-weight: 500;
color: #999999;
.tcp-text {
color: var(--ui-BG-Main);
}
}
2024-05-23 01:38:19 +08:00
}
2024-05-29 17:07:37 +08:00
.shake {
animation: shake 0.05s linear 4 alternate;
}
@keyframes shake {
from {
transform: translateX(-5rpx);
}
to {
transform: translateX(5rpx);
}
2024-05-22 18:05:56 +08:00
}
}
</style>