mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 02:04:26 +08:00
paste amount on number pad sheet for ios
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
<div class="margin-top padding-horizontal" v-if="hint">
|
<div class="margin-top padding-horizontal" v-if="hint">
|
||||||
<span>{{ hint }}</span>
|
<span>{{ hint }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="numpad-values">
|
<div class="numpad-values" @click="paste">
|
||||||
<span class="numpad-value" :class="currentDisplayNumClass">{{ currentDisplay }}</span>
|
<span class="numpad-value" :class="currentDisplayNumClass">{{ currentDisplay }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="numpad-buttons">
|
<div class="numpad-buttons">
|
||||||
@@ -72,11 +72,12 @@
|
|||||||
import { ref, computed, watch } from 'vue';
|
import { ref, computed, watch } from 'vue';
|
||||||
|
|
||||||
import { useI18n } from '@/locales/helpers.ts';
|
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 { NumeralSystem } from '@/core/numeral.ts';
|
||||||
import { ALL_CURRENCIES } from '@/consts/currency.ts';
|
import { ALL_CURRENCIES } from '@/consts/currency.ts';
|
||||||
import { isNumber } from '@/lib/common.ts';
|
import { isNumber } from '@/lib/common.ts';
|
||||||
|
import logger from '@/lib/logger.ts';
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: number;
|
modelValue: number;
|
||||||
@@ -98,12 +99,15 @@ const {
|
|||||||
getAllLocalizedDigits,
|
getAllLocalizedDigits,
|
||||||
getCurrentNumeralSystemType,
|
getCurrentNumeralSystemType,
|
||||||
getCurrentDecimalSeparator,
|
getCurrentDecimalSeparator,
|
||||||
|
parseAmountFromLocalizedNumerals,
|
||||||
parseAmountFromWesternArabicNumerals,
|
parseAmountFromWesternArabicNumerals,
|
||||||
formatAmountToWesternArabicNumeralsWithoutDigitGrouping,
|
formatAmountToWesternArabicNumeralsWithoutDigitGrouping,
|
||||||
appendDigitGroupingSymbolAndDecimalSeparator
|
appendDigitGroupingSymbolAndDecimalSeparator
|
||||||
} = useI18n();
|
} = useI18n();
|
||||||
const { showToast } = useI18nUIComponents();
|
const { showToast } = useI18nUIComponents();
|
||||||
|
|
||||||
|
const isSupportClipboard = !!navigator.clipboard;
|
||||||
|
|
||||||
const previousValue = ref<string>('');
|
const previousValue = ref<string>('');
|
||||||
const currentSymbol = ref<string>('');
|
const currentSymbol = ref<string>('');
|
||||||
const currentValue = ref<string>(getInitedStringValue(props.modelValue, props.flipNegative));
|
const currentValue = ref<string>(getInitedStringValue(props.modelValue, props.flipNegative));
|
||||||
@@ -311,6 +315,43 @@ function clear(): void {
|
|||||||
currentSymbol.value = '';
|
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 {
|
function confirm(): boolean {
|
||||||
if (currentSymbol.value && currentValue.value.length >= 1) {
|
if (currentSymbol.value && currentValue.value.length >= 1) {
|
||||||
const previous = parseAmountFromWesternArabicNumerals(previousValue.value);
|
const previous = parseAmountFromWesternArabicNumerals(previousValue.value);
|
||||||
|
|||||||
Reference in New Issue
Block a user