Pārlūkot izejas kodu

新功能添加

caijynb 2 gadi atpakaļ
vecāks
revīzija
477753d1ee
3 mainītis faili ar 28 papildinājumiem un 6 dzēšanām
  1. 2 1
      main.py
  2. 1 1
      templates/base_index.html
  3. 25 4
      templates/simple_backtest.html

+ 2 - 1
main.py

@@ -81,7 +81,8 @@ def simple_backtest():
             return render_template('simple_backtest.html',
                                    tables=[df.to_html(classes='table table-striped')],
                                    titles=df.columns.values,
-                                   up_probability=up_probability)
+                                   up_probability=up_probability,
+                                   file_name=filename)
 
     # 对于GET请求,渲染'simple_backtest.html'但不包含表格数据
     return render_template('simple_backtest.html')

+ 1 - 1
templates/base_index.html

@@ -1,5 +1,5 @@
 <!DOCTYPE html>
-<html lang="en">
+<html>
 <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">

+ 25 - 4
templates/simple_backtest.html

@@ -7,8 +7,9 @@
                 <form action="/simple_backtest" method="post" enctype="multipart/form-data" class="mb-3">
                     <div class="input-group mb-3">
                         <div class="custom-file">
-                            <input type="file" class="custom-file-input" name="file" id="fileInput">
-                            <label class="custom-file-label" for="fileInput">文件路径</label>
+                            <input type="file" class="custom-file-input" name="file" id="fileInput"
+                                   onchange="updateLabel()">
+                            <label class="custom-file-label" for="fileInput">选择文件</label>
                         </div>
                         <div class="input-group-append">
                             <button class="btn btn-outline-secondary" type="submit">上传</button>
@@ -19,7 +20,7 @@
         </div>
 
         {% if tables %}
-            <h2 class="text-center">分析结果</h2>
+            <h2 class="text-center">{{ file_name }}分析结果</h2>
             <div class="table-responsive">
                 {% for table in tables %}
                     {{ table|safe }}
@@ -28,4 +29,24 @@
         {% endif %}
     </div>
 
-{% endblock %}
+    <script>
+        // 当文件选择变化时,保存文件名到本地存储
+        function updateLabel() {
+            var input = document.getElementById('fileInput');
+            var label = input.nextElementSibling;
+            var fileName = input.files[0].name;
+            label.innerHTML = fileName;
+            localStorage.setItem('lastUploadedFileName', fileName); // 保存文件名到本地存储
+        }
+
+        // 页面加载完成后,检查是否有保存的文件名
+        document.addEventListener('DOMContentLoaded', function () {
+            var lastFileName = localStorage.getItem('lastUploadedFileName');
+            if (lastFileName) {
+                var label = document.querySelector('.custom-file-label');
+                label.innerHTML = lastFileName;
+            }
+        });
+    </script>
+
+{% endblock %}