From 186e3659fb4ed94446b5bd2c62b4b3d483bdae89 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 22 Jul 2026 18:58:13 +0800 Subject: [PATCH] fix: size format MB/GB, add new_kb_form with button binds --- init.py | 9 ++++++++- wwwroot/knowledge_bases_list/index.ui | 5 ++++- wwwroot/knowledge_bases_list/new_kb_form.ui | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 wwwroot/knowledge_bases_list/new_kb_form.ui diff --git a/init.py b/init.py index d9761d2..ad4c055 100644 --- a/init.py +++ b/init.py @@ -29,7 +29,14 @@ async def kb_list_handler(request, params_kw, *args, **kwargs): doc_recs = await sor.R("documents", {"kb_id": r.id}) doc_count = len(doc_recs) total_size = r.total_size or 0 - size_str = f"{total_size/1024:.0f}KB" if total_size else "0B" + if total_size >= 1073741824: + size_str = f"{total_size/1073741824:.1f}GB" + elif total_size >= 1048576: + size_str = f"{total_size/1048576:.0f}MB" + elif total_size >= 1024: + size_str = f"{total_size/1024:.0f}KB" + else: + size_str = f"{total_size}B" engine = r.embedding_engine or "CLIP" card = {"widgettype":"VBox","options":{"cwidth":16,"cheight":12,"bgcolor":"#f0f7ff","padding":"16px","css":"card clickable","border":"1px solid #d0e4f7"},"subwidgets":[ {"widgettype":"Text","options":{"text":"📚 " + str(r.name),"cfontsize":16,"fontWeight":"bold"}}, diff --git a/wwwroot/knowledge_bases_list/index.ui b/wwwroot/knowledge_bases_list/index.ui index e2656ed..bdfefa0 100644 --- a/wwwroot/knowledge_bases_list/index.ui +++ b/wwwroot/knowledge_bases_list/index.ui @@ -15,7 +15,10 @@ {"widgettype": "Text", "options": {"text": "知识库", "cfontsize": 22, "fontWeight": "bold", "color": "#333"}}, {"widgettype": "Text", "options": {"text": "点击知识库进入文档管理,支持多级目录和拖拽上传", "cfontsize": 14, "color": "#888"}} ]}, - {"widgettype": "Button", "options": {"label": "+ 新建知识库", "bgcolor": "#4a90d9", "color": "#fff"}} + {"widgettype": "Button", "options": {"label": "+ 新建知识库", "bgcolor": "#4a90d9", "color": "#fff"}, "binds": [ + {"wid": "self", "event": "tap", "actiontype": "urlwidget", "target": "app.rag_main_content", "mode": "replace", + "options": {"url": "{{entire_url('/knowledge_bases_list/new_kb_form.ui')}}"}} + ]} ] }, { diff --git a/wwwroot/knowledge_bases_list/new_kb_form.ui b/wwwroot/knowledge_bases_list/new_kb_form.ui new file mode 100644 index 0000000..732f842 --- /dev/null +++ b/wwwroot/knowledge_bases_list/new_kb_form.ui @@ -0,0 +1,17 @@ +{ + "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": "kb_name", "width": "100%"}}, + {"widgettype": "Text", "options": {"text": "描述"}}, + {"widgettype": "Input", "options": {"id": "kb_desc", "width": "100%"}}, + {"widgettype": "Button", "options": {"label": "创建", "bgcolor": "#4a90d9", "color": "#fff"}}, + {"widgettype": "Button", "options": {"label": "取消", "bgcolor": "#e0e0e0", "color": "#666"}, "binds": [ + {"wid": "self", "event": "tap", "actiontype": "urlwidget", "target": "app.rag_main_content", "mode": "replace", + "options": {"url": "{{entire_url('/knowledge_bases_list/index.ui')}}"}} + ]} + ] +}