| | |
| | | <view class="cursor" v-if="code.length === index && isFocused"></view> |
| | | </view> |
| | | </view> |
| | | <input class="hidden-input" type="number" :maxlength="6" v-model="code" :focus="isFocused" @blur="isFocused = false" @focus="isFocused = true" /> |
| | | <input |
| | | class="hidden-input" |
| | | type="text" |
| | | :value="code" |
| | | :maxlength="6" |
| | | :focus="isFocused" |
| | | @input="handleCodeInput" |
| | | @blur="isFocused = false" |
| | | @focus="isFocused = true" |
| | | /> |
| | | <view class="get-code-btn" :class="{ disabled: loading }" @tap="verifyCode"> |
| | | {{ loading ? '验证中...' : '立即验证' }} |
| | | </view> |
| | |
| | | } |
| | | |
| | | /** |
| | | * 验证码输入统一按左到右处理,并只保留 6 位数字。 |
| | | */ |
| | | const handleCodeInput = (event: { detail?: { value?: string } }) => { |
| | | const rawValue = event?.detail?.value || '' |
| | | const nextValue = rawValue.replace(/\D/g, '').slice(0, 6) |
| | | const previousValue = code.value |
| | | if (!nextValue) { |
| | | code.value = '' |
| | | return |
| | | } |
| | | if (nextValue.length <= previousValue.length) { |
| | | code.value = nextValue |
| | | return |
| | | } |
| | | if (nextValue.startsWith(previousValue)) { |
| | | code.value = nextValue |
| | | return |
| | | } |
| | | if (nextValue.endsWith(previousValue) && nextValue.length === previousValue.length + 1) { |
| | | code.value = (previousValue + nextValue.slice(0, 1)).slice(0, 6) |
| | | return |
| | | } |
| | | code.value = nextValue |
| | | } |
| | | |
| | | /** |
| | | * 校验验证码并绑定当前微信登录账号手机号。 |
| | | */ |
| | | const verifyCode = async () => { |