Parcourir la source

feat: 添加页脚

SongZihuan il y a 2 ans
Parent
commit
67a95aad46
3 fichiers modifiés avec 53 ajouts et 3 suppressions
  1. 42 1
      templates/base.html
  2. 9 2
      web/__init__.py
  3. 2 0
      web/configure.py

+ 42 - 1
templates/base.html

@@ -112,9 +112,50 @@
     {% endfor %}
     {% endfor %}
     </section>
     </section>
 
 
-    {% block content %} {% endblock %}
+    <div id="content">
+        {% block content %} {% endblock %}
+    </div>
 
 
     {% block javascript_foot %}
     {% block javascript_foot %}
     {% endblock %}
     {% endblock %}
+
+    {% block footer %}
+        {# footer 最后加载 #}
+        <footer id="foot" class="text-center">
+            <hr>
+            {{ conf['FOOT'] }}
+            {% if get_icp() %}
+                <br> <a id="ICP2" href="https://beian.miit.gov.cn" target="_blank" class="my-2"
+                    style="display:inline-block;text-decoration:none;height:20px;line-height:20px;" >
+                    {{ get_icp() }} </a>
+            {% endif %}
+        </footer>
+
+        <script>
+            function SetFooter (mutationsList, observer) {
+                let foot = document.getElementById('foot')
+                let content = document.getElementById('content')
+                let content_height = content.getBoundingClientRect().bottom  // 返回 content距离视窗底部的位置
+                let win_height = 0
+                if (window.innerHeight)  // 浏览器窗口的大小
+                    win_height = window.innerHeight;
+                else if ((document.body) && (document.body.clientHeight))  // body的大小, 也表示浏览器窗口的大小
+                    win_height = document.body.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);
+            observer.observe(content, {
+                attributes: true, // 属性的变动
+                subtree: true, // 是否将观察器应用于该节点的所有后代节点
+            });
+            SetFooter()
+        </script>
+    {% endblock %}
 </body>
 </body>
 </html>
 </html>

+ 9 - 2
web/__init__.py

@@ -1,4 +1,4 @@
-from flask import Flask, render_template, Response
+from flask import Flask, render_template, Response, request
 from flask.logging import default_handler
 from flask.logging import default_handler
 import logging
 import logging
 import logging.handlers
 import logging.handlers
@@ -27,10 +27,17 @@ class HuamMailFlask(Flask):
         @self.context_processor
         @self.context_processor
         def inject_base():
         def inject_base():
             """ app默认模板变量 """
             """ app默认模板变量 """
-            return {"conf": conf}
+            return {"conf": conf,
+                    "get_icp": self.get_icp}
 
 
         self.error_page([400, 401, 403, 404, 405, 408, 410, 413, 414, 423, 500, 501, 502])
         self.error_page([400, 401, 403, 404, 405, 408, 410, 413, 414, 423, 500, 501, 502])
 
 
+    @staticmethod
+    def get_icp():
+        for i in conf["ICP"]:
+            if i in request.host:
+                return conf["ICP"][i]
+
     def blueprint(self):
     def blueprint(self):
         from .index import index
         from .index import index
         self.register_blueprint(index, url_prefix="/")
         self.register_blueprint(index, url_prefix="/")

+ 2 - 0
web/configure.py

@@ -40,6 +40,8 @@ conf: Dict[str, any] = {
     "DEBUG_PROFILE": False,
     "DEBUG_PROFILE": False,
 
 
     "LOGO": "HuanMail.ico",
     "LOGO": "HuanMail.ico",
+    "FOOT": "HuanMail 感谢您的使用",
+    "ICP": [],
 }
 }