diff --git a/app.py b/app.py index 45a74af..dc4150b 100644 --- a/app.py +++ b/app.py @@ -177,7 +177,7 @@ def api_upload_document(): @app.route('/api/documents/', methods=['GET']) def api_get_document(doc_id): - """获取文档详情""" + """获取文档详情API""" doc = Document.query.get_or_404(doc_id) chunks = DocumentChunk.query.filter_by(document_id=doc_id).all() @@ -188,6 +188,14 @@ def api_get_document(doc_id): }) +@app.route('/documents/') +def document_detail_page(doc_id): + """文档详情页面""" + doc = Document.query.get_or_404(doc_id) + chunks = DocumentChunk.query.filter_by(document_id=doc_id).order_by(DocumentChunk.chunk_index).all() + return render_template('document_detail.html', doc=doc, chunks=chunks) + + @app.route('/api/documents/', methods=['DELETE']) def api_delete_document(doc_id): """删除文档""" diff --git a/models.py b/models.py index 44ad38c..542690c 100644 --- a/models.py +++ b/models.py @@ -92,6 +92,8 @@ class Document(db.Model): return { 'id': self.id, 'filename': self.filename, + 'file_type': self.file_type, + 'file_size': self.file_size, 'title': self.title, 'status': self.status, 'summary': self.summary, diff --git a/templates/document_detail.html b/templates/document_detail.html new file mode 100644 index 0000000..e617e8e --- /dev/null +++ b/templates/document_detail.html @@ -0,0 +1,212 @@ + + + + + + {{ doc.title or doc.filename }} - 文档详情 + + + + + + + +
+ + + +
+
+
文档信息
+
+ {% if doc.status == 'indexed' %} + 已索引 + {% elif doc.status == 'processing' %} + 处理中 + {% elif doc.status == 'failed' %} + 失败 + {% else %} + 待索引 + {% endif %} +
+
+
+
+
+ + + + + + + + + + + + + + + + + +
文件名{{ doc.filename }}
标题{{ doc.title or '-' }}
文件类型{{ doc.file_type }}
文件大小{{ (doc.file_size / 1024)|round(1) }} KB
+
+
+ + + + + + + + + + + + + + + + + +
分块数{{ doc.chunk_count }}
字数{{ doc.word_count|default(0) }}
上传时间{{ doc.created_at.strftime('%Y-%m-%d %H:%M') if doc.created_at else '-' }}
索引时间{{ doc.indexed_at.strftime('%Y-%m-%d %H:%M') if doc.indexed_at else '-' }}
+
+
+ + {% if doc.summary %} +
+
文档摘要
+

{{ doc.summary }}

+
+ {% endif %} + + {% if doc.keywords %} +
+
关键词
+
+ {% for kw in doc.get_keywords() %} + {{ kw }} + {% endfor %} +
+
+ {% endif %} + + {% if doc.category %} +
+
分类
+ {{ doc.category }} +
+ {% endif %} +
+
+ + +
+
+
文档分块 ({{ chunks|length }} 个)
+
+
+ {% if chunks %} +
+ {% for chunk in chunks %} +
+

+ +

+
+
+ {% if chunk.summary %} +
+ 摘要: {{ chunk.summary }} +
+ {% endif %} + + {% if chunk.keywords %} +
+ {% for kw in chunk.get_keywords() %} + {{ kw }} + {% endfor %} +
+ {% endif %} + +
{{ chunk.content }}
+
+
+
+ {% endfor %} +
+ {% else %} +

暂无分块数据,请先索引文档

+ {% endif %} +
+
+ +
+ + 返回列表 + + {% if doc.status == 'pending' %} + + {% endif %} + +
+
+ + + + + \ No newline at end of file