SongZihuan 3 лет назад
Родитель
Сommit
c081b4c67c
3 измененных файлов с 51 добавлено и 14 удалено
  1. 2 1
      app/app.py
  2. 2 1
      configure/__init__.py
  3. 47 12
      templates/base.html

+ 2 - 1
app/app.py

@@ -47,7 +47,8 @@ class HEnglishFlask(Flask):
         @self.context_processor
         def inject_base():
             return {"title": self.config["TITLE"],
-                    "about": self.config["ABOUT"]}
+                    "about": self.config["ABOUT"],
+                    "footer": self.config["FOOTER"]}
 
         @self.login_manager.user_loader
         def user_loader(name: str):

+ 2 - 1
configure/__init__.py

@@ -5,6 +5,7 @@ root = os.path.abspath(os.path.join(__file__, '..', '..'))
 conf = {
     "SECRET_KEY": "HEnglish",
     "TITLE": "HEnglish :D",
+    "FOOTER": "Power by HEnglish",
     "ABOUT": "An useful English learning website for personal.",
     "DB_TEMPLATE": f"{os.path.join(root, 'resource', 'template')}",
     "DB_PATH": f"{os.path.join(root, 'var', 'db')}",
@@ -13,7 +14,7 @@ conf = {
     "LOG_LEVEL": "DEBUG",
     "SERVER_NAME": None,
     "MAX_CONTENT_LENGTH": 5 * 1024 * 1024,
-    "LOG_FILE_NAME_PID": False
+    "LOG_FILE_NAME_PID": False,
 }
 
 

+ 47 - 12
templates/base.html

@@ -27,19 +27,21 @@
 </head>
 <body>
 
-<h1 class="text-center m-1"> Welcome to {{ title }} ! </h1>
-<p class="col-8 offset-2 text-center" > <a href="{{ url_for("test.introduce") }}"> {{ about }} </a> </p>
-
-<section class="container mt-2 mb-2">
-{% for message in get_flashed_messages() %}
-    <div class="alert alert-info">
-        <button type="button" class="close" data-dismiss="alert">&times;</button>
-        {{ message }}
-    </div>
-{% endfor %}
-</section>
+<section id="content">
+    <h1 class="text-center m-1"> Welcome to {{ title }} ! </h1>
+    <p class="col-8 offset-2 text-center" > <a href="{{ url_for("test.introduce") }}"> {{ about }} </a> </p>
+
+    <section class="container mt-2 mb-2">
+    {% for message in get_flashed_messages() %}
+        <div class="alert alert-info">
+            <button type="button" class="close" data-dismiss="alert">&times;</button>
+            {{ message }}
+        </div>
+    {% endfor %}
+    </section>
 
-{% block body %} {% endblock %}
+    {% block body %} {% endblock %}
+</section>
 
 {% block javascript %}
     <script src="https://cdn.staticfile.org/popper.js/0.2.0/popper.min.js"></script>
@@ -47,5 +49,38 @@
     <script src="https://cdn.staticfile.org/bootstrap/4.6.1/js/bootstrap.min.js"></script>
 {% endblock %}
 
+{% block footer %}
+    {# footer 最后加载 #}
+    <footer id="foot" class="pb-3 text-center">
+        <hr>
+        {{ footer }}
+    </footer>
+    <script>
+        function SetFooter (mutationsList, observer) {
+            let foot = document.getElementById('foot')
+            let content_height = content.getBoundingClientRect().bottom
+            let win_height = 0
+            if (window.innerHeight)
+                win_height = window.innerHeight;
+            else if ((document.body) && (document.body.clientHeight))
+                win_height = document.body.clientHeight;
+
+            console.log(foot.clientHeight)
+            if (win_height - content_height - foot.clientHeight <= 0)
+                foot.style.marginTop = "0"
+            else
+                foot.style.marginTop = (win_height - content_height - foot.clientHeight).toString() + "px"
+        }
+        let MutationObserver = window.MutationObserver;
+        let observer = new MutationObserver(SetFooter);
+        let content = document.getElementById('content')
+        observer.observe(content, {
+            attributes: true, // 属性的变动
+            subtree: true, // 是否将观察器应用于该节点的所有后代节点
+        });
+        SetFooter()
+    </script>
+{% endblock %}
+
 </body>
 </html>