From 228b881e5a893ec010a194ac42011a4169d0c590 Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期二, 21 四月 2026 14:24:15 +0800
Subject: [PATCH] 料箱码查询优化

---
 rsf-admin/src/utils/common.js |   64 ++++++++++++++++++++++++++++++-
 1 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/rsf-admin/src/utils/common.js b/rsf-admin/src/utils/common.js
index 2083ca8..53ff85c 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;
@@ -6,10 +41,15 @@
     const navMenus = [];
     const traverse = (nodes) => {
         nodes.forEach((node) => {
-            if (!node.children) {
-                navMenus.push(node);
+            // 鍙跺瓙锛氭棤瀛愭垨 children 涓虹┖鏁扮粍锛涗粎鏀堕泦鏈� component 鐨勮妭鐐癸紙椤甸潰璧勬簮锛�
+            const children = node.children;
+            const hasChildren = Array.isArray(children) && children.length > 0;
+            if (!hasChildren) {
+                if (node.component) {
+                    navMenus.push(node);
+                }
             } else {
-                traverse(node.children);
+                traverse(children);
             }
         });
     };
@@ -50,3 +90,21 @@
     });
     return result;
 };
+
+export const haveChildren = (item) => {
+    if (Array.isArray(item)) {
+        return item.map((k) => haveChildren(k));
+    }
+
+    if (item && typeof item === 'object') {
+        if (item.id !== undefined) {
+            item.id = item.id.toString();
+        }
+
+        if (item.children && Array.isArray(item.children)) {
+            item.children = haveChildren(item.children);
+        }
+    }
+
+    return item;
+};

--
Gitblit v1.9.1