| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <template>
- <view class="mask" :class="isLogin ? 'none' : !isLogin ? 'show' : ''">
- <view class="mask-content" @click.stop.prevent="stopPrevent">
- <view class="c-input-wrap">
- <u-input class="inner_input" fontSize="26rpx" placeholderClass="plac" placeholder="请输入手机号" border="none" v-model="form.phone" clearable></u-input>
- </view>
- <view class="c-input-wrap">
- <u-input class="inner_input" fontSize="26rpx" placeholderClass="plac" placeholder="请输入验证码" border="none" v-model="form.code"></u-input>
- <view class="divide"></view>
- <view class="tip-btn" :class="{disable: send}" @click="getCode">{{tips}}</view>
- </view>
- <u-button type="primary" shape="circle" class="c-button" text="登录" @click="loginAction"></u-button>
- </view>
- <u-code :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-code>
- <u-toast ref="uToast"></u-toast>
- </view>
- </template>
- <script>
- import { mapActions, mapState, mapGetters } from 'vuex';
- export default {
- name:"c-pop-login",
- data() {
- return {
- tips: '获取验证码',
- seconds: 60,
- send: false,
- form: {
- phone: '',
- code: '',
- }
- };
- },
- props: {
- onComplate: {
- type: Function,
- default: () => { }
- },
- },
- computed: {
- ...mapGetters(['isLogin']),
- },
- mounted() {
-
- },
- methods: {
- ...mapActions({
- 'login': 'login',
- 'loginRefresh': 'loginRefresh',
- }),
- stopPrevent(){
-
- },
- codeChange(text) {
- this.tips = text;
- },
- getCode() {
- if(this.$refs.uCode.canGetCode) {
- // 模拟向后端请求验证码
- this.$refs.uToast.show({
- type: 'loading',
- message: '正在获取验证码',
- })
-
- // TODO 发起请求:
- this.$api('h5.getCode', {mobile: this.form.phone}).then(res => {
- console.log(res)
- this.$refs.uToast.hide()
- if(res.code == 1){
- // 这里此提示会被this.start()方法中的提示覆盖
- uni.$u.toast('验证码已发送')
- // 通知验证码组件内部开始倒计时
- this.$refs.uCode.start()
- }
- })
- } else {
- uni.$u.toast('倒计时结束后再发送');
- }
- },
- end() {
- this.send = false;
- },
- start() {
- this.send = true;
- },
- loginAction() {
- this.$refs.uToast.show({
- type: 'loading',
- message: '正在登录,请稍后',
- })
- this.login({mobile: this.form.phone, code: this.form.code}).then(res => {
- this.$refs.uToast.hide()
- if(res.code == 1){
- // 这里此提示会被this.start()方法中的提示覆盖
- uni.$u.toast('登录成功')
- // 通知验证码组件内部开始倒计时
- this.$refs.uCode.start()
- }
- this.onComplate()
- })
- }
- },
- }
- </script>
- <style lang="scss" scoped>
- .mask{
- display: flex;
- align-items: center;
- justify-content: center;
- position: fixed;
- left: 0;
- top: var(--window-top);
- bottom: 0;
- width: 100vw;
- background: rgba(0,0,0,0);
- z-index: 10001;
- transition: .3s;
-
- .mask-content{
- padding-top: 60rpx;
- display: flex;
- flex-direction: column;
- width: 590rpx;
- max-height: 45vh;
- min-height: 361rpx;
- background: #fff;
- border-radius: 15px;
- }
-
- &.none{
- display: none;
- }
- &.show{
- background: rgba(0,0,0,.4);
-
- .mask-content{
- transform: translateY(0);
- }
- }
-
- }
- .c-button {
- color: #fff;
- width: 510rpx;
- margin-top: 20rpx;
- }
- .c-input-wrap{
- margin: 0 auto;
- width: 510rpx;
- height: 70rpx;
- background-color: #F0F2F4;
- border-radius: 35px;
- padding: 0 14px;
- box-sizing: border-box;
- margin-bottom: 30rpx;
- display: flex;
- align-items: center;
- .divide{
- width: 1px;
- height: 40rpx;
- border-left: 1px solid #FD8701;
- }
- .tip-btn{
- text-align: center;
- min-width: 178rpx;
- flex-shrink: 0;
- font-size: 24rpx;
- font-family: PingFang SC;
- font-weight: 500;
- color: #FD8701;
-
- &.disable{
- color: #999;
- }
- }
- & /deep/ .inner_input{
- display: flex;
- height: 100%;
- }
- }
- </style>
|