Преглед изворни кода

fix(uniapp): readonly 模式保留后端 photos + checkResult→result 映射

之前 loadDetail 不管什么模式都把 photos/result 清成空:
  items.value = (data.items || []).map((it) => ({
    ...it,
    result: undefined,
    photos: []  // 覆盖了后端 record_item.photos
  }))

导致 readonly '查看详情' 显示:
  - 检查结果两个按钮都是空(后端 checkResult='0' 正常没映射)
  - 现场照片区永远空(后端 photos 被覆盖成 [])

修复:按 readonly 区分
  - readonly=true: 保留后端字段
    - checkResult '0'/'1' → result 'NORMAL'/'ABNORMAL' 给模板
    - photos 字符串逗号分隔 → 数组
    - remark → reason
  - readonly=false: 清空用户态字段,让用户重新填
yangjingjing пре 1 дан
родитељ
комит
465c2a1ad9
2 измењених фајлова са 49 додато и 13 уклоњено
  1. 25 7
      src/pages/inspection/check/index.vue
  2. 24 6
      src/pages/qualityInspection/check/index.vue

+ 25 - 7
src/pages/inspection/check/index.vue

@@ -170,13 +170,31 @@ async function loadDetail() {
         ...data,
         punchLocation: raw.punchLocation || raw.location || ''
       }
-      items.value = (data.items || []).map((it) => ({
-        ...it,
-        needPhoto: it.needPhoto === '1' || it.needPhoto === true,
-        result: undefined,
-        reason: '',
-        photos: []
-      }))
+      items.value = (data.items || []).map((it) => {
+        const base: any = {
+          ...it,
+          needPhoto: it.needPhoto === '1' || it.needPhoto === true
+        }
+        if (readonly.value) {
+          // readonly 模式:保留后端返回的已打卡数据
+          // - checkResult: '0' 正常 / '1' 异常 → 映射成 NORMAL/ABNORMAL 给模板用
+          // - photos: 后端 record_item.photos(逗号分隔,可能为空)
+          // - problemCount / remark: 透传
+          base.result =
+            (it as any).checkResult === '0' ? 'NORMAL'
+            : (it as any).checkResult === '1' ? 'ABNORMAL'
+            : undefined
+          base.reason = (it as any).remark || ''
+          const photos = (it as any).photos as string | undefined
+          base.photos = photos ? photos.split(',').filter(Boolean) : []
+        } else {
+          // 编辑模式:清空用户态字段,让用户重新填
+          base.result = undefined
+          base.reason = ''
+          base.photos = []
+        }
+        return base
+      })
     }
   } catch (e: any) {
     // 接口失败:清空数据 + 错误提示(不再使用假数据)

+ 24 - 6
src/pages/qualityInspection/check/index.vue

@@ -152,12 +152,30 @@ async function loadDetail() {
     const data = await getQualityTaskDetail(taskId.value)
     if (data) {
       task.value = data
-      items.value = (data.items || []).map((it) => ({
-        ...it,
-        result: undefined,
-        reason: '',
-        photos: []
-      }))
+      items.value = (data.items || []).map((it) => {
+        const base: any = {
+          ...it,
+          needPhoto: it.needPhoto === '1' || it.needPhoto === true
+        }
+        if (readonly.value) {
+          // readonly 模式:保留后端返回的已打卡数据
+          // - checkResult: '0' 正常 / '1' 异常 → 映射成 NORMAL/ABNORMAL 给模板用
+          // - photos: 后端 record_item.photos(逗号分隔)
+          base.result =
+            (it as any).checkResult === '0' ? 'NORMAL'
+            : (it as any).checkResult === '1' ? 'ABNORMAL'
+            : undefined
+          base.reason = (it as any).remark || ''
+          const photos = (it as any).photos as string | undefined
+          base.photos = photos ? photos.split(',').filter(Boolean) : []
+        } else {
+          // 编辑模式:清空用户态字段,让用户重新填
+          base.result = undefined
+          base.reason = ''
+          base.photos = []
+        }
+        return base
+      })
     }
   } catch (e: any) {
     task.value = {} as any