From 837a62a53414e0e8295cd9e0bf601ab14e9622f7 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 23 Nov 2025 02:32:12 +0800 Subject: [PATCH] paste amount on number pad sheet for ios --- src/components/mobile/NumberPadSheet.vue | 45 ++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/components/mobile/NumberPadSheet.vue b/src/components/mobile/NumberPadSheet.vue index 4dc8d58f..a3a1e7cb 100644 --- a/src/components/mobile/NumberPadSheet.vue +++ b/src/components/mobile/NumberPadSheet.vue @@ -6,7 +6,7 @@
{{ hint }}
-
+
{{ currentDisplay }}
@@ -72,11 +72,12 @@ import { ref, computed, watch } from 'vue'; import { useI18n } from '@/locales/helpers.ts'; -import { useI18nUIComponents } from '@/lib/ui/mobile.ts'; +import { useI18nUIComponents, isiOS } from '@/lib/ui/mobile.ts'; import { NumeralSystem } from '@/core/numeral.ts'; import { ALL_CURRENCIES } from '@/consts/currency.ts'; import { isNumber } from '@/lib/common.ts'; +import logger from '@/lib/logger.ts'; const props = defineProps<{ modelValue: number; @@ -98,12 +99,15 @@ const { getAllLocalizedDigits, getCurrentNumeralSystemType, getCurrentDecimalSeparator, + parseAmountFromLocalizedNumerals, parseAmountFromWesternArabicNumerals, formatAmountToWesternArabicNumeralsWithoutDigitGrouping, appendDigitGroupingSymbolAndDecimalSeparator } = useI18n(); const { showToast } = useI18nUIComponents(); +const isSupportClipboard = !!navigator.clipboard; + const previousValue = ref(''); const currentSymbol = ref(''); const currentValue = ref(getInitedStringValue(props.modelValue, props.flipNegative)); @@ -311,6 +315,43 @@ function clear(): void { currentSymbol.value = ''; } +function paste(): void { + if (!isiOS() || !isSupportClipboard) { + return; + } + + navigator.clipboard.readText().then(text => { + if (!text) { + return; + } + + const parsedAmount = parseAmountFromLocalizedNumerals(text); + + if (Number.isNaN(parsedAmount) || !Number.isFinite(parsedAmount)) { + showToast('Cannot parse amount from clipboard'); + return; + } + + if (isNumber(props.minValue)) { + if (parsedAmount < (props.minValue)) { + showToast('Numeric Overflow'); + return; + } + } + + if (isNumber(props.maxValue)) { + if (parsedAmount > (props.maxValue)) { + showToast('Numeric Overflow'); + return; + } + } + + currentValue.value = getStringValue(parsedAmount, false); + }).catch(error => { + logger.error('failed to read clipboard text', error); + }); +} + function confirm(): boolean { if (currentSymbol.value && currentValue.value.length >= 1) { const previous = parseAmountFromWesternArabicNumerals(previousValue.value);