From 7ce1ea8fa47751145c92a00525cd4ada2d997aba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E9=A6=99=E7=90=AA?= <624506849@qq.com> Date: Wed, 1 Jul 2026 15:09:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20formatPrice=20?= =?UTF-8?q?=E5=AF=B9=E7=A9=BA=E5=80=BC=E5=92=8C=E9=9D=9E=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E4=BB=B7=E6=A0=BC=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免表格调用 unitPrice 时因 price 为 undefined/null/非法字符串导致报错。 Co-authored-by: Cursor --- manager/src/utils/filters.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/manager/src/utils/filters.js b/manager/src/utils/filters.js index 16dd6008..2edd163a 100644 --- a/manager/src/utils/filters.js +++ b/manager/src/utils/filters.js @@ -1,3 +1,5 @@ +import { getRouter } from "@/libs/router-holder"; + /** * 金钱单位置换 2999 --> 2,999.00 * @param val @@ -32,11 +34,13 @@ export function enCode(v1) { return v1; } -import {router} from "@/router/index"; /** * 自定义跳转 */ export function customRouterPush(push){ + const router = getRouter(); + if (!router) return; + const setting = window.localStorage.getItem('admin-setting') ? JSON.parse(window.localStorage.getItem('admin-setting')) : {}; if(setting.isUseTabsRouter){ @@ -142,8 +146,14 @@ let timeout = null; * @returns {string} */ export function formatPrice(price) { - if (typeof price !== 'number') return price - return String(Number(price).toFixed(2)).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + if (price === null || price === undefined || price === "") { + return "0.00"; + } + const num = typeof price === "number" ? price : Number(price); + if (Number.isNaN(num)) { + return "0.00"; + } + return String(num.toFixed(2)).replace(/\B(?=(\d{3})+(?!\d))/g, ","); } /**