林海 1 өдөр өмнө
parent
commit
cefa97772c
2 өөрчлөгдсөн 51 нэмэгдсэн , 30 устгасан
  1. 23 1
      app.py
  2. 28 29
      templates/home.html

+ 23 - 1
app.py

@@ -20,10 +20,32 @@ from datetime import datetime
 # Suppress InsecureRequestWarning
 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
 
-app = Flask(__name__, static_folder='static', static_url_path='/manager/static')
+# 静态资源目录使用绝对路径,避免服务器工作目录不同导致找不到文件
+_BASE_DIR = os.path.dirname(os.path.abspath(__file__))
+_STATIC_DIR = os.path.join(_BASE_DIR, 'static')
+_HOME_IMAGES_DIR = os.path.join(_STATIC_DIR, 'images', 'home')
+_HOME_FONTS_DIR = os.path.join(_STATIC_DIR, 'fonts', 'home')
+
+app = Flask(__name__, static_folder=_STATIC_DIR, static_url_path='/manager/static')
 app.secret_key = 'genealogy_secret_key'
 app.config['UPLOAD_FOLDER'] = 'uploads'
 os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
+os.makedirs(_HOME_IMAGES_DIR, exist_ok=True)
+os.makedirs(_HOME_FONTS_DIR, exist_ok=True)
+
+
+@app.context_processor
+def inject_home_assets():
+    """首页静态资源 URL 助手,统一走 /manager/static/ 前缀。"""
+    prefix = app.static_url_path.rstrip('/')
+
+    def home_img(filename):
+        return f"{prefix}/images/home/{filename}"
+
+    def home_font(filename):
+        return f"{prefix}/fonts/home/{filename}"
+
+    return dict(home_img=home_img, home_font=home_font, static_prefix=prefix)
 
 # 数据库配置
 DB_CONFIG = {

+ 28 - 29
templates/home.html

@@ -8,25 +8,25 @@
     <style>
         @font-face {
             font-family: "HuakangWeibei";
-            src: url("{{ url_for('static', filename='fonts/home/HuakangWeibei.ttf') }}") format("truetype");
+            src: url("{{ home_font('HuakangWeibei.ttf') }}") format("truetype");
             font-weight: normal;
             font-style: normal;
         }
         @font-face {
             font-family: "AdobeKaiti";
-            src: url("{{ url_for('static', filename='fonts/home/AdobeKaitiStd-Regular.otf') }}") format("opentype");
+            src: url("{{ home_font('AdobeKaitiStd-Regular.otf') }}") format("opentype");
             font-weight: normal;
             font-style: normal;
         }
         @font-face {
             font-family: "SourceHanSans";
-            src: url("{{ url_for('static', filename='fonts/home/SourceHanSansSC-Regular.otf') }}") format("opentype");
+            src: url("{{ home_font('SourceHanSansSC-Regular.otf') }}") format("opentype");
             font-weight: normal;
             font-style: normal;
         }
         @font-face {
             font-family: "SourceHanSerif";
-            src: url("{{ url_for('static', filename='fonts/home/SourceHanSerifCN-Regular.otf') }}") format("opentype");
+            src: url("{{ home_font('SourceHanSerifCN-Regular.otf') }}") format("opentype");
             font-weight: normal;
             font-style: normal;
         }
@@ -43,7 +43,7 @@
             position: fixed;
             inset: 0;
             z-index: 0;
-            background: url("{{ url_for('static', filename='images/home/bg.png') }}") center center / cover no-repeat;
+            background: url("{{ home_img('bg.png') }}") center center / cover no-repeat;
         }
 
         .page-wrap {
@@ -109,14 +109,26 @@
             height: 62px;
             text-decoration: none;
             flex-shrink: 0;
+            background-repeat: no-repeat;
+            background-position: center;
+            background-size: 100% 100%;
+            border: none;
         }
 
-        .action-btn img {
-            position: absolute;
-            inset: 0;
-            width: 100%;
-            height: 100%;
-            display: block;
+        .action-btn--members {
+            background-image: url("{{ home_img('btn-members-gold.png') }}");
+        }
+
+        .action-btn--scan {
+            background-image: url("{{ home_img('btn-scan-silver.png') }}");
+        }
+
+        .action-btn--members:hover {
+            background-image: url("{{ home_img('btn-members-gold.png') }}");
+        }
+
+        .action-btn--scan:hover {
+            background-image: url("{{ home_img('btn-scan-gold.png') }}");
         }
 
         .action-btn-text {
@@ -140,15 +152,6 @@
             transform: translateX(12px);
         }
 
-        .action-btn .btn-img-hover { display: none; }
-        .action-btn .btn-img-default { display: block; }
-
-        .action-btn--members:hover .btn-img-default { display: block; }
-        .action-btn--members:hover .btn-img-hover { display: none; }
-
-        .action-btn--scan:hover .btn-img-default { display: none; }
-        .action-btn--scan:hover .btn-img-hover { display: block; }
-
         /* 快速导航 */
         .nav-section {
             width: 100%;
@@ -162,7 +165,7 @@
             justify-content: center;
             width: 232px;
             height: 48px;
-            background: url("{{ url_for('static', filename='images/home/nav-frame.png') }}") center / 100% 100% no-repeat;
+            background: url("{{ home_img('nav-frame.png') }}") center / 100% 100% no-repeat;
             margin-bottom: 16px;
         }
 
@@ -212,7 +215,7 @@
         .committee-panel {
             width: 100%;
             height: 242px;
-            background: url("{{ url_for('static', filename='images/home/committee-bg.png') }}") center / 100% 100% no-repeat;
+            background: url("{{ home_img('committee-bg.png') }}") center / 100% 100% no-repeat;
             position: relative;
             padding: 24px 40px 24px calc(100% * 72 / 2115);
             margin-bottom: 36px;
@@ -267,7 +270,7 @@
             width: 11px;
             height: 11px;
             flex-shrink: 0;
-            background: url("{{ url_for('static', filename='images/home/committee-dot.png') }}") center / contain no-repeat;
+            background: url("{{ home_img('committee-dot.png') }}") center / contain no-repeat;
         }
 
         .cm-label {
@@ -334,20 +337,16 @@
 <div class="page-wrap">
     <div class="page-inner">
 
-        <img src="{{ url_for('static', filename='images/home/logo.png') }}" alt="留" class="logo">
+        <img src="{{ home_img('logo.png') }}" alt="留" class="logo">
 
         <h1 class="main-title">留氏(衢州)族谱信息管理系统</h1>
         <p class="edition">二〇二五年度版</p>
 
         <div class="action-btns">
             <a href="{{ url_for('members') }}" class="action-btn action-btn--members">
-                <img src="{{ url_for('static', filename='images/home/btn-members-gold.png') }}" alt="" class="btn-img-default">
-                <img src="{{ url_for('static', filename='images/home/btn-members-silver.png') }}" alt="" class="btn-img-hover">
                 <span class="action-btn-text">成员管理</span>
             </a>
             <a href="{{ url_for('index') }}" class="action-btn action-btn--scan">
-                <img src="{{ url_for('static', filename='images/home/btn-scan-silver.png') }}" alt="" class="btn-img-default">
-                <img src="{{ url_for('static', filename='images/home/btn-scan-gold.png') }}" alt="" class="btn-img-hover">
                 <span class="action-btn-text">扫描件管理</span>
             </a>
         </div>
@@ -363,7 +362,7 @@
                 <span class="sep">/</span>
                 <a href="{{ url_for('tree') }}">关系树状图</a>
                 <span class="sep">/</span>
-                <img src="{{ url_for('static', filename='images/home/nav-seal.png') }}" alt="系统管理" class="nav-seal">
+                <img src="{{ home_img('nav-seal.png') }}" alt="系统管理" class="nav-seal">
                 <span class="sep">/</span>
                 <a href="{{ url_for('index') }}">扫描件管理</a>
                 <span class="sep">/</span>