From c81fc5e2a4f4153be2bb8602ed14a0743e6ecd29 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期四, 05 三月 2026 11:14:50 +0800
Subject: [PATCH] RCS对接优化
---
rsf-admin/src/utils/common.js | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/rsf-admin/src/utils/common.js b/rsf-admin/src/utils/common.js
index 309c6eb..a230a7f 100644
--- a/rsf-admin/src/utils/common.js
+++ b/rsf-admin/src/utils/common.js
@@ -1,4 +1,39 @@
+/** 鍓嶇鏁伴噺鏄剧ず锛氱粺涓�淇濈暀2浣嶅皬鏁帮紙浠呭睍绀猴紝鍚庣涓嶅彉锛� */
+export const formatQuantity = (value) => {
+ if (value == null || value === '') return '0.00';
+ const n = Number(value);
+ if (Number.isNaN(n)) return '0.00';
+ if (n < 0) return '0.00';
+ return n.toFixed(2);
+};
+
+/** 鐢ㄤ簬 react-admin NumberField 鐨勬暟閲忓睍绀� options锛�2浣嶅皬鏁帮級 */
+export const QTY_NUMBER_OPTIONS = { minimumFractionDigits: 2, maximumFractionDigits: 2 };
+
+/** 鏍¢獙鏈�澶� N 浣嶅皬鏁帮紝鐢ㄤ簬鏁伴噺绫诲瓧娈碉紱瓒呰繃鏃惰繑鍥為敊璇俊鎭苟闃绘鎻愪氦 */
+export const maxDecimalPlaces = (maxDecimals, message) => {
+ const factor = Math.pow(10, maxDecimals);
+ const msg = message || `鏈�澶�${maxDecimals}浣嶅皬鏁癭;
+ return (value) => {
+ if (value == null || value === '') return undefined;
+ const n = Number(value);
+ if (Number.isNaN(n)) return undefined;
+ const rounded = Math.round(n * factor) / factor;
+ if (Math.abs(n - rounded) > 1e-10) return msg;
+ return undefined;
+ };
+};
+
+/** 鍒ゆ柇鏁板�兼槸鍚﹁秴杩� 6 浣嶅皬鏁帮紙鐢ㄤ簬鎻愪氦鍓嶆牎楠岋級 */
+export const hasMoreThan6Decimals = (value) => {
+ if (value == null || value === '') return false;
+ const n = Number(value);
+ if (Number.isNaN(n)) return false;
+ const rounded = Math.round(n * 1e6) / 1e6;
+ return Math.abs(n - rounded) > 1e-10;
+};
+
export const extractNavMenus = (data) => {
if (!data) {
return;
--
Gitblit v1.9.1