From 6ae6ee885f0acb59f4c8b2d2439fb58a0a345701 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 19 十月 2026 16:29:14 +0800
Subject: [PATCH] feat: support formatted inspection values

---
 src/views/standard/model/index.vue               |   14 +++++++
 src/utils/inspectionValueFormat.js               |   58 +++++++++++++++++++++++++++++
 package.json                                     |    1 
 src/components/Excel/luckysheet.vue              |    7 +++
 src/views/business/inspectionTask/inspection.vue |   14 ++++++
 5 files changed, 93 insertions(+), 1 deletions(-)

diff --git a/package.json b/package.json
index ca6f270..2605259 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,7 @@
     "html2canvas": "^1.4.1",
     "js-beautify": "1.15.4",
     "js-cookie": "3.0.5",
+    "jsbarcode": "^3.12.3",
     "jsencrypt": "3.3.2",
     "jspdf": "^2.5.2",
     "mammoth": "^1.13.0",
diff --git a/src/components/Excel/luckysheet.vue b/src/components/Excel/luckysheet.vue
index bf779ad..204b6eb 100644
--- a/src/components/Excel/luckysheet.vue
+++ b/src/components/Excel/luckysheet.vue
@@ -51,6 +51,13 @@
   mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1024 1024'%3E%3Cpath d='M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896m0 192a58.43 58.43 0 0 0-58.24 63.744l23.36 256.384a35.072 35.072 0 0 0 69.76 0l23.296-256.384A58.43 58.43 0 0 0 512 256m0 512a51.2 51.2 0 1 0 0-102.4 51.2 51.2 0 0 0 0 102.4'/%3E%3C/svg%3E") center/contain no-repeat;
 }
 
+/* Luckysheet 鐨勫伐鍏锋爮涓嬫媺鑿滃崟锛堟壒娉ㄣ�佸瓧浣撻鑹茬瓑锛夋槸鎸傚湪 body 涓婄殑锛�
+   榛樿 z-index 鍙湁 1004锛涗笂闈� #luckysheet 鎶埌浜� 99999锛屼細鎶婅繖浜涜彍鍗曟暣涓洊浣忥紝
+   琛ㄧ幇涓衡�滅偣鎵规敞娌″弽搴斺�濄�傛妸 body 绾ц彍鍗曟姮鍒板鍣ㄤ箣涓娿�� */
+.luckysheet-cols-menu {
+  z-index: 100001 !important;
+}
+
 #luckysheet .save:hover {
   opacity: 0.8;
 }
diff --git a/src/utils/inspectionValueFormat.js b/src/utils/inspectionValueFormat.js
new file mode 100644
index 0000000..f0f536a
--- /dev/null
+++ b/src/utils/inspectionValueFormat.js
@@ -0,0 +1,58 @@
+/**
+ * 瑙f瀽鍘熷璁板綍妯℃澘涓殑妫�楠屽�兼壒娉ㄣ��
+ * 鍏煎鏃ф牸寮忊�滄楠屽�尖�濓紝骞舵敮鎸侊細妫�楠屽�硷紝2銆佹楠屽�硷紝2锛岀瀛﹁鏁版硶銆�
+ */
+export function parseInspectionValueAnnotation(annotation) {
+  if (typeof annotation !== 'string' || !annotation.includes('妫�楠屽��')) return null;
+  // 鎵规敞鍏佽涓枃閫楀彿銆佽嫳鏂囬�楀彿浠ュ強鈥滃拰鈥濊繛鎺ユ牸寮忓弬鏁般��
+  const parts = annotation
+    .replace(/锛�/g, ',')
+    .replace(/\s+/g, '')
+    .replace(/鍜�/g, ',')
+    .split(',')
+    .map(item => item.trim())
+    .filter(Boolean);
+  const decimalPlaces = parts[1] === '' || parts[1] == null ? null : Number(parts[1]);
+  if (decimalPlaces != null && (!Number.isInteger(decimalPlaces) || decimalPlaces < 0 || decimalPlaces > 15)) {
+    return { error: '灏忔暟浣嶆暟蹇呴』鏄� 0 鍒� 15 鐨勬暣鏁�' };
+  }
+  const displayMode = parts.slice(2).includes('绉戝璁℃暟娉�') ? 'SCIENTIFIC' : 'NORMAL';
+  const roundingNames = {
+    '鍥涜垗浜斿叆': 'HALF_UP',
+    '鍥涜垗鍏叆': 'HALF_UP_6',
+    '鍚戜笂鑸嶅叆': 'CEILING',
+    '鍚戜笅鑸嶅叆': 'FLOOR',
+    '鎴柇': 'DOWN'
+  };
+  const roundingPart = parts.slice(2).find(item => Object.prototype.hasOwnProperty.call(roundingNames, item));
+  const unsupported = parts.slice(2).filter(item => item && item !== '绉戝璁℃暟娉�' && !roundingNames[item]);
+  if (unsupported.length || parts.length > 4) {
+    return { error: '妫�楠屽�兼壒娉ㄦ牸寮忓簲涓猴細妫�楠屽�硷紝2锛屽洓鑸嶄簲鍏� 鎴� 妫�楠屽�硷紝2锛岀瀛﹁鏁版硶锛屽洓鑸嶄簲鍏�' };
+  }
+  return { decimalPlaces, displayMode, roundingMode: roundingPart ? roundingNames[roundingPart] : 'HALF_UP' };
+}
+
+export function formatInspectionValue(value, config) {
+  if (!config || config.error || config.decimalPlaces == null || value === '' || value == null) return value;
+  const number = Number(value);
+  if (!Number.isFinite(number)) return value;
+  const factor = 10 ** config.decimalPlaces;
+  let rounded;
+  if (config.roundingMode === 'CEILING') rounded = Math.ceil(number * factor) / factor;
+  else if (config.roundingMode === 'FLOOR') rounded = Math.floor(number * factor) / factor;
+  else if (config.roundingMode === 'DOWN') rounded = (number < 0 ? Math.ceil(number * factor) : Math.floor(number * factor)) / factor;
+  else if (config.roundingMode === 'HALF_UP_6') {
+    const absolute = Math.abs(number) * factor;
+    const base = Math.floor(absolute);
+    const fraction = absolute - base;
+    rounded = (number < 0 ? -1 : 1) * ((fraction >= 0.6 ? base + 1 : base) / factor);
+  } else rounded = Math.round((number + (number >= 0 ? Number.EPSILON : -Number.EPSILON)) * factor) / factor;
+  return config.displayMode === 'SCIENTIFIC'
+    ? rounded.toExponential(config.decimalPlaces)
+    : rounded.toFixed(config.decimalPlaces);
+}
+
+export function validateInspectionValueAnnotation(annotation) {
+  const config = parseInspectionValueAnnotation(annotation);
+  return config && config.error ? config.error : null;
+}
diff --git a/src/views/business/inspectionTask/inspection.vue b/src/views/business/inspectionTask/inspection.vue
index bc31b8c..0150dfc 100644
--- a/src/views/business/inspectionTask/inspection.vue
+++ b/src/views/business/inspectionTask/inspection.vue
@@ -521,6 +521,7 @@
 import { mapGetters } from "@/utils/store-compat";
 import viewManHourDia from "@/views/business/inspectionTask/components/viewManHourDia.vue";
 import {getDicts} from "@/api/system/dict/data";
+import { parseInspectionValueAnnotation, formatInspectionValue } from "@/utils/inspectionValueFormat";
 export default {
   name: 'Inspection',
   components: {
@@ -1575,6 +1576,17 @@
     // 妫�楠屽�艰緭鍏ュ悗瑙﹀彂鐨勫嚱鏁�
     changeInput(m, code, n) {
       if (n) {
+        const config = parseInspectionValueAnnotation(n.v && n.v.ps && n.v.ps.value);
+        if (config && !config.error && config.decimalPlaces != null && typeof n.v.v === 'string') {
+          const numericPattern = config.displayMode === 'SCIENTIFIC'
+            ? /^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/
+            : /^[+-]?\d*\.?\d+$/;
+          if (n.v.v.trim() && !numericPattern.test(n.v.v.trim())) {
+            this.$message.warning('璇ユ楠屽�煎繀椤诲~鍐欐暟瀛�');
+            return;
+          }
+          n.v.v = formatInspectionValue(n.v.v, config);
+        }
         // 瀹氫箟涓�涓嚱鏁版潵楠岃瘉鍒嗘暟鏄惁鏈夋晥
         if (typeof n.v.v == "string") {
           function isValidFraction(fraction) {
@@ -1705,7 +1717,7 @@
         const v = n.v.v;
         // 鑳藉姏鑼冨洿宸插簾寮�,妫�楠屽�肩被鍨嬩笉鍐嶄綔涓哄垽鏂緷鎹�傛暣涓插彧鐢辩畻寮忓瓧绗︾粍鎴愭椂鎵嶈鑼冨寲鏍煎紡,
         // 鍑虹幇涓枃绛夊叾瀹冨瓧绗﹀嵆鎸夋枃鏈鐞嗗師鏍蜂繚鐣�,鍚﹀垯鏂囧瓧浼氳閫愬瓧鍒犳帀
-        if (typeof v !== "string" || /[^\d.^e>锛炩墺鈮�<锛滄柇瑁傝剢鍖朶-/+]/.test(v)) {
+        if (typeof v !== "string" || /[^\d.^eE>锛炩墺鈮�<锛滄柇瑁傝剢鍖朶-/+]/.test(v)) {
           return;
         }
         n.v.v = v
diff --git a/src/views/standard/model/index.vue b/src/views/standard/model/index.vue
index 9821820..d4e0274 100644
--- a/src/views/standard/model/index.vue
+++ b/src/views/standard/model/index.vue
@@ -64,6 +64,7 @@
   delStandardTemplate,
   getEditTemplatePreparation,
 } from "@/api/standard/model";
+import { validateInspectionValueAnnotation } from "@/utils/inspectionValueFormat";
 export default {
   name: 'Model',
   components: {
@@ -349,7 +350,12 @@
           }
         }
       }
+      let annotationError = null;
       data.data[0].celldata.forEach((a) => {
+        if (a.v && a.v.ps && typeof a.v.ps.value === "string") {
+          const error = validateInspectionValueAnnotation(a.v.ps.value);
+          if (!annotationError && error) annotationError = `鍗曞厓鏍�(${a.r + 1}琛�${a.c + 1}鍒�)锛�${error}`;
+        }
         if (
           a.v.ps != undefined &&
           (a.v.ps.value === "妫�楠屽��" ||
@@ -362,6 +368,11 @@
           }
         }
       });
+      if (annotationError) {
+        this.loading = false;
+        this.$message.error(annotationError);
+        return;
+      }
       upStandardTemplate({
         id: this.row.id,
         thing: JSON.stringify(data),
@@ -370,6 +381,9 @@
         this.loading = false;
         this.$message.success("宸蹭繚瀛�");
         this.isShow = false;
+      }).catch((error) => {
+        this.loading = false;
+        this.$message.error(error.message || "妯℃澘淇濆瓨澶辫触");
       });
     },
     isClose(done) {

--
Gitblit v1.9.3