feat: bricks-native CRUD - dspy handlers + form + button binds

This commit is contained in:
yumoqing 2026-07-22 18:41:07 +08:00
parent 7af39b0737
commit c48aa36f1b
3 changed files with 122 additions and 33 deletions

View File

@ -18,52 +18,42 @@
"options": {"spacing": "4px", "alignItems": "center"},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "📂", "cfontsize": 16}},
{"widgettype": "Text", "options": {"text": "{{params_kw.folder_label or '全部文件'}}", "cfontsize": 16, "fontWeight": "bold", "color": "#333"}},
{"widgettype": "Text", "options": {"text": "({{params_kw.folder_id or 'root'}})", "cfontsize": 11, "color": "#aaa"}}
{"widgettype": "Text", "options": {"text": "{{params_kw.folder_label or '全部文件'}}", "cfontsize": 16, "fontWeight": "bold", "color": "#333"}}
]
},
{
"widgettype": "HBox",
"options": {"spacing": "8px"},
"subwidgets": [
{"widgettype": "Button", "options": {"label": "📁 上传文件", "bgcolor": "#4a90d9", "color": "#fff"}},
{"widgettype": "Button", "options": {"label": "📂 新建子目录", "bgcolor": "#e8e8e8", "color": "#666"}},
{"widgettype": "Button", "options": {"label": "🗑 删除选中", "bgcolor": "#f56c6c", "color": "#fff"}}
{
"widgettype": "Button",
"options": {"label": "📂 新建子目录", "bgcolor": "#e8e8e8", "color": "#666"},
"binds": [
{
"wid": "self",
"event": "tap",
"actiontype": "urlwidget",
"target": "app.detail_content",
"mode": "replace",
"options": {
"url": "{{entire_url('/knowledge_bases_list/new_dir_form.ui')}}",
"params": {
"kb_id": "{{params_kw.kb_id or ''}}",
"folder_id": "{{params_kw.folder_id or ''}}",
"folder_label": "{{params_kw.folder_label or ''}}"
}
}
}
]
}
]
}
]
},
{
"widgettype": "VBox",
"options": {
"width": "100%",
"cheight": 5,
"bgcolor": "#f8f9fa",
"padding": "12px",
"css": "card",
"border": "2px dashed #d0d0d0",
"alignItems": "center",
"justifyContent": "center"
},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "拖拽文件到此处上传到当前目录", "cfontsize": 13, "color": "#888"}}
]
},
{
"widgettype": "HBox",
"options": {"width": "100%", "bgcolor": "#f5f5f5", "padding": "8px 12px", "borderBottom": "1px solid #e0e0e0"},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "文件名", "cfontsize": 12, "fontWeight": "bold", "color": "#888", "cwidth": 18}},
{"widgettype": "Text", "options": {"text": "类型", "cfontsize": 12, "fontWeight": "bold", "color": "#888", "cwidth": 6}},
{"widgettype": "Text", "options": {"text": "大小", "cfontsize": 12, "fontWeight": "bold", "color": "#888", "cwidth": 6}},
{"widgettype": "Text", "options": {"text": "状态", "cfontsize": 12, "fontWeight": "bold", "color": "#888", "cwidth": 6}},
{"widgettype": "Text", "options": {"text": "上传时间", "cfontsize": 12, "fontWeight": "bold", "color": "#888"}}
]
},
{
"widgettype": "Text",
"options": {
"text": "当前目录暂无文件",
"text": "当前目录暂无内容",
"color": "#aaa",
"cfontsize": 13,
"halign": "center"

View File

@ -0,0 +1,55 @@
{
"widgettype": "VBox",
"options": {"spacing": "12px", "padding": "16px"},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "新建目录", "cfontsize": 18, "fontWeight": "bold"}},
{"widgettype": "Text", "options": {"text": "", "cheight": 0.5}},
{"widgettype": "Text", "options": {"text": "目录名称"}},
{
"widgettype": "Input",
"options": {"id": "dir_name_input", "width": "100%"}
},
{
"widgettype": "Button",
"options": {"label": "创建", "bgcolor": "#4a90d9", "color": "#fff"},
"binds": [
{
"wid": "self",
"event": "tap",
"actiontype": "urlwidget",
"target": "app.detail_content",
"mode": "replace",
"options": {
"url": "{{entire_url('/knowledge_bases_list/tree_crud.dspy')}}",
"params": {
"action": "create_dir",
"kb_id": "{{params_kw.kb_id or ''}}",
"dir_name": "${app.dir_name_input.text}",
"parent_id": "{{params_kw.folder_id or ''}}"
}
}
}
]
},
{
"widgettype": "Button",
"options": {"label": "取消", "bgcolor": "#e0e0e0", "color": "#666"},
"binds": [
{
"wid": "self",
"event": "tap",
"actiontype": "urlwidget",
"target": "app.detail_content",
"mode": "replace",
"options": {
"url": "{{entire_url('/knowledge_bases_list/folder_content.ui')}}",
"params": {
"folder_id": "{{params_kw.folder_id or ''}}",
"folder_label": "{{params_kw.folder_label or ''}}"
}
}
}
]
}
]
}

View File

@ -0,0 +1,44 @@
action = params_kw.get("action", "")
kb_id = params_kw.get("kb_id", "")
env = request._run_ns
if action == "create_dir":
dir_name = params_kw.get("dir_name", "")
parent_id = params_kw.get("parent_id", "")
if dir_name:
async with get_sor_context(env, 'rag') as sor:
dir_id = "dir_" + str(abs(hash(dir_name + parent_id)))[:12]
await sor.sqlExe(
"INSERT INTO document_chunks (id, doc_id, kb_id, chunk_index, chunk_type, content, description, created_at) "
"VALUES (${id}$, '', ${kb_id}$, 0, 'directory', ${name}$, ${parent}$, NOW())",
{"id": dir_id, "kb_id": kb_id, "name": dir_name, "parent": parent_id})
elif action == "delete_item":
item_id = params_kw.get("item_id", "")
if item_id:
async with get_sor_context(env, 'rag') as sor:
await sor.sqlExe("DELETE FROM document_chunks WHERE id=${id}$", {"id": item_id})
# Return refreshed folder content widget
folder_id = params_kw.get("folder_id", "")
folder_label = params_kw.get("folder_label", "")
folder_label = folder_label or dir_name or "全部文件"
result = {
"widgettype": "VBox",
"options": {"spacing": "12px"},
"subwidgets": [
{
"widgettype": "HBox",
"options": {"spacing": "4px"},
"subwidgets": [
{"widgettype": "Text", "options": {"text": "📂 " + str(folder_label), "cfontsize": 16, "fontWeight": "bold", "color": "#333"}},
{"widgettype": "Text", "options": {"text": "操作成功", "cfontsize": 12, "color": "#50b86c"}}
]
},
{
"widgettype": "Text",
"options": {"text": "操作已完成,请刷新目录树", "color": "#888", "cfontsize": 13}
}
]
}