88 lines
1.9 KiB
Vue
88 lines
1.9 KiB
Vue
<script setup lang="ts">
|
||
import { useCountDown } from '@/composables/useCountDown'
|
||
|
||
const code = defineModel<string>('code', { default: '' })
|
||
|
||
const emit = defineEmits<{ getCode: [] }>()
|
||
|
||
const { seconds, isCounting, start } = useCountDown(60)
|
||
|
||
function onGetCode(): void {
|
||
if (isCounting.value) return
|
||
start(60)
|
||
emit('getCode')
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<div class="sms-code">
|
||
<input
|
||
v-model="code"
|
||
class="sms-code__input"
|
||
type="text"
|
||
placeholder="请输入验证码"
|
||
/>
|
||
<button class="sms-code__btn" :disabled="isCounting" @click="onGetCode">
|
||
{{ isCounting ? `${seconds}秒后重新获取` : '获取验证码' }}
|
||
</button>
|
||
</div>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
.sms-code {
|
||
.flex(row, stretch);
|
||
gap: @spacing-sm;
|
||
|
||
&__input {
|
||
flex: 1;
|
||
min-width: 0;
|
||
height: 40px;
|
||
padding: 0 12px;
|
||
border: 1px solid #dde1e7;
|
||
border-radius: @radius-sm;
|
||
background: @white;
|
||
font-size: 13px;
|
||
color: #1f2937;
|
||
outline: none;
|
||
transition: border-color 0.2s;
|
||
|
||
&:focus {
|
||
border-color: @primary-strong;
|
||
}
|
||
|
||
&::placeholder {
|
||
color: #1f2937;
|
||
}
|
||
}
|
||
|
||
// 设计稿 #38:「获取验证码」是带蓝色描边的独立按钮(62×16 文字居中),
|
||
// 不是纯文字链接。按键宽 88px,与输入框间距 @spacing-sm。
|
||
&__btn {
|
||
flex-shrink: 0;
|
||
width: 88px;
|
||
height: 40px;
|
||
padding: 0;
|
||
border: 1px solid @primary-strong;
|
||
border-radius: @radius-sm;
|
||
background: @white;
|
||
color: @primary-strong;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
text-align: center;
|
||
cursor: pointer;
|
||
transition: all 0.2s;
|
||
|
||
&:hover:not(:disabled) {
|
||
background: @primary-strong;
|
||
color: @white;
|
||
}
|
||
|
||
&:disabled {
|
||
border-color: @text-color-disabled;
|
||
color: @text-color-disabled;
|
||
cursor: not-allowed;
|
||
}
|
||
}
|
||
}
|
||
</style>
|