commit f9892636aade5ed0969966d2fbbd50d858a2a372 Author: jc <419690370@qq.com> Date: Tue Mar 11 21:49:38 2025 +0800 first commit diff --git a/app.py b/app.py new file mode 100644 index 0000000..6966c4d --- /dev/null +++ b/app.py @@ -0,0 +1,25 @@ +from flask import Flask, jsonify, send_from_directory + +app = Flask(__name__, static_folder="public", static_url_path="") + +# 根路径返回 index.html +@app.route("/") +def serve_index(): + return send_from_directory(app.static_folder, "index.html") + +# API 子路径,提供每日菜谱数据 +@app.route("/api/menu") +def api_menu(): + # 模拟每日菜谱数据 + menu = { + "message": "Today's Menu", + "data": [ + {"name": "番茄炒蛋", "ingredients": ["番茄", "鸡蛋", "盐", "糖"]}, + {"name": "清炒时蔬", "ingredients": ["西兰花", "胡萝卜", "蒜末"]}, + {"name": "红烧肉", "ingredients": ["五花肉", "酱油", "糖", "料酒"]} + ] + } + return jsonify(menu) + +if __name__ == "__main__": + app.run(debug=True, port=80) \ No newline at end of file diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..f8792f7 --- /dev/null +++ b/public/index.html @@ -0,0 +1,16 @@ + + + + + + Daily Menu + + + +
+

Today's Menu

+ +
+ + + \ No newline at end of file diff --git a/public/script.js b/public/script.js new file mode 100644 index 0000000..c0ba07b --- /dev/null +++ b/public/script.js @@ -0,0 +1,29 @@ +document.addEventListener("DOMContentLoaded", function () { + fetch("/api/menu") + .then(response => response.json()) + .then(data => { + const menuContainer = document.getElementById("menu-container"); + const menuItems = data.data; + + menuItems.forEach(item => { + const menuItem = document.createElement("div"); + menuItem.classList.add("menu-item"); + + const menuName = document.createElement("div"); + menuName.classList.add("menu-name"); + menuName.textContent = item.name; + + const menuIngredients = document.createElement("div"); + menuIngredients.classList.add("menu-ingredients"); + menuIngredients.textContent = `Ingredients: ${item.ingredients.join(", ")}`; + + menuItem.appendChild(menuName); + menuItem.appendChild(menuIngredients); + + menuContainer.appendChild(menuItem); + }); + }) + .catch(error => { + console.error("Error fetching menu data:", error); + }); +}); \ No newline at end of file diff --git a/public/styles.css b/public/styles.css new file mode 100644 index 0000000..e775f3c --- /dev/null +++ b/public/styles.css @@ -0,0 +1,41 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f9; + margin: 0; + padding: 0; +} + +.container { + max-width: 800px; + margin: 20px auto; + padding: 20px; + background: #fff; + border-radius: 8px; + box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); +} + +h1 { + text-align: center; + color: #333; +} + +.menu-item { + margin-bottom: 20px; + padding: 10px; + border-bottom: 1px solid #ddd; +} + +.menu-item:last-child { + border-bottom: none; +} + +.menu-name { + font-size: 1.2em; + font-weight: bold; + color: #444; +} + +.menu-ingredients { + font-size: 0.9em; + color: #666; +} \ No newline at end of file