Files
dacli/docs/archive/jnpf-browser-automation/scripts/build_controls.py
T

181 lines
8.7 KiB
Python

"""
build_controls.py — 生成 controls_config.json (不调 AI 端点)
v2 (2026-06-17): 扩 10 → 20 控件 (新增 colorPicker/rate/slider/treeSelect/
uploadImg/uploadFile/relationForm/userSelect/organizeSelect/editor)
参考: $ccWorkDir/dacli/src/commands/form/_ai.ts (AiFormModel 字段结构)
$ccWorkDir/web/.../FormGenerator/src/helper/componentMap.ts (GenItem 模板)
"""
import json, sys
# 20 控件 jnpfKey 列表 (v1: input/textarea/inputNumber/select/radio/checkbox/
# switch/datePicker/timePicker/cascader
# v2 新增: colorPicker/rate/slider/treeSelect/uploadImg/
# uploadFile/relationForm/userSelect/organizeSelect/editor)
CONTROLS_DEF = [
# ===== v1 原有 10 控件 =====
("input", "单行输入", "f_title", "标题", "ctrl input 测试", {}),
("textarea", "多行输入", "f_desc", "描述", "textarea line1\\nline2 测试", {"autoSize": {"minRows": 4, "maxRows": 4}}),
("inputNumber", "数字输入", "f_qty", "数量", "100", {"min": 0, "max": 9999, "precision": 0}),
("select", "下拉选择", "f_status", "状态", "待处理", {
"options": [
{"label": "待处理", "value": "1"},
{"label": "处理中", "value": "2"},
{"label": "已完成", "value": "3"}
]
}),
("radio", "单选框组", "f_priority", "优先级", "高", {
"options": [
{"label": "高", "value": "1"},
{"label": "中", "value": "2"},
{"label": "低", "value": "3"}
]
}),
("checkbox", "多选框组", "f_tags", "标签", ["紧急", "重要"], {
"options": [
{"label": "紧急", "value": "1"},
{"label": "重要", "value": "2"},
{"label": "一般", "value": "3"}
]
}),
("switch", "开关", "f_enabled", "是否启用", True, {}),
("datePicker", "日期选择", "f_deadline", "截止日期", "today+1", {"format": "yyyy-MM-dd"}),
("timePicker", "时间选择", "f_remind_time", "提醒时间", "10:30", {"format": "HH:mm"}),
("cascader", "级联选择", "f_region", "地区", ["北京市", "北京市", "东城区"], {
"options": [
{"value": "1", "label": "北京市", "children": [
{"value": "101", "label": "北京市", "children": [
{"value": "10101", "label": "东城区"}
]}
]}
]
}),
# ===== v2 新增 10 控件 (2026-06-17) =====
# 1. colorPicker — click panel + pick color
("colorPicker", "颜色选择", "f_color", "颜色", "#1890ff", {
"colorFormat": "hex", "showAlpha": False
}),
# 2. rate — click N stars
("rate", "评分", "f_score", "评分", 4, {
"count": 5, "allowHalf": False
}),
# 3. slider — click rail at position
("slider", "滑块", "f_progress", "进度", 60, {
"min": 0, "max": 100, "step": 1
}),
# 4. treeSelect — tree-style dropdown
("treeSelect", "下拉树形", "f_dept", "部门", "技术部", {
"options": [
{"value": "1", "label": "技术部", "children": [
{"value": "11", "label": "前端组"},
{"value": "12", "label": "后端组"}
]},
{"value": "2", "label": "产品部", "children": [
{"value": "21", "label": "产品组"}
]}
],
"props": {"label": "label", "value": "value", "children": "children"},
"multiple": False
}),
# 5. uploadImg — file input (image), fillValue 是 test file path
("uploadImg", "图片上传", "f_avatar", "头像", "test.png", {
"fileSize": 5, "sizeUnit": "MB", "limit": 3, "accept": "image/*",
"buttonText": "上传图片", "showType": "button"
}),
# 6. uploadFile — file input (any file)
("uploadFile", "文件上传", "f_attachment", "附件", "test.txt", {
"fileSize": 10, "sizeUnit": "MB", "limit": 5, "accept": "*/*",
"buttonText": "上传文件", "showType": "button"
}),
# 7. relationForm — popup with table (关联表单, 需指定 modelId)
("relationForm", "关联表单", "f_link_id", "关联单据", None, {
"modelId": "", # 空 = 暂不绑 form, 仍可触发 popup
"relationField": "f_name",
"placeholder": "请选择关联单据",
"hasPage": False,
"pageSize": 20,
"columnOptions": [
{"label": "名称", "value": "f_name", "width": 200},
{"label": "编码", "value": "f_code", "width": 150}
]
}),
# 8. userSelect — popup user multi-select
("userSelect", "用户选择", "f_assignee", "负责人", ["管理员"], {
"ableRelation": False,
"multiple": True,
"selectType": "all"
}),
# 9. organizeSelect — popup org tree
("organizeSelect", "组织选择", "f_org", "所属组织", "技术部", {
"ableRelation": False,
"multiple": False,
"selectType": "department"
}),
# 10. editor — rich text (tinymce/wangeditor)
("editor", "富文本", "f_content", "内容", "<p>富文本测试内容, 含 <strong>加粗</strong> 和换行<br/>第二行</p>", {
"placeholder": "请输入内容"
}),
]
USER_END_MAP = {
# v1 原有
"input": {"fillSelector": ".ant-modal input.ant-input", "fillMethod": "press_sequentially"},
"textarea": {"fillSelector": ".ant-modal textarea", "fillMethod": "press_sequentially"},
"inputNumber": {"fillSelector": ".ant-modal .ant-input-number-input", "fillMethod": "press_sequentially"},
"select": {"fillSelector": ".ant-modal .ant-select", "fillMethod": "select_option"},
"radio": {"fillSelector": ".ant-modal .ant-radio-wrapper", "fillMethod": "click_radio"},
"checkbox": {"fillSelector": ".ant-modal .ant-checkbox-wrapper", "fillMethod": "click_checkbox"},
"switch": {"fillSelector": ".ant-modal .ant-switch", "fillMethod": "click_switch"},
"datePicker": {"fillSelector": ".ant-modal .ant-picker input", "fillMethod": "date_picker"},
"timePicker": {"fillSelector": ".ant-modal .ant-picker input", "fillMethod": "time_picker"},
"cascader": {"fillSelector": ".ant-modal .ant-cascader-picker", "fillMethod": "cascader"},
# v2 新增
"colorPicker": {"fillSelector": ".ant-modal .ant-color-picker-trigger", "fillMethod": "click_color_picker"},
"rate": {"fillSelector": ".ant-modal .ant-rate", "fillMethod": "click_rate_star"},
"slider": {"fillSelector": ".ant-modal .ant-slider", "fillMethod": "click_slider_rail"},
"treeSelect": {"fillSelector": ".ant-modal .ant-select.ant-tree-select, .ant-modal .ant-tree-select", "fillMethod": "click_tree_select"},
"uploadImg": {"fillSelector": ".ant-modal input[type=file][accept^='image'], .ant-modal input[type=file]", "fillMethod": "set_file_input_img"},
"uploadFile": {"fillSelector": ".ant-modal input[type=file]", "fillMethod": "set_file_input_file"},
"relationForm": {"fillSelector": ".ant-modal .jnpf-relation-form-trigger, .ant-modal .relation-form-trigger", "fillMethod": "click_relation_form_popup"},
"userSelect": {"fillSelector": ".ant-modal .jnpf-user-select, .ant-modal .user-select-trigger", "fillMethod": "click_user_select_popup"},
"organizeSelect": {"fillSelector": ".ant-modal .jnpf-organize-select, .ant-modal .organize-select-trigger", "fillMethod": "click_organize_select_popup"},
"editor": {"fillSelector": ".ant-modal .jnpf-editor-content, .ant-modal [contenteditable=true]", "fillMethod": "editor_input"},
}
def build_controls() -> dict:
controls = []
for jnpfKey, label, fieldName, fieldLabel, fillValue, configSchema in CONTROLS_DEF:
if jnpfKey not in USER_END_MAP:
raise SystemExit(f"✗ USER_END_MAP 缺条目: {jnpfKey}")
ue = {**USER_END_MAP[jnpfKey], "fillValue": fillValue}
controls.append({
"jnpfKey": jnpfKey,
"label": label,
"fieldName": fieldName,
"fieldLabel": fieldLabel,
"required": False,
"configSchema": configSchema,
"userEnd": ue,
})
return {
"version": "v2",
"date": "2026-06-17",
"appCode": "tdd",
"parentMenuId": "836650888410965189",
"targetTable": "spike_dm2",
"formPrefix": "tddCtrl",
"dacliFallback": True,
"injectMode": True,
"controls": controls,
}
if __name__ == "__main__":
cfg = build_controls()
out = sys.argv[1] if len(sys.argv) > 1 else "controls_config.json"
with open(out, "w", encoding="utf-8") as f:
json.dump(cfg, f, ensure_ascii=False, indent=2)
print(f"✓ 写入 {out}, 共 {len(cfg['controls'])} 控件 (v2)")
for i, c in enumerate(cfg["controls"], 1):
print(f" {i:2d}. {c['jnpfKey']:14} {c['fieldLabel']}")