passwordModal.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <Popup isClose ref="popRef">
  3. <template #content>
  4. <Input type="number" :placeholder="t(placeholder)" :maxlength="maxlength" border="surround" @focus="handleInput"
  5. v-model="password" />
  6. </template>
  7. <template #footer>
  8. <view class="submit_btn" @click="submit">
  9. <trans _t="确认" />
  10. </view>
  11. </template>
  12. </Popup>
  13. </template>
  14. <script setup>
  15. import { ref } from 'vue'
  16. import { useVibrate } from '@/utils'
  17. import Popup from './popup.vue';
  18. import Input from "./input";
  19. import { t } from "@/locale"
  20. const popRef = ref(null);
  21. const { vibrate } = useVibrate()
  22. const props = defineProps({
  23. placeholder: { type: String, default: '请输入支付密码' },
  24. maxlength: { type: Number, default: 6 },
  25. errorMsg: { type: String, default: '密码错误,请重新输入' }
  26. })
  27. const emit = defineEmits(['complete', 'close'])
  28. const password = ref('')
  29. const showError = ref(false)
  30. const open = () => {
  31. reset()
  32. popRef.value && popRef.value.open()
  33. }
  34. const close = () => {
  35. emit('close')
  36. popRef.value && popRef.value.close()
  37. }
  38. // 处理输入
  39. const handleInput = (num) => {
  40. if (password.value.length >= props.maxlength) return
  41. vibrate()
  42. password.value += num
  43. }
  44. const submit = () => {
  45. if (password.value.length === props.maxlength) {
  46. emit('complete', password.value)
  47. }
  48. }
  49. // 重置输入
  50. const reset = () => {
  51. password.value = ''
  52. }
  53. defineExpose({ open, close, reset })
  54. </script>
  55. <style lang="less" scoped>
  56. @import url('@/style.less');
  57. .submit_btn {
  58. height: 38px;
  59. padding: 16rpx 30rpx;
  60. background-color: var(--black);
  61. color: var(--light);
  62. .flex_center();
  63. border-radius: 16rpx;
  64. .size(24rpx);
  65. }
  66. </style>