#!/usr/bin/env python # -*- coding: utf-8 -*- """二维码/条形码单元格:预览时解析静态值或 #{参数}""" import copy from typing import Any, Dict from online_dev.report_manager.engine.preview_mvp import _replace_params_in_value def apply_code_cells( snapshot: Dict[str, Any], params: Dict[str, Any], ) -> Dict[str, Any]: """扫描 snapshot 中 qrCode/jsbarcode 单元格,将 field 解析后写入 v""" if not snapshot: return snapshot or {} result = copy.deepcopy(snapshot) sheets = result.get("sheets") or {} for sheet in sheets.values(): if not isinstance(sheet, dict): continue cell_data = sheet.get("cellData") or {} for row_key, row in cell_data.items(): if not isinstance(row, dict): continue for col_key, cell in row.items(): if not isinstance(cell, dict): continue custom = cell.get("custom") or {} code_type = custom.get("type") if code_type not in ("qrCode", "jsbarcode"): continue raw = custom.get("field") or cell.get("v") or "" if raw is None: continue resolved = _replace_params_in_value(str(raw), params) cell["v"] = resolved custom["field"] = resolved cell["custom"] = custom result["sheets"] = sheets return result