Przeglądaj źródła

fix(inspection): 巡检结果 0/1 翻译成'正常/异常'中文 + 颜色正确(绿/红)

原代码:el-tag 直接 dump 后端存的 '0'/'1' 数字
用户看到'巡检结果 0'不知道啥意思

修法:
- getResultTag 加 '0'/'1' key(0=success 绿,1=danger 红)
- 新增 getResultLabel(r) 翻译函数:0/1 -> 正常/异常
- 4 个 el-tag 全部用 getResultLabel(checkResult) 显示中文

影响:inspectionTask + qualityInspectionTask 两边列表打卡结果列/详情弹窗描述/项目明细表共 4 处
yangjingjing 2 dni temu
rodzic
commit
eef1357ed4

+ 21 - 5
src/views/risk/inspectionTask/index.vue

@@ -128,7 +128,7 @@
         </el-table-column>
         <el-table-column label="打卡结果" align="center" prop="checkResult" width="100">
           <template #default="scope">
-            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ scope.row.checkResult }}</el-tag>
+            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ getResultLabel(scope.row.checkResult) }}</el-tag>
             <span v-else>-</span>
           </template>
         </el-table-column>
@@ -347,7 +347,7 @@
         </el-table-column>
         <el-table-column label="打卡结果" align="center" width="100">
           <template #default="scope">
-            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ scope.row.checkResult }}</el-tag>
+            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ getResultLabel(scope.row.checkResult) }}</el-tag>
             <span v-else>-</span>
           </template>
         </el-table-column>
@@ -385,7 +385,7 @@
           <el-tag :type="getStatusTag(detailForm.recordStatus)">{{ detailForm.recordStatus }}</el-tag>
         </el-descriptions-item>
         <el-descriptions-item label="打卡结果">
-          <el-tag v-if="detailForm.checkResult" :type="getResultTag(detailForm.checkResult)">{{ detailForm.checkResult }}</el-tag>
+          <el-tag v-if="detailForm.checkResult" :type="getResultTag(detailForm.checkResult)">{{ getResultLabel(detailForm.checkResult) }}</el-tag>
           <span v-else>-</span>
         </el-descriptions-item>
         <el-descriptions-item label="打卡地点">{{ detailForm.checkInLocation }}</el-descriptions-item>
@@ -407,7 +407,7 @@
         <el-table-column label="巡检内容" prop="itemContent" />
         <el-table-column label="巡检结果" prop="checkResult" width="100">
           <template #default="scope">
-            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)" size="small">{{ scope.row.checkResult }}</el-tag>
+            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)" size="small">{{ getResultLabel(scope.row.checkResult) }}</el-tag>
             <span v-else>-</span>
           </template>
         </el-table-column>
@@ -1030,11 +1030,27 @@ const getStatusTag = (s: string): 'primary' | 'success' | 'warning' | 'info' | '
 const getResultTag = (r: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
   const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
     正常: 'success',
-    异常: 'danger'
+    异常: 'danger',
+    '0': 'success', // 0=正常
+    '1': 'danger'  // 1=异常
   };
   return (map[r] || 'info') as any;
 };
 
+/**
+ * 巡检结果码 → 中文标签
+ * - 后端存储:0=正常 / 1=异常(也兼容直接存"正常"/"异常"的老数据)
+ */
+const getResultLabel = (r: string): string => {
+  const map: Record<string, string> = {
+    '0': '正常',
+    '1': '异常',
+    正常: '正常',
+    异常: '异常'
+  };
+  return map[r] || r || '-';
+};
+
 onMounted(async () => {
   await loadAll();
   await loadDeptChainUsers();

+ 21 - 5
src/views/risk/qualityInspectionTask/index.vue

@@ -129,7 +129,7 @@
         </el-table-column>
         <el-table-column label="打卡结果" align="center" prop="checkResult" width="100">
           <template #default="scope">
-            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ scope.row.checkResult }}</el-tag>
+            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ getResultLabel(scope.row.checkResult) }}</el-tag>
             <span v-else>-</span>
           </template>
         </el-table-column>
@@ -348,7 +348,7 @@
         </el-table-column>
         <el-table-column label="打卡结果" align="center" width="100">
           <template #default="scope">
-            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ scope.row.checkResult }}</el-tag>
+            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)">{{ getResultLabel(scope.row.checkResult) }}</el-tag>
             <span v-else>-</span>
           </template>
         </el-table-column>
@@ -386,7 +386,7 @@
           <el-tag :type="getStatusTag(detailForm.recordStatus)">{{ detailForm.recordStatus }}</el-tag>
         </el-descriptions-item>
         <el-descriptions-item label="打卡结果">
-          <el-tag v-if="detailForm.checkResult" :type="getResultTag(detailForm.checkResult)">{{ detailForm.checkResult }}</el-tag>
+          <el-tag v-if="detailForm.checkResult" :type="getResultTag(detailForm.checkResult)">{{ getResultLabel(detailForm.checkResult) }}</el-tag>
           <span v-else>-</span>
         </el-descriptions-item>
         <el-descriptions-item label="打卡地点">{{ detailForm.checkInLocation }}</el-descriptions-item>
@@ -408,7 +408,7 @@
         <el-table-column label="巡检内容" prop="itemContent" />
         <el-table-column label="巡检结果" prop="checkResult" width="100">
           <template #default="scope">
-            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)" size="small">{{ scope.row.checkResult }}</el-tag>
+            <el-tag v-if="scope.row.checkResult" :type="getResultTag(scope.row.checkResult)" size="small">{{ getResultLabel(scope.row.checkResult) }}</el-tag>
             <span v-else>-</span>
           </template>
         </el-table-column>
@@ -1014,11 +1014,27 @@ const getStatusTag = (s: string): 'primary' | 'success' | 'warning' | 'info' | '
 const getResultTag = (r: string): 'primary' | 'success' | 'warning' | 'info' | 'danger' => {
   const map: Record<string, 'primary' | 'success' | 'warning' | 'info' | 'danger'> = {
     正常: 'success',
-    异常: 'danger'
+    异常: 'danger',
+    '0': 'success', // 0=正常
+    '1': 'danger'  // 1=异常
   };
   return (map[r] || 'info') as any;
 };
 
+/**
+ * 巡检结果码 → 中文标签
+ * - 后端存储:0=正常 / 1=异常(也兼容直接存"正常"/"异常"的老数据)
+ */
+const getResultLabel = (r: string): string => {
+  const map: Record<string, string> = {
+    '0': '正常',
+    '1': '异常',
+    正常: '正常',
+    异常: '异常'
+  };
+  return map[r] || r || '-';
+};
+
 onMounted(async () => {
   await loadAll();
   await loadDeptChainUsers();