mirror of https://github.com/certd/certd
fix: 修复某处金额转换丢失精度的bug
parent
b31c0b6a8d
commit
d2d6f12218
|
@ -9,6 +9,10 @@ export * from './util.merge.js';
|
|||
export * from './util.cache.js';
|
||||
export * from './util.string.js';
|
||||
export * from './util.lock.js';
|
||||
export * from './util.mitter.js';
|
||||
export * from './util.id.js';
|
||||
export * from './util.domain.js';
|
||||
export * from './util.amount.js';
|
||||
import { stringUtils } from './util.string.js';
|
||||
import sleep from './util.sleep.js';
|
||||
import { http, download } from './util.request.js';
|
||||
|
@ -23,6 +27,7 @@ import { cache } from './util.cache.js';
|
|||
import dayjs from 'dayjs';
|
||||
import { domainUtils } from './util.domain.js';
|
||||
import { optionsUtils } from './util.options.js';
|
||||
import { amountUtils } from './util.amount.js';
|
||||
import { nanoid } from 'nanoid';
|
||||
import * as id from './util.id.js';
|
||||
import { locker } from './util.lock.js';
|
||||
|
@ -46,4 +51,5 @@ export const utils = {
|
|||
string: stringUtils,
|
||||
locker,
|
||||
mitter,
|
||||
amount: amountUtils,
|
||||
};
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
export const amountUtils = {
|
||||
toCent(amount: number): number {
|
||||
return parseInt((amount * 100).toFixed(0));
|
||||
},
|
||||
|
||||
toYuan(amount: number): number {
|
||||
return parseFloat((amount / 100).toFixed(2));
|
||||
},
|
||||
};
|
|
@ -6,6 +6,7 @@ import * as mitt from "./util.mitt";
|
|||
import { routerUtils } from "./util.router";
|
||||
import { treeUtils } from "./util.tree";
|
||||
import { hashUtils } from "./util.hash";
|
||||
import { amountUtils } from "./util.amount";
|
||||
export const util = {
|
||||
...envs,
|
||||
...sites,
|
||||
|
@ -14,5 +15,7 @@ export const util = {
|
|||
...mitt,
|
||||
router: routerUtils,
|
||||
tree: treeUtils,
|
||||
hash: hashUtils
|
||||
hash: hashUtils,
|
||||
amount: amountUtils
|
||||
};
|
||||
export const utils = util;
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
export const amountUtils = {
|
||||
toCent(amount: number): number {
|
||||
return parseInt((amount * 100).toFixed(0));
|
||||
},
|
||||
|
||||
toYuan(amount: number): number {
|
||||
return parseFloat((amount / 100).toFixed(2));
|
||||
}
|
||||
};
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { computed } from "vue";
|
||||
|
||||
import { utils } from "/@/utils";
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: number;
|
||||
|
@ -34,11 +34,11 @@ const priceValue = computed(() => {
|
|||
if (props.modelValue == null) {
|
||||
return 0;
|
||||
}
|
||||
return (props.modelValue / 100.0).toFixed(2);
|
||||
return utils.amount.toYuan(props.modelValue);
|
||||
});
|
||||
|
||||
const priceLabel = computed(() => {
|
||||
if (priceValue.value === 0 || priceValue.value === "0.00") {
|
||||
if (priceValue.value === 0) {
|
||||
return "免费";
|
||||
}
|
||||
return `¥${priceValue.value}`;
|
||||
|
@ -47,7 +47,7 @@ const priceLabel = computed(() => {
|
|||
const emit = defineEmits(["update:modelValue"]);
|
||||
|
||||
const onPriceChange = (price: number) => {
|
||||
emit("update:modelValue", price * 100);
|
||||
emit("update:modelValue", utils.amount.toCent(price));
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue