duqing2026 commited on
Commit
f2970fe
·
1 Parent(s): fe0f188

feat: enhance functionality with templates, fix jinja2/vue conflicts, and improve error handling

Browse files
Files changed (3) hide show
  1. app.py +10 -0
  2. templates/builder.html +13 -0
  3. templates/export_template.html +4 -0
app.py CHANGED
@@ -2,9 +2,19 @@ from flask import Flask, render_template, request, send_file, make_response
2
  import io
3
  import json
4
  import os
 
5
 
6
  app = Flask(__name__)
7
 
 
 
 
 
 
 
 
 
 
8
  @app.route('/')
9
  def index():
10
  return render_template('builder.html')
 
2
  import io
3
  import json
4
  import os
5
+ import traceback
6
 
7
  app = Flask(__name__)
8
 
9
+ @app.route('/health')
10
+ def health():
11
+ return "OK", 200
12
+
13
+ @app.errorhandler(Exception)
14
+ def handle_exception(e):
15
+ traceback.print_exc()
16
+ return f"Internal Server Error: {str(e)}", 500
17
+
18
  @app.route('/')
19
  def index():
20
  return render_template('builder.html')
templates/builder.html CHANGED
@@ -29,6 +29,19 @@
29
  </div>
30
  </div>
31
  <div class="flex gap-3">
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  <button @click="resetData" class="px-4 py-2 text-gray-600 hover:text-gray-800 transition">
33
  <i class="fas fa-undo mr-2"></i>重置
34
  </button>
 
29
  </div>
30
  </div>
31
  <div class="flex gap-3">
32
+ <div class="relative group">
33
+ <button class="px-4 py-2 text-gray-600 hover:text-gray-800 transition flex items-center">
34
+ <i class="fas fa-folder-open mr-2"></i> 载入模板
35
+ </button>
36
+ <div class="absolute top-full right-0 mt-2 w-56 bg-white rounded-lg shadow-xl border border-gray-100 hidden group-hover:block z-50">
37
+ <a v-for="(tpl, key) in templates" :key="key"
38
+ @click="loadTemplate(key)"
39
+ class="block px-4 py-3 text-sm text-gray-700 hover:bg-indigo-50 hover:text-indigo-600 cursor-pointer border-b border-gray-100 last:border-0">
40
+ <div class="font-bold">{{ tpl.title }}</div>
41
+ <div class="text-xs text-gray-400 mt-1 truncate">{{ tpl.description }}</div>
42
+ </a>
43
+ </div>
44
+ </div>
45
  <button @click="resetData" class="px-4 py-2 text-gray-600 hover:text-gray-800 transition">
46
  <i class="fas fa-undo mr-2"></i>重置
47
  </button>
templates/export_template.html CHANGED
@@ -14,6 +14,7 @@
14
  </style>
15
  </head>
16
  <body class="min-h-screen py-8 px-4 sm:px-6 lg:px-8">
 
17
  <div id="app" v-cloak class="max-w-3xl mx-auto">
18
 
19
  <!-- Main Card -->
@@ -94,7 +95,9 @@
94
  const { createApp, ref, computed, onMounted, watch } = Vue;
95
 
96
  // Data injected from Flask
 
97
  const initialData = {{ initial_data|safe }};
 
98
 
99
  createApp({
100
  setup() {
@@ -173,6 +176,7 @@
173
  resetProgress
174
  };
175
  }
 
176
  }).mount('#app');
177
  </script>
178
  </body>
 
14
  </style>
15
  </head>
16
  <body class="min-h-screen py-8 px-4 sm:px-6 lg:px-8">
17
+ {% raw %}
18
  <div id="app" v-cloak class="max-w-3xl mx-auto">
19
 
20
  <!-- Main Card -->
 
95
  const { createApp, ref, computed, onMounted, watch } = Vue;
96
 
97
  // Data injected from Flask
98
+ {% endraw %}
99
  const initialData = {{ initial_data|safe }};
100
+ {% raw %}
101
 
102
  createApp({
103
  setup() {
 
176
  resetProgress
177
  };
178
  }
179
+ {% endraw %}
180
  }).mount('#app');
181
  </script>
182
  </body>