Files
wecom_it_smart_desk/data/seed-templates/build_all.py
T
Simon cec5607c45 feat(admin): Flowcharts.vue JSON 在线编辑 + 9 套排查模板种子数据
为管理后台'排查流程图'模块加 JSON 在线编辑能力 + 提供 9 套
办公 IT 常见故障排查模板种子数据(账号/系统/企微/VPN/邮箱/网络/
打印机/软件/硬件),管理员可基于此学习、筛选、修改、新增。

## 选型(按'优选开源'原则)
- @codemirror/lang-json / state / theme-one-dark / view
- codemirror(核心)
- vue-codemirror(Vue 3 集成)
- vue-json-pretty(JSON 树形预览)
全部为社区成熟开源组件,非自行开发

## 改动
- frontend-admin/package.json: 加 6 个 npm 依赖
- frontend-admin/src/api/troubleshooting.ts(新): TS 类型 +
  5 个 API client(listTemplates / getTemplate / createTemplate /
  updateTemplate / deleteTemplate) + formatJson/validateJson/
  countNodes/countDecisions 工具函数
- frontend-admin/src/components/flowchart/FlowchartEditorDialog.vue(新):
  双面板编辑器(左 CodeMirror + 右 vue-json-pretty),
  实时 JSON 校验 + 节点/决策统计 + 格式/复制/导出按钮
- frontend-admin/src/views/Flowcharts.vue(改): 列表 + 导入/导出/
  新建按钮 + EditorDialog 集成 + 文件上传 + 删除确认

## 9 套种子数据
- 01-account-password.json 账号密码
- 02-pc-system.json        电脑系统
- 03-wecom.json            企微问题
- 04-vpn.json              VPN 接入
- 05-email.json            邮箱
- 06-network.json          网络
- 07-printer.json          打印机
- 08-software.json         软件
- 09-hardware.json         硬件
每套 ~150-200 行,结构:name / category / description /
estimated_time / difficulty / tags / root_node(决策树)

## 工具脚本
- data/seed-templates/build_all.py: 合并 9 个 JSON 成 00-all.json
2026-06-16 14:30:09 +08:00

55 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""
把 9 套排查流程图 JSON 合并到一个数组,输出 00-all.json(便于一次性 import)。
用法:python build_all.py
"""
import json
import glob
import os
import sys
from pathlib import Path
HERE = Path(__file__).parent
def main():
# 1. 找 9 个单文件(排除 00-all.json 和 build_all.py)
files = sorted(HERE.glob("[0-9][0-9]-*.json"))
if not files:
print("❌ 没找到任何 0X-*.json 文件")
sys.exit(1)
print(f"📦 找到 {len(files)} 个模板文件:")
for f in files:
print(f" - {f.name}")
# 2. 逐个读 + 校验
templates = []
for f in files:
try:
with open(f, "r", encoding="utf-8") as fp:
tpl = json.load(fp)
# 简单校验
for required in ("name", "category", "root_node"):
if required not in tpl:
raise ValueError(f"缺少必要字段: {required}")
templates.append(tpl)
print(f"{f.name}: {tpl['name']} ({len(json.dumps(tpl, ensure_ascii=False))} 字符)")
except Exception as e:
print(f"{f.name}: {e}")
sys.exit(1)
# 3. 输出汇总文件
out = HERE / "00-all.json"
with open(out, "w", encoding="utf-8") as fp:
json.dump(templates, fp, ensure_ascii=False, indent=2)
print(f"\n✅ 已生成 {out.name} (共 {len(templates)} 套)")
print(f"\n💡 接下来你可以:")
print(f" 1. 打开 {out.name} 预览 9 套完整内容")
print(f" 2. 在 Admin 后台的「排查流程图」页 → 「导入 JSON」选择此文件")
print(f" 3. 或调用后端 API:")
print(f" for tpl in templates: POST /api/troubleshooting-templates")
if __name__ == "__main__":
main()