Skip to content

Commit 1fb7c28

Browse files
authored
Merge pull request #5019 from VisActor/docs/skill-workflow
docs: add workflow scenarios for VTable diagnosis and configuration g…
2 parents bcc9a94 + 7fd685a commit 1fb7c28

8 files changed

Lines changed: 971 additions & 2 deletions

File tree

.prettierignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ shrinkwrap.json
2323

2424
# Build outputs
2525
dist
26-
lib
26+
lib
27+
28+
# Skill templates (contain placeholder syntax that formatters break)
29+
skills/vtable-development-assistant/template/

skills/vtable-development-assistant/SKILL.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ references/
3737
| 属性、property | `references/knowledge/06-api-properties.md` |
3838
| 事件、on、监听、click、scroll | `references/knowledge/07-events.md``references/type/event-types.md` |
3939
| 维度、dimension、指标、indicator | `references/knowledge/08-pivot-dimensions.md``references/type/pivot-types.md` |
40-
| 数据、records、dataSource | `references/knowledge/09-data-binding.md` |
40+
| 数据、records、dataSource | `references/knowledge/09-data-bindingd.md` |
4141
| 交互、选择、hover、编辑、拖拽、排序 | `references/knowledge/10-interaction.md` |
4242
| 最佳实践、模式、怎么做 | `references/knowledge/11-common-patterns.md``references/examples/` |
4343

@@ -51,3 +51,36 @@ references/
5151
6. **销毁表格必须调用 `tableInstance.release()`**
5252
7. 透视表数据分析需要配置 `dataConfig` 中的 `aggregationRules`
5353
8. 自定义布局优先推荐 JSX 方案(`customLayout`),低级需求用 `customRender`
54+
55+
## 脚本生成强制规则
56+
57+
- 所有输出必须通过脚本生成 HTML,不允许手写 HTML 或仅输出片段
58+
- 诊断场景使用 `scripts/generate_diagnosis_html.py`
59+
- 生成/编辑场景使用 `scripts/generate_demo_html.py`
60+
- 输出必须包含脚本命令与生成文件路径,确保可复现
61+
- 未输出脚本命令与文件路径时,必须补齐后再回答
62+
- 输入代码不得包含 `import` / `export`,需先移除再写入 spec.js 或 config.js
63+
- 禁止创建或覆盖 `scripts/` 下脚本文件,必须直接调用已有脚本
64+
65+
**绝对路径调用示例**
66+
67+
```bash
68+
python3 scripts/generate_demo_html.py --spec-file spec.js --output output/demo.html
69+
```
70+
71+
**环境无关调用说明**
72+
73+
- 在任意目录运行脚本时,脚本会基于自身位置定位模板
74+
- 不需要使用绝对路径
75+
76+
**示例(诊断)**
77+
78+
```bash
79+
python3 scripts/generate_diagnosis_html.py --config-file config.js --output output/diagnosis.html
80+
```
81+
82+
**示例(生成/编辑)**
83+
84+
```bash
85+
python3 scripts/generate_demo_html.py --spec-file spec.js --output output/demo.html
86+
```
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from pathlib import Path
2+
import argparse
3+
4+
5+
def escape_js_string(value: str) -> str:
6+
return (
7+
value.replace("\\", "\\\\")
8+
.replace("`", "\\`")
9+
.replace("${", "\\${")
10+
.replace("\n", "\\n")
11+
.replace("\r", "\\r")
12+
.replace("\t", "\\t")
13+
)
14+
15+
16+
def main():
17+
parser = argparse.ArgumentParser(description="Generate VTable demo HTML")
18+
parser.add_argument("--title", default="VTable 表格示例")
19+
parser.add_argument("--desc", default="基于需求生成的可运行表格配置")
20+
parser.add_argument("--feature", default="补充主要功能说明")
21+
parser.add_argument("--tips", default="补充编辑提示")
22+
parser.add_argument("--spec-file")
23+
parser.add_argument("--output", default="output/demo.html")
24+
args = parser.parse_args()
25+
26+
template_path = Path(__file__).resolve().parent.parent / "template" / "demo.html"
27+
if not template_path.exists():
28+
raise FileNotFoundError(f"模板不存在: {template_path}")
29+
30+
if args.spec_file:
31+
spec_path = Path(args.spec_file)
32+
if not spec_path.exists():
33+
raise FileNotFoundError(f"配置文件不存在: {spec_path}")
34+
spec_code = spec_path.read_text(encoding="utf-8")
35+
else:
36+
spec_code = """const tableInstance = new VTable.ListTable({
37+
container: document.getElementById('container'),
38+
records: [{ name: "张三", age: 25 }],
39+
columns: [
40+
{ field: "name", title: "姓名", width: 100 },
41+
{ field: "age", title: "年龄", width: 80 }
42+
],
43+
width: 600,
44+
height: 400
45+
});"""
46+
47+
html = template_path.read_text(encoding="utf-8")
48+
html = html.replace("{{REPORT_TITLE}}", args.title)
49+
html = html.replace("{{REPORT_DESC}}", args.desc)
50+
html = html.replace("{{FEATURE_DESC}}", args.feature)
51+
html = html.replace("{{EDIT_TIPS}}", args.tips)
52+
html = html.replace("{{INITIAL_CODE}}", escape_js_string(spec_code.strip()))
53+
54+
output_path = Path(args.output)
55+
output_path.parent.mkdir(parents=True, exist_ok=True)
56+
output_path.write_text(html, encoding="utf-8")
57+
print(f"生成完成: {output_path.resolve()}")
58+
59+
60+
if __name__ == "__main__":
61+
main()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)