code refactor

This commit is contained in:
MaysWind
2023-07-02 00:51:26 +08:00
parent 4e8f530fbb
commit 9adfd286f9
17 changed files with 139 additions and 67 deletions
+10 -3
View File
@@ -63,6 +63,9 @@
</template>
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import { isString, appendThousandsSeparator } from '@/lib/common.js';
import { numericCurrencyToString, stringCurrencyToNumeric } from '@/lib/currency.js';
@@ -87,9 +90,13 @@ export default {
}
},
computed: {
...mapStores(useSettingsStore),
isEnableThousandsSeparator() {
return this.settingsStore.appSettings.thousandsSeparator;
},
currentDisplay() {
const previousValue = appendThousandsSeparator(this.previousValue);
const currentValue = appendThousandsSeparator(this.currentValue);
const previousValue = appendThousandsSeparator(this.previousValue, this.isEnableThousandsSeparator);
const currentValue = appendThousandsSeparator(this.currentValue, this.isEnableThousandsSeparator);
if (this.currentSymbol) {
return `${previousValue} ${this.currentSymbol} ${currentValue}`;
@@ -118,7 +125,7 @@ export default {
},
methods: {
getStringValue(value) {
let str = numericCurrencyToString(value);
let str = numericCurrencyToString(value, this.isEnableThousandsSeparator);
if (str.indexOf(',')) {
str = str.replaceAll(/,/g, '');
+11 -1
View File
@@ -77,6 +77,9 @@
</template>
<script>
import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js';
import colorConstants from '@/consts/color.js';
import { formatPercent } from '@/lib/common.js';
@@ -124,6 +127,7 @@ export default {
}
},
computed: {
...mapStores(useSettingsStore),
validItems: function () {
let totalValidValue = 0;
@@ -154,7 +158,7 @@ export default {
};
finalItem.displayPercent = formatPercent(finalItem.percent, 2, '&lt;0.01');
finalItem.displayValue = this.$locale.getDisplayCurrency(finalItem.value, (finalItem.currency || this.defaultCurrency));
finalItem.displayValue = this.getDisplayCurrency(finalItem.value, (finalItem.currency || this.defaultCurrency));
validItems.push(finalItem);
}
@@ -281,6 +285,12 @@ export default {
const allPreviousLength = allPreviousPercent * this.circumference;
return this.circumference - allPreviousLength + offset;
},
getDisplayCurrency(value, currencyCode) {
return this.$locale.getDisplayCurrency(value, currencyCode, {
currencyDisplayMode: this.settingsStore.appSettings.currencyDisplayMode,
enableThousandsSeparator: this.settingsStore.appSettings.thousandsSeparator
});
}
}
}