wangzhibo
4 天以前 10595d8632f959d0954d1939243196f4eed02372
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<template>
    <cl-page background-color="#fff">
        <view class="page-captcha">
            <cl-topbar :border="false"> </cl-topbar>
 
            <view class="container">
                <text class="label">输入验证码</text>
                <text class="tips">已发送至 +86 {{ form.phone }}</text>
 
                <view class="code">
                    <cl-captcha
                        focus
                        v-model="form.smsCode"
                        :length="len"
                        :gutter="26"
                        @done="next"
                    />
                </view>
 
                <cl-button
                    type="primary"
                    :disabled="form.smsCode.length !== len"
                    :loading="saving"
                    fill
                    :height="90"
                    :font-size="30"
                    @tap="next"
                >
                    确定
                </cl-button>
 
                <view class="send">
                    <sms-btn
                        size="small"
                        :border="false"
                        :phone="form.phone"
                        :ref="setRefs('smsBtn')"
                    />
                </view>
            </view>
        </view>
    </cl-page>
</template>
 
<script lang="ts" setup>
import { onReady } from "@dcloudio/uni-app";
import { reactive, ref } from "vue";
import { useCool, useStore } from "/@/cool";
import { useUi } from "/$/cool-ui";
import SmsBtn from "/@/components/sms-btn.vue";
 
const { service, router, refs, setRefs } = useCool();
const { user } = useStore();
const ui = useUi();
 
// 验证码长度
const len = 4;
 
// 保存状态
const saving = ref(false);
 
// 表单
const form = reactive({
    smsCode: "",
    phone: "",
});
 
// 下一步
function next() {
    saving.value = true;
 
    service.user.login
        .phone(form)
        .then(async (res) => {
            // 设置token
            user.setToken(res);
 
            // 设置用户信息
            await user.get();
 
            // 登录跳转
            router.nextLogin();
        })
        .catch((err) => {
            ui.showTips(err.message || "登录失效,请重试~");
            saving.value = false;
            form.smsCode = "";
        });
}
 
onReady(() => {
    form.phone = router.query.phone || "";
    refs.smsBtn.startCountdown();
});
</script>
 
<style lang="scss" scoped>
.page-captcha {
    .container {
        display: flex;
        flex-direction: column;
        width: 80%;
        margin: 0 auto;
        padding-top: 140rpx;
    }
 
    .label {
        font-size: 52rpx;
        font-weight: 500;
        margin-bottom: 44rpx;
        font-weight: bold;
        color: #151515;
    }
 
    .tips {
        font-size: 28rpx;
        color: #151515;
        font-weight: 500;
    }
 
    .code {
        margin: 34rpx -26rpx 62rpx -26rpx;
    }
 
    .send {
        display: flex;
        justify-content: center;
        font-size: 24rpx;
        margin-top: 30rpx;
    }
}
</style>