Forráskód Böngészése

修改发布商品规格显示异常问题

ext.liuqiwen3 1 hete
szülő
commit
4a3776c4f6
1 módosított fájl, 40 hozzáadás és 21 törlés
  1. 40 21
      pages/merchantCenters/releaseProduct.vue

+ 40 - 21
pages/merchantCenters/releaseProduct.vue

@@ -556,7 +556,18 @@
 
 	// 规格更新回调
 	const onUpdateAttr = (data) => {
+    console.log(data)
+    const formattedData = data.map(item => {
+      return {
+        ...item,
+        attrValue: typeof item.attrValue === 'string' ?
+            JSON.parse(item.attrValue) :
+            item.attrValue
+      };
+    });
 		const table = attrFormat(data)
+    console.log(table)
+
 		attr.value = data.concat();
 		attrTable.value = table
 	}
@@ -1373,31 +1384,39 @@
     }
 
     try {
-      // 尝试解析JSON
-      const data = JSON.parse(attr.attrValue);
-      const result = [];
-
-      // 遍历所有属性
-      for (const [key, value] of Object.entries(data)) {
-        if (key === "单规格") {
-          // 如果是单规格,直接返回值
-          return value;
-        } else if (key === "重量" || key === "重量(克)" || key.endsWith("重量")) {
-          // 如果属性名包含"重量",添加单位g
-          result.push(`${key}:${value}g`);
-        } else {
-          // 圈号直接显示
-          result.push(`${key}:${value}`);
-        }
+      let data = attr.attrValue;
+
+      // 如果attrValue是字符串,尝试解析JSON
+      if (typeof data === 'string') {
+        data = JSON.parse(data);
       }
 
-      // 用逗号连接所有属性
-      return result.join(",");
+      // 如果解析后是对象,处理对象格式
+      if (typeof data === 'object' && data !== null) {
+        const result = [];
+
+        // 遍历所有属性
+        for (const [key, value] of Object.entries(data)) {
+          if (key === "单规格") {
+            // 如果是单规格,直接返回值
+            return value;
+          } else {
+            // 其他属性按 key:value 格式显示
+            result.push(`${key}:${value}`);
+          }
+        }
+
+        // 用逗号连接所有属性
+        return result.join(",");
+      } else {
+        // 如果不是对象,返回原始值
+        return typeof attr.attrValue === 'string' ? attr.attrValue : String(attr.attrValue);
+      }
 
     } catch (error) {
-      // 如果不是有效的JSON,返回原始值
-      console.error("解析JSON失败:", error);
-      return attr.attrValue;
+      // 如果解析失败,返回原始值
+      console.log("解析JSON失败,使用原始值:", attr.attrValue, error);
+      return typeof attr.attrValue === 'string' ? attr.attrValue : String(attr.attrValue);
     }
   };
 </script>