feat: formatNumber 移动到 @vben/utils
parent
21f2472561
commit
fcce15c0b8
|
@ -10,7 +10,12 @@ import {
|
||||||
setupVbenVxeTable,
|
setupVbenVxeTable,
|
||||||
useVbenVxeGrid,
|
useVbenVxeGrid,
|
||||||
} from '@vben/plugins/vxe-table';
|
} from '@vben/plugins/vxe-table';
|
||||||
import { isFunction, isString } from '@vben/utils';
|
import {
|
||||||
|
floatToFixed2,
|
||||||
|
formatToFractionDigit,
|
||||||
|
isFunction,
|
||||||
|
isString,
|
||||||
|
} from '@vben/utils';
|
||||||
|
|
||||||
import { Button, Image, Popconfirm, Switch } from 'ant-design-vue';
|
import { Button, Image, Popconfirm, Switch } from 'ant-design-vue';
|
||||||
|
|
||||||
|
@ -313,33 +318,13 @@ setupVbenVxeTable({
|
||||||
// add by 星语:数量格式化,例如说:金额
|
// add by 星语:数量格式化,例如说:金额
|
||||||
vxeUI.formats.add('formatNumber', {
|
vxeUI.formats.add('formatNumber', {
|
||||||
tableCellFormatMethod({ cellValue }, digits = 2) {
|
tableCellFormatMethod({ cellValue }, digits = 2) {
|
||||||
if (cellValue === null || cellValue === undefined) {
|
return formatToFractionDigit(cellValue, digits);
|
||||||
return '';
|
|
||||||
}
|
|
||||||
if (isString(cellValue)) {
|
|
||||||
cellValue = Number.parseFloat(cellValue);
|
|
||||||
}
|
|
||||||
// 如果非 number,则直接返回空串
|
|
||||||
if (Number.isNaN(cellValue)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return cellValue.toFixed(digits);
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
vxeUI.formats.add('formatAmount2', {
|
vxeUI.formats.add('formatAmount2', {
|
||||||
tableCellFormatMethod({ cellValue }) {
|
tableCellFormatMethod({ cellValue }) {
|
||||||
if (cellValue === null || cellValue === undefined) {
|
return `${floatToFixed2(cellValue)}元`;
|
||||||
return '0.00';
|
|
||||||
}
|
|
||||||
if (isString(cellValue)) {
|
|
||||||
cellValue = Number.parseFloat(cellValue);
|
|
||||||
}
|
|
||||||
// 如果非 number,则直接返回空串
|
|
||||||
if (Number.isNaN(cellValue)) {
|
|
||||||
return '0.00';
|
|
||||||
}
|
|
||||||
return `${(cellValue / 100).toFixed(2)}元`;
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
export * from './constants';
|
export * from './constants';
|
||||||
export * from './dict';
|
export * from './dict';
|
||||||
export * from './download';
|
export * from './download';
|
||||||
export * from './formatNumber';
|
|
||||||
export * from './formCreate';
|
export * from './formCreate';
|
||||||
export * from './rangePickerProps';
|
export * from './rangePickerProps';
|
||||||
export * from './routerHelper';
|
export * from './routerHelper';
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
import type { DescriptionItemSchema } from '#/components/description';
|
import type { DescriptionItemSchema } from '#/components/description';
|
||||||
|
|
||||||
import { formatDateTime } from '@vben/utils';
|
import { erpPriceInputFormatter, formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
import { erpPriceInputFormatter } from '#/utils';
|
|
||||||
|
|
||||||
/** 详情页的字段 */
|
/** 详情页的字段 */
|
||||||
export function useDetailSchema(): DescriptionItemSchema[] {
|
export function useDetailSchema(): DescriptionItemSchema[] {
|
||||||
|
|
|
@ -3,10 +3,10 @@ import type { DescriptionItemSchema } from '#/components/description';
|
||||||
|
|
||||||
import { h } from 'vue';
|
import { h } from 'vue';
|
||||||
|
|
||||||
import { formatDateTime } from '@vben/utils';
|
import { erpPriceInputFormatter, formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
import { DictTag } from '#/components/dict-tag';
|
import { DictTag } from '#/components/dict-tag';
|
||||||
import { DICT_TYPE, erpPriceInputFormatter } from '#/utils';
|
import { DICT_TYPE } from '#/utils';
|
||||||
|
|
||||||
/** 详情页的字段 */
|
/** 详情页的字段 */
|
||||||
export function useDetailSchema(): DescriptionItemSchema[] {
|
export function useDetailSchema(): DescriptionItemSchema[] {
|
||||||
|
|
|
@ -3,10 +3,10 @@ import type { DescriptionItemSchema } from '#/components/description';
|
||||||
|
|
||||||
import { h } from 'vue';
|
import { h } from 'vue';
|
||||||
|
|
||||||
import { formatDateTime } from '@vben/utils';
|
import { erpPriceInputFormatter, formatDateTime } from '@vben/utils';
|
||||||
|
|
||||||
import { DictTag } from '#/components/dict-tag';
|
import { DictTag } from '#/components/dict-tag';
|
||||||
import { DICT_TYPE, erpPriceInputFormatter } from '#/utils';
|
import { DICT_TYPE } from '#/utils';
|
||||||
|
|
||||||
/** 详情页的字段 */
|
/** 详情页的字段 */
|
||||||
export function useDetailSchema(): DescriptionItemSchema[] {
|
export function useDetailSchema(): DescriptionItemSchema[] {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { useRouter } from 'vue-router';
|
||||||
import { confirm, DocAlert, Page } from '@vben/common-ui';
|
import { confirm, DocAlert, Page } from '@vben/common-ui';
|
||||||
import {
|
import {
|
||||||
downloadFileFromBlobPart,
|
downloadFileFromBlobPart,
|
||||||
|
fenToYuan,
|
||||||
handleTree,
|
handleTree,
|
||||||
treeToString,
|
treeToString,
|
||||||
} from '@vben/utils';
|
} from '@vben/utils';
|
||||||
|
@ -24,7 +25,7 @@ import {
|
||||||
updateStatus,
|
updateStatus,
|
||||||
} from '#/api/mall/product/spu';
|
} from '#/api/mall/product/spu';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { fenToYuan, ProductSpuStatusEnum } from '#/utils';
|
import { ProductSpuStatusEnum } from '#/utils';
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import type { MallOrderApi } from '#/api/mall/trade/order';
|
||||||
import { h, onMounted, ref } from 'vue';
|
import { h, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
import { Page, prompt } from '@vben/common-ui';
|
import { Page, prompt } from '@vben/common-ui';
|
||||||
|
import { fenToYuan } from '@vben/utils';
|
||||||
|
|
||||||
import { Card, Input, message } from 'ant-design-vue';
|
import { Card, Input, message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ import {
|
||||||
getOrderSummary,
|
getOrderSummary,
|
||||||
} from '#/api/mall/trade/order';
|
} from '#/api/mall/trade/order';
|
||||||
import { SummaryCard } from '#/components/summary-card';
|
import { SummaryCard } from '#/components/summary-card';
|
||||||
import { DeliveryTypeEnum, fenToYuan, TradeOrderStatusEnum } from '#/utils';
|
import { DeliveryTypeEnum, TradeOrderStatusEnum } from '#/utils';
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { h } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { DocAlert, Page, prompt, useVbenModal } from '@vben/common-ui';
|
import { DocAlert, Page, prompt, useVbenModal } from '@vben/common-ui';
|
||||||
|
import { fenToYuan } from '@vben/utils';
|
||||||
|
|
||||||
import { Image, List, Tag, Textarea } from 'ant-design-vue';
|
import { Image, List, Tag, Textarea } from 'ant-design-vue';
|
||||||
|
|
||||||
|
@ -13,12 +14,7 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { getOrderPage, updateOrderRemark } from '#/api/mall/trade/order';
|
import { getOrderPage, updateOrderRemark } from '#/api/mall/trade/order';
|
||||||
import { DictTag } from '#/components/dict-tag';
|
import { DictTag } from '#/components/dict-tag';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import {
|
import { DeliveryTypeEnum, DICT_TYPE, TradeOrderStatusEnum } from '#/utils';
|
||||||
DeliveryTypeEnum,
|
|
||||||
DICT_TYPE,
|
|
||||||
fenToYuan,
|
|
||||||
TradeOrderStatusEnum,
|
|
||||||
} from '#/utils';
|
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
import DeleveryForm from './modules/delevery-form.vue';
|
import DeleveryForm from './modules/delevery-form.vue';
|
||||||
|
|
|
@ -2,10 +2,11 @@
|
||||||
import type { MemberUserApi } from '#/api/member/user';
|
import type { MemberUserApi } from '#/api/member/user';
|
||||||
import type { PayWalletApi } from '#/api/pay/wallet/balance';
|
import type { PayWalletApi } from '#/api/pay/wallet/balance';
|
||||||
|
|
||||||
|
import { fenToYuan } from '@vben/utils';
|
||||||
|
|
||||||
import { Card } from 'ant-design-vue';
|
import { Card } from 'ant-design-vue';
|
||||||
|
|
||||||
import { useDescription } from '#/components/description';
|
import { useDescription } from '#/components/description';
|
||||||
import { fenToYuan } from '#/utils';
|
|
||||||
|
|
||||||
withDefaults(
|
withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
|
|
|
@ -3,6 +3,8 @@ import type { VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||||
|
|
||||||
import { h } from 'vue';
|
import { h } from 'vue';
|
||||||
|
|
||||||
|
import { convertToInteger, formatToFraction } from '@vben/utils';
|
||||||
|
|
||||||
import { Tag } from 'ant-design-vue';
|
import { Tag } from 'ant-design-vue';
|
||||||
|
|
||||||
import { z } from '#/adapter/form';
|
import { z } from '#/adapter/form';
|
||||||
|
@ -12,9 +14,7 @@ import { getSimpleTagList } from '#/api/member/tag';
|
||||||
import { getAreaTree } from '#/api/system/area';
|
import { getAreaTree } from '#/api/system/area';
|
||||||
import {
|
import {
|
||||||
CommonStatusEnum,
|
CommonStatusEnum,
|
||||||
convertToInteger,
|
|
||||||
DICT_TYPE,
|
DICT_TYPE,
|
||||||
formatToFraction,
|
|
||||||
getDictOptions,
|
getDictOptions,
|
||||||
getRangePickerDefaultProps,
|
getRangePickerDefaultProps,
|
||||||
} from '#/utils';
|
} from '#/utils';
|
||||||
|
|
|
@ -4,6 +4,7 @@ import type { MemberUserApi } from '#/api/member/user';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { formatToFraction } from '@vben/utils';
|
||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
@ -11,7 +12,6 @@ import { useVbenForm } from '#/adapter/form';
|
||||||
import { getUser, updateUser } from '#/api/member/user';
|
import { getUser, updateUser } from '#/api/member/user';
|
||||||
import { getWallet } from '#/api/pay/wallet/balance';
|
import { getWallet } from '#/api/pay/wallet/balance';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { formatToFraction } from '#/utils';
|
|
||||||
|
|
||||||
import { useBalanceFormSchema } from '../data';
|
import { useBalanceFormSchema } from '../data';
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { useRoute, useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { useTabs } from '@vben/hooks';
|
import { useTabs } from '@vben/hooks';
|
||||||
import { formatDate } from '@vben/utils';
|
import { fenToYuan, formatDate } from '@vben/utils';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
@ -19,7 +19,6 @@ import {
|
||||||
|
|
||||||
import { getOrder, submitOrder } from '#/api/pay/order';
|
import { getOrder, submitOrder } from '#/api/pay/order';
|
||||||
import {
|
import {
|
||||||
fenToYuan,
|
|
||||||
PayChannelEnum,
|
PayChannelEnum,
|
||||||
PayDisplayModeEnum,
|
PayDisplayModeEnum,
|
||||||
PayOrderStatusEnum,
|
PayOrderStatusEnum,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import type { WalletRechargePackageApi } from '#/api/pay/wallet/rechargePackage'
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
import { useVbenModal } from '@vben/common-ui';
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { fenToYuan, yuanToFen } from '@vben/utils';
|
||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
import { message } from 'ant-design-vue';
|
||||||
|
|
||||||
|
@ -14,7 +15,6 @@ import {
|
||||||
updatePackage,
|
updatePackage,
|
||||||
} from '#/api/pay/wallet/rechargePackage';
|
} from '#/api/pay/wallet/rechargePackage';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
import { fenToYuan, yuanToFen } from '#/utils';
|
|
||||||
|
|
||||||
import { useFormSchema } from '../data';
|
import { useFormSchema } from '../data';
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,25 @@
|
||||||
// TODO @xingyu:感觉 formatToFraction 可以整合起来;【优先级:低】
|
import { isEmpty, isString, isUndefined } from './inference';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将一个整数转换为分数保留传入的小数
|
||||||
|
* @param num
|
||||||
|
* @param digit
|
||||||
|
*/
|
||||||
|
export function formatToFractionDigit(
|
||||||
|
num: number | string | undefined,
|
||||||
|
digit: number = 2,
|
||||||
|
): string {
|
||||||
|
if (isUndefined(num)) return '0.00';
|
||||||
|
const parsedNumber = isString(num) ? Number.parseFloat(num) : num;
|
||||||
|
return (parsedNumber / 100).toFixed(digit);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将一个整数转换为分数保留两位小数
|
* 将一个整数转换为分数保留两位小数
|
||||||
* @param num
|
* @param num
|
||||||
*/
|
*/
|
||||||
export function formatToFraction(num: number | string | undefined): string {
|
export function formatToFraction(num: number | string | undefined): string {
|
||||||
if (num === undefined) return '0.00';
|
return formatToFractionDigit(num, 2);
|
||||||
const parsedNumber = typeof num === 'string' ? Number.parseFloat(num) : num;
|
|
||||||
return (parsedNumber / 100).toFixed(2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,9 +30,7 @@ export function formatToFraction(num: number | string | undefined): string {
|
||||||
*/
|
*/
|
||||||
export function floatToFixed2(num: number | string | undefined): string {
|
export function floatToFixed2(num: number | string | undefined): string {
|
||||||
let str = '0.00';
|
let str = '0.00';
|
||||||
if (num === undefined) {
|
if (isUndefined(num)) return str;
|
||||||
return str;
|
|
||||||
}
|
|
||||||
const f = formatToFraction(num);
|
const f = formatToFraction(num);
|
||||||
const decimalPart = f.toString().split('.')[1];
|
const decimalPart = f.toString().split('.')[1];
|
||||||
const len = decimalPart ? decimalPart.length : 0;
|
const len = decimalPart ? decimalPart.length : 0;
|
||||||
|
@ -45,8 +56,8 @@ export function floatToFixed2(num: number | string | undefined): string {
|
||||||
* @param num
|
* @param num
|
||||||
*/
|
*/
|
||||||
export function convertToInteger(num: number | string | undefined): number {
|
export function convertToInteger(num: number | string | undefined): number {
|
||||||
if (num === undefined) return 0;
|
if (isUndefined(num)) return 0;
|
||||||
const parsedNumber = typeof num === 'string' ? Number.parseFloat(num) : num;
|
const parsedNumber = isString(num) ? Number.parseFloat(num) : num;
|
||||||
return Math.round(parsedNumber * 100);
|
return Math.round(parsedNumber * 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +136,6 @@ export function erpCountInputFormatter(num: number | string | undefined) {
|
||||||
return erpNumberFormatter(num, ERP_COUNT_DIGIT);
|
return erpNumberFormatter(num, ERP_COUNT_DIGIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// noinspection JSCommentMatchesSignature
|
|
||||||
/**
|
/**
|
||||||
* 【ERP】格式化数量,保留三位小数
|
* 【ERP】格式化数量,保留三位小数
|
||||||
*
|
*
|
||||||
|
@ -148,7 +158,6 @@ export function erpPriceInputFormatter(num: number | string | undefined) {
|
||||||
return erpNumberFormatter(num, ERP_PRICE_DIGIT);
|
return erpNumberFormatter(num, ERP_PRICE_DIGIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// noinspection JSCommentMatchesSignature
|
|
||||||
/**
|
/**
|
||||||
* 【ERP】格式化金额,保留二位小数
|
* 【ERP】格式化金额,保留二位小数
|
||||||
*
|
*
|
||||||
|
@ -167,9 +176,7 @@ export function erpPriceTableColumnFormatter(cellValue: any) {
|
||||||
* @return 总价格。如果有任一为空,则返回 undefined
|
* @return 总价格。如果有任一为空,则返回 undefined
|
||||||
*/
|
*/
|
||||||
export function erpPriceMultiply(price: number, count: number) {
|
export function erpPriceMultiply(price: number, count: number) {
|
||||||
if (price === null || count === null) {
|
if (isEmpty(price) || isEmpty(count)) return undefined;
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
return Number.parseFloat((price * count).toFixed(ERP_PRICE_DIGIT));
|
return Number.parseFloat((price * count).toFixed(ERP_PRICE_DIGIT));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ export * from './date';
|
||||||
export * from './diff';
|
export * from './diff';
|
||||||
export * from './dom';
|
export * from './dom';
|
||||||
export * from './download';
|
export * from './download';
|
||||||
|
export * from './formatNumber';
|
||||||
export * from './inference';
|
export * from './inference';
|
||||||
export * from './letter';
|
export * from './letter';
|
||||||
export * from './merge';
|
export * from './merge';
|
||||||
|
|
Loading…
Reference in New Issue