Hai Lin 5 giorni fa
parent
commit
88b43c3463
2 ha cambiato i file con 23 aggiunte e 3 eliminazioni
  1. 1 1
      app.py
  2. 22 2
      templates/tree.html

+ 1 - 1
app.py

@@ -16,7 +16,7 @@ from datetime import datetime
 # Suppress InsecureRequestWarning
 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
 
-app = Flask(__name__)
+app = Flask(__name__, static_folder='static', static_url_path='/static')
 app.secret_key = 'genealogy_secret_key'
 app.config['UPLOAD_FOLDER'] = 'uploads'
 os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)

+ 22 - 2
templates/tree.html

@@ -161,12 +161,32 @@
 {% endblock %}
 
 {% block extra_js %}
+<!-- 优先使用本地 D3.js -->
 <script src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
+<!--  fallback to CDN if local fails -->
 <script>
-    (function() {
-        if (typeof d3 === 'undefined') {
+    if (typeof d3 === 'undefined') {
+        var script = document.createElement('script');
+        script.src = 'https://cdn.jsdelivr.net/npm/d3@7.8.5/dist/d3.min.js';
+        script.onload = function() {
+            if (typeof d3 !== 'undefined') {
+                loadTree();
+            } else {
+                var container = document.getElementById('tree-container');
+                if (container) container.innerHTML = '<div class="h-100 d-flex align-items-center justify-content-center text-danger small">D3.js 未加载,请检查网络或稍后重试。</div>';
+            }
+        };
+        script.onerror = function() {
             var container = document.getElementById('tree-container');
             if (container) container.innerHTML = '<div class="h-100 d-flex align-items-center justify-content-center text-danger small">D3.js 未加载,请检查网络或稍后重试。</div>';
+        };
+        document.head.appendChild(script);
+    }
+</script>
+<script>
+    (function() {
+        if (typeof d3 === 'undefined') {
+            // CDN will handle loading and initialization
         }
     })();
     let currentData = null;