mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 10:14:26 +08:00
code refactor
This commit is contained in:
@@ -68,9 +68,8 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
|
|
||||||
import { useI18n } from '@/locales/helper.js';
|
import { useI18n } from '@/locales/helpers.ts';
|
||||||
import { useI18nUIComponents } from '@/lib/ui/mobile.ts';
|
import { useI18nUIComponents } from '@/lib/ui/mobile.ts';
|
||||||
import { useUserStore } from '@/stores/user.ts';
|
|
||||||
|
|
||||||
import { ALL_CURRENCIES } from '@/consts/currency.ts';
|
import { ALL_CURRENCIES } from '@/consts/currency.ts';
|
||||||
import { isString, isNumber, removeAll } from '@/lib/common.ts';
|
import { isString, isNumber, removeAll } from '@/lib/common.ts';
|
||||||
@@ -84,7 +83,6 @@ const {
|
|||||||
formatAmount
|
formatAmount
|
||||||
} = useI18n();
|
} = useI18n();
|
||||||
const { showToast } = useI18nUIComponents();
|
const { showToast } = useI18nUIComponents();
|
||||||
const userStore = useUserStore();
|
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue: number | string;
|
modelValue: number | string;
|
||||||
@@ -103,7 +101,7 @@ const previousValue = ref<string>('');
|
|||||||
const currentSymbol = ref<string>('');
|
const currentSymbol = ref<string>('');
|
||||||
const currentValue = ref<string>(getStringValue(props.modelValue));
|
const currentValue = ref<string>(getStringValue(props.modelValue));
|
||||||
|
|
||||||
const decimalSeparator = computed<string>(() => getCurrentDecimalSeparator(userStore));
|
const decimalSeparator = computed<string>(() => getCurrentDecimalSeparator());
|
||||||
|
|
||||||
const supportDecimalSeparator = computed<boolean>(() => {
|
const supportDecimalSeparator = computed<boolean>(() => {
|
||||||
if (!props.currency || !ALL_CURRENCIES[props.currency] || !isNumber(ALL_CURRENCIES[props.currency].fraction)) {
|
if (!props.currency || !ALL_CURRENCIES[props.currency] || !isNumber(ALL_CURRENCIES[props.currency].fraction)) {
|
||||||
@@ -114,8 +112,8 @@ const supportDecimalSeparator = computed<boolean>(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const currentDisplay = computed<string>(() => {
|
const currentDisplay = computed<string>(() => {
|
||||||
const finalPreviousValue = appendDigitGroupingSymbol(userStore, previousValue.value);
|
const finalPreviousValue = appendDigitGroupingSymbol(previousValue.value);
|
||||||
const finalCurrentValue = appendDigitGroupingSymbol(userStore, currentValue.value);
|
const finalCurrentValue = appendDigitGroupingSymbol(currentValue.value);
|
||||||
|
|
||||||
if (currentSymbol.value) {
|
if (currentSymbol.value) {
|
||||||
return `${finalPreviousValue} ${currentSymbol.value} ${finalCurrentValue}`;
|
return `${finalPreviousValue} ${currentSymbol.value} ${finalCurrentValue}`;
|
||||||
@@ -147,15 +145,15 @@ function getStringValue(value: number | string): string {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
let str = formatAmount(userStore, value, props.currency);
|
let str = formatAmount(value, props.currency);
|
||||||
|
|
||||||
const digitGroupingSymbol = getCurrentDigitGroupingSymbol(userStore);
|
const digitGroupingSymbol = getCurrentDigitGroupingSymbol();
|
||||||
|
|
||||||
if (str.indexOf(digitGroupingSymbol) >= 0) {
|
if (str.indexOf(digitGroupingSymbol) >= 0) {
|
||||||
str = removeAll(str, digitGroupingSymbol);
|
str = removeAll(str, digitGroupingSymbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
const decimalSeparator = getCurrentDecimalSeparator(userStore);
|
const decimalSeparator = getCurrentDecimalSeparator();
|
||||||
const decimalSeparatorPos = str.indexOf(decimalSeparator);
|
const decimalSeparatorPos = str.indexOf(decimalSeparator);
|
||||||
|
|
||||||
if (decimalSeparatorPos < 0) {
|
if (decimalSeparatorPos < 0) {
|
||||||
@@ -210,7 +208,7 @@ function inputNum(num: number): void {
|
|||||||
const newValue = currentValue.value + num.toString();
|
const newValue = currentValue.value + num.toString();
|
||||||
|
|
||||||
if (isNumber(props.minValue)) {
|
if (isNumber(props.minValue)) {
|
||||||
const current = parseAmount(userStore, newValue);
|
const current = parseAmount(newValue);
|
||||||
|
|
||||||
if (current < (props.minValue as number)) {
|
if (current < (props.minValue as number)) {
|
||||||
return;
|
return;
|
||||||
@@ -218,7 +216,7 @@ function inputNum(num: number): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isNumber(props.maxValue)) {
|
if (isNumber(props.maxValue)) {
|
||||||
const current = parseAmount(userStore, newValue);
|
const current = parseAmount(newValue);
|
||||||
|
|
||||||
if (current > (props.maxValue as number)) {
|
if (current > (props.maxValue as number)) {
|
||||||
return;
|
return;
|
||||||
@@ -291,8 +289,8 @@ function clear(): void {
|
|||||||
|
|
||||||
function confirm(): boolean {
|
function confirm(): boolean {
|
||||||
if (currentSymbol.value && currentValue.value.length >= 1) {
|
if (currentSymbol.value && currentValue.value.length >= 1) {
|
||||||
const previous = parseAmount(userStore, previousValue.value);
|
const previous = parseAmount(previousValue.value);
|
||||||
const current = parseAmount(userStore, currentValue.value);
|
const current = parseAmount(currentValue.value);
|
||||||
let finalValue = 0;
|
let finalValue = 0;
|
||||||
|
|
||||||
switch (currentSymbol.value) {
|
switch (currentSymbol.value) {
|
||||||
@@ -335,7 +333,7 @@ function confirm(): boolean {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const value = parseAmount(userStore, currentValue.value);
|
const value = parseAmount(currentValue.value);
|
||||||
|
|
||||||
emit('update:modelValue', value);
|
emit('update:modelValue', value);
|
||||||
close();
|
close();
|
||||||
|
|||||||
Reference in New Issue
Block a user