|
| 1 | +from pathlib import Path |
| 2 | +import argparse |
| 3 | + |
| 4 | + |
| 5 | +def main(): |
| 6 | + parser = argparse.ArgumentParser(description="Generate VTable diagnosis HTML") |
| 7 | + parser.add_argument("--title", default="VTable 问题诊断报告") |
| 8 | + parser.add_argument("--desc", default="基于用户配置的诊断与修复结果") |
| 9 | + parser.add_argument("--config-file") |
| 10 | + parser.add_argument("--output", default="output/diagnosis.html") |
| 11 | + args = parser.parse_args() |
| 12 | + |
| 13 | + template_path = Path(__file__).resolve().parent.parent / "template" / "diagnosis.html" |
| 14 | + if not template_path.exists(): |
| 15 | + raise FileNotFoundError(f"模板不存在: {template_path}") |
| 16 | + |
| 17 | + if args.config_file: |
| 18 | + config_path = Path(args.config_file) |
| 19 | + if not config_path.exists(): |
| 20 | + raise FileNotFoundError(f"配置文件不存在: {config_path}") |
| 21 | + config_block = config_path.read_text(encoding="utf-8") |
| 22 | + else: |
| 23 | + config_block = """const problemReview = { |
| 24 | + specCode: `const tableInstance = new VTable.ListTable({ |
| 25 | + container: document.getElementById('container'), |
| 26 | + records: [{ name: "张三", age: 25 }], |
| 27 | + columns: [ |
| 28 | + { field: "name", title: "姓名", width: 100 }, |
| 29 | + { field: "age", title: "年龄", width: 80 } |
| 30 | + ], |
| 31 | + width: 600, |
| 32 | + height: 400 |
| 33 | +});` |
| 34 | +}; |
| 35 | +
|
| 36 | +const diagnosis = { |
| 37 | + problem: "示例问题描述", |
| 38 | + cause: "示例原因分析", |
| 39 | + suggestion: "示例修复建议" |
| 40 | +}; |
| 41 | +
|
| 42 | +const solutions = [ |
| 43 | + { |
| 44 | + title: "示例修复方案", |
| 45 | + description: "修复方案描述", |
| 46 | + specCode: `const tableInstance = new VTable.ListTable({ |
| 47 | + container: document.getElementById('container'), |
| 48 | + records: [{ name: "张三", age: 25 }], |
| 49 | + columns: [ |
| 50 | + { field: "name", title: "姓名", width: 120 }, |
| 51 | + { field: "age", title: "年龄", width: 80 } |
| 52 | + ], |
| 53 | + width: 600, |
| 54 | + height: 400 |
| 55 | +});` |
| 56 | + } |
| 57 | +];""" |
| 58 | + |
| 59 | + html = template_path.read_text(encoding="utf-8") |
| 60 | + if "{{CONFIG_BLOCK}}" not in html: |
| 61 | + raise ValueError("模板缺少 CONFIG_BLOCK 占位符") |
| 62 | + |
| 63 | + html = html.replace("{{REPORT_TITLE}}", args.title) |
| 64 | + html = html.replace("{{REPORT_DESC}}", args.desc) |
| 65 | + html = html.replace("{{CONFIG_BLOCK}}", config_block) |
| 66 | + |
| 67 | + output_path = Path(args.output) |
| 68 | + output_path.parent.mkdir(parents=True, exist_ok=True) |
| 69 | + output_path.write_text(html, encoding="utf-8") |
| 70 | + print(f"生成完成: {output_path.resolve()}") |
| 71 | + |
| 72 | + |
| 73 | +if __name__ == "__main__": |
| 74 | + main() |
0 commit comments